rubyx/test/mom/test_while_simple.rb
Torsten Rüger 5a43cbff15 Fixing tests for implicit return
previous commit affected rather many test, as the implicit returns add extra instructions
Also added some explicit returns, so as not to test the return logic too much. return (ie return nl) is a knonwn 3 risc operation.
2019-08-17 23:29:42 +03:00

48 lines
1.3 KiB
Ruby

require_relative "helper"
module Risc
class TestWhileSimple < MiniTest::Test
include Statements
def setup
super
@input = "while(@a) ; arg = 5 end;return"
@expect = [Label, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, #4
IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #9
SlotToReg, RegToSlot, Branch, Label, LoadConstant, #14
RegToSlot, Branch] #19
end
def test_while_instructions
assert_nil msg = check_nil , msg
end
def test_false_load
produced = produce_body
assert_equal Parfait::FalseClass , produced.next(3).constant.class
end
def test_false_check
produced = produce_body
assert_equal produced.next(13) , produced.next(5).label
end
def test_nil_load
produced = produce_body
assert_equal Parfait::NilClass , produced.next(6).constant.class
end
def test_nil_check
produced = produce_body
assert_equal produced.next(13) , produced.next(8).label
end
def test_merge_label
produced = produce_body
assert produced.next(13).name.start_with?("merge_label")
end
def test_back_jump # should jump back to condition label
produced = produce_body
assert_equal produced , produced.next(12).label
end
end
end