2018-03-20 09:00:38 +01:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class TestIfElse < MiniTest::Test
|
|
|
|
include Statements
|
|
|
|
|
|
|
|
def setup
|
2019-09-12 21:27:10 +02:00
|
|
|
@input = "if(@true_object) ; arg = 5 ; else; arg = 6; end;return"
|
2019-08-22 21:56:44 +02:00
|
|
|
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #4
|
|
|
|
LoadConstant, OperatorInstruction, IsZero, Label, LoadConstant, #9
|
|
|
|
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #14
|
|
|
|
Label, LoadConstant, RegToSlot, Branch] #19
|
2018-03-20 09:00:38 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_if_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(2).constant.class
|
2018-03-20 09:00:38 +01:00
|
|
|
end
|
|
|
|
def test_false_check
|
|
|
|
produced = produce_body
|
2019-08-22 21:56:44 +02:00
|
|
|
assert_equal IsZero , produced.next(7).class
|
|
|
|
assert_equal Label , produced.next(12).class
|
|
|
|
assert_equal produced.next(12).name , produced.next(7).label.name
|
2018-03-20 09:00:38 +01:00
|
|
|
end
|
|
|
|
def test_nil_load
|
|
|
|
produced = produce_body
|
2018-03-31 12:47:02 +02:00
|
|
|
assert_equal Parfait::NilClass , produced.next(5).constant.class
|
2018-03-20 09:00:38 +01:00
|
|
|
end
|
|
|
|
def test_nil_check
|
|
|
|
produced = produce_body
|
2019-08-22 21:56:44 +02:00
|
|
|
assert_equal IsZero , produced.next(4).class
|
|
|
|
assert_equal Label , produced.next(12).class
|
|
|
|
assert_equal produced.next(12).name , produced.next(4).label.name
|
2018-03-20 09:00:38 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_true_label
|
|
|
|
produced = produce_body
|
2019-08-22 21:56:44 +02:00
|
|
|
assert_equal Label , produced.next(8).class
|
2018-03-24 17:54:36 +01:00
|
|
|
assert produced.next(8).name.start_with?("true_label")
|
2018-03-20 09:00:38 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_merge_label
|
|
|
|
produced = produce_body
|
2019-08-22 21:56:44 +02:00
|
|
|
assert_equal Label , produced.next(15).class
|
|
|
|
assert produced.next(15).name.start_with?("merge_label")
|
2018-03-20 09:00:38 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_true_jump # should jumpp to merge label
|
|
|
|
produced = produce_body
|
2019-08-22 21:56:44 +02:00
|
|
|
assert_equal Branch , produced.next(11).class
|
|
|
|
assert produced.next(11).label.name.start_with?("merge_label")
|
2018-03-20 09:00:38 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|