Get Byte interpreter test

This commit is contained in:
Torsten Ruger 2016-12-15 22:15:58 +02:00
parent 193278c8c2
commit bc22c40101
3 changed files with 68 additions and 1 deletions

View File

@ -170,7 +170,7 @@ module Register
if object.is_a?(Symbol)
raise "Unsupported action, must convert symbol to word:#{object}"
else
value = object.get_internal_byte( index )
value = object.get_char( index )
end
#value = value.object_id unless value.is_a? Fixnum
set_register( @instruction.register , value )

View File

@ -4,3 +4,4 @@ require_relative "test_if"
require_relative "test_puts"
require_relative "test_plus"
require_relative "test_mult"
require_relative "test_word"

View File

@ -0,0 +1,66 @@
require_relative "helper"
class TestWord < MiniTest::Test
include Ticker
def setup
@string_input = <<HERE
class Space
int main()
"Hello".get_internal_byte(1)
end
end
HERE
@input = s(:statements, s(:class, :Space, s(:derives, nil), s(:statements,
s(:function, :Integer, s(:name, :main), s(:parameters),
s(:statements, s(:call,
s(:name, :get_internal_byte),
s(:arguments, s(:int, 1)),
s(:receiver, s(:string, "Hello"))))))))
super
end
def test_chain
#show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
"LoadConstant","SetSlot","FunctionCall","Label","GetSlot",
"LoadConstant","SetSlot","LoadConstant","SetSlot","LoadConstant",
"SetSlot","LoadConstant","SetSlot","LoadConstant","SetSlot",
"RegisterTransfer","FunctionCall","Label","GetSlot","GetSlot",
"GetByte","SetSlot","Label","FunctionReturn","RegisterTransfer",
"GetSlot","GetSlot","Label","FunctionReturn","RegisterTransfer",
"Syscall","NilClass"]
end
def test_branch
was = @interpreter.instruction
assert_equal Register::Branch , ticks(1).class
assert was != @interpreter.instruction
assert @interpreter.instruction , "should have gone to next instruction"
end
def test_load
assert_equal Register::LoadConstant , ticks(3).class
assert_equal Parfait::Space , @interpreter.get_register(:r2).class
assert_equal :r2, @interpreter.instruction.array.symbol
end
def test_get
assert_equal Register::GetSlot , ticks(4).class
assert @interpreter.get_register( :r1 )
assert Integer , @interpreter.get_register( :r1 ).class
end
def test_call
assert_equal Register::FunctionCall , ticks(8).class
end
def test_exit
done = ticks(37)
assert_equal NilClass , done.class
end
def test_get_byte
done = ticks(26)
assert_equal Register::GetByte , done.class
assert_equal "H".ord , @interpreter.get_register(done.register)
end
end