rubyx/test/sol/test_assignment.rb

87 lines
2.4 KiB
Ruby
Raw Normal View History

2017-04-13 13:14:43 +02:00
require_relative "helper"
module Sol
class TestAssignSlotMachine < MiniTest::Test
include SolCompile
2017-04-13 13:14:43 +02:00
def setup
@compiler = compile_main( "local = 5;return")
@ins = @compiler.slot_instructions.next
2017-04-13 13:14:43 +02:00
end
def test_class_compiles
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
2017-04-13 13:14:43 +02:00
end
def test_slot_is_set
assert @ins.left
2017-04-13 13:14:43 +02:00
end
def test_slot_starts_at_message
assert_equal :message , @ins.left.known_object
2017-04-13 13:14:43 +02:00
end
2019-08-23 09:21:22 +02:00
def test_slot_gets_local
assert_equal :local1 , @ins.left.slots[0]
2017-04-13 13:14:43 +02:00
end
def test_slot_assigns_something
assert @ins.right
2017-04-13 13:14:43 +02:00
end
def test_slot_assigns_int
assert_equal SlotMachine::IntegerConstant , @ins.right.known_object.class
2017-04-13 13:14:43 +02:00
end
end
#otherwise as above, but assigning instance, so should get a SlotLoad
class TestAssignSlotMachineInstanceToLocal < MiniTest::Test
include SolCompile
2017-09-10 12:04:36 +02:00
def setup
@compiler = compile_main( "@a = 5 ; local = @a;return")
@ins = @compiler.slot_instructions.next
2017-09-10 12:04:36 +02:00
end
def test_class_compiles
assert_equal SlotMachine::SlotLoad , @ins.next.class , @ins
2017-09-10 12:04:36 +02:00
end
end
2017-09-10 12:33:32 +02:00
2017-04-13 13:14:43 +02:00
#compiling to an argument should result in different second parameter in the slot array
2017-09-10 12:33:32 +02:00
class TestAssignToArg < MiniTest::Test
include SolCompile
2017-04-13 13:14:43 +02:00
def setup
@compiler = compile_main( "arg = 5;return")
@ins = @compiler.slot_instructions.next
2017-04-13 13:14:43 +02:00
end
def test_class_compiles
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
2017-04-13 13:14:43 +02:00
end
def test_slot_is_set
assert @ins.left
2017-04-13 13:14:43 +02:00
end
def test_slot_starts_at_message
assert_equal :message , @ins.left.known_object
2017-04-13 13:14:43 +02:00
end
2019-08-22 20:24:02 +02:00
def test_slot_gets_arg
assert_equal :arg1 , @ins.left.slots[0]
2017-04-13 13:14:43 +02:00
end
2017-09-10 12:33:32 +02:00
end
class TestAssignSlotMachineToInstance < MiniTest::Test
include SolCompile
2017-09-10 12:33:32 +02:00
def setup
2019-02-08 22:03:23 +01:00
Parfait.boot!(Parfait.default_test_options)
2017-04-13 13:14:43 +02:00
end
2017-09-10 12:33:32 +02:00
def test_assigns_const
@compiler = compile_main( "@a = 5;return")
@ins = @compiler.slot_instructions.next
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
assert_equal SlotMachine::IntegerConstant , @ins.right.known_object.class , @ins
2017-09-10 12:33:32 +02:00
end
def test_assigns_move
@compiler = compile_main( "@a = arg;return")
@ins = @compiler.slot_instructions.next
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
assert_equal SlotMachine::MessageSlot , @ins.right.class , @ins
2017-04-13 13:14:43 +02:00
end
end
end