diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_module.rb | 3 | ||||
-rw-r--r-- | test/ruby/test_symbol.rb | 15 |
2 files changed, 18 insertions, 0 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index e6c107961d..1aa7f8c691 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -495,6 +495,9 @@ class TestModule < Test::Unit::TestCase def test_const_get_invalid_name c1 = Class.new assert_raise(NameError) { c1.const_defined?(:foo) } + name = "gadzooks" + assert !Symbol.all_symbols.any? {|sym| sym.to_s == name} + assert_raise(NameError) { c1.const_defined?(name) } end def test_const_get_no_inherited diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index 9061f191bf..282964cdf5 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -144,4 +144,19 @@ class TestSymbol < Test::Unit::TestCase assert_equal(':"\\u3042\\u3044\\u3046"', "\u3042\u3044\u3046".encode(e).to_sym.inspect) end end + + def test_no_inadvertent_symbol_creation + feature5072 = '[ruby-core:38367]' + c = Class.new + s = "gadzooks" + {:respond_to? => "#{s}1", :method_defined? => "#{s}2", + :public_method_defined? => "#{s}3", :private_method_defined? => "#{s}4", + :protected_method_defined? => "#{s}5", :const_defined? => "A#{s}", + :instance_variable_defined? => "@#{s}", :class_variable_defined? => "@@#{s}" + }.each do |meth, str| + msg = "#{meth}(#{str}) #{feature5072}" + assert !c.send(meth, str), msg + assert !Symbol.all_symbols.any? {|sym| sym.to_s == str}, msg + end + end end |