better way to test object registers
also some cleaning, by using more helpers
This commit is contained in:
@ -20,32 +20,17 @@ module SlotMachine
|
||||
assert_equal Risc::RegToSlot , @instructions.next(3).class
|
||||
assert_equal NilClass , @instructions.next(4).class
|
||||
end
|
||||
def test_ins_next_reg
|
||||
assert_equal :"message.caller.type" , @instructions.next.register.symbol
|
||||
def test_ins
|
||||
assert_slot_to_reg @instructions ,:message , 6 , "message.caller"
|
||||
end
|
||||
def test_ins_next_arr
|
||||
assert_equal :"message.caller" , @instructions.next.array.symbol
|
||||
def test_ins_next
|
||||
assert_slot_to_reg @instructions.next ,"message.caller" , 0 , "message.caller.type"
|
||||
end
|
||||
def test_ins_next_index
|
||||
assert_equal 0 , @instructions.next.index
|
||||
def test_ins_next_2
|
||||
assert_slot_to_reg @instructions.next(2) , :message , 6 , "message.caller"
|
||||
end
|
||||
def test_ins_next_2_reg
|
||||
assert_equal :"message.caller" , @instructions.next(2).register.symbol
|
||||
end
|
||||
def test_ins_next_2_arr
|
||||
assert_equal :"message" , @instructions.next(2).array.symbol
|
||||
end
|
||||
def test_ins_next_2_index
|
||||
assert_equal 6 , @instructions.next(2).index
|
||||
end
|
||||
def test_ins_next_3_reg
|
||||
assert_equal :"message.caller.type" , @instructions.next(3).register.symbol
|
||||
end
|
||||
def test_ins_next_3_arr
|
||||
assert_equal :"message.caller" , @instructions.next(3).array.symbol
|
||||
end
|
||||
def test_ins_next_3_index
|
||||
assert_equal 0 , @instructions.next(3).index
|
||||
def test_ins_next_3
|
||||
assert_reg_to_slot @instructions.next(3) ,"message.caller.type" , "message.caller" , 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -17,34 +17,18 @@ module SlotMachine
|
||||
assert_equal Risc::SlotToReg , @instructions.class
|
||||
assert_equal Risc::LoadConstant, @instructions.next.class
|
||||
end
|
||||
|
||||
def test_ins_next_class
|
||||
assert_equal Risc::RegToSlot , @instructions.next(2).class
|
||||
assert_equal NilClass , @instructions.next(3).class
|
||||
end
|
||||
def test_ins_load
|
||||
assert @instructions.next.register.is_object?
|
||||
assert_equal Parfait::CacheEntry , @instructions.next.constant.class
|
||||
def test_ins
|
||||
assert_slot_to_reg @instructions , :message , 0 , "message.type"
|
||||
end
|
||||
|
||||
def test_ins_next_reg
|
||||
assert_equal :"message.type" , @instructions.register.symbol
|
||||
def test_ins_next
|
||||
assert_load @instructions.next , Parfait::CacheEntry , "id_"
|
||||
end
|
||||
def test_ins_next_arr
|
||||
assert_equal :message , @instructions.array.symbol
|
||||
end
|
||||
def test_ins_next_index
|
||||
assert_equal 0 , @instructions.index
|
||||
end
|
||||
|
||||
def test_ins_next_2_reg
|
||||
assert_equal :"message.type" , @instructions.next(2).register.symbol
|
||||
end
|
||||
def test_ins_next_2_arr
|
||||
assert @instructions.next(2).array.is_object?
|
||||
end
|
||||
def test_ins_next_2_index
|
||||
assert_equal 1 , @instructions.next(2).index
|
||||
def test_ins_next_2
|
||||
assert_reg_to_slot @instructions.next(2) , :"message.type" , "id_", 1
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -14,26 +14,20 @@ module SlotMachine
|
||||
assert_slot_to_reg risc(1) ,:message , 6 , :"message.caller"
|
||||
end
|
||||
def test_2_load
|
||||
assert_load risc(2) , Parfait::FalseClass
|
||||
assert_load risc(2) , Parfait::FalseClass, "id_"
|
||||
end
|
||||
def test_3_op
|
||||
assert_equal Risc::OperatorInstruction , risc(3).class
|
||||
assert risc(3).left.is_object?
|
||||
assert_equal :"message.caller" , risc(3).right.symbol
|
||||
assert_equal :- , risc(3).operator
|
||||
assert_operator risc(3) , :- , "id_" , "message.caller"
|
||||
end
|
||||
def test_4_zero
|
||||
assert_equal Risc::IsZero , risc(4).class
|
||||
assert_label risc(4).label , "target"
|
||||
end
|
||||
def test_5_load
|
||||
assert_load risc(5) , Parfait::NilClass
|
||||
assert_load risc(5) , Parfait::NilClass , "id_"
|
||||
end
|
||||
def test_6_op
|
||||
assert_equal Risc::OperatorInstruction , risc(6).class
|
||||
assert risc(6).left.is_object?
|
||||
assert_equal :"message.caller" , risc(6).right.symbol
|
||||
assert_equal :- , risc(6).operator
|
||||
assert_operator risc(6), :- , "id_", "message.caller"
|
||||
end
|
||||
def test_7_zero
|
||||
assert_equal Risc::IsZero , risc(7).class
|
||||
|
@ -10,11 +10,8 @@ module SlotMachine
|
||||
register = @slotted.to_register(compiler , InstructionMock.new)
|
||||
@instruction = compiler.risc_instructions.next
|
||||
end
|
||||
def test_def_class
|
||||
assert_equal Risc::LoadConstant , @instruction.class
|
||||
end
|
||||
def test_def_register
|
||||
assert @instruction.register.is_object?
|
||||
def test_load
|
||||
assert_load @instruction , Parfait::Word , "id_"
|
||||
end
|
||||
def test_def_const
|
||||
assert_equal "hi" , @instruction.constant.to_string
|
||||
@ -28,11 +25,8 @@ module SlotMachine
|
||||
register = @slotted.to_register(compiler , InstructionMock.new)
|
||||
@instruction = compiler.risc_instructions.next
|
||||
end
|
||||
def test_def_class
|
||||
assert_equal Risc::LoadConstant , @instruction.class
|
||||
end
|
||||
def test_def_register
|
||||
assert @instruction.register.is_object?
|
||||
def test_load
|
||||
assert_load @instruction , Parfait::Word , "id_"
|
||||
end
|
||||
def test_def_const
|
||||
assert_equal "hi" , @instruction.constant.to_string
|
||||
@ -41,10 +35,7 @@ module SlotMachine
|
||||
assert_equal "StringConstant.type" , @slotted.to_s
|
||||
end
|
||||
def test_def_register2
|
||||
assert @instruction.next.register.is_object?
|
||||
end
|
||||
def test_def_next_index
|
||||
assert_equal 0 , @instruction.next.index
|
||||
assert_slot_to_reg @instruction.next , "id_" , 0 , "id_.0"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -6,59 +6,37 @@ module SlotMachine
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
compiler = Risc.test_compiler
|
||||
@slotted = Slotted.for(Parfait.object_space , [:type])
|
||||
@slotted = Slotted.for(Parfait.object_space , slot2)
|
||||
register = @slotted.to_register(compiler , InstructionMock.new)
|
||||
@instruction = compiler.risc_instructions.next
|
||||
end
|
||||
def test_def_class
|
||||
assert_equal Risc::LoadConstant , @instruction.class
|
||||
def slot2
|
||||
[:type]
|
||||
end
|
||||
def test_def_register
|
||||
assert @instruction.register.is_object?
|
||||
end
|
||||
def test_def_const
|
||||
assert_equal Parfait::Space , @instruction.constant.class
|
||||
def test_load
|
||||
assert_load @instruction , Parfait::Space , "id_"
|
||||
end
|
||||
def test_to_s
|
||||
assert_equal "Space.type" , @slotted.to_s
|
||||
assert_equal "Space." + slot2.join(".") , @slotted.to_s
|
||||
end
|
||||
def test_def_register2
|
||||
reg = @instruction.next.register
|
||||
assert reg.is_object?
|
||||
assert reg.symbol.to_s.index(".") , reg.symbol.to_s
|
||||
end
|
||||
def test_def_next_index
|
||||
assert_equal 0 , @instruction.next.index
|
||||
assert_slot_to_reg @instruction.next , "id_" , 0 , "id_.type"
|
||||
end
|
||||
end
|
||||
class TestSlottedObjectType2 < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
compiler = Risc.test_compiler
|
||||
@slotted = Slotted.for(Parfait.object_space , [:type , :type])
|
||||
register = @slotted.to_register(compiler , InstructionMock.new)
|
||||
@instruction = compiler.risc_instructions.next
|
||||
end
|
||||
def test_def_register2
|
||||
reg = @instruction.next.register
|
||||
assert reg.is_object?
|
||||
assert_equal "type", reg.symbol.to_s.split(".").last
|
||||
assert_equal 2, reg.symbol.to_s.split(".").length
|
||||
end
|
||||
end
|
||||
class TestSlottedObjectType3 < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
compiler = Risc.test_compiler
|
||||
@slotted = Slotted.for(Parfait.object_space , [:type , :type , :type])
|
||||
register = @slotted.to_register(compiler , InstructionMock.new)
|
||||
@instruction = compiler.risc_instructions.next
|
||||
class TestSlottedObjectType2 < TestSlottedObjectType
|
||||
def slot2
|
||||
[:type , :type]
|
||||
end
|
||||
def test_def_register3
|
||||
reg = @instruction.next.next.register
|
||||
assert reg.is_object?
|
||||
assert_equal "type", reg.symbol.to_s.split(".").last
|
||||
assert_equal 3, reg.symbol.to_s.split(".").length
|
||||
assert_slot_to_reg @instruction.next(2) , "id_.type" , 0 , "id_.type.type"
|
||||
end
|
||||
end
|
||||
class TestSlottedObjectType3 < TestSlottedObjectType
|
||||
def slot2
|
||||
[:type , :type , :type ]
|
||||
end
|
||||
def test_def_register3
|
||||
assert_slot_to_reg @instruction.next(3) , "id_.type.type" , 0 , "id_.type.type.type"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user