soml-parser/test/unit/test_basic.rb

93 lines
2.5 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
2015-09-15 17:57:31 +02:00
@string_input = 'true'
2014-06-30 16:51:07 +02:00
@parse_output = {:true => 'true'}
2015-09-15 17:57:31 +02:00
@transform_output = s(:true)
2014-06-30 16:51:07 +02:00
@parser = @parser.basic_type
end
def test_false
2015-09-15 17:57:31 +02:00
@string_input = 'false'
2014-06-30 16:51:07 +02:00
@parse_output = {:false => 'false'}
2015-09-15 17:57:31 +02:00
@transform_output = s(:false)
2014-06-30 16:51:07 +02:00
@parser = @parser.basic_type
end
def test_nil
2015-09-15 17:57:31 +02:00
@string_input = 'nil'
2014-06-30 16:51:07 +02:00
@parse_output = {:nil => 'nil'}
2015-09-15 17:57:31 +02:00
@transform_output = s(:nil)
2014-06-30 16:51:07 +02:00
@parser = @parser.basic_type
end
2014-06-04 18:56:50 +02:00
def test_number
@string_input = '42 '
@parse_output = {:integer => '42'}
2015-09-15 17:57:31 +02:00
@transform_output = s(:int , 42)
2014-06-04 18:56:50 +02:00
@parser = @parser.integer
end
def test_name
@string_input = 'foo '
@parse_output = {:name => 'foo'}
2015-09-15 17:57:31 +02:00
@transform_output = s(:name, 'foo')
2014-06-04 18:56:50 +02:00
@parser = @parser.name
end
def test_name_underscode_start
@string_input = '_bar '
@parse_output = {:name => '_bar'}
2015-09-15 17:57:31 +02:00
@transform_output = s(:name, '_bar')
2014-06-04 18:56:50 +02:00
@parser = @parser.name
end
def test_name_underscode_middle
@string_input = 'foo_bar '
@parse_output = {:name => 'foo_bar'}
2015-09-15 17:57:31 +02:00
@transform_output = s(:name, 'foo_bar')
2014-06-04 18:56:50 +02:00
@parser = @parser.name
end
2015-09-15 17:57:31 +02:00
def test_field
@string_input = 'int foo_bar '
@parse_output = {:type=>"int", :name=>"foo_bar"}
@transform_output = s(:field , :int , :foo_bar)
@parser = @parser.field
end
2014-06-04 18:56:50 +02:00
def test_module_name
@string_input = 'FooBar '
@parse_output = {:module_name=>"FooBar"}
2015-09-15 17:57:31 +02:00
@transform_output = s(:module , "FooBar")
2014-06-04 18:56:50 +02:00
@parser = @parser.module_name
end
def test_comment
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
def test_string
@string_input = "\"hello\""
@parse_output = {:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}]}
2015-09-15 17:57:31 +02:00
@transform_output = s(:string, "hello")
2014-06-04 18:56:50 +02:00
@parser = @parser.string
end
def test_string_escapes
out = 'hello \nyou'
@string_input = '"' + out + '"'
2015-09-15 17:57:31 +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-09-15 17:57:31 +02:00
@transform_output = s(:string, out)
2014-06-04 18:56:50 +02:00
@parser = @parser.string
end
2015-09-15 17:57:31 +02:00
end