fix conditional tests

This commit is contained in:
Torsten Ruger 2016-12-10 22:49:04 +02:00
parent 5a1a42cd48
commit 99454b3efe

View File

@ -1,21 +1,23 @@
require_relative 'helper' require_relative 'helper'
module Register module Register
class TestIfStatement #< MiniTest::Test class TestIfStatement < MiniTest::Test
include Statements include Statements
def test_if_basicr def test_if_basicr
@input = <<HERE @input = s(:statements,
class Space s(:if_statement, :plus,
int main() s(:condition,
if_plus( 10 - 12) s(:operator_value, :-,
return 3 s(:int, 10),
else s(:int, 12))),
return 4 s(:true_statements,
end s(:return,
end s(:int, 3))),
end s(:false_statements,
HERE s(:return,
s(:int, 4)))))
@expect = [Label, LoadConstant,LoadConstant, OperatorInstruction,IsPlus , @expect = [Label, LoadConstant,LoadConstant, OperatorInstruction,IsPlus ,
LoadConstant,SetSlot,Branch , Label , LoadConstant ,SetSlot, LoadConstant,SetSlot,Branch , Label , LoadConstant ,SetSlot,
Label,Label,FunctionReturn] Label,Label,FunctionReturn]
@ -24,15 +26,17 @@ HERE
def test_if_small_minus def test_if_small_minus
@input = <<HERE @input = s(:statements,
class Space s(:if_statement, :minus,
int main() s(:condition,
if_minus( 10 - 12) s(:operator_value, :-,
return 3 s(:int, 10),
end s(:int, 12))),
end s(:true_statements,
end s(:return,
HERE s(:int, 3))),
s(:false_statements, nil)))
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch, Label , @expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch, Label ,
LoadConstant, SetSlot, Label, Label, FunctionReturn] LoadConstant, SetSlot, Label, Label, FunctionReturn]
check check
@ -40,15 +44,17 @@ HERE
def test_if_small_zero def test_if_small_zero
@input = <<HERE @input = s(:statements,
class Space s(:if_statement, :zero,
int main() s(:condition,
if_zero( 10 - 12) s(:operator_value, :-,
return 3 s(:int, 10),
end s(:int, 12))),
end s(:true_statements,
end s(:return,
HERE s(:int, 3))),
s(:false_statements, nil)))
@expect = [Label, LoadConstant,LoadConstant,OperatorInstruction,IsZero , @expect = [Label, LoadConstant,LoadConstant,OperatorInstruction,IsZero ,
Branch , Label , LoadConstant ,SetSlot, Branch , Label , LoadConstant ,SetSlot,
Label,Label, FunctionReturn] Label,Label, FunctionReturn]