start with some slot definition tests
This commit is contained in:
parent
000bf0a9b3
commit
473866e76b
13
test/mom/instruction/helper.rb
Normal file
13
test/mom/instruction/helper.rb
Normal file
@ -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
|
54
test/mom/instruction/test_slot_definition.rb
Normal file
54
test/mom/instruction/test_slot_definition.rb
Normal file
@ -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
|
13
test/mom/instruction/test_slot_load.rb
Normal file
13
test/mom/instruction/test_slot_load.rb
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user