Fixes for all test of next commit

This commit is contained in:
Torsten Rüger 2020-02-17 14:27:42 +07:00
parent 21817b182e
commit 93103d551f
16 changed files with 109 additions and 62 deletions

View File

@ -12,10 +12,8 @@ module SlotLanguage
end
def test_assign
assert_equal SlotMachine::SlotLoad , @slot.next.class
assert_equal :message , @slot.next.left.known_object
assert_equal [:a] , @slot.next.left.slots
assert_equal :message , @slot.next.right.known_object
assert_equal [:b] , @slot.next.right.slots
assert_equal "message.a" , @slot.next.left.to_s
assert_equal "message.b" , @slot.next.right.to_s
end
def test_length
assert_equal 2 , @slot.length

View File

@ -0,0 +1,30 @@
require_relative "helper"
module SlotMachine
class TestSlot < MiniTest::Test
def slot(slot = :caller , nekst = nil)
sl = Slot.new(slot)
sl.set_next( Slot.new(nekst)) if nekst
sl
end
def test_name
assert_equal :caller , slot.name
end
def test_length
assert_equal 1 , slot.length
end
def test_length2
assert_equal 2 , slot(:caller , :next).length
end
def test_to_s
assert_equal "caller" , slot.to_s
end
def test_to_s2
assert_equal "caller.next" , slot(:caller , :next).to_s
end
def test_create_fail_none
assert_raises {slot(nil)}
end
end
end

View File

@ -1,23 +1,16 @@
require_relative "helper"
module SlotMachine
class TestSlotBasics < MiniTest::Test
def slot(slot = :caller)
SlottedMessage.new(slot)
end
def test_create_ok1
assert_equal :message , slot.known_object
end
def test_create_ok2
assert_equal Array , slot.slots.class
assert_equal :caller , slot.slots.first
end
class TestSlotted < MiniTest::Test
def test_to_s
assert_equal "[message, caller]" , slot.to_s
assert_equal "message.caller" , SlottedMessage.new(:caller).to_s
end
def test_create_fail_none
assert_raises {slot(nil)}
def test_for_mess
assert_equal 2 , SlottedMessage.new(:caller).slots_length
end
def test_for_const
slotted = Slotted.for(StringConstant.new("hi") , [])
assert_equal "StringConstant" , slotted.to_s
end
end
end

View File

@ -5,10 +5,10 @@ module SlotMachine
class TestSlotConstant < MiniTest::Test
def setup
Parfait.boot!(Parfait.default_test_options)
@compiler = Risc::FakeCompiler.new
@definition = Slotted.for(StringConstant.new("hi") , [])
@register = @definition.to_register(@compiler , InstructionMock.new)
@instruction = @compiler.instructions.first
compiler = Risc::FakeCompiler.new
@slotted = Slotted.for(StringConstant.new("hi") , [])
register = @slotted.to_register(compiler , InstructionMock.new)
@instruction = compiler.instructions.first
end
def test_def_class
assert_equal Risc::LoadConstant , @instruction.class
@ -19,16 +19,13 @@ module SlotMachine
def test_def_const
assert_equal "hi" , @instruction.constant.to_string
end
def test_to_s
assert_equal "[StringConstant]" , @definition.to_s
end
end
class TestSlotConstantType < MiniTest::Test
def setup
Parfait.boot!(Parfait.default_test_options)
@compiler = Risc::FakeCompiler.new
@definition = Slotted.for(StringConstant.new("hi") , [:type])
@register = @definition.to_register(@compiler , InstructionMock.new)
@slotted = Slotted.for(StringConstant.new("hi") , [:type])
register = @slotted.to_register(@compiler , InstructionMock.new)
@instruction = @compiler.instructions.first
end
def test_def_class
@ -41,7 +38,7 @@ module SlotMachine
assert_equal "hi" , @instruction.constant.to_string
end
def test_to_s
assert_equal "[StringConstant, type]" , @definition.to_s
assert_equal "StringConstant.type" , @slotted.to_s
end
def test_def_register2
assert_equal :r1 , @compiler.instructions[1].register.symbol

View File

@ -1,23 +1,20 @@
require_relative "helper"
module SlotMachine
class TestSlotBasics < MiniTest::Test
class TestSlottedMessage < MiniTest::Test
def slot(slot = :caller)
def slotted(slot = :caller)
SlottedMessage.new(slot)
end
def test_create_ok1
assert_equal :message , slot.known_object
assert_equal :message , slotted.known_object
end
def test_create_ok2
assert_equal Array , slot.slots.class
assert_equal :caller , slot.slots.first
end
def test_to_s
assert_equal "[message, caller]" , slot.to_s
assert_equal Slot , slotted.slots.class
assert_equal :caller , slotted.slots.name
end
def test_create_fail_none
assert_raises {slot(nil)}
assert_raises {slotted(nil)}
end
end
end

View File

@ -1,7 +1,7 @@
require_relative "helper"
module SlotMachine
class TestSlotKnown1 < MiniTest::Test
class TestSlottedMessage2 < MiniTest::Test
def setup
Parfait.boot!(Parfait.default_test_options)
compiler = Risc::FakeCompiler.new

View File

@ -0,0 +1,32 @@
require_relative "helper"
module SlotMachine
class TestSlottedObjectType < MiniTest::Test
def setup
Parfait.boot!(Parfait.default_test_options)
@compiler = Risc::FakeCompiler.new
@slotted = Slotted.for(Parfait.object_space , [:type])
register = @slotted.to_register(@compiler , InstructionMock.new)
@instruction = @compiler.instructions.first
end
def test_def_class
assert_equal Risc::LoadConstant , @instruction.class
end
def test_def_register
assert_equal :r1 , @instruction.register.symbol
end
def test_def_const
assert_equal Parfait::Space , @instruction.constant.class
end
def test_to_s
assert_equal "Space.type" , @slotted.to_s
end
def test_def_register2
assert_equal :r1 , @compiler.instructions[1].register.symbol
end
def test_def_next_index
assert_equal 0 , @compiler.instructions[1].index
end
end
end

View File

@ -54,11 +54,11 @@ module Sol
end
def test_left
assert_equal SlottedMessage , @ins.left.class
assert_equal [:return_value] , @ins.left.slots
assert_equal :return_value , @ins.left.slots.name
end
def test_right
assert_equal SlottedMessage , @ins.right.class
assert_equal [:receiver , :inst] , @ins.right.slots
assert_equal "receiver.inst" , @ins.right.slots.to_s
end
end
end

View File

@ -17,7 +17,7 @@ module SolBlocks
assert_equal :message , @ins.left.known_object
end
def test_slots_left
assert_equal [:local1] , @ins.left.slots
assert_equal :local1 , @ins.left.slots.name
end
def test_slot_assigns_something
assert @ins.right
@ -36,10 +36,10 @@ module SolBlocks
assert_equal SlotMachine::SlotLoad , @ins.class , @ins
end
def test_slots_left
assert_equal [:local1] , @ins.left.slots
assert_equal :local1 , @ins.left.slots.name
end
def test_slots_right
assert_equal [:receiver, :a] , @ins.right.slots
assert_equal "receiver.a" , @ins.right.slots.to_s
end
end
@ -57,7 +57,7 @@ module SolBlocks
assert @ins.left
end
def test_slots_left
assert_equal [:caller,:caller, :arg1] , @ins.left.slots
assert_equal "caller.caller.arg1" , @ins.left.slots.to_s
end
end

View File

@ -14,8 +14,8 @@ module Sol
def test_type_update
load = @ins.next(2)
assert_equal :message , load.right.known_object , load
assert_equal :local1 , load.right.slots[0] , load
assert_equal :type , load.right.slots[1] , load
assert_equal :local1 , load.right.slots.name , load
assert_equal :type , load.right.slots.next_slot.name , load
end
def test_check_resolve_call
assert_equal ResolveMethod , @ins.next(3).class , @ins

View File

@ -12,8 +12,8 @@ module Sol
[SlotMachine::IntegerConstant , 5]
end
def test_args_two_move
assert_equal :next_message, @ins.next(1).arguments[1].left.slots[0]
assert_equal :arg2, @ins.next(1).arguments[1].left.slots[1]
assert_equal :next_message, @ins.next(1).arguments[1].left.slots.name
assert_equal :arg2, @ins.next(1).arguments[1].left.slots.next_slot.name
end
def test_args_two_str
assert_equal SlotMachine::IntegerConstant, @ins.next(1).arguments[1].right.known_object.class

View File

@ -19,7 +19,7 @@ module Sol
assert_equal :message , @ins.left.known_object
end
def test_slot_gets_local
assert_equal :local1 , @ins.left.slots[0]
assert_equal :local1 , @ins.left.slots.name
end
def test_slot_assigns_something
assert @ins.right
@ -60,7 +60,7 @@ module Sol
assert_equal :message , @ins.left.known_object
end
def test_slot_gets_arg
assert_equal :arg1 , @ins.left.slots[0]
assert_equal :arg1 , @ins.left.slots.name
end
end

View File

@ -19,10 +19,10 @@ module Sol
assert_equal :message , @ins.left.known_object
end
def test_slot_gets_self
assert_equal :receiver , @ins.left.slots[0]
assert_equal :receiver , @ins.left.slots.name
end
def test_slot_assigns_to_local
assert_equal :a , @ins.left.slots[-1]
assert_equal :a , @ins.left.slots.next_slot.name
end
def test_slot_assigns_something
assert @ins.right

View File

@ -22,7 +22,7 @@ module Sol
assert_equal :message , @ins.left.known_object
end
def test_slot_gets_local
assert_equal :local1 , @ins.left.slots[0]
assert_equal :local1 , @ins.left.slots.name
end
def test_slot_assigns_something
assert @ins.right
@ -51,7 +51,7 @@ module Sol
assert_equal :message , @ins.left.known_object
end
def test_slot_gets_arg
assert_equal :arg1 , @ins.left.slots[0]
assert_equal :arg1 , @ins.left.slots.name
end
def test_slot_assigns_something
assert @ins.right

View File

@ -22,7 +22,7 @@ module Sol
assert_equal :message , @ins.left.known_object
end
def test_slot_gets_return
assert_equal :return_value , @ins.left.slots[0]
assert_equal :return_value , @ins.left.slots.name
end
def test_slot_assigns_something
assert @ins.right

View File

@ -25,18 +25,18 @@ module Sol
left = @ins.next(3).arguments[0].left
assert_equal Symbol, left.known_object.class
assert_equal :message, left.known_object
assert_equal [:next_message, :arg1], left.slots
assert_equal "message.next_message.arg1", left.to_s
end
def test_check_left
assert_equal SlottedObject, @ins.left.class
assert_equal Parfait::CallableMethod, @ins.left.known_object.class
assert_equal :main, @ins.left.known_object.name
assert @ins.left.slots.empty?
assert !@ins.left.slots
end
def test_check_right
assert_equal SlottedMessage, @ins.right.class
assert_equal :message, @ins.right.known_object
assert_equal [:method] , @ins.right.slots
assert_equal "message.method" , @ins.right.to_s
end
def test_label
assert_equal Label, @ins.next(1).class
@ -48,7 +48,7 @@ module Sol
end
def test_receiver
assert_equal :message , @ins.next(3).receiver.known_object
assert_equal [:receiver] , @ins.next(3).receiver.slots
assert_equal :receiver , @ins.next(3).receiver.slots.name
end
def test_yield
assert_equal BlockYield, @ins.next(4).class
@ -58,8 +58,8 @@ module Sol
assert_equal SlotLoad, @ins.next(5).class
assert_equal :message, @ins.next(5).left.known_object
assert_equal :message, @ins.next(5).right.known_object
assert_equal [:return_value], @ins.next(5).left.slots
assert_equal [:return_value], @ins.next(5).right.slots
assert_equal :return_value, @ins.next(5).left.slots.name
assert_equal :return_value, @ins.next(5).right.slots.name
end
def test_return
assert_equal ReturnJump, @ins.next(6).class