rubyx/test/register/interpreter/test_add.rb

61 lines
1.9 KiB
Ruby
Raw Normal View History

2015-08-04 21:01:20 +02:00
require_relative "helper"
class AddTest < MiniTest::Test
2015-09-27 21:39:10 +02:00
include Ticker
2015-08-04 21:01:20 +02:00
def setup
@string_input = <<HERE
2015-11-30 15:20:39 +01:00
class Space
int main()
return 5 + 7
end
end
HERE
2016-12-10 22:07:04 +01:00
@input = s(:statements, s(:class, :Space, s(:derives, nil), s(:statements, s(:function, :Integer, s(:name, :main), s(:parameters), s(:statements, s(:return, s(:operator_value, :+, s(:int, 5), s(:int, 7))))))))
super
end
2015-10-16 16:13:08 +02:00
def test_chain
#show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
"LoadConstant","SetSlot","FunctionCall","Label","LoadConstant",
"LoadConstant","OperatorInstruction","SetSlot","Label","FunctionReturn",
"RegisterTransfer","Syscall","NilClass"]
2015-08-04 21:01:20 +02:00
end
def test_get
assert_equal Register::GetSlot , ticks(4).class
assert @interpreter.get_register( :r2 )
2015-11-04 19:27:48 +01:00
assert Integer , @interpreter.get_register( :r2 ).class
2015-08-04 21:01:20 +02:00
end
def test_transfer
transfer = ticks 16
2015-08-04 21:01:20 +02:00
assert_equal Register::RegisterTransfer , transfer.class
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
end
def test_call
ret = ticks(15)
assert_equal Register::FunctionReturn , ret.class
object = @interpreter.get_register( ret.register )
link = object.get_internal_word( ret.index )
assert_equal Register::Label , link.class
2015-08-04 21:01:20 +02:00
end
2015-10-16 20:42:11 +02:00
def test_adding
done_op = ticks(12)
2015-10-16 20:42:11 +02:00
assert_equal Register::OperatorInstruction , done_op.class
left = @interpreter.get_register(done_op.left)
rr = done_op.right
2015-08-08 23:53:04 +02:00
right = @interpreter.get_register(rr)
assert_equal Fixnum , left.class
assert_equal Fixnum , right.class
2015-10-16 20:42:11 +02:00
assert_equal 7 , right
assert_equal 12 , left
done_tr = ticks(4)
2015-10-16 20:42:11 +02:00
assert_equal Register::RegisterTransfer , done_tr.class
result = @interpreter.get_register(done_op.left)
assert_equal result , 12
2015-08-04 21:01:20 +02:00
end
end