rubyx/test/compiler/statements/test_while.rb
Torsten Ruger 50379a1fea update to new syntax and patch tests
basic semantics remain, but have to improve test for new functionality
that has to be written for new branch types
2015-10-19 15:31:48 +03:00

62 lines
1.4 KiB
Ruby

require_relative 'helper'
module Register
class TestWhile < MiniTest::Test
include Statements
def test_while_mini
@string_input = <<HERE
class Object
int main()
while_plus(1)
return 3
end
end
end
HERE
@expect = [[SaveReturn],[LoadConstant,IsZeroBranch,LoadConstant,AlwaysBranch],
[],[RegisterTransfer,GetSlot,FunctionReturn]]
check
end
def test_while_assign
@string_input = <<HERE
class Object
int main()
int n = 5
while_minus(n > 0)
n = n - 1
end
end
end
HERE
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot,LoadConstant,OperatorInstruction,
IsZeroBranch,GetSlot,GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,AlwaysBranch],
[],[RegisterTransfer,GetSlot,FunctionReturn]]
check
end
def test_while_return
@string_input = <<HERE
class Object
int main()
int n = 10
while_notzero( n > 5)
n = n + 1
return n
end
end
end
HERE
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],
[GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsZeroBranch,GetSlot,
GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,GetSlot,
GetSlot,AlwaysBranch] ,
[],[RegisterTransfer,GetSlot,FunctionReturn]]
check
end
end
end