2017-04-02 19:13:14 +03:00
|
|
|
require_relative "helper"
|
2017-04-02 13:24:09 +03:00
|
|
|
|
2018-07-19 14:46:51 +03:00
|
|
|
module Ruby
|
2018-07-19 16:30:36 +03:00
|
|
|
class TestVariables < MiniTest::Test
|
2018-06-29 22:46:39 +03:00
|
|
|
include RubyTests
|
2017-04-02 13:24:09 +03:00
|
|
|
|
|
|
|
# "free standing" local can not be tested as it will result in send
|
2018-07-19 16:30:36 +03:00
|
|
|
# in other words there is no way of knowing if a name is variable or method
|
2017-04-05 14:03:36 +03:00
|
|
|
# one needs an assignemnt first, to "tell" the parser it's a local
|
|
|
|
def test_local_basic
|
2018-06-29 22:46:39 +03:00
|
|
|
lst = compile( "foo = 1 ; foo")
|
2017-04-05 14:03:36 +03:00
|
|
|
assert_equal ScopeStatement , lst.class
|
|
|
|
assert_equal LocalVariable , lst.statements[1].class
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_local_nane
|
2018-06-29 22:46:39 +03:00
|
|
|
lst = compile( "foo = 1 ; foo")
|
2017-04-05 14:03:36 +03:00
|
|
|
assert_equal LocalVariable , lst.statements[1].class
|
|
|
|
end
|
2017-04-02 13:24:09 +03:00
|
|
|
|
2017-04-04 14:04:35 +03:00
|
|
|
def test_instance_basic
|
2018-06-29 22:46:39 +03:00
|
|
|
lst = compile( "@var" )
|
2017-04-04 14:04:35 +03:00
|
|
|
assert_equal InstanceVariable , lst.class
|
|
|
|
assert_equal :var , lst.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_instance_return
|
2018-06-29 22:46:39 +03:00
|
|
|
lst = compile( "return @var" )
|
2017-04-04 14:04:35 +03:00
|
|
|
assert_equal InstanceVariable , lst.return_value.class
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_basic
|
2018-06-29 22:46:39 +03:00
|
|
|
lst = compile( "@@var" )
|
2017-04-04 14:04:35 +03:00
|
|
|
assert_equal ClassVariable , lst.class
|
|
|
|
assert_equal :var , lst.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_return
|
2018-06-29 22:46:39 +03:00
|
|
|
lst = compile( "return @@var" )
|
2017-04-04 14:04:35 +03:00
|
|
|
assert_equal ClassVariable , lst.return_value.class
|
|
|
|
end
|
2017-04-04 18:00:21 +03:00
|
|
|
|
|
|
|
def test_module_basic
|
2018-06-29 22:46:39 +03:00
|
|
|
lst = compile( "Module" )
|
2017-04-04 18:00:21 +03:00
|
|
|
assert_equal ModuleName , lst.class
|
|
|
|
assert_equal :Module , lst.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_module_base_scoped
|
2018-06-29 22:46:39 +03:00
|
|
|
lst = compile( "::Module" )
|
2017-04-04 18:00:21 +03:00
|
|
|
assert_equal ModuleName , lst.class
|
|
|
|
assert_equal :Module , lst.name
|
|
|
|
end
|
2017-04-02 13:24:09 +03:00
|
|
|
end
|
2019-10-04 00:36:49 +03:00
|
|
|
class TestVariablesSol < MiniTest::Test
|
2018-07-20 14:22:26 +03:00
|
|
|
include RubyTests
|
|
|
|
def test_local_basic
|
2019-10-04 00:36:49 +03:00
|
|
|
lst = compile( "foo = 1 ; return foo").to_sol
|
|
|
|
assert_equal Sol::LocalVariable , lst.statements[1].return_value.class
|
2018-07-20 14:22:26 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_instance_basic
|
2019-10-04 00:36:49 +03:00
|
|
|
lst = compile( "@var" ).to_sol
|
|
|
|
assert_equal Sol::InstanceVariable , lst.class
|
2018-07-20 14:22:26 +03:00
|
|
|
assert_equal :var , lst.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_instance_return
|
2019-10-04 00:36:49 +03:00
|
|
|
lst = compile( "return @var" ).to_sol
|
|
|
|
assert_equal Sol::InstanceVariable , lst.return_value.class
|
2018-07-20 14:22:26 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_basic
|
2019-10-04 00:36:49 +03:00
|
|
|
lst = compile( "@@var" ).to_sol
|
|
|
|
assert_equal Sol::ClassVariable , lst.class
|
2018-07-20 14:22:26 +03:00
|
|
|
assert_equal :var , lst.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_return
|
2019-10-04 00:36:49 +03:00
|
|
|
lst = compile( "return @@var" ).to_sol
|
|
|
|
assert_equal Sol::ClassVariable , lst.return_value.class
|
2018-07-20 14:22:26 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_module_basic
|
2019-10-04 00:36:49 +03:00
|
|
|
lst = compile( "Module" ).to_sol
|
|
|
|
assert_equal Sol::ModuleName , lst.class
|
2018-07-20 14:22:26 +03:00
|
|
|
assert_equal :Module , lst.name
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2017-04-02 13:24:09 +03:00
|
|
|
end
|