fix and test vool return statement
This commit is contained in:
parent
c545bfdfc6
commit
83ab197d03
@ -99,9 +99,8 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def on_return statement
|
def on_return statement
|
||||||
w = ReturnStatement.new()
|
return_value = process(statement.children.first)
|
||||||
w.return_value = process(statement.children.first)
|
ReturnStatement.new( return_value )
|
||||||
w
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_function statement
|
def on_function statement
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class ReturnStatement < Statement
|
class ReturnStatement < Statement
|
||||||
attr_accessor :return_value
|
attr_accessor :return_value
|
||||||
|
|
||||||
|
def initialize(value)
|
||||||
|
@return_value = value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,5 +6,6 @@ require_relative "test_hash_statement"
|
|||||||
require_relative "test_if_statement"
|
require_relative "test_if_statement"
|
||||||
require_relative "test_method_statement"
|
require_relative "test_method_statement"
|
||||||
require_relative "test_send_statement"
|
require_relative "test_send_statement"
|
||||||
|
require_relative "test_return_statement"
|
||||||
require_relative "test_variables"
|
require_relative "test_variables"
|
||||||
require_relative "test_while_statement"
|
require_relative "test_while_statement"
|
||||||
|
23
test/vool/test_return_statement.rb
Normal file
23
test/vool/test_return_statement.rb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module Vool
|
||||||
|
class TestReturnStatement < MiniTest::Test
|
||||||
|
|
||||||
|
def test_return_const
|
||||||
|
lst = Compiler.compile( "return 1" )
|
||||||
|
assert_equal ReturnStatement , lst.class
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_return_value
|
||||||
|
lst = Compiler.compile( "return 1" )
|
||||||
|
assert_equal 1 , lst.return_value.value
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_return_send
|
||||||
|
lst = Compiler.compile( "return foo" )
|
||||||
|
assert_equal SendStatement , lst.return_value.class
|
||||||
|
assert_equal :foo , lst.return_value.name
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user