2018-07-09 15:48:23 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module VoolBlocks
|
|
|
|
class TestAssignMom < MiniTest::Test
|
2019-08-07 14:08:45 +02:00
|
|
|
include VoolCompile
|
2018-07-09 15:48:23 +02:00
|
|
|
|
|
|
|
def setup
|
2019-02-08 22:03:23 +01:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2018-07-09 15:48:23 +02:00
|
|
|
@ins = compile_first_block( "local = 5")
|
|
|
|
end
|
|
|
|
|
2018-07-10 21:03:32 +02:00
|
|
|
def test_block_compiles
|
|
|
|
assert_equal Mom::SlotLoad , @ins.class , @ins
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
2018-07-18 09:13:19 +02:00
|
|
|
def test_slot_is_set
|
2018-07-09 15:48:23 +02:00
|
|
|
assert @ins.left
|
|
|
|
end
|
2018-07-18 09:13:19 +02:00
|
|
|
def test_slot_starts_at_message
|
2018-07-09 15:48:23 +02:00
|
|
|
assert_equal :message , @ins.left.known_object
|
|
|
|
end
|
2018-07-18 12:57:38 +02:00
|
|
|
def test_slots_left
|
|
|
|
assert_equal [:frame , :local] , @ins.left.slots
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
2018-07-18 09:13:19 +02:00
|
|
|
def test_slot_assigns_something
|
2018-07-09 15:48:23 +02:00
|
|
|
assert @ins.right
|
|
|
|
end
|
2018-07-18 09:13:19 +02:00
|
|
|
def test_slot_assigns_int
|
2018-07-09 15:48:23 +02:00
|
|
|
assert_equal Mom::IntegerConstant , @ins.right.known_object.class
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestAssignMomInstanceToLocal < MiniTest::Test
|
2019-08-07 14:08:45 +02:00
|
|
|
include VoolCompile
|
2018-07-09 15:48:23 +02:00
|
|
|
def setup
|
2019-02-08 22:03:23 +01:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2018-07-18 12:57:38 +02:00
|
|
|
@ins = compile_first_block( "local = @a" , "@a = 5") #second arg in method scope
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
2018-07-18 09:13:19 +02:00
|
|
|
def test_class_compiles
|
|
|
|
assert_equal Mom::SlotLoad , @ins.class , @ins
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
2018-07-18 12:57:38 +02:00
|
|
|
def test_slots_left
|
|
|
|
assert_equal [:frame, :local] , @ins.left.slots
|
|
|
|
end
|
|
|
|
def test_slots_right
|
|
|
|
assert_equal [:receiver, :a] , @ins.right.slots
|
|
|
|
end
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
class TestAssignToArg < MiniTest::Test
|
2019-08-07 14:08:45 +02:00
|
|
|
include VoolCompile
|
2018-07-09 15:48:23 +02:00
|
|
|
|
|
|
|
def setup
|
2019-02-08 22:03:23 +01:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2018-07-18 12:57:38 +02:00
|
|
|
@ins = compile_first_block( "arg = 5")
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
|
|
|
|
2018-07-18 12:57:38 +02:00
|
|
|
def test_class_compiles
|
2018-07-09 15:48:23 +02:00
|
|
|
assert_equal Mom::SlotLoad , @ins.class , @ins
|
|
|
|
end
|
2018-07-18 12:57:38 +02:00
|
|
|
def test_slot_is_set
|
2018-07-09 15:48:23 +02:00
|
|
|
assert @ins.left
|
|
|
|
end
|
2018-07-18 12:57:38 +02:00
|
|
|
def test_slots_left
|
2018-07-31 17:00:42 +02:00
|
|
|
assert_equal [:caller,:caller, :arguments, :arg] , @ins.left.slots
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestAssignMomToInstance < MiniTest::Test
|
2019-08-07 14:08:45 +02:00
|
|
|
include VoolCompile
|
2018-07-09 15:48:23 +02:00
|
|
|
def setup
|
2019-02-08 22:03:23 +01:00
|
|
|
Parfait.boot!(Parfait.default_test_options)
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
2018-07-18 12:57:38 +02:00
|
|
|
def test_assigns_const
|
2018-07-21 11:51:20 +02:00
|
|
|
@ins = compile_first_block( "@a = 5")
|
2018-07-09 15:48:23 +02:00
|
|
|
assert_equal Mom::SlotLoad , @ins.class , @ins
|
|
|
|
assert_equal Mom::IntegerConstant , @ins.right.known_object.class , @ins
|
|
|
|
end
|
2018-07-18 12:57:38 +02:00
|
|
|
def test_assigns_move
|
2018-07-21 11:51:20 +02:00
|
|
|
@ins = compile_first_block( "@a = arg")
|
2018-07-09 15:48:23 +02:00
|
|
|
assert_equal Mom::SlotLoad , @ins.class , @ins
|
|
|
|
assert_equal Mom::SlotDefinition , @ins.right.class , @ins
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|