rubyx/test/vm/method_compiler/test_if_statement.rb
2017-01-14 19:28:44 +02:00

37 lines
1.6 KiB
Ruby

require_relative 'helper'
module Register
class TestIfStatement < MiniTest::Test
include Statements
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)))))
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsPlus, LoadConstant ,
RegToSlot, Branch, Label, LoadConstant, RegToSlot, Label ,
LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_nil msg = check_nil , msg
end
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)))
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch ,
Label, LoadConstant, RegToSlot, Label, LoadConstant, SlotToReg ,
RegToSlot, Label, FunctionReturn]
assert_nil msg = check_nil , msg
end
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)))
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsZero, Branch ,
Label, LoadConstant, RegToSlot, Label, LoadConstant, SlotToReg ,
RegToSlot, Label, FunctionReturn]
assert_nil msg = check_nil , msg
end
end
end