rubyx/test/ruby/test_variables.rb

95 lines
2.5 KiB
Ruby
Raw Normal View History

require_relative "helper"
module Ruby
2018-07-19 15:30:36 +02:00
class TestVariables < MiniTest::Test
include RubyTests
# "free standing" local can not be tested as it will result in send
2018-07-19 15:30:36 +02:00
# in other words there is no way of knowing if a name is variable or method
# one needs an assignemnt first, to "tell" the parser it's a local
def test_local_basic
lst = compile( "foo = 1 ; foo")
assert_equal ScopeStatement , lst.class
assert_equal LocalVariable , lst.statements[1].class
end
def test_local_nane
lst = compile( "foo = 1 ; foo")
assert_equal LocalVariable , lst.statements[1].class
end
def test_instance_basic
lst = compile( "@var" )
assert_equal InstanceVariable , lst.class
assert_equal :var , lst.name
end
def test_instance_return
lst = compile( "return @var" )
assert_equal InstanceVariable , lst.return_value.class
end
def test_class_basic
lst = compile( "@@var" )
assert_equal ClassVariable , lst.class
assert_equal :var , lst.name
end
def test_class_return
lst = compile( "return @@var" )
assert_equal ClassVariable , lst.return_value.class
end
2017-04-04 17:00:21 +02:00
def test_module_basic
lst = 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
lst = 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
assert_raises {compile( "M::Module" ) }
2017-04-04 17:00:21 +02:00
end
end
2018-07-20 13:22:26 +02:00
class TestVariablesVool < MiniTest::Test
include RubyTests
def test_local_basic
lst = compile( "foo = 1 ; foo").to_vool
assert_equal Vool::LocalVariable , lst.statements[1].class
end
def test_instance_basic
lst = compile( "@var" ).to_vool
assert_equal Vool::InstanceVariable , lst.class
assert_equal :var , lst.name
end
def test_instance_return
lst = compile( "return @var" ).to_vool
assert_equal InstanceVariable , lst.return_value.class
end
def test_class_basic
lst = compile( "@@var" ).to_vool
assert_equal Vool::ClassVariable , lst.class
assert_equal :var , lst.name
end
def test_class_return
lst = compile( "return @@var" ).to_vool
assert_equal ClassVariable , lst.return_value.class
end
def test_module_basic
lst = compile( "Module" ).to_vool
assert_equal Vool::ModuleName , lst.class
assert_equal :Module , lst.name
end
end
end