2015-08-04 22:01:20 +03:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
class AddTest < MiniTest::Test
|
2015-09-27 22:39:10 +03:00
|
|
|
include Ticker
|
2015-10-06 00:27:13 +03:00
|
|
|
|
2015-08-04 22:01:20 +03:00
|
|
|
def setup
|
2015-11-08 14:30:28 +02:00
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
return 5 + 7
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
|
|
|
super
|
|
|
|
end
|
2015-10-16 17:13:08 +03:00
|
|
|
|
2015-11-08 14:30:28 +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 22:01:20 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_get
|
2015-10-23 21:27:36 +03:00
|
|
|
assert_equal Register::GetSlot , ticks(4).class
|
2015-10-18 17:20:19 +03:00
|
|
|
assert @interpreter.get_register( :r2 )
|
2015-11-04 20:27:48 +02:00
|
|
|
assert Integer , @interpreter.get_register( :r2 ).class
|
2015-08-04 22:01:20 +03:00
|
|
|
end
|
|
|
|
def test_transfer
|
2015-11-07 22:20:21 +02:00
|
|
|
transfer = ticks 16
|
2015-08-04 22:01:20 +03:00
|
|
|
assert_equal Register::RegisterTransfer , transfer.class
|
|
|
|
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
|
|
|
|
end
|
|
|
|
def test_call
|
2015-11-07 22:20:21 +02:00
|
|
|
ret = ticks(15)
|
2015-11-03 11:25:02 +02:00
|
|
|
assert_equal Register::FunctionReturn , ret.class
|
|
|
|
|
2015-11-07 20:10:55 +02:00
|
|
|
object = @interpreter.get_register( ret.register )
|
2015-11-07 17:40:59 +02:00
|
|
|
link = object.get_internal( ret.index )
|
2015-11-03 11:25:02 +02:00
|
|
|
|
|
|
|
assert_equal Register::Label , link.class
|
2015-08-04 22:01:20 +03:00
|
|
|
end
|
2015-10-16 21:42:11 +03:00
|
|
|
def test_adding
|
2015-11-07 22:20:21 +02:00
|
|
|
done_op = ticks(12)
|
2015-10-16 21:42:11 +03:00
|
|
|
assert_equal Register::OperatorInstruction , done_op.class
|
|
|
|
left = @interpreter.get_register(done_op.left)
|
|
|
|
rr = done_op.right
|
2015-08-09 00:53:04 +03:00
|
|
|
right = @interpreter.get_register(rr)
|
|
|
|
assert_equal Fixnum , left.class
|
|
|
|
assert_equal Fixnum , right.class
|
2015-10-16 21:42:11 +03:00
|
|
|
assert_equal 7 , right
|
|
|
|
assert_equal 12 , left
|
2015-11-07 22:20:21 +02:00
|
|
|
done_tr = ticks(4)
|
2015-10-16 21:42:11 +03:00
|
|
|
assert_equal Register::RegisterTransfer , done_tr.class
|
|
|
|
result = @interpreter.get_register(done_op.left)
|
|
|
|
assert_equal result , 12
|
2015-08-04 22:01:20 +03:00
|
|
|
end
|
|
|
|
end
|