rubyx/test/vool/blocks/test_assign.rb

86 lines
2.2 KiB
Ruby
Raw Normal View History

require_relative "../helper"
module VoolBlocks
class TestAssignMom < MiniTest::Test
include VoolCompile
def setup
2019-02-08 22:03:23 +01:00
Parfait.boot!(Parfait.default_test_options)
@ins = compile_first_block( "local = 5")
end
def test_block_compiles
assert_equal Mom::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
2018-07-18 12:57:38 +02:00
def test_slots_left
assert_equal [:frame , :local] , @ins.left.slots
end
def test_slot_assigns_something
assert @ins.right
end
def test_slot_assigns_int
assert_equal Mom::IntegerConstant , @ins.right.known_object.class
end
end
class TestAssignMomInstanceToLocal < MiniTest::Test
include VoolCompile
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
end
def test_class_compiles
assert_equal Mom::SlotLoad , @ins.class , @ins
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
end
class TestAssignToArg < MiniTest::Test
include VoolCompile
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")
end
2018-07-18 12:57:38 +02:00
def test_class_compiles
assert_equal Mom::SlotLoad , @ins.class , @ins
end
2018-07-18 12:57:38 +02:00
def test_slot_is_set
assert @ins.left
end
2018-07-18 12:57:38 +02:00
def test_slots_left
assert_equal [:caller,:caller, :arguments, :arg] , @ins.left.slots
end
end
class TestAssignMomToInstance < MiniTest::Test
include VoolCompile
def setup
2019-02-08 22:03:23 +01:00
Parfait.boot!(Parfait.default_test_options)
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")
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")
assert_equal Mom::SlotLoad , @ins.class , @ins
assert_equal Mom::SlotDefinition , @ins.right.class , @ins
end
end
end