diff --git a/test/mom/instruction/helper.rb b/test/mom/instruction/helper.rb new file mode 100644 index 00000000..e527e429 --- /dev/null +++ b/test/mom/instruction/helper.rb @@ -0,0 +1,13 @@ +require_relative '../helper' + +module Mom + class CompilerMock + def use_reg( type ) + Risc.tmp_reg(type , nil) + end + def add_constant(c) + end + end + class InstructionMock < Instruction + end +end diff --git a/test/mom/instruction/test_slot_definition.rb b/test/mom/instruction/test_slot_definition.rb new file mode 100644 index 00000000..d822ce87 --- /dev/null +++ b/test/mom/instruction/test_slot_definition.rb @@ -0,0 +1,54 @@ +require_relative "helper" + +module Mom + class TestSlotDefinitionBasics < MiniTest::Test + + def slot(slot = :caller) + SlotDefinition.new(:message , 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 + def test_create_fail_none + assert_raises {slot(nil)} + end + end + class TestSlotDefinitionConstant < MiniTest::Test + def setup + Risc.machine.boot + @compiler = CompilerMock.new + @definition = SlotDefinition.new(StringConstant.new("hi") , []) + @instruction = @definition.to_register(@compiler , InstructionMock.new) + 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 "hi" , @instruction.constant.to_string + end + end + class TestSlotDefinitionKnown1 < MiniTest::Test + def setup + Risc.machine.boot + @compiler = CompilerMock.new + @definition = SlotDefinition.new(:message , :caller) + @instruction = @definition.to_register(@compiler , InstructionMock.new) + end + def test_def_class + assert_equal Risc::SlotToReg , @instruction.class + end + def test_def_array + assert_equal :r0 , @instruction.array.symbol + end + def test_def_register + assert_equal :r1 , @instruction.register.symbol + end + end +end diff --git a/test/mom/instruction/test_slot_load.rb b/test/mom/instruction/test_slot_load.rb new file mode 100644 index 00000000..da034898 --- /dev/null +++ b/test/mom/instruction/test_slot_load.rb @@ -0,0 +1,13 @@ +require_relative "helper" + +module Mom + class TestSlotLoad < MiniTest::Test + + def setup + end + + def test_while_instructions + assert_nil nil + end + end +end