summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-14 02:25:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-14 02:25:58 +0000
commit241ca7bfff26b1f624ef64212b68d76efcb78f9d (patch)
tree63b20717be85a882ae66cac86e213da3c49d314d /test/ruby
parenta68c69d196b76d42cf74aba497a37cbf1be87bf9 (diff)
object.c: nested path const_defined?
* object.c (rb_mod_const_defined): support nested class path as well as const_get. [Feature #7414] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44194 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_module.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 26dbf9a588..5b5e04b0da 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -303,6 +303,26 @@ class TestModule < Test::Unit::TestCase
end
end
+ def test_nested_defined
+ assert_send([Object, :const_defined?, [self.class.name, 'Other'].join('::')])
+ assert_send([self.class, :const_defined?, 'User::USER'])
+ assert_not_send([self.class, :const_defined?, 'User::Foo'])
+ end
+
+ def test_nested_defined_symbol
+ const = [self.class, Other].join('::').to_sym
+ assert_raise(NameError) {Object.const_defined?(const)}
+
+ const = [User, 'USER'].join('::').to_sym
+ assert_raise(NameError) {self.class.const_defined?(const)}
+ end
+
+ def test_nested_defined_bad_class
+ assert_raise(TypeError) do
+ self.class.const_defined?('User::USER::Foo')
+ end
+ end
+
def test_const_set
assert_not_operator(Other, :const_defined?, :KOALA)
Other.const_set(:KOALA, 99)