2015-10-15 08:47:11 +02:00
|
|
|
require_relative 'helper'
|
|
|
|
|
2015-10-15 09:24:10 +02:00
|
|
|
module Register
|
2017-01-03 21:37:25 +01:00
|
|
|
class TestIfStatement < MiniTest::Test
|
|
|
|
include Statements
|
2015-10-15 08:47:11 +02:00
|
|
|
|
2017-01-03 21:37:25 +01:00
|
|
|
def test_if_basicr
|
|
|
|
@input = s(:statements, s(:if_statement, :plus, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, s(:return, s(:int, 4)))))
|
2016-12-10 21:49:04 +01:00
|
|
|
|
2017-01-04 20:38:38 +01:00
|
|
|
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsPlus, LoadConstant ,
|
|
|
|
RegToSlot, Branch, Label, LoadConstant, RegToSlot, Label ,
|
|
|
|
LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
|
|
|
assert_nil msg = check_nil , msg
|
2017-01-03 21:37:25 +01:00
|
|
|
end
|
2015-10-15 08:47:11 +02:00
|
|
|
|
|
|
|
|
2017-01-03 21:37:25 +01:00
|
|
|
def test_if_small_minus
|
|
|
|
@input = s(:statements, s(:if_statement, :minus, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, nil)))
|
2016-12-10 21:49:04 +01:00
|
|
|
|
2017-01-04 20:38:38 +01:00
|
|
|
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch ,
|
|
|
|
Label, LoadConstant, RegToSlot, Label, LoadConstant, SlotToReg ,
|
|
|
|
RegToSlot, Label, FunctionReturn]
|
|
|
|
assert_nil msg = check_nil , msg
|
2017-01-03 21:37:25 +01:00
|
|
|
end
|
2015-10-15 08:47:11 +02:00
|
|
|
|
|
|
|
|
2017-01-03 21:37:25 +01:00
|
|
|
def test_if_small_zero
|
|
|
|
@input = s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, nil)))
|
2016-12-10 21:49:04 +01:00
|
|
|
|
2017-01-04 20:38:38 +01:00
|
|
|
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsZero, Branch ,
|
|
|
|
Label, LoadConstant, RegToSlot, Label, LoadConstant, SlotToReg ,
|
|
|
|
RegToSlot, Label, FunctionReturn]
|
|
|
|
assert_nil msg = check_nil , msg
|
2017-01-03 21:37:25 +01:00
|
|
|
end
|
2015-10-15 08:47:11 +02:00
|
|
|
end
|
|
|
|
end
|