2019-08-17 22:29:42 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Ruby
|
|
|
|
# other Return tests (standalone?) only test the statement
|
|
|
|
# But to get the implicit return, we test the method, as it inserts
|
|
|
|
# the implicit return
|
|
|
|
class TestMethodStatementRet < MiniTest::Test
|
|
|
|
include RubyTests
|
|
|
|
def test_single_const
|
2019-10-03 23:36:49 +02:00
|
|
|
@lst = compile( "def tryout(arg1, arg2) ; true ; end " ).to_sol
|
|
|
|
assert_equal Sol::ReturnStatement , @lst.body.class
|
2019-08-17 22:29:42 +02:00
|
|
|
end
|
|
|
|
def test_single_instance
|
2019-10-03 23:36:49 +02:00
|
|
|
@lst = compile( "def tryout(arg1, arg2) ; @a ; end " ).to_sol
|
|
|
|
assert_equal Sol::ReturnStatement , @lst.body.class
|
2019-08-17 22:29:42 +02:00
|
|
|
end
|
|
|
|
def test_single_call
|
2019-10-03 23:36:49 +02:00
|
|
|
@lst = compile( "def tryout(arg1, arg2) ; is_true() ; end " ).to_sol
|
|
|
|
assert_equal Sol::ReturnStatement , @lst.body.class
|
2019-08-17 22:29:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_multi_const
|
2019-10-03 23:36:49 +02:00
|
|
|
@lst = compile( "def tryout(arg1, arg2) ; @a = some_call(); true ; end " ).to_sol
|
|
|
|
assert_equal Sol::ReturnStatement , @lst.body.last.class
|
2019-08-17 22:29:42 +02:00
|
|
|
end
|
|
|
|
def test_multi_instance
|
2019-10-03 23:36:49 +02:00
|
|
|
@lst = compile( "def tryout(arg1, arg2) ; @a = some_call(); @a ; end " ).to_sol
|
|
|
|
assert_equal Sol::ReturnStatement , @lst.body.last.class
|
2019-08-17 22:29:42 +02:00
|
|
|
end
|
|
|
|
def test_multi_call
|
2019-10-03 23:36:49 +02:00
|
|
|
@lst = compile( "def tryout(arg1, arg2) ; is_true() ; some_call() ; end " ).to_sol
|
|
|
|
assert_equal Sol::ReturnStatement , @lst.body.last.class
|
2019-08-17 22:29:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_return
|
2019-10-03 23:36:49 +02:00
|
|
|
@lst = compile( "def tryout(arg1, arg2) ; return 1 ; end " ).to_sol
|
|
|
|
assert_equal Sol::ReturnStatement , @lst.body.class
|
|
|
|
assert_equal Sol::IntegerConstant , @lst.body.return_value.class
|
2019-08-17 22:29:42 +02:00
|
|
|
end
|
|
|
|
def test_local_assign
|
2019-10-03 23:36:49 +02:00
|
|
|
@lst = compile( "def tryout(arg1, arg2) ; a = 1 ; end " ).to_sol
|
|
|
|
assert_equal Sol::Statements , @lst.body.class
|
|
|
|
assert_equal Sol::ReturnStatement , @lst.body.last.class
|
|
|
|
assert_equal Sol::LocalVariable , @lst.body.last.return_value.class
|
2019-08-17 22:29:42 +02:00
|
|
|
end
|
|
|
|
def test_local_assign
|
2019-10-03 23:36:49 +02:00
|
|
|
@lst = compile( "def tryout(arg1, arg2) ; @a = 1 ; end " ).to_sol
|
|
|
|
assert_equal Sol::Statements , @lst.body.class
|
|
|
|
assert_equal Sol::ReturnStatement , @lst.body.last.class
|
|
|
|
assert_equal Sol::InstanceVariable , @lst.body.last.return_value.class
|
2019-08-17 22:29:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|