2017-04-02 18:13:14 +02:00
|
|
|
require_relative "helper"
|
2017-04-02 12:24:09 +02:00
|
|
|
|
|
|
|
module Vool
|
|
|
|
class TestVariables < MiniTest::Test
|
|
|
|
|
|
|
|
# "free standing" local can not be tested as it will result in send
|
|
|
|
# in other words ther is no way of knowing if a name is variable or method
|
2017-04-05 13:03:36 +02:00
|
|
|
# one needs an assignemnt first, to "tell" the parser it's a local
|
|
|
|
def test_local_basic
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( "foo = 1 ; foo")
|
2017-04-05 13:03:36 +02:00
|
|
|
assert_equal ScopeStatement , lst.class
|
|
|
|
assert_equal LocalVariable , lst.statements[1].class
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_local_nane
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( "foo = 1 ; foo")
|
2017-04-05 13:03:36 +02:00
|
|
|
assert_equal LocalVariable , lst.statements[1].class
|
|
|
|
end
|
2017-04-02 12:24:09 +02:00
|
|
|
|
2017-04-04 13:04:35 +02:00
|
|
|
def test_instance_basic
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( "@var" )
|
2017-04-04 13:04:35 +02:00
|
|
|
assert_equal InstanceVariable , lst.class
|
|
|
|
assert_equal :var , lst.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_instance_return
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( "return @var" )
|
2017-04-04 13:04:35 +02:00
|
|
|
assert_equal InstanceVariable , lst.return_value.class
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_basic
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( "@@var" )
|
2017-04-04 13:04:35 +02:00
|
|
|
assert_equal ClassVariable , lst.class
|
|
|
|
assert_equal :var , lst.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_return
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( "return @@var" )
|
2017-04-04 13:04:35 +02:00
|
|
|
assert_equal ClassVariable , lst.return_value.class
|
|
|
|
end
|
2017-04-04 17:00:21 +02:00
|
|
|
|
|
|
|
def test_module_basic
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( "Module" )
|
2017-04-04 17:00:21 +02:00
|
|
|
assert_equal ModuleName , lst.class
|
|
|
|
assert_equal :Module , lst.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_module_base_scoped
|
2017-04-06 14:36:41 +02:00
|
|
|
lst = RubyCompiler.compile( "::Module" )
|
2017-04-04 17:00:21 +02:00
|
|
|
assert_equal ModuleName , lst.class
|
|
|
|
assert_equal :Module , lst.name
|
|
|
|
end
|
|
|
|
def test_module_module_scoped
|
2017-04-06 14:36:41 +02:00
|
|
|
assert_raises {RubyCompiler.compile( "M::Module" ) }
|
2017-04-04 17:00:21 +02:00
|
|
|
end
|
2017-04-02 12:24:09 +02:00
|
|
|
end
|
|
|
|
end
|