fix the compound type parser tests
This commit is contained in:
parent
0b07e77782
commit
21a53c6a7f
@ -10,9 +10,9 @@ module Parser
|
||||
rule(:integer => simple(:value)) { Ast::IntegerExpression.new(value.to_i) }
|
||||
rule(:name => simple(:name)) { Ast::NameExpression.new(name.to_s) }
|
||||
|
||||
rule(:array => sequence(:array) ) { Ast::ArrayExpression.new(array) }
|
||||
rule(:array_constant => sequence(:array_constant) ) { Ast::ArrayExpression.new(array_constant) }
|
||||
rule(:array_element => simple(:array_element)) { array_element }
|
||||
rule(:hash => sequence(:hash) ) { Ast::HashExpression.new(hash) }
|
||||
rule(:hash_constant => sequence(:hash_constant) ) { Ast::HashExpression.new(hash_constant) }
|
||||
rule(:hash_key => simple(:hash_key) , :hash_value => simple(:hash_value)) { Ast::AssociationExpression.new(hash_key,hash_value) }
|
||||
rule(:hash_pair => simple(:hash_pair) ) { hash_pair }
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
require_relative "test_basic"
|
||||
#require_relative "test_compound"
|
||||
require_relative "test_compound"
|
||||
require_relative "test_arguments"
|
||||
require_relative "test_expressions"
|
||||
require_relative "test_call_site"
|
||||
|
@ -6,39 +6,39 @@ class TestCompound < MiniTest::Test
|
||||
|
||||
def test_one_array
|
||||
@string_input = '[42]'
|
||||
@parse_output = {:array=>[{:array_element=>{:integer=>"42"}}]}
|
||||
@parse_output = {:array_constant=>[{:array_element=>{:integer=>"42"}}]}
|
||||
@transform_output = Ast::ArrayExpression.new([Ast::IntegerExpression.new(42)])
|
||||
@parser = @parser.array
|
||||
@parser = @parser.array_constant
|
||||
end
|
||||
|
||||
def test_array_list
|
||||
@string_input = '[42, foo]'
|
||||
@parse_output = {:array=>[{:array_element=>{:integer=>"42"}}, {:array_element=>{:name=>"foo"}}]}
|
||||
@parse_output = {:array_constant=>[{:array_element=>{:integer=>"42"}}, {:array_element=>{:name=>"foo"}}]}
|
||||
@transform_output = Ast::ArrayExpression.new([Ast::IntegerExpression.new(42), Ast::NameExpression.new("foo")])
|
||||
@parser = @parser.array
|
||||
@parser = @parser.array_constant
|
||||
end
|
||||
|
||||
def test_array_ops
|
||||
@string_input = '[ 3 + 4 , foo(22) ]'
|
||||
@parse_output = {:array=>[{:array_element=>{:l=>{:integer=>"3"}, :o=>"+ ", :r=>{:integer=>"4"}}}, {:array_element=>{:call_site=>{:name=>"foo"}, :argument_list=>[{:argument=>{:integer=>"22"}}]}}]}
|
||||
@parse_output = {:array_constant=>[{:array_element=>{:l=>{:integer=>"3"}, :o=>"+ ", :r=>{:integer=>"4"}}}, {:array_element=>{:call_site=>{:name=>"foo"}, :argument_list=>[{:argument=>{:integer=>"22"}}]}}]}
|
||||
@transform_output = Ast::ArrayExpression.new(
|
||||
[Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(3),Ast::IntegerExpression.new(4)),
|
||||
Ast::CallSiteExpression.new("foo", [Ast::IntegerExpression.new(22)] )])
|
||||
@parser = @parser.array
|
||||
@parser = @parser.array_constant
|
||||
end
|
||||
|
||||
def test_hash
|
||||
@string_input = '{ foo => 33 }'
|
||||
@parse_output = {:hash=>[{:hash_pair=>{:hash_key=>{:name=>"foo"}, :hash_value=>{:integer=>"33"}}}]}
|
||||
@parse_output = {:hash_constant=>[{:hash_pair=>{:hash_key=>{:name=>"foo"}, :hash_value=>{:integer=>"33"}}}]}
|
||||
@transform_output = Ast::HashExpression.new([Ast::AssociationExpression.new(Ast::NameExpression.new("foo") , Ast::IntegerExpression.new(33))])
|
||||
@parser = @parser.hash
|
||||
@parser = @parser.hash_constant
|
||||
end
|
||||
|
||||
def test_hash_list
|
||||
@string_input = "{foo => 33 , bar => 42}"
|
||||
@parse_output = {:hash=>[{:hash_pair=>{:hash_key=>{:name=>"foo"}, :hash_value=>{:integer=>"33"}}}, {:hash_pair=>{:hash_key=>{:name=>"bar"}, :hash_value=>{:integer=>"42"}}}]}
|
||||
@parse_output = {:hash_constant=>[{:hash_pair=>{:hash_key=>{:name=>"foo"}, :hash_value=>{:integer=>"33"}}}, {:hash_pair=>{:hash_key=>{:name=>"bar"}, :hash_value=>{:integer=>"42"}}}]}
|
||||
@transform_output = Ast::HashExpression.new([Ast::AssociationExpression.new(Ast::NameExpression.new("foo") , Ast::IntegerExpression.new(33)),Ast::AssociationExpression.new(Ast::NameExpression.new("bar") , Ast::IntegerExpression.new(42))])
|
||||
@parser = @parser.hash
|
||||
@parser = @parser.hash_constant
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user