diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-26 17:27:44 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-10-26 17:27:44 +0000 |
commit | b88c9aa1fe0ec07db14544939f9001d66de1bd0a (patch) | |
tree | 1707c28259164f4ce98cd2c00a0e7c1a0da7a94e /test/ruby | |
parent | a11576816197d75fa17d959e74cabb612ba8b8be (diff) | |
download | ruby-b88c9aa1fe0ec07db14544939f9001d66de1bd0a.tar.gz |
* object.c (Init_Object), constant.h, variable.c
(rb_mod_private_constant, rb_mod_public_constant,
set_const_visibility, rb_const_get_0): add Module#public_constant
and private_constant. [ruby-dev:39685][ruby-core:32698]
* test/ruby/test_module.rb: add tests for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_module.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index e5f1e69749..87a4905e3c 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -939,4 +939,24 @@ class TestModule < Test::Unit::TestCase assert_nothing_raised(bug3406) {c.x = 1} assert_equal(1, c.x, bug3406) end + + def test_private_constant + c = Class.new + c.const_set(:FOO, "foo") + assert_equal("foo", c::FOO) + c.private_constant(:FOO) + assert_raise(NameError) { c::FOO } + assert_equal("foo", c.class_eval("FOO")) + end + + def test_public_constant + c = Class.new + c.const_set(:FOO, "foo") + assert_equal("foo", c::FOO) + c.private_constant(:FOO) + assert_raise(NameError) { c::FOO } + assert_equal("foo", c.class_eval("FOO")) + c.public_constant(:FOO) + assert_equal("foo", c::FOO) + end end |