2015-08-29 10:45:16 +02:00
|
|
|
require_relative "../setup"
|
2014-06-04 18:56:50 +02:00
|
|
|
|
|
|
|
class TestBasic < MiniTest::Test
|
2015-08-29 15:08:28 +02:00
|
|
|
#test basics and keyword expressions. Keywords includes BasicTypes
|
2015-08-29 10:45:16 +02:00
|
|
|
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-29 15:08:28 +02:00
|
|
|
@input = 'true '
|
2015-08-28 22:37:25 +02:00
|
|
|
@output = Ast::TrueExpression.new()
|
2015-08-29 10:45:16 +02:00
|
|
|
check
|
2014-06-30 16:51:07 +02:00
|
|
|
end
|
2015-08-29 10:45:16 +02:00
|
|
|
|
|
|
|
def test_false
|
2015-08-28 22:37:25 +02:00
|
|
|
@input = 'false '
|
|
|
|
@output = Ast::FalseExpression.new()
|
2015-08-29 10:45:16 +02:00
|
|
|
check
|
2014-06-30 16:51:07 +02:00
|
|
|
end
|
2015-08-29 10:45:16 +02:00
|
|
|
|
|
|
|
def test_nil
|
2015-08-28 22:37:25 +02:00
|
|
|
@input = 'nil '
|
|
|
|
@output = Ast::NilExpression.new()
|
2015-08-29 10:45:16 +02:00
|
|
|
check
|
2014-06-30 16:51:07 +02:00
|
|
|
end
|
|
|
|
|
2015-08-29 15:08:28 +02:00
|
|
|
def test_integer
|
2015-08-28 22:37:25 +02:00
|
|
|
@input = '42 '
|
|
|
|
@output = Ast::IntegerExpression.new(42)
|
2015-08-29 15:08:28 +02:00
|
|
|
check
|
2014-06-04 18:56:50 +02:00
|
|
|
end
|
|
|
|
|
2015-08-29 15:08:28 +02:00
|
|
|
def test_name
|
2015-08-28 22:37:25 +02:00
|
|
|
@input = 'foo '
|
|
|
|
@output = Ast::NameExpression.new('foo')
|
2015-08-29 15:08:28 +02:00
|
|
|
check
|
2014-06-04 18:56:50 +02:00
|
|
|
end
|
|
|
|
|
2015-08-29 15:08:28 +02:00
|
|
|
def test_name_underscode_start
|
2015-08-28 22:37:25 +02:00
|
|
|
@input = '_bar '
|
|
|
|
@output = Ast::NameExpression.new('_bar')
|
2015-08-29 15:08:28 +02:00
|
|
|
check
|
2014-06-04 18:56:50 +02:00
|
|
|
end
|
|
|
|
|
2015-08-29 15:08:28 +02:00
|
|
|
def test_name_underscode_middle
|
2015-08-28 22:37:25 +02:00
|
|
|
@input = 'foo_bar '
|
|
|
|
@output = Ast::NameExpression.new('foo_bar')
|
2015-08-29 15:08:28 +02:00
|
|
|
check
|
2014-06-04 18:56:50 +02:00
|
|
|
end
|
|
|
|
|
2015-08-29 15:08:28 +02:00
|
|
|
def test_instance_variable
|
2015-08-28 22:37:25 +02:00
|
|
|
@input = '@foo_bar '
|
|
|
|
@output = Ast::VariableExpression.new(:foo_bar)
|
2015-08-29 15:08:28 +02:00
|
|
|
check
|
2014-06-04 18:56:50 +02:00
|
|
|
end
|
|
|
|
|
2015-08-29 15:30:15 +02:00
|
|
|
def test_module_name
|
2015-08-28 22:37:25 +02:00
|
|
|
@input = 'FooBar '
|
|
|
|
@output = Ast::ModuleName.new("FooBar")
|
2015-08-29 15:08:28 +02:00
|
|
|
check
|
2014-06-04 18:56:50 +02:00
|
|
|
end
|
|
|
|
|
2015-08-29 15:30:15 +02:00
|
|
|
def ttest_comment # maybe a non test at this point (higher up)
|
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
|
2015-08-29 15:30:15 +02:00
|
|
|
@output = @output #dont transform
|
2015-08-29 15:08:28 +02:00
|
|
|
check
|
2014-06-04 18:56:50 +02:00
|
|
|
end
|
|
|
|
|
2015-08-29 15:30:15 +02:00
|
|
|
def test_string
|
|
|
|
@input = '"hello"'
|
2015-08-28 22:37:25 +02:00
|
|
|
@output = Ast::StringExpression.new('hello')
|
2015-08-29 15:08:28 +02:00
|
|
|
check
|
2014-06-04 18:56:50 +02:00
|
|
|
end
|
|
|
|
|
2015-08-29 15:30:15 +02:00
|
|
|
def test_string_escapes
|
2014-06-04 18:56:50 +02:00
|
|
|
out = 'hello \nyou'
|
2015-08-28 22:37:25 +02:00
|
|
|
@input = '"' + out + '"'
|
|
|
|
@output = Ast::StringExpression.new(out)
|
2015-08-29 15:08:28 +02:00
|
|
|
check
|
2014-06-04 18:56:50 +02:00
|
|
|
end
|
|
|
|
|
2015-08-27 20:01:30 +02:00
|
|
|
end
|