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
|
|
|
|
@string_input = as_main(" return 'Hello again'.putstring ")
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_chain
|
2018-04-04 19:05:09 +02:00
|
|
|
#show_main_ticks # get output of what is
|
2018-08-12 14:02:23 +02:00
|
|
|
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
|
|
|
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot,
|
2018-11-24 21:40:22 +01:00
|
|
|
SlotToReg, FunctionCall, LoadConstant, SlotToReg, LoadConstant, # 20
|
|
|
|
OperatorInstruction, IsNotZero, SlotToReg, RegToSlot, RegToSlot,
|
|
|
|
Branch, SlotToReg, SlotToReg, Transfer, Syscall, # 30
|
|
|
|
Transfer, Transfer, SlotToReg, RegToSlot, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, Branch, # 40
|
|
|
|
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
|
|
|
|
FunctionReturn, SlotToReg, SlotToReg, RegToSlot, SlotToReg, # 50
|
|
|
|
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg,
|
|
|
|
RegToSlot, Branch, LoadConstant, SlotToReg, RegToSlot, # 60
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
|
|
|
|
Transfer, SlotToReg, SlotToReg, Syscall, NilClass, ] # 70
|
2018-04-01 17:57:43 +02:00
|
|
|
assert_equal "Hello again" , @interpreter.stdout
|
2018-06-19 17:55:47 +02:00
|
|
|
assert_equal 11 , get_return #bytes written
|
2018-04-01 17:57:43 +02:00
|
|
|
end
|
|
|
|
def test_call
|
2018-08-12 14:02:23 +02:00
|
|
|
cal = main_ticks(17)
|
2018-04-01 17:57:43 +02:00
|
|
|
assert_equal FunctionCall , cal.class
|
|
|
|
assert_equal :putstring , cal.method.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_putstring_sys
|
2018-11-24 21:40:22 +01:00
|
|
|
done = main_ticks(30)
|
2018-04-01 17:57:43 +02:00
|
|
|
assert_equal Syscall , done.class
|
|
|
|
assert_equal "Hello again" , @interpreter.stdout
|
|
|
|
assert_equal 11 , @interpreter.get_register(:r0)
|
|
|
|
assert_equal Parfait::Word , @interpreter.get_register(:r1).class
|
|
|
|
assert_equal "Hello again" , @interpreter.get_register(:r1).to_string
|
|
|
|
end
|
|
|
|
def test_move_sys_return
|
2018-11-24 21:40:22 +01:00
|
|
|
sl = main_ticks(31)
|
|
|
|
assert_transfer(sl, :r0 ,:r3)
|
|
|
|
assert_equal 11 , @interpreter.get_register(:r3)
|
2018-04-01 17:57:43 +02:00
|
|
|
end
|
2018-08-17 21:43:17 +02:00
|
|
|
def test_restore_message
|
2018-11-24 21:40:22 +01:00
|
|
|
sl = main_ticks(32)
|
2018-08-15 16:52:21 +02:00
|
|
|
assert_transfer(sl, :r8 ,:r0)
|
2018-04-01 17:57:43 +02:00
|
|
|
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
|
|
|
|
end
|
2018-11-24 21:40:22 +01:00
|
|
|
def test_move_sys_return
|
|
|
|
sl = main_ticks(37)
|
|
|
|
assert_reg_to_slot( sl , :r1 ,:r2 , 5)
|
2018-04-01 17:57:43 +02:00
|
|
|
end
|
2018-08-17 21:43:17 +02:00
|
|
|
def test_return
|
2018-11-24 21:40:22 +01:00
|
|
|
done = main_ticks(65)
|
2018-04-01 17:57:43 +02:00
|
|
|
assert_equal FunctionReturn , done.class
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|