rubyx/test/compiler/fragments/test_if.rb

59 lines
1.1 KiB
Ruby
Raw Normal View History

2014-05-24 09:18:54 +02:00
require_relative 'helper'
class TestIf < MiniTest::Test
include Fragments
2015-07-18 14:28:57 +02:00
def test_if_basic
@string_input = <<HERE
class Object
int main()
2015-10-07 09:04:55 +02:00
int n = 10
if( n < 12)
return 3
else
return 4
end
end
2015-07-18 14:28:57 +02:00
end
HERE
2015-10-09 20:53:22 +02:00
@expect = [[Virtual::MethodEnter,Virtual::Set,Virtual::Set,Register::GetSlot,
Register::GetSlot,Register::OperatorInstruction,Register::IsZeroBranch] ,
[Virtual::Set,Register::AlwaysBranch] ,[Virtual::Set] ,[] ,[Virtual::MethodReturn] ]
2015-07-18 14:28:57 +02:00
check
end
2015-07-19 12:03:21 +02:00
def test_return
@string_input = <<HERE
class Object
int main()
return 5
end
end
2015-07-19 12:03:21 +02:00
HERE
2015-10-09 20:53:22 +02:00
@expect = [[Virtual::MethodEnter,Virtual::Set] , [Virtual::MethodReturn]]
2015-07-19 12:03:21 +02:00
check
end
def test_if_function
2014-05-24 09:18:54 +02:00
@string_input = <<HERE
class Object
int itest(int n)
if( n < 12)
"then".putstring()
else
"else".putstring()
end
2015-07-19 10:15:38 +02:00
end
int main()
itest(20)
end
end
2014-05-24 09:18:54 +02:00
HERE
2015-10-10 11:04:34 +02:00
@expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,
2015-10-09 20:53:22 +02:00
Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn] ]
2015-07-18 14:28:57 +02:00
check
2014-05-24 09:18:54 +02:00
end
end