soml-parser/test/unit/test_compound.rb

51 lines
2.3 KiB
Ruby
Raw Normal View History

2014-06-26 10:55:49 +02:00
require_relative "../parser_helper"
2014-06-04 18:56:50 +02:00
class TestCompound < MiniTest::Test
# include the magic (setup and parse -> test method translation), see there
include ParserHelper
def test_one_array
2015-08-28 22:37:25 +02:00
@input = '[42]'
2014-06-04 18:56:50 +02:00
@parse_output = {:array_constant=>[{:array_element=>{:integer=>"42"}}]}
2015-08-28 22:37:25 +02:00
@output = Ast::ArrayExpression.new([Ast::IntegerExpression.new(42)])
@root = :array_constant
2014-06-04 18:56:50 +02:00
end
def test_array_list
2015-08-28 22:37:25 +02:00
@input = '[42, foo]'
2014-06-04 18:56:50 +02:00
@parse_output = {:array_constant=>[{:array_element=>{:integer=>"42"}}, {:array_element=>{:name=>"foo"}}]}
2015-08-28 22:37:25 +02:00
@output = Ast::ArrayExpression.new([Ast::IntegerExpression.new(42), Ast::NameExpression.new("foo")])
@root = :array_constant
2014-06-04 18:56:50 +02:00
end
2014-06-30 16:51:07 +02:00
def test_array_list2
2015-08-28 22:37:25 +02:00
@input = '[42, nil]'
2014-06-30 16:51:07 +02:00
@parse_output = {:array_constant=>[{:array_element=>{:integer=>"42"}}, {:array_element=>{:nil=>"nil"}}]}
2015-08-28 22:37:25 +02:00
@output = Ast::ArrayExpression.new([Ast::IntegerExpression.new(42), Ast::NilExpression.new()])
@root = :array_constant
2014-06-30 16:51:07 +02:00
end
2014-06-04 18:56:50 +02:00
def test_array_ops
2015-08-28 22:37:25 +02:00
@input = '[ 3 + 4 , foo(22) ]'
2014-06-04 18:56:50 +02:00
@parse_output = {:array_constant=>[{:array_element=>{:l=>{:integer=>"3"}, :o=>"+ ", :r=>{:integer=>"4"}}}, {:array_element=>{:call_site=>{:name=>"foo"}, :argument_list=>[{:argument=>{:integer=>"22"}}]}}]}
2015-08-28 22:37:25 +02:00
@output = Ast::ArrayExpression.new(
2014-06-04 18:56:50 +02:00
[Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(3),Ast::IntegerExpression.new(4)),
Ast::CallSiteExpression.new("foo", [Ast::IntegerExpression.new(22)] )])
2015-08-28 22:37:25 +02:00
@root = :array_constant
2014-06-04 18:56:50 +02:00
end
def test_hash
2015-08-28 22:37:25 +02:00
@input = '{ foo => 33 }'
2014-06-04 18:56:50 +02:00
@parse_output = {:hash_constant=>[{:hash_pair=>{:hash_key=>{:name=>"foo"}, :hash_value=>{:integer=>"33"}}}]}
2015-08-28 22:37:25 +02:00
@output = Ast::HashExpression.new([Ast::AssociationExpression.new(Ast::NameExpression.new("foo") , Ast::IntegerExpression.new(33))])
@root = :hash_constant
2014-06-04 18:56:50 +02:00
end
def test_hash_list
2015-08-28 22:37:25 +02:00
@input = "{foo => 33 , bar => 42}"
2014-06-04 18:56:50 +02:00
@parse_output = {:hash_constant=>[{:hash_pair=>{:hash_key=>{:name=>"foo"}, :hash_value=>{:integer=>"33"}}}, {:hash_pair=>{:hash_key=>{:name=>"bar"}, :hash_value=>{:integer=>"42"}}}]}
2015-08-28 22:37:25 +02:00
@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))])
@root = :hash_constant
2014-06-04 18:56:50 +02:00
end
end