rubyx/test/parser/test_basic.rb

45 lines
1.4 KiB
Ruby
Raw Normal View History

require_relative "helper"
class TestBasic < MiniTest::Test
# include the magic (setup and parse -> test method translation), see there
include ParserHelper
def test_number
@string_input = '42 '
@parse_output = {:integer => '42'}
2014-05-05 08:51:16 +02:00
@transform_output = Ast::IntegerExpression.new(42)
@parser = @parser.integer
end
def test_name
@string_input = 'foo '
@parse_output = {:name => 'foo'}
2014-05-05 08:51:16 +02:00
@transform_output = Ast::NameExpression.new('foo')
@parser = @parser.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
@parse_output = out
2014-05-08 17:37:52 +02:00
@transform_output = @parse_output #dont transform
@parser = @parser.comment
end
def test_string
2014-05-08 17:42:24 +02:00
@string_input = "\"hello\""
@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')
@parser = @parser.string
end
2014-05-08 18:29:35 +02:00
def test_string_escapes
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
end