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
|
2019-09-12 21:27:10 +02:00
|
|
|
@input = "while(@true_object) ; arg = 5 end;return"
|
2019-08-17 22:29:42 +02:00
|
|
|
@expect = [Label, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, #4
|
|
|
|
IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #9
|
2019-08-22 22:10:29 +02:00
|
|
|
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #14
|
|
|
|
Branch] #19
|
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
|
2018-03-31 12:47:02 +02:00
|
|
|
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
|
2019-08-22 22:10:29 +02:00
|
|
|
assert_equal IsZero , produced.next(5).class
|
|
|
|
assert_equal Label , produced.next(12).class
|
|
|
|
assert_equal produced.next(12).name , produced.next(5).label.name
|
2018-03-20 12:02:07 +01:00
|
|
|
end
|
|
|
|
def test_nil_load
|
|
|
|
produced = produce_body
|
2018-03-31 12:47:02 +02:00
|
|
|
assert_equal Parfait::NilClass , produced.next(6).constant.class
|
2018-03-20 12:02:07 +01:00
|
|
|
end
|
|
|
|
def test_merge_label
|
|
|
|
produced = produce_body
|
2019-08-22 22:10:29 +02:00
|
|
|
assert produced.next(12).name.start_with?("merge_label")
|
2018-03-20 12:02:07 +01:00
|
|
|
end
|
2018-03-20 17:35:09 +01:00
|
|
|
def test_back_jump # should jump back to condition label
|
2018-03-20 12:02:07 +01:00
|
|
|
produced = produce_body
|
2019-08-22 22:10:29 +02:00
|
|
|
assert_equal Branch , produced.next(11).class
|
|
|
|
assert_equal produced.name , produced.next(11).label.name
|
2018-03-20 12:02:07 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|