2018-04-23 12:16:46 +02:00
|
|
|
require_relative "../helper"
|
2018-04-01 21:42:27 +02:00
|
|
|
|
|
|
|
module Risc
|
2018-04-24 18:46:22 +02:00
|
|
|
class InterpreterIfConstant < MiniTest::Test
|
2018-04-01 21:42:27 +02:00
|
|
|
include Ticker
|
|
|
|
|
|
|
|
def setup
|
2018-06-19 17:55:47 +02:00
|
|
|
@string_input = as_main 'if( 10 ); return 1;else;return 2;end'
|
2018-04-01 21:42:27 +02:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_if
|
2018-04-04 19:05:09 +02:00
|
|
|
#show_main_ticks # get output of what is in main
|
2018-05-24 18:38:48 +02:00
|
|
|
check_main_chain [LoadConstant, LoadConstant, OperatorInstruction, IsZero, LoadConstant,
|
|
|
|
OperatorInstruction, IsZero, LoadConstant, RegToSlot, SlotToReg,
|
2018-05-25 19:40:39 +02:00
|
|
|
SlotToReg, RegToSlot, SlotToReg, Branch, SlotToReg,
|
2018-07-22 21:29:32 +02:00
|
|
|
SlotToReg, FunctionReturn, Transfer, SlotToReg, SlotToReg,
|
|
|
|
Branch, Syscall, NilClass]
|
2018-06-19 17:55:47 +02:00
|
|
|
assert_equal 1 , get_return
|
2018-04-19 09:34:15 +02:00
|
|
|
end
|
|
|
|
def test_load_10
|
2018-05-24 18:38:48 +02:00
|
|
|
load = main_ticks(1)
|
2018-04-19 09:34:15 +02:00
|
|
|
assert_equal LoadConstant , load.class
|
|
|
|
assert_equal 10 , load.constant.value
|
|
|
|
end
|
|
|
|
def test_load_false
|
2018-05-24 18:38:48 +02:00
|
|
|
load = main_ticks(2)
|
2018-04-19 09:34:15 +02:00
|
|
|
assert_equal LoadConstant , load.class
|
|
|
|
assert_equal Parfait::FalseClass , load.constant.class
|
|
|
|
end
|
|
|
|
def test_compare
|
2018-05-24 18:38:48 +02:00
|
|
|
op = main_ticks(3)
|
2018-04-19 09:34:15 +02:00
|
|
|
assert_equal OperatorInstruction , op.class
|
|
|
|
assert_equal :- , op.operator
|
|
|
|
end
|
|
|
|
def test_not_zero
|
2018-05-24 18:38:48 +02:00
|
|
|
check = main_ticks(4)
|
2018-04-19 09:34:15 +02:00
|
|
|
assert_equal IsZero , check.class
|
|
|
|
assert check.label.name.start_with?("false_label") , check.label.name
|
2018-04-01 21:42:27 +02:00
|
|
|
end
|
|
|
|
def test_exit
|
2018-06-19 17:55:47 +02:00
|
|
|
done = main_ticks(22)
|
2018-04-01 21:42:27 +02:00
|
|
|
assert_equal Syscall , done.class
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|