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-06-19 17:55:47 +02:00
|
|
|
check_main_chain [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
2018-05-24 20:20:56 +02:00
|
|
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
2018-05-25 19:40:39 +02:00
|
|
|
RegToSlot, SlotToReg, RegToSlot, Branch, SlotToReg,
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, FunctionCall, SlotToReg,
|
|
|
|
SlotToReg, Transfer, Syscall, Transfer, Transfer,
|
|
|
|
LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot,
|
|
|
|
RegToSlot, SlotToReg, Branch, SlotToReg, RegToSlot,
|
2018-05-30 11:54:40 +02:00
|
|
|
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg,
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
|
2018-06-19 18:52:06 +02:00
|
|
|
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg,
|
|
|
|
Branch, SlotToReg, Syscall, NilClass]
|
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-05-25 19:40:39 +02:00
|
|
|
cal = main_ticks(24)
|
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-05-25 19:40:39 +02:00
|
|
|
done = main_ticks(28)
|
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-05-25 19:40:39 +02:00
|
|
|
sl = main_ticks(29)
|
2018-04-01 17:57:43 +02:00
|
|
|
assert_equal Transfer , sl.class
|
|
|
|
assert_equal :r0 , sl.from.symbol
|
2018-07-15 15:30:50 +02:00
|
|
|
assert_equal :r2 , sl.to.symbol
|
|
|
|
assert_equal 11 , @interpreter.get_register(:r2)
|
2018-04-01 17:57:43 +02:00
|
|
|
end
|
|
|
|
def test_restore_message
|
2018-05-25 19:40:39 +02:00
|
|
|
sl = main_ticks(30)
|
2018-04-01 17:57:43 +02:00
|
|
|
assert_equal Transfer , sl.class
|
|
|
|
assert_equal :r8 , sl.from.symbol
|
|
|
|
assert_equal :r0 , sl.to.symbol
|
|
|
|
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
|
|
|
|
end
|
|
|
|
def test_save_sys_return
|
2018-05-25 19:40:39 +02:00
|
|
|
sl = main_ticks(35)
|
2018-04-01 17:57:43 +02:00
|
|
|
assert_equal RegToSlot , sl.class
|
2018-07-15 15:30:50 +02:00
|
|
|
assert_equal :r2 , sl.register.symbol #return
|
|
|
|
assert_equal :r3 , sl.array.symbol #parfait integer
|
2018-05-28 14:09:59 +02:00
|
|
|
assert_equal 2 , sl.index
|
2018-04-01 17:57:43 +02:00
|
|
|
end
|
|
|
|
def test_return
|
2018-05-30 11:54:40 +02:00
|
|
|
done = main_ticks(44)
|
2018-04-01 17:57:43 +02:00
|
|
|
assert_equal FunctionReturn , done.class
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|