2018-04-23 12:16:46 +02:00
|
|
|
require_relative "../helper"
|
2018-04-01 17:57:43 +02:00
|
|
|
|
|
|
|
module Risc
|
|
|
|
class TestPuts < MiniTest::Test
|
|
|
|
include Ticker
|
|
|
|
|
|
|
|
def setup
|
2019-09-13 13:07:12 +02:00
|
|
|
@preload = "Word.put"
|
2018-04-01 17:57:43 +02:00
|
|
|
@string_input = as_main(" return 'Hello again'.putstring ")
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_chain
|
2020-03-22 10:29:56 +01:00
|
|
|
#show_main_ticks # get output of what is
|
2020-03-16 16:51:21 +01:00
|
|
|
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
2019-08-23 18:25:02 +02:00
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
2020-03-16 16:32:24 +01:00
|
|
|
FunctionCall, LoadConstant, LoadConstant, SlotToReg, OperatorInstruction, #15
|
2019-08-23 18:25:02 +02:00
|
|
|
IsNotZero, SlotToReg, RegToSlot, RegToSlot, SlotToReg, #20
|
2020-03-16 16:32:24 +01:00
|
|
|
SlotToReg, Transfer, Transfer, Transfer, Syscall, #25
|
|
|
|
Transfer, Transfer, SlotToReg, Branch, RegToSlot, #30
|
|
|
|
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, #35
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, #40
|
|
|
|
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, #45
|
2019-09-13 13:07:12 +02:00
|
|
|
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, #50
|
2020-03-16 16:51:21 +01:00
|
|
|
SlotToReg, Transfer, Syscall, NilClass,] #55
|
2018-04-01 17:57:43 +02:00
|
|
|
assert_equal "Hello again" , @interpreter.stdout
|
2020-03-16 16:32:24 +01:00
|
|
|
assert_equal Integer , get_return.class
|
2020-03-22 13:30:03 +01:00
|
|
|
assert_equal 11 , get_return #bytes written
|
2018-04-01 17:57:43 +02:00
|
|
|
end
|
|
|
|
def test_call
|
2019-08-23 18:25:02 +02:00
|
|
|
cal = main_ticks(11)
|
2018-04-01 17:57:43 +02:00
|
|
|
assert_equal FunctionCall , cal.class
|
|
|
|
assert_equal :putstring , cal.method.name
|
|
|
|
end
|
|
|
|
|
2020-03-16 16:32:24 +01:00
|
|
|
def test_pre_sys
|
|
|
|
done = main_ticks(24)
|
2020-03-22 10:29:56 +01:00
|
|
|
assert_equal Parfait::Word , @interpreter.get_register(:r0).class
|
|
|
|
assert_equal "Hello again" , @interpreter.get_register(:r0).to_string
|
|
|
|
assert_equal 11 , @interpreter.get_register(:r1)
|
2020-03-16 16:32:24 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_sys
|
|
|
|
done = main_ticks(25)
|
2018-04-01 17:57:43 +02:00
|
|
|
assert_equal Syscall , done.class
|
|
|
|
assert_equal "Hello again" , @interpreter.stdout
|
2020-03-22 13:30:03 +01:00
|
|
|
assert_equal 11 , @interpreter.get_register(@interpreter.std_reg(:syscall_1))
|
2018-04-01 17:57:43 +02:00
|
|
|
end
|
2020-03-16 16:32:24 +01:00
|
|
|
|
2018-04-01 17:57:43 +02:00
|
|
|
def test_move_sys_return
|
2020-03-22 09:42:50 +01:00
|
|
|
assert_transfer(26, :r0 ,:r1)
|
2020-03-22 13:30:03 +01:00
|
|
|
assert_equal 11 , @interpreter.get_register(@interpreter.std_reg(:syscall_1))
|
2018-04-01 17:57:43 +02:00
|
|
|
end
|
2018-08-17 21:43:17 +02:00
|
|
|
def test_restore_message
|
2020-03-22 10:29:56 +01:00
|
|
|
assert_transfer(27, :r14 ,:r13)
|
|
|
|
assert_equal Parfait::Message , @interpreter.get_register(:r13).class
|
2018-04-01 17:57:43 +02:00
|
|
|
end
|
2018-08-17 21:43:17 +02:00
|
|
|
def test_return
|
2019-09-13 13:07:12 +02:00
|
|
|
done = main_ticks(48)
|
2018-04-01 17:57:43 +02:00
|
|
|
assert_equal FunctionReturn , done.class
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|