2014-06-26 12:06:46 +03:00
|
|
|
require_relative "../parser_helper"
|
|
|
|
|
2014-06-26 13:43:50 +03:00
|
|
|
class RootTestBasic < MiniTest::Test
|
2014-06-26 12:06:46 +03:00
|
|
|
# include the magic (setup and parse -> test method translation), see there
|
|
|
|
include ParserHelper
|
2015-09-15 18:57:31 +03:00
|
|
|
|
2014-06-26 12:06:46 +03:00
|
|
|
def test_number
|
|
|
|
@string_input = '42 '
|
|
|
|
@parse_output = {:expression_list=>[{:integer=>"42"}]}
|
2015-09-15 18:57:31 +03:00
|
|
|
@transform_output = s(:list, [s(:int, 42)])
|
2014-06-26 12:06:46 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_name
|
|
|
|
@string_input = 'foo '
|
|
|
|
@parse_output = {:expression_list=>[{:name=>"foo"}]}
|
2015-09-15 18:57:31 +03:00
|
|
|
@transform_output = s(:list, [s(:name, "foo")])
|
2014-06-26 12:06:46 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_name_underscode_start
|
|
|
|
@string_input = '_bar '
|
|
|
|
@parse_output = {:expression_list=>[{:name=>"_bar"}]}
|
2015-09-15 18:57:31 +03:00
|
|
|
@transform_output = s(:list, [s(:name, "_bar")])
|
2014-06-26 12:06:46 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_name_underscode_middle
|
|
|
|
@string_input = 'foo_bar '
|
|
|
|
@parse_output = {:expression_list=>[{:name=>"foo_bar"}]}
|
2015-09-15 18:57:31 +03:00
|
|
|
@transform_output = s(:list, [s(:name, "foo_bar")])
|
2014-06-26 12:06:46 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_module_name
|
|
|
|
@string_input = 'FooBar '
|
|
|
|
@parse_output = {:expression_list=>[{:module_name=>"FooBar"}]}
|
2015-09-15 18:57:31 +03:00
|
|
|
@transform_output = s(:list, [s(:module, "FooBar")])
|
2014-06-26 12:06:46 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def ttest_comment
|
|
|
|
out = "# i am a comment \n"
|
|
|
|
@string_input = out.dup #NEEDS the return, which is what delimits the comment
|
|
|
|
@parse_output = out
|
|
|
|
@transform_output = @parse_output #dont transform
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_string
|
|
|
|
@string_input = "\"hello\""
|
|
|
|
@parse_output = {:expression_list=>[{:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}]}]}
|
2015-09-15 18:57:31 +03:00
|
|
|
@transform_output = s(:list, [s(:string, "hello")])
|
2014-06-26 12:06:46 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_string_escapes
|
|
|
|
out = 'hello \nyou'
|
|
|
|
@string_input = '"' + out + '"'
|
|
|
|
@parse_output = {:expression_list=>[{:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}, {:char=>" "}, {:char=>" "}, {:esc=>"n"}, {:char=>"y"}, {:char=>"o"}, {:char=>"u"}]}]}
|
2015-09-15 18:57:31 +03:00
|
|
|
@transform_output = s(:list, [s(:string, out)])
|
2014-06-26 12:06:46 +03:00
|
|
|
end
|
|
|
|
|
2015-09-15 18:57:31 +03:00
|
|
|
end
|