mirror of
https://github.com/ruby/ruby.git
synced 2025-09-23 20:44:00 +02:00
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
This commit is contained in:
parent
a68c69d196
commit
241ca7bfff
3 changed files with 103 additions and 10 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue