2014-06-26 11:55:49 +03:00
|
|
|
require_relative "../parser_helper"
|
2014-06-04 19:56:50 +03:00
|
|
|
|
|
|
|
class TestReturn < MiniTest::Test
|
|
|
|
# include the magic (setup and parse -> test method translation), see there
|
|
|
|
include ParserHelper
|
|
|
|
|
|
|
|
def test_return_int
|
2015-08-28 23:37:25 +03:00
|
|
|
@input = 'return 42'
|
2014-06-04 19:56:50 +03:00
|
|
|
@parse_output = {:return=>"return", :return_expression=>{:integer=>"42"}}
|
2015-08-28 23:37:25 +03:00
|
|
|
@output = Ast::ReturnExpression.new(Ast::IntegerExpression.new(42) )
|
|
|
|
@root = :simple_return
|
2014-06-04 19:56:50 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_return_variable
|
2015-08-28 23:37:25 +03:00
|
|
|
@input = 'return foo'
|
2014-06-04 19:56:50 +03:00
|
|
|
@parse_output = {:return=>"return", :return_expression=>{:name=>"foo"}}
|
2015-08-28 23:37:25 +03:00
|
|
|
@output = Ast::ReturnExpression.new(Ast::NameExpression.new("foo") )
|
|
|
|
@root = :simple_return
|
2014-06-04 19:56:50 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_return_string
|
2015-08-28 23:37:25 +03:00
|
|
|
@input = 'return "hello"'
|
2014-06-04 19:56:50 +03:00
|
|
|
@parse_output = {:return=>"return", :return_expression=>{:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}]}}
|
2015-08-28 23:37:25 +03:00
|
|
|
@output = Ast::ReturnExpression.new(Ast::StringExpression.new("hello") )
|
|
|
|
@root = :simple_return
|
2014-06-04 19:56:50 +03:00
|
|
|
end
|
|
|
|
|
2014-06-30 17:51:07 +03:00
|
|
|
def test_return_true
|
2015-08-28 23:37:25 +03:00
|
|
|
@input = 'return true'
|
2014-06-30 17:51:07 +03:00
|
|
|
@parse_output = {:return=>"return", :return_expression=>{:true=>"true"}}
|
2015-08-28 23:37:25 +03:00
|
|
|
@output = Ast::ReturnExpression.new(Ast::TrueExpression.new() )
|
|
|
|
@root = :simple_return
|
2014-06-30 17:51:07 +03:00
|
|
|
end
|
|
|
|
|
2014-06-04 19:56:50 +03:00
|
|
|
end
|