2018-03-19 16:50:11 +01:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class TestIfNoElse < MiniTest::Test
|
|
|
|
include Statements
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
@input = "if(@a) ; arg = 5 ; end"
|
2018-03-24 17:54:36 +01:00
|
|
|
@expect = [SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsNotZero ,
|
|
|
|
LoadConstant, OperatorInstruction, IsNotZero, Label, LoadConstant ,
|
|
|
|
SlotToReg, RegToSlot, Label]
|
2018-03-19 16:50:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_if_instructions
|
|
|
|
assert_nil msg = check_nil , msg
|
|
|
|
end
|
|
|
|
|
2018-03-20 09:00:38 +01:00
|
|
|
def test_false_load
|
2018-03-19 16:50:11 +01:00
|
|
|
produced = produce_body
|
2018-03-31 12:47:02 +02:00
|
|
|
assert_equal Parfait::FalseClass , produced.next(2).constant.class
|
2018-03-19 16:50:11 +01:00
|
|
|
end
|
2018-03-24 17:54:36 +01:00
|
|
|
def test_isnotzero
|
|
|
|
produced = produce_body
|
|
|
|
assert_equal IsNotZero , produced.next(4).class
|
|
|
|
assert produced.next(4).label.name.start_with?("false_label")
|
|
|
|
end
|
|
|
|
def test_false_label
|
|
|
|
produced = produce_body
|
|
|
|
assert_equal Label , produced.next(12).class
|
|
|
|
end
|
2018-03-20 09:00:38 +01:00
|
|
|
def test_false_check
|
|
|
|
produced = produce_body
|
2018-03-24 17:54:36 +01:00
|
|
|
assert_equal produced.next(12) , produced.next(4).label
|
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
|
2018-03-24 17:54:36 +01:00
|
|
|
assert_equal Label , produced.next(4).label.class
|
|
|
|
assert_equal produced.next(12) , produced.next(4).label
|
2018-03-20 09:00:38 +01:00
|
|
|
end
|
|
|
|
def test_true_label
|
|
|
|
produced = produce_body
|
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
|
|
|
|
|
2018-03-19 16:50:11 +01:00
|
|
|
end
|
|
|
|
end
|