summaryrefslogtreecommitdiff
path: root/test/ruby/test_module.rb
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <[email protected]>2020-09-01 21:22:20 -0400
committerMarc-AndrĂ© Lafortune <[email protected]>2020-09-02 00:05:14 -0400
commit5e16857315bf55307c5fc887ca6f03bfa0630a93 (patch)
treed42bcc39f4cdfb958d620f3d1389f2aa677b77cb /test/ruby/test_module.rb
parent11922b5e030808b16fd2c604637e046b2d01b0f0 (diff)
Fix constant names set using const_set on a singleton class
Fixes [Bug #14895]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3502
Diffstat (limited to 'test/ruby/test_module.rb')
-rw-r--r--test/ruby/test_module.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index d2da384cbd..94e415b08c 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -767,13 +767,13 @@ class TestModule < Test::Unit::TestCase
n = Module.new
m.const_set(:N, n)
assert_nil(m.name)
- assert_nil(n.name)
+ assert_match(/::N$/, n.name)
assert_equal([:N], m.constants)
m.module_eval("module O end")
assert_equal([:N, :O], m.constants.sort)
m.module_eval("class C; end")
assert_equal([:C, :N, :O], m.constants.sort)
- assert_nil(m::N.name)
+ assert_match(/::N$/, m::N.name)
assert_match(/\A#<Module:.*>::O\z/, m::O.name)
assert_match(/\A#<Module:.*>::C\z/, m::C.name)
self.class.const_set(:M, m)
@@ -2724,6 +2724,12 @@ class TestModule < Test::Unit::TestCase
assert_not_predicate m.clone(freeze: false), :frozen?
end
+ def test_module_name_in_singleton_method
+ s = Object.new.singleton_class
+ mod = s.const_set(:Foo, Module.new)
+ assert_match(/::Foo$/, mod.name, '[Bug #14895]')
+ end
+
private
def assert_top_method_is_private(method)