2014-04-29 12:50:07 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
class TestBasic < MiniTest::Test
|
2014-04-29 13:09:10 +02:00
|
|
|
# include the magic (setup and parse -> test method translation), see there
|
|
|
|
include ParserHelper
|
|
|
|
|
2014-04-29 15:22:39 +02:00
|
|
|
def test_number
|
2014-04-29 13:09:10 +02:00
|
|
|
@string_input = '42 '
|
2014-04-29 12:50:07 +02:00
|
|
|
@parse_output = {:integer => '42'}
|
2014-05-05 08:51:16 +02:00
|
|
|
@transform_output = Ast::IntegerExpression.new(42)
|
2014-04-29 12:50:07 +02:00
|
|
|
@parser = @parser.integer
|
|
|
|
end
|
|
|
|
|
2014-04-29 15:22:39 +02:00
|
|
|
def test_name
|
2014-04-29 13:09:10 +02:00
|
|
|
@string_input = 'foo '
|
2014-04-29 12:50:07 +02:00
|
|
|
@parse_output = {:name => 'foo'}
|
2014-05-05 08:51:16 +02:00
|
|
|
@transform_output = Ast::NameExpression.new('foo')
|
2014-04-29 12:50:07 +02:00
|
|
|
@parser = @parser.name
|
|
|
|
end
|
|
|
|
|
2014-05-30 11:06:42 +02:00
|
|
|
def test_name_underscode_start
|
|
|
|
@string_input = '_bar '
|
|
|
|
@parse_output = {:name => '_bar'}
|
|
|
|
@transform_output = Ast::NameExpression.new('_bar')
|
|
|
|
@parser = @parser.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_name_underscode_middle
|
|
|
|
@string_input = 'foo_bar '
|
|
|
|
@parse_output = {:name => 'foo_bar'}
|
|
|
|
@transform_output = Ast::NameExpression.new('foo_bar')
|
|
|
|
@parser = @parser.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_instance_variable
|
|
|
|
@string_input = '@foo_bar '
|
|
|
|
@parse_output = {:instance_variable=>{:name=>"foo_bar"}}
|
2014-06-03 19:47:06 +02:00
|
|
|
@transform_output = Ast::VariableExpression.new(:foo_bar)
|
2014-05-30 11:06:42 +02:00
|
|
|
@parser = @parser.instance_variable
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_module_name
|
|
|
|
@string_input = 'FooBar '
|
|
|
|
@parse_output = {:module_name=>"FooBar"}
|
|
|
|
@transform_output = Ast::ModuleName.new("FooBar")
|
|
|
|
@parser = @parser.module_name
|
|
|
|
end
|
|
|
|
|
2014-05-08 17:37:52 +02:00
|
|
|
def test_comment
|
2014-05-08 20:09:07 +02:00
|
|
|
out = "# i am a comment \n"
|
|
|
|
@string_input = out.dup #NEEDS the return, which is what delimits the comment
|
2014-05-14 21:34:53 +02:00
|
|
|
@parse_output = out
|
2014-05-08 17:37:52 +02:00
|
|
|
@transform_output = @parse_output #dont transform
|
|
|
|
@parser = @parser.comment
|
|
|
|
end
|
|
|
|
|
2014-04-29 15:22:39 +02:00
|
|
|
def test_string
|
2014-05-08 17:42:24 +02:00
|
|
|
@string_input = "\"hello\""
|
2014-05-09 12:51:47 +02:00
|
|
|
@parse_output = {:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}]}
|
2014-05-05 08:51:16 +02:00
|
|
|
@transform_output = Ast::StringExpression.new('hello')
|
2014-04-29 12:50:07 +02:00
|
|
|
@parser = @parser.string
|
|
|
|
end
|
|
|
|
|
2014-05-08 18:29:35 +02:00
|
|
|
def test_string_escapes
|
2014-05-09 12:51:47 +02:00
|
|
|
out = 'hello \nyou'
|
|
|
|
@string_input = '"' + out + '"'
|
|
|
|
@parse_output = {:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"},
|
|
|
|
{:char=>" "}, {:char=>" "}, {:esc=>"n"}, {:char=>"y"}, {:char=>"o"}, {:char=>"u"}]}
|
2014-05-08 18:29:35 +02:00
|
|
|
@transform_output = Ast::StringExpression.new(out)
|
|
|
|
@parser = @parser.string
|
|
|
|
end
|
|
|
|
|
2014-04-29 12:50:07 +02:00
|
|
|
end
|