rubyx/test/mom/test_while_simple.rb

47 lines
1.3 KiB
Ruby
Raw Normal View History

2018-03-20 12:02:07 +01:00
require_relative "helper"
module Risc
2018-04-20 09:27:06 +02:00
class TestWhileSimple < MiniTest::Test
2018-03-20 12:02:07 +01:00
include Statements
def setup
super
@input = "while(@a) ; arg = 5 end"
@expect = [Label, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction,
IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant,
SlotToReg, RegToSlot, Branch, Label]
2018-03-20 12:02:07 +01:00
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
2018-03-20 12:02:07 +01:00
end
def test_false_check
produced = produce_body
assert_equal produced.next(13) , produced.next(5).label
2018-03-20 12:02:07 +01:00
end
def test_nil_load
produced = produce_body
assert_equal Parfait::NilClass , produced.next(6).constant.class
2018-03-20 12:02:07 +01:00
end
def test_nil_check
produced = produce_body
assert_equal produced.next(13) , produced.next(8).label
2018-03-20 12:02:07 +01:00
end
def test_merge_label
produced = produce_body
assert produced.next(13).name.start_with?("merge_label")
2018-03-20 12:02:07 +01:00
end
def test_back_jump # should jump back to condition label
2018-03-20 12:02:07 +01:00
produced = produce_body
assert_equal produced , produced.next(12).label
2018-03-20 12:02:07 +01:00
end
end
end