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()
|
|
|
|
if( 10 < 12)
|
|
|
|
return 3
|
|
|
|
else
|
|
|
|
return 4
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-15 09:24:10 +02:00
|
|
|
@expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant,
|
|
|
|
OperatorInstruction,IsZeroBranch] ,
|
|
|
|
[LoadConstant,AlwaysBranch] ,[LoadConstant] ,[] ,
|
2015-10-15 08:47:11 +02:00
|
|
|
[Virtual::MethodReturn]]
|
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def test_if_small
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
if( 10 < 12)
|
|
|
|
return 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-15 09:24:10 +02:00
|
|
|
@expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant,
|
|
|
|
OperatorInstruction,IsZeroBranch] ,
|
|
|
|
[AlwaysBranch] ,[LoadConstant] ,[] ,
|
2015-10-15 08:47:11 +02:00
|
|
|
[Virtual::MethodReturn]]
|
|
|
|
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-15 09:24:10 +02:00
|
|
|
@expect = [ [Virtual::MethodEnter,GetSlot,SetSlot,LoadConstant,
|
|
|
|
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,
|
|
|
|
GetSlot] ,[Virtual::MethodReturn] ]
|
2015-10-15 08:47:11 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
end
|
2015-10-15 09:24:10 +02:00
|
|
|
end
|