soml-parser/test/unit/test_basic.rb

93 lines
2.7 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 TestBasic < MiniTest::Test
# include the magic (setup and parse -> test method translation), see there
include ParserHelper
2014-06-30 16:51:07 +02:00
def test_true
@string_input = 'true '
@parse_output = {:true => 'true'}
@transform_output = Ast::TrueExpression.new()
2015-08-27 20:01:30 +02:00
@root = :keyword_true
2014-06-30 16:51:07 +02:00
end
2015-08-27 20:01:30 +02:00
def ttest_false
2014-06-30 16:51:07 +02:00
@string_input = 'false '
@parse_output = {:false => 'false'}
@transform_output = Ast::FalseExpression.new()
@parser = @parser.basic_type
end
2015-08-27 20:01:30 +02:00
def ttest_nil
2014-06-30 16:51:07 +02:00
@string_input = 'nil '
@parse_output = {:nil => 'nil'}
@transform_output = Ast::NilExpression.new()
@parser = @parser.basic_type
end
2015-08-27 20:01:30 +02:00
def ttest_number
2014-06-04 18:56:50 +02:00
@string_input = '42 '
@parse_output = {:integer => '42'}
@transform_output = Ast::IntegerExpression.new(42)
@parser = @parser.integer
end
2015-08-27 20:01:30 +02:00
def ttest_name
2014-06-04 18:56:50 +02:00
@string_input = 'foo '
@parse_output = {:name => 'foo'}
@transform_output = Ast::NameExpression.new('foo')
@parser = @parser.name
end
2015-08-27 20:01:30 +02:00
def ttest_name_underscode_start
2014-06-04 18:56:50 +02:00
@string_input = '_bar '
@parse_output = {:name => '_bar'}
@transform_output = Ast::NameExpression.new('_bar')
@parser = @parser.name
end
2015-08-27 20:01:30 +02:00
def ttest_name_underscode_middle
2014-06-04 18:56:50 +02:00
@string_input = 'foo_bar '
@parse_output = {:name => 'foo_bar'}
@transform_output = Ast::NameExpression.new('foo_bar')
@parser = @parser.name
end
2015-08-27 20:01:30 +02:00
def ttest_instance_variable
2014-06-04 18:56:50 +02:00
@string_input = '@foo_bar '
@parse_output = {:instance_variable=>{:name=>"foo_bar"}}
@transform_output = Ast::VariableExpression.new(:foo_bar)
@parser = @parser.instance_variable
end
2015-08-27 20:01:30 +02:00
def ttest_module_name
2014-06-04 18:56:50 +02:00
@string_input = 'FooBar '
@parse_output = {:module_name=>"FooBar"}
@transform_output = Ast::ModuleName.new("FooBar")
@parser = @parser.module_name
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"
@string_input = out.dup #NEEDS the return, which is what delimits the comment
@parse_output = out
@transform_output = @parse_output #dont transform
@parser = @parser.comment
end
2015-08-27 20:01:30 +02:00
def ttest_string
2014-06-04 18:56:50 +02:00
@string_input = "\"hello\""
@parse_output = {:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}]}
@transform_output = Ast::StringExpression.new('hello')
@parser = @parser.string
end
2015-08-27 20:01:30 +02:00
def ttest_string_escapes
2014-06-04 18:56:50 +02:00
out = 'hello \nyou'
@string_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"}]}
@transform_output = Ast::StringExpression.new(out)
@parser = @parser.string
end
2015-08-27 20:01:30 +02:00
end