test return statement

This commit is contained in:
Torsten Ruger 2015-10-15 10:21:07 +03:00
parent f8efdd910c
commit 90ed4dd73b
3 changed files with 71 additions and 13 deletions

View File

@ -1 +1,2 @@
require_relative "test_if"
require_relative "test_return"

View File

@ -41,19 +41,6 @@ HERE
end
def ttest_return
@string_input = <<HERE
class Object
int main()
return 5
end
end
HERE
@expect = [[Virtual::MethodEnter,Register::LoadConstant] , [Virtual::MethodReturn]]
check
end
def ttest_call_function
@string_input = <<HERE
class Object

View File

@ -0,0 +1,70 @@
require_relative 'helper'
class TestReturnStatement < MiniTest::Test
include Statements
def test_return_int
@string_input = <<HERE
class Object
int main()
return 5
end
end
HERE
@expect = [[Virtual::MethodEnter,Register::LoadConstant] , [Virtual::MethodReturn]]
check
end
def test_return_local
@string_input = <<HERE
class Object
int main()
int runner
return runner
end
end
HERE
@expect = [[Virtual::MethodEnter,Register::GetSlot] , [Virtual::MethodReturn]]
check
end
def test_return_local_assign
@string_input = <<HERE
class Object
int main()
int runner = 5
return runner
end
end
HERE
@expect = [[Virtual::MethodEnter,Register::LoadConstant, Register::GetSlot] , [Virtual::MethodReturn]]
check
end
def test_return_field
@string_input = <<HERE
class Object
field int runner
int main()
return self.runner
end
end
HERE
@expect = [[Virtual::MethodEnter,Register::GetSlot] , [Virtual::MethodReturn]]
check
end
def test_return_call
@string_input = <<HERE
class Object
int main()
return main()
end
end
HERE
@expect = [[Virtual::MethodEnter,Register::GetSlot,Register::SetSlot, Register::LoadConstant,
Register::SetSlot,Virtual::MethodCall,Register::GetSlot] , [Virtual::MethodReturn]]
check
end
end