fix and test vool return statement

This commit is contained in:
Torsten Ruger 2017-04-04 10:42:20 +03:00
parent c545bfdfc6
commit 83ab197d03
4 changed files with 30 additions and 3 deletions

View File

@ -99,9 +99,8 @@ module Vool
end
def on_return statement
w = ReturnStatement.new()
w.return_value = process(statement.children.first)
w
return_value = process(statement.children.first)
ReturnStatement.new( return_value )
end
def on_function statement

View File

@ -1,5 +1,9 @@
module Vool
class ReturnStatement < Statement
attr_accessor :return_value
def initialize(value)
@return_value = value
end
end
end

View File

@ -6,5 +6,6 @@ require_relative "test_hash_statement"
require_relative "test_if_statement"
require_relative "test_method_statement"
require_relative "test_send_statement"
require_relative "test_return_statement"
require_relative "test_variables"
require_relative "test_while_statement"

View 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