2014-06-26 11:26:34 +02:00
|
|
|
require_relative "../parser_helper"
|
|
|
|
|
2014-06-26 12:43:50 +02:00
|
|
|
class RootTestCompound < MiniTest::Test
|
2014-06-26 11:26:34 +02:00
|
|
|
# include the magic (setup and parse -> test method translation), see there
|
|
|
|
include ParserHelper
|
2015-09-15 17:57:31 +02:00
|
|
|
|
2014-06-26 11:26:34 +02:00
|
|
|
def test_one_array
|
|
|
|
@string_input = '[42]'
|
|
|
|
@parse_output = {:expression_list=>[{:array_constant=>[{:array_element=>{:integer=>"42"}}]}]}
|
2015-09-15 17:57:31 +02:00
|
|
|
@transform_output = s(:list, [s(:array, [s(:int, 42)])])
|
2014-06-26 11:26:34 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_array_list
|
|
|
|
@string_input = '[42, foo]'
|
|
|
|
@parse_output = {:expression_list=>[{:array_constant=>[{:array_element=>{:integer=>"42"}}, {:array_element=>{:name=>"foo"}}]}]}
|
2015-09-15 17:57:31 +02:00
|
|
|
@transform_output = s(:list, [s(:array, [s(:int, 42), s(:name, "foo")])])
|
2014-06-26 11:26:34 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_array_ops
|
|
|
|
@string_input = '[ 3 + 4 , foo(22) ]'
|
|
|
|
@parse_output = {:expression_list=>[{:array_constant=>[{:array_element=>{:l=>{:integer=>"3"}, :o=>"+ ", :r=>{:integer=>"4"}}}, {:array_element=>{:call_site=>{:name=>"foo"}, :argument_list=>[{:argument=>{:integer=>"22"}}]}}]}]}
|
2015-09-15 17:57:31 +02:00
|
|
|
@transform_output = s(:list, [s(:array, [s(:operator, "+", s(:int, 3), s(:int, 4)), s(:call, s(:name, "foo"), [s(:int, 22)])])])
|
2014-06-26 11:26:34 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_hash
|
|
|
|
@string_input = '{ foo => 33 }'
|
|
|
|
@parse_output = {:expression_list=>[{:hash_constant=>[{:hash_pair=>{:hash_key=>{:name=>"foo"}, :hash_value=>{:integer=>"33"}}}]}]}
|
2015-09-15 17:57:31 +02:00
|
|
|
@transform_output = s(:list, [s(:hash, [s(:assoc, s(:name, "foo"), s(:int, 33))])])
|
2014-06-26 11:26:34 +02:00
|
|
|
end
|
|
|
|
|
2014-06-30 16:51:07 +02:00
|
|
|
def test_hash2
|
|
|
|
@string_input = '{ foo => true }'
|
|
|
|
@parse_output = {:expression_list=>[{:hash_constant=>[{:hash_pair=>{:hash_key=>{:name=>"foo"}, :hash_value=>{:true=>"true"}}}]}]}
|
2015-09-15 17:57:31 +02:00
|
|
|
@transform_output = s(:list, [s(:hash, [s(:assoc, s(:name, "foo"), s(:true))])])
|
2014-06-30 16:51:07 +02:00
|
|
|
end
|
|
|
|
|
2014-06-26 11:26:34 +02:00
|
|
|
def test_hash_list
|
|
|
|
@string_input = "{foo => 33 , bar => 42}"
|
|
|
|
@parse_output = {:expression_list=>[{:hash_constant=>[{:hash_pair=>{:hash_key=>{:name=>"foo"}, :hash_value=>{:integer=>"33"}}}, {:hash_pair=>{:hash_key=>{:name=>"bar"}, :hash_value=>{:integer=>"42"}}}]}]}
|
2015-09-15 17:57:31 +02:00
|
|
|
@transform_output = s(:list, [s(:hash, [s(:assoc, s(:name, "foo"), s(:int, 33)), s(:assoc, s(:name, "bar"), s(:int, 42))])])
|
2014-06-26 11:26:34 +02:00
|
|
|
end
|
|
|
|
|
2015-09-15 17:57:31 +02:00
|
|
|
end
|