From 93103d551fcee74bcb3edacc7044c1ca42dbd27a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20R=C3=BCger?= Date: Mon, 17 Feb 2020 14:27:42 +0700 Subject: [PATCH] Fixes for all test of next commit --- test/slot_language/test_macro_maker.rb | 6 ++-- test/slot_machine/test_slot.rb | 30 +++++++++++++++++ test/slot_machine/test_slotted.rb | 23 +++++-------- test/slot_machine/test_slotted_constant.rb | 17 ++++------ test/slot_machine/test_slotted_message.rb | 15 ++++----- ...t_slotted2.rb => test_slotted_message2.rb} | 2 +- test/slot_machine/test_slotted_object.rb | 32 +++++++++++++++++++ test/sol/class_send/test_class_instance.rb | 4 +-- test/sol/lambdas/test_assign.rb | 8 ++--- test/sol/send/test_send_cached_simple.rb | 4 +-- test/sol/send/test_send_simple_args.rb | 4 +-- test/sol/test_assignment.rb | 4 +-- test/sol/test_ivar.rb | 4 +-- test/sol/test_local_assignment.rb | 4 +-- test/sol/test_return.rb | 2 +- test/sol/test_yield_statement.rb | 12 +++---- 16 files changed, 109 insertions(+), 62 deletions(-) create mode 100644 test/slot_machine/test_slot.rb rename test/slot_machine/{test_slotted2.rb => test_slotted_message2.rb} (94%) create mode 100644 test/slot_machine/test_slotted_object.rb diff --git a/test/slot_language/test_macro_maker.rb b/test/slot_language/test_macro_maker.rb index bf43fbb8..79f5ca6e 100644 --- a/test/slot_language/test_macro_maker.rb +++ b/test/slot_language/test_macro_maker.rb @@ -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 diff --git a/test/slot_machine/test_slot.rb b/test/slot_machine/test_slot.rb new file mode 100644 index 00000000..036e8cce --- /dev/null +++ b/test/slot_machine/test_slot.rb @@ -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 diff --git a/test/slot_machine/test_slotted.rb b/test/slot_machine/test_slotted.rb index a818b46c..c7d83f97 100644 --- a/test/slot_machine/test_slotted.rb +++ b/test/slot_machine/test_slotted.rb @@ -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 diff --git a/test/slot_machine/test_slotted_constant.rb b/test/slot_machine/test_slotted_constant.rb index 8a8de79e..26c9f837 100644 --- a/test/slot_machine/test_slotted_constant.rb +++ b/test/slot_machine/test_slotted_constant.rb @@ -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 diff --git a/test/slot_machine/test_slotted_message.rb b/test/slot_machine/test_slotted_message.rb index a818b46c..124c78c7 100644 --- a/test/slot_machine/test_slotted_message.rb +++ b/test/slot_machine/test_slotted_message.rb @@ -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 diff --git a/test/slot_machine/test_slotted2.rb b/test/slot_machine/test_slotted_message2.rb similarity index 94% rename from test/slot_machine/test_slotted2.rb rename to test/slot_machine/test_slotted_message2.rb index c886622a..6e497c80 100644 --- a/test/slot_machine/test_slotted2.rb +++ b/test/slot_machine/test_slotted_message2.rb @@ -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 diff --git a/test/slot_machine/test_slotted_object.rb b/test/slot_machine/test_slotted_object.rb new file mode 100644 index 00000000..d0c96cd0 --- /dev/null +++ b/test/slot_machine/test_slotted_object.rb @@ -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 diff --git a/test/sol/class_send/test_class_instance.rb b/test/sol/class_send/test_class_instance.rb index dd68c8fd..f3374e62 100644 --- a/test/sol/class_send/test_class_instance.rb +++ b/test/sol/class_send/test_class_instance.rb @@ -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 diff --git a/test/sol/lambdas/test_assign.rb b/test/sol/lambdas/test_assign.rb index 5004ed3a..24cbcf32 100644 --- a/test/sol/lambdas/test_assign.rb +++ b/test/sol/lambdas/test_assign.rb @@ -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 diff --git a/test/sol/send/test_send_cached_simple.rb b/test/sol/send/test_send_cached_simple.rb index d50d4618..44b15155 100644 --- a/test/sol/send/test_send_cached_simple.rb +++ b/test/sol/send/test_send_cached_simple.rb @@ -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 diff --git a/test/sol/send/test_send_simple_args.rb b/test/sol/send/test_send_simple_args.rb index 7af91a92..1fa1a0da 100644 --- a/test/sol/send/test_send_simple_args.rb +++ b/test/sol/send/test_send_simple_args.rb @@ -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 diff --git a/test/sol/test_assignment.rb b/test/sol/test_assignment.rb index cbfd0f25..ba8122f6 100644 --- a/test/sol/test_assignment.rb +++ b/test/sol/test_assignment.rb @@ -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 diff --git a/test/sol/test_ivar.rb b/test/sol/test_ivar.rb index c43d8983..111bdefd 100644 --- a/test/sol/test_ivar.rb +++ b/test/sol/test_ivar.rb @@ -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 diff --git a/test/sol/test_local_assignment.rb b/test/sol/test_local_assignment.rb index 757f6df8..1a4265e7 100644 --- a/test/sol/test_local_assignment.rb +++ b/test/sol/test_local_assignment.rb @@ -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 diff --git a/test/sol/test_return.rb b/test/sol/test_return.rb index e6309be7..531448cb 100644 --- a/test/sol/test_return.rb +++ b/test/sol/test_return.rb @@ -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 diff --git a/test/sol/test_yield_statement.rb b/test/sol/test_yield_statement.rb index b5d42809..78a2bb0f 100644 --- a/test/sol/test_yield_statement.rb +++ b/test/sol/test_yield_statement.rb @@ -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