fix while statement tests

This commit is contained in:
Torsten Ruger 2016-12-10 22:42:02 +02:00
parent e82c86f6c1
commit 17cb917104

View File

@ -1,37 +1,41 @@
require_relative 'helper' require_relative 'helper'
module Register module Register
class TestWhile #< MiniTest::Test class TestWhile < MiniTest::Test
include Statements include Statements
def test_while_mini def test_while_mini
@input = <<HERE @input = s(:statements,
class Space s(:while_statement, :plus,
int main() s(:conditional,
while_plus(1) s(:int, 1)),
return 3 s(:statements,
end s(:return,
end s(:int, 3)))))
end
HERE
@expect = [Label, Branch, Label, LoadConstant, SetSlot, Label, LoadConstant , @expect = [Label, Branch, Label, LoadConstant, SetSlot, Label, LoadConstant ,
IsPlus, Label, FunctionReturn] IsPlus, Label, FunctionReturn]
check check
end end
def test_while_assign def test_while_assign
@input = <<HERE @input = s(:statements,
class Space s(:field_def, :Integer,
int main() s(:name, :n),
int n = 5 s(:int, 5)),
while_plus(n) s(:while_statement, :plus,
n = n - 1 s(:conditional,
end s(:name, :n)),
return n s(:statements,
end s(:assignment,
end s(:name, :n),
HERE s(:operator_value, :-,
s(:name, :n),
s(:int, 1))))),
s(:return,
s(:name, :n)))
@expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot , @expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot ,
GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label, GetSlot , GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label, GetSlot ,
GetSlot, IsPlus, GetSlot, GetSlot, SetSlot, Label, FunctionReturn] GetSlot, IsPlus, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
@ -40,17 +44,24 @@ HERE
def test_while_return def test_while_return
@input = <<HERE @input = s(:statements,
class Space s(:field_def, :Integer,
int main() s(:name, :n),
int n = 10 s(:int, 10)),
while_plus( n - 5) s(:while_statement, :plus,
n = n + 1 s(:conditional,
return n s(:operator_value, :-,
end s(:name, :n),
end s(:int, 5))),
end s(:statements,
HERE s(:assignment,
s(:name, :n),
s(:operator_value, :+,
s(:name, :n),
s(:int, 1))),
s(:return,
s(:name, :n)))))
@expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot , @expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot ,
GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, GetSlot, GetSlot , GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, GetSlot, GetSlot ,
SetSlot, Label, GetSlot, GetSlot, LoadConstant, OperatorInstruction, IsPlus , SetSlot, Label, GetSlot, GetSlot, LoadConstant, OperatorInstruction, IsPlus ,