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-08 17:37:52 +02:00
|
|
|
def test_comment
|
|
|
|
@string_input = '# i am a comment\n' #NEEDS the return, which is what delimits the comment
|
|
|
|
@parse_output = {:comment => ' i am a comment'}
|
|
|
|
@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-04-29 12:50:07 +02:00
|
|
|
@parse_output = {:string=>"hello"}
|
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
|
|
|
|
out = "hello nyou"
|
|
|
|
out[6] = '\\'
|
|
|
|
@string_input = "\"#{out}\""
|
|
|
|
# puts will show that this is a string with a \n in it.
|
|
|
|
# but he who knows the ruby string rules well enough to do this in the input may win a beer at the ...
|
|
|
|
# puts @string_input
|
|
|
|
@parse_output = {:string=>out} #chop quotes off
|
|
|
|
@transform_output = Ast::StringExpression.new(out)
|
|
|
|
@parser = @parser.string
|
|
|
|
end
|
|
|
|
|
2014-04-29 15:49:37 +02:00
|
|
|
def test_assignment
|
|
|
|
@string_input = "a = 5"
|
|
|
|
@parse_output = { :asignee => { :name=>"a" } , :asigned => { :integer => "5" } }
|
2014-05-05 08:51:16 +02:00
|
|
|
@transform_output = Ast::AssignmentExpression.new("a", Ast::IntegerExpression.new(5) )
|
2014-04-29 15:49:37 +02:00
|
|
|
@parser = @parser.assignment
|
|
|
|
end
|
|
|
|
|
2014-04-29 12:50:07 +02:00
|
|
|
end
|