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
|
|
|
|
|
|
|
|
def test_if_basic
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
2015-10-19 14:31:48 +02:00
|
|
|
if_plus( 10 < 12)
|
2015-10-15 08:47:11 +02:00
|
|
|
return 3
|
|
|
|
else
|
|
|
|
return 4
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-18 16:39:35 +02:00
|
|
|
@expect = [[SaveReturn,LoadConstant,LoadConstant,
|
2015-10-19 15:08:00 +02:00
|
|
|
OperatorInstruction,IsZero] ,
|
|
|
|
[LoadConstant,Branch] ,[LoadConstant] ,[] ,
|
2015-10-18 16:32:32 +02:00
|
|
|
[RegisterTransfer,GetSlot,FunctionReturn]]
|
2015-10-15 08:47:11 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def test_if_small
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
2015-10-19 14:31:48 +02:00
|
|
|
if_minus( 10 < 12)
|
2015-10-15 08:47:11 +02:00
|
|
|
return 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-18 16:39:35 +02:00
|
|
|
@expect = [[SaveReturn,LoadConstant,LoadConstant,
|
2015-10-19 15:08:00 +02:00
|
|
|
OperatorInstruction,IsZero] ,
|
|
|
|
[Branch] ,[LoadConstant] ,[] ,
|
2015-10-18 16:32:32 +02:00
|
|
|
[RegisterTransfer,GetSlot,FunctionReturn]]
|
2015-10-15 08:47:11 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def ttest_call_function
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int itest(int n)
|
|
|
|
return 4
|
|
|
|
end
|
|
|
|
|
|
|
|
int main()
|
|
|
|
itest(20)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-18 16:39:35 +02:00
|
|
|
@expect = [ [SaveReturn,GetSlot,SetSlot,LoadConstant,
|
2015-10-18 18:27:46 +02:00
|
|
|
SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,
|
2015-10-18 16:32:32 +02:00
|
|
|
GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
|
2015-10-15 08:47:11 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
end
|
2015-10-15 09:24:10 +02:00
|
|
|
end
|