rubyx/test/vool/test_return.rb

57 lines
1.4 KiB
Ruby
Raw Normal View History

2017-04-14 09:52:23 +02:00
require_relative "helper"
module Vool
class TestReturnMom < MiniTest::Test
include VoolCompile
2017-04-14 09:52:23 +02:00
def setup
@compiler = compile_main( "return 5")
@ins = @compiler.mom_instructions.next
2017-04-14 09:52:23 +02:00
end
def test_class_compiles
assert_equal SlotLoad , @ins.class , @ins
2017-04-14 09:52:23 +02:00
end
def test_slot_is_set
assert @ins.left
2017-04-14 09:52:23 +02:00
end
def test_two_instructions_are_returned
assert_equal 5 , @ins.length
end
2017-04-14 09:52:23 +02:00
def test_slot_starts_at_message
assert_equal :message , @ins.left.known_object
2017-04-14 09:52:23 +02:00
end
def test_slot_gets_return
assert_equal :return_value , @ins.left.slots[0]
2017-04-14 09:52:23 +02:00
end
def test_slot_assigns_something
assert @ins.right
2017-04-14 09:52:23 +02:00
end
def test_slot_assigns_int
assert_equal Mom::IntegerConstant , @ins.right.known_object.class
end
def test_second_is_return
assert_equal ReturnJump, @ins.next(1).class
2018-03-16 14:56:27 +01:00
end
def test_array
check_array [SlotLoad, ReturnJump, Label, ReturnSequence, Label], @ins
2017-04-14 09:52:23 +02:00
end
end
class TestReturnSendMom < MiniTest::Test
include VoolCompile
def setup
@compiler = compile_main( "return 5.div4" , "Integer.div4" )
@ins = @compiler.mom_instructions.next
end
2019-08-13 10:14:36 +02:00
def test_return_is_last
assert_equal ReturnJump , @ins.next(4).class
2018-03-16 15:09:35 +01:00
end
2019-08-13 10:14:36 +02:00
def test_array
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, ReturnJump ,
Label, ReturnSequence, Label] , @ins
end
end
2017-04-14 09:52:23 +02:00
end