Fixes for all test of next commit

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

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