test return statement
This commit is contained in:
parent
f8efdd910c
commit
90ed4dd73b
@ -1 +1,2 @@
|
||||
require_relative "test_if"
|
||||
require_relative "test_return"
|
||||
|
@ -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
|
||||
|
70
test/compiler/statements/test_return.rb
Normal file
70
test/compiler/statements/test_return.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user