soml-parser/test/unit/test_basic.rb

99 lines
2.3 KiB
Ruby
Raw Normal View History

require_relative "../setup"
2014-06-04 18:56:50 +02:00
class TestBasic < MiniTest::Test
# include the magic (setup and parse -> test method translation), see there
#include ParserHelper
def setup
@parser = Keywords
end
def check
parse = @parser.parse(@input)
assert_equal @input , parse
assert_equal @output , parse.value
end
2014-06-30 16:51:07 +02:00
def test_true
2015-08-28 22:37:25 +02:00
@input = 'true '
@output = Ast::TrueExpression.new()
check
2014-06-30 16:51:07 +02:00
end
def test_false
2015-08-28 22:37:25 +02:00
@input = 'false '
@output = Ast::FalseExpression.new()
check
2014-06-30 16:51:07 +02:00
end
def test_nil
2015-08-28 22:37:25 +02:00
@input = 'nil '
@output = Ast::NilExpression.new()
check
2014-06-30 16:51:07 +02:00
end
2015-08-27 20:01:30 +02:00
def ttest_number
2015-08-28 22:37:25 +02:00
@input = '42 '
@output = Ast::IntegerExpression.new(42)
@root = :integer
2014-06-04 18:56:50 +02:00
end
2015-08-27 20:01:30 +02:00
def ttest_name
2015-08-28 22:37:25 +02:00
@input = 'foo '
@output = Ast::NameExpression.new('foo')
@root = :name
2014-06-04 18:56:50 +02:00
end
2015-08-27 20:01:30 +02:00
def ttest_name_underscode_start
2015-08-28 22:37:25 +02:00
@input = '_bar '
@output = Ast::NameExpression.new('_bar')
@root = :name
2014-06-04 18:56:50 +02:00
end
2015-08-27 20:01:30 +02:00
def ttest_name_underscode_middle
2015-08-28 22:37:25 +02:00
@input = 'foo_bar '
2014-06-04 18:56:50 +02:00
@parse_output = {:name => 'foo_bar'}
2015-08-28 22:37:25 +02:00
@output = Ast::NameExpression.new('foo_bar')
@root = :name
2014-06-04 18:56:50 +02:00
end
2015-08-27 20:01:30 +02:00
def ttest_instance_variable
2015-08-28 22:37:25 +02:00
@input = '@foo_bar '
2014-06-04 18:56:50 +02:00
@parse_output = {:instance_variable=>{:name=>"foo_bar"}}
2015-08-28 22:37:25 +02:00
@output = Ast::VariableExpression.new(:foo_bar)
@root = :instance_variable
2014-06-04 18:56:50 +02:00
end
2015-08-27 20:01:30 +02:00
def ttest_module_name
2015-08-28 22:37:25 +02:00
@input = 'FooBar '
2014-06-04 18:56:50 +02:00
@parse_output = {:module_name=>"FooBar"}
2015-08-28 22:37:25 +02:00
@output = Ast::ModuleName.new("FooBar")
@root = :module_name
2014-06-04 18:56:50 +02:00
end
2015-08-27 20:01:30 +02:00
def ttest_comment
2014-06-04 18:56:50 +02:00
out = "# i am a comment \n"
2015-08-28 22:37:25 +02:00
@input = out.dup #NEEDS the return, which is what delimits the comment
2014-06-04 18:56:50 +02:00
@parse_output = out
2015-08-28 22:37:25 +02:00
@output = @parse_output #dont transform
@root = :comment
2014-06-04 18:56:50 +02:00
end
2015-08-27 20:01:30 +02:00
def ttest_string
2015-08-28 22:37:25 +02:00
@input = "\"hello\""
2014-06-04 18:56:50 +02:00
@parse_output = {:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}]}
2015-08-28 22:37:25 +02:00
@output = Ast::StringExpression.new('hello')
@root = :string
2014-06-04 18:56:50 +02:00
end
2015-08-27 20:01:30 +02:00
def ttest_string_escapes
2014-06-04 18:56:50 +02:00
out = 'hello \nyou'
2015-08-28 22:37:25 +02:00
@input = '"' + out + '"'
2015-08-27 20:01:30 +02:00
@parse_output = {:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"},
2014-06-04 18:56:50 +02:00
{:char=>" "}, {:char=>" "}, {:esc=>"n"}, {:char=>"y"}, {:char=>"o"}, {:char=>"u"}]}
2015-08-28 22:37:25 +02:00
@output = Ast::StringExpression.new(out)
@root = :string
2014-06-04 18:56:50 +02:00
end
2015-08-27 20:01:30 +02:00
end