2018-03-20 09:00:38 +01:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class TestIfElse < MiniTest::Test
|
|
|
|
include Statements
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
@input = "if(@a) ; arg = 5 ; else; arg = 6; end"
|
|
|
|
@expect = [SlotToReg, SlotToReg, LoadConstant, IsSame, LoadConstant, IsSame ,
|
2018-03-20 17:35:09 +01:00
|
|
|
Label, LoadConstant, SlotToReg, RegToSlot, Unconditional, Label ,
|
2018-03-20 09:00:38 +01:00
|
|
|
LoadConstant, SlotToReg, RegToSlot, Label]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_if_instructions
|
|
|
|
assert_nil msg = check_nil , msg
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_false_load
|
|
|
|
produced = produce_body
|
2018-03-21 22:08:06 +01:00
|
|
|
assert_equal Mom::FalseConstant , produced.next(2).constant.class
|
2018-03-20 09:00:38 +01:00
|
|
|
end
|
|
|
|
def test_false_check
|
|
|
|
produced = produce_body
|
|
|
|
assert_equal produced.next(11) , produced.next(3).label
|
|
|
|
end
|
|
|
|
def test_nil_load
|
|
|
|
produced = produce_body
|
2018-03-21 22:08:06 +01:00
|
|
|
assert_equal Mom::NilConstant , produced.next(4).constant.class
|
2018-03-20 09:00:38 +01:00
|
|
|
end
|
|
|
|
def test_nil_check
|
|
|
|
produced = produce_body
|
|
|
|
assert_equal produced.next(11) , produced.next(5).label
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_true_label
|
|
|
|
produced = produce_body
|
|
|
|
assert produced.next(6).name.start_with?("true_label")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_merge_label
|
|
|
|
produced = produce_body
|
|
|
|
assert produced.next(15).name.start_with?("merge_label")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_true_jump # should jumpp to merge label
|
|
|
|
produced = produce_body
|
2018-03-20 17:35:09 +01:00
|
|
|
assert produced.next(10).label.name.start_with?("merge_label")
|
2018-03-20 09:00:38 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|