rubyx/test/risc/interpreter/conditional/test_if_constant.rb

47 lines
1.4 KiB
Ruby
Raw Normal View History

2018-04-23 12:16:46 +02:00
require_relative "../helper"
module Risc
2018-04-24 18:46:22 +02:00
class InterpreterIfConstant < MiniTest::Test
include Ticker
def setup
@string_input = as_main 'if( 10 ); return "then";else;return "else";end'
super
end
def test_if
#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,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn,
Transfer, Syscall, NilClass]
assert_equal Parfait::Word , get_return.class
assert_equal "then" , get_return.to_string
end
def test_load_10
2018-05-24 18:38:48 +02:00
load = main_ticks(1)
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)
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)
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)
assert_equal IsZero , check.class
assert check.label.name.start_with?("false_label") , check.label.name
end
def test_exit
2018-05-24 18:38:48 +02:00
done = main_ticks(17)
assert_equal Syscall , done.class
end
end
end