From 241ca7bfff26b1f624ef64212b68d76efcb78f9d Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 14 Dec 2013 02:25:58 +0000 Subject: 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 --- test/ruby/test_module.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/ruby') 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) -- cgit v1.2.3