Fixing tests for implicit return

previous commit affected rather many test, as the implicit returns add extra instructions
Also added some explicit returns, so as not to test the return logic too much. return (ie return nl) is a knonwn 3 risc operation.
This commit is contained in:
2019-08-17 23:29:42 +03:00
parent 32f908c127
commit 5a43cbff15
43 changed files with 152 additions and 107 deletions

View File

@ -36,21 +36,4 @@ module Ruby
assert_equal LocalAssignment , lst.body.class
end
end
class TestMethodStatementTrans < MiniTest::Test
include RubyTests
def setup()
input = "def tryout(arg1, arg2) ; a = arg1 ; end "
@lst = compile( input ).to_vool
end
def test_method
assert_equal Vool::MethodStatement , @lst.class
end
def test_method_args
assert_equal [:arg1, :arg2] , @lst.args
end
def test_body_is_scope_zero_statement
assert_equal Vool::LocalAssignment , @lst.body.class
end
end
end

View File

@ -0,0 +1,53 @@
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
@lst = compile( "def tryout(arg1, arg2) ; true ; end " ).to_vool
assert_equal Vool::ReturnStatement , @lst.body.class
end
def test_single_instance
@lst = compile( "def tryout(arg1, arg2) ; @a ; end " ).to_vool
assert_equal Vool::ReturnStatement , @lst.body.class
end
def test_single_call
@lst = compile( "def tryout(arg1, arg2) ; is_true() ; end " ).to_vool
assert_equal Vool::ReturnStatement , @lst.body.class
end
def test_multi_const
@lst = compile( "def tryout(arg1, arg2) ; @a = some_call(); true ; end " ).to_vool
assert_equal Vool::ReturnStatement , @lst.body.last.class
end
def test_multi_instance
@lst = compile( "def tryout(arg1, arg2) ; @a = some_call(); @a ; end " ).to_vool
assert_equal Vool::ReturnStatement , @lst.body.last.class
end
def test_multi_call
@lst = compile( "def tryout(arg1, arg2) ; is_true() ; some_call() ; end " ).to_vool
assert_equal Vool::ReturnStatement , @lst.body.last.class
end
def test_return
@lst = compile( "def tryout(arg1, arg2) ; return 1 ; end " ).to_vool
assert_equal Vool::ReturnStatement , @lst.body.class
assert_equal Vool::IntegerConstant , @lst.body.return_value.class
end
def test_local_assign
@lst = compile( "def tryout(arg1, arg2) ; a = 1 ; end " ).to_vool
assert_equal Vool::Statements , @lst.body.class
assert_equal Vool::ReturnStatement , @lst.body.last.class
assert_equal Vool::LocalVariable , @lst.body.last.return_value.class
end
def test_local_assign
@lst = compile( "def tryout(arg1, arg2) ; @a = 1 ; end " ).to_vool
assert_equal Vool::Statements , @lst.body.class
assert_equal Vool::ReturnStatement , @lst.body.last.class
assert_equal Vool::InstanceVariable , @lst.body.last.return_value.class
end
end
end