Skip to content

Commit

Permalink
Merge pull request #57 from yui-knk/test_for_named_references
Browse files Browse the repository at this point in the history
Test for named references
  • Loading branch information
yui-knk committed Jul 31, 2023
2 parents 44b8cb4 + 573e42a commit 5ce0e39
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion spec/lrama/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def test_rules(rules, input, expected)
%w['*'],
%w[NUM val 3]
]
expected = "9"

test_rules(<<~Rules, input, "=> 9")
%union {
Expand Down Expand Up @@ -109,4 +108,36 @@ def test_rules(rules, input, expected)
Rules
end
end

describe "named references" do
it "returns 3 for '1 2 +" do
# 1 2 + #=> 3
input = [
%w[NUM val 1],
%w[NUM val 2],
%w['+'],
]

test_rules(<<~Rules, input, "=> 3")
%union {
int val;
}
%token <val> NUM
%type <val> expr
%%
line: expr
{ printf("=> %d", $expr); }
;
expr[result]: NUM
| expr[left] expr[right] '+'
{ $result = $left + $right; }
;
%%
Rules
end
end
end

0 comments on commit 5ce0e39

Please sign in to comment.