soml-parser/test/unit/test_return.rb

36 lines
1.1 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 TestReturn < MiniTest::Test
# include the magic (setup and parse -> test method translation), see there
include ParserHelper
2015-09-15 17:57:31 +02:00
2014-06-04 18:56:50 +02:00
def test_return_int
@string_input = 'return 42'
@parse_output = {:return=>"return", :return_expression=>{:integer=>"42"}}
2015-09-15 17:57:31 +02:00
@transform_output = s(:return, s(:int, 42))
2014-06-04 18:56:50 +02:00
@parser = @parser.simple_return
end
def test_return_variable
@string_input = 'return foo'
@parse_output = {:return=>"return", :return_expression=>{:name=>"foo"}}
2015-09-15 17:57:31 +02:00
@transform_output = s(:return, s(:name, "foo"))
2014-06-04 18:56:50 +02:00
@parser = @parser.simple_return
end
def test_return_string
@string_input = 'return "hello"'
@parse_output = {:return=>"return", :return_expression=>{:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}]}}
2015-09-15 17:57:31 +02:00
@transform_output = s(:return, s(:string, "hello"))
2014-06-04 18:56:50 +02:00
@parser = @parser.simple_return
end
2014-06-30 16:51:07 +02:00
def test_return_true
@string_input = 'return true'
@parse_output = {:return=>"return", :return_expression=>{:true=>"true"}}
2015-09-15 17:57:31 +02:00
@transform_output = s(:return, s(:true))
2014-06-30 16:51:07 +02:00
@parser = @parser.simple_return
end
2015-09-15 17:57:31 +02:00
end