rubyx/test/sol/lambdas/test_assign.rb

81 lines
2.1 KiB
Ruby
Raw Normal View History

require_relative "../helper"
module SolBlocks
class TestAssignSlotMachine < MiniTest::Test
include SolCompile
def setup
@ins = compile_main_block( "local = 5" )
end
def test_block_compiles
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
end
def test_slot_is_set
assert @ins.left
end
def test_slot_starts_at_message
assert_equal :message , @ins.left.known_object
end
def test_slots_left
2019-08-23 09:21:22 +02:00
assert_equal [:local1] , @ins.left.slots
end
def test_slot_assigns_something
assert @ins.right
end
def test_slot_assigns_int
assert_equal SlotMachine::IntegerConstant , @ins.right.known_object.class
end
end
class TestAssignSlotMachineInstanceToLocal < MiniTest::Test
include SolCompile
def setup
@ins = compile_main_block( "local = @a" , "@a = 5") #second arg in method scope
end
def test_class_compiles
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
end
def test_slots_left
2019-08-23 09:21:22 +02:00
assert_equal [:local1] , @ins.left.slots
2018-07-18 12:57:38 +02:00
end
def test_slots_right
2018-07-18 12:57:38 +02:00
assert_equal [:receiver, :a] , @ins.right.slots
end
end
class TestAssignToArg < MiniTest::Test
include SolCompile
def setup
@ins = compile_main_block( "arg = 5")
end
def test_class_compiles
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
end
def test_slot_is_set
assert @ins.left
end
def test_slots_left
2019-08-22 20:24:02 +02:00
assert_equal [:caller,:caller, :arg1] , @ins.left.slots
end
end
class TestAssignSlotMachineToInstance < MiniTest::Test
include SolCompile
def setup
end
def test_assigns_const
@ins = compile_main_block( "@a = 5")
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
assert_equal SlotMachine::IntegerConstant , @ins.right.known_object.class , @ins
end
def test_assigns_move
@ins = compile_main_block( "@a = arg")
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
assert_equal SlotMachine::SlotDefinition , @ins.right.class , @ins
end
end
end