diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-01-28 17:57:34 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-01-28 17:57:34 +0000 |
commit | a2ec8666cf8fbb579fa48c73bd114908dbbc4a85 (patch) | |
tree | e0c5418d9cea6530b490ea64bd9d8077ef34ad85 /test/ruby/test_class.rb | |
parent | f0483c494fe092a35ba2022702c554eac68efddf (diff) | |
download | ruby-a2ec8666cf8fbb579fa48c73bd114908dbbc4a85.tar.gz |
* compile.c (NODE_CLASS, NODE_MODULE), insns.def (defineclass): raise
an exception when "class Foo::Bar" is evaluated and Foo::Bar is
private. To implement this, define_type of "defineclass" is added
so that the instruction can distinguish whether the class definition
is scoped (class Foo::Bar) or not (class Bar).
* test/ruby/test_class.rb (test_redefine_private_class),
test/ruby/test_module.rb
(test_define_module_under_private_constant): add tests for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_class.rb')
-rw-r--r-- | test/ruby/test_class.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index 3f18294e0f..55940a8891 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -240,4 +240,22 @@ class TestClass < Test::Unit::TestCase def test_nested_class_removal assert_normal_exit('File.__send__(:remove_const, :Stat); at_exit{File.stat(".")}; GC.start') end + + class PrivateClass + end + private_constant :PrivateClass + + def test_redefine_private_class + assert_raise(NameError) do + eval("class ::TestClass::PrivateClass; end") + end + eval <<-END + class ::TestClass + class PrivateClass + def foo; 42; end + end + end + END + assert_equal(42, PrivateClass.new.foo) + end end |