2015-10-15 08:47:11 +02:00
|
|
|
require_relative 'helper'
|
|
|
|
|
2015-10-15 09:24:10 +02:00
|
|
|
module Register
|
2015-10-15 08:47:11 +02:00
|
|
|
class TestIfStatement < MiniTest::Test
|
|
|
|
include Statements
|
|
|
|
|
2015-10-27 20:04:46 +01:00
|
|
|
def test_if_basicr
|
2015-10-15 08:47:11 +02:00
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
2015-10-19 15:22:24 +02:00
|
|
|
if_plus( 10 - 12)
|
2015-10-15 08:47:11 +02:00
|
|
|
return 3
|
|
|
|
else
|
|
|
|
return 4
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-11-02 19:12:01 +01:00
|
|
|
@expect = [Label, LoadConstant,LoadConstant, OperatorInstruction,IsPlus ,
|
2015-10-27 20:04:46 +01:00
|
|
|
LoadConstant,SetSlot,Branch , Label , LoadConstant ,SetSlot,
|
2015-11-07 21:20:21 +01:00
|
|
|
Label,Label,FunctionReturn]
|
2015-10-15 08:47:11 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-10-19 15:22:24 +02:00
|
|
|
def test_if_small_minus
|
2015-10-15 08:47:11 +02:00
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
2015-10-19 15:22:24 +02:00
|
|
|
if_minus( 10 - 12)
|
2015-10-15 08:47:11 +02:00
|
|
|
return 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-11-07 21:20:21 +01:00
|
|
|
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch, Label ,
|
|
|
|
LoadConstant, SetSlot, Label, Label, FunctionReturn]
|
2015-10-15 08:47:11 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-10-19 15:22:24 +02:00
|
|
|
def test_if_small_zero
|
2015-10-15 08:47:11 +02:00
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
2015-10-19 15:22:24 +02:00
|
|
|
if_zero( 10 - 12)
|
|
|
|
return 3
|
|
|
|
end
|
2015-10-15 08:47:11 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-11-02 19:12:01 +01:00
|
|
|
@expect = [Label, LoadConstant,LoadConstant,OperatorInstruction,IsZero ,
|
2015-10-27 20:04:46 +01:00
|
|
|
Branch , Label , LoadConstant ,SetSlot,
|
2015-11-07 21:20:21 +01:00
|
|
|
Label,Label, FunctionReturn]
|
2015-10-15 08:47:11 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
end
|
2015-10-15 09:24:10 +02:00
|
|
|
end
|