2015-10-16 12:17:02 +02:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
module Register
|
|
|
|
class TestWhile < MiniTest::Test
|
|
|
|
include Statements
|
|
|
|
|
|
|
|
|
|
|
|
def test_while_mini
|
|
|
|
@string_input = <<HERE
|
2015-11-30 15:20:39 +01:00
|
|
|
class Space
|
2015-10-16 12:17:02 +02:00
|
|
|
int main()
|
2015-10-19 14:31:48 +02:00
|
|
|
while_plus(1)
|
2015-10-16 12:17:02 +02:00
|
|
|
return 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-11-04 19:28:02 +01:00
|
|
|
@expect = [Label, Branch, Label, LoadConstant, SetSlot, Label, LoadConstant ,
|
2015-11-07 21:20:21 +01:00
|
|
|
IsPlus, Label, FunctionReturn]
|
2015-10-16 12:17:02 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_while_assign
|
|
|
|
@string_input = <<HERE
|
2015-11-30 15:20:39 +01:00
|
|
|
class Space
|
2015-10-16 12:17:02 +02:00
|
|
|
int main()
|
|
|
|
int n = 5
|
2015-10-19 15:37:12 +02:00
|
|
|
while_plus(n)
|
2015-10-16 12:17:02 +02:00
|
|
|
n = n - 1
|
|
|
|
end
|
2015-10-23 20:27:36 +02:00
|
|
|
return n
|
2015-10-16 12:17:02 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-11-04 19:28:02 +01:00
|
|
|
@expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot ,
|
|
|
|
GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label, GetSlot ,
|
2015-11-07 21:20:21 +01:00
|
|
|
GetSlot, IsPlus, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
|
2015-10-16 12:17:02 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def test_while_return
|
|
|
|
@string_input = <<HERE
|
2015-11-30 15:20:39 +01:00
|
|
|
class Space
|
2015-10-16 12:17:02 +02:00
|
|
|
int main()
|
|
|
|
int n = 10
|
2015-10-19 15:37:12 +02:00
|
|
|
while_plus( n - 5)
|
2015-10-16 12:17:02 +02:00
|
|
|
n = n + 1
|
|
|
|
return n
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-11-04 19:28:02 +01:00
|
|
|
@expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot ,
|
|
|
|
GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, GetSlot, GetSlot ,
|
|
|
|
SetSlot, Label, GetSlot, GetSlot, LoadConstant, OperatorInstruction, IsPlus ,
|
2015-11-07 21:20:21 +01:00
|
|
|
Label, FunctionReturn]
|
2015-10-16 12:17:02 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|