diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_module.rb | 8 | ||||
-rw-r--r-- | test/ruby/test_symbol.rb | 33 |
2 files changed, 41 insertions, 0 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index b6e827a944..e2680dd700 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -472,6 +472,9 @@ class TestModule < Test::Unit::TestCase assert_raise(NameError) { c2::Bar } assert_raise(NameError) { c2.const_get(:Bar) } assert_raise(NameError) { c2.const_get(:Bar, false) } + assert_raise(NameError) { c2.const_get("Bar", false) } + assert_raise(NameError) { c2.const_get("BaR11", false) } + assert_raise(NameError) { Object.const_get("BaR11", false) } c1.instance_eval do def const_missing(x) @@ -483,6 +486,11 @@ class TestModule < Test::Unit::TestCase assert_equal(:Bar, c2::Bar) assert_equal(:Bar, c2.const_get(:Bar)) assert_equal(:Bar, c2.const_get(:Bar, false)) + assert_equal(:Bar, c2.const_get("Bar")) + assert_equal(:Bar, c2.const_get("Bar", false)) + + v = c2.const_get("Bar11", false) + assert_equal("Bar11".to_sym, v) assert_raise(NameError) { c1.const_get(:foo) } end diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index 0113504b14..104731a172 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -197,4 +197,37 @@ class TestSymbol < Test::Unit::TestCase assert !Symbol.all_symbols.any? {|sym| sym.to_s == str}, msg end end + + def test_no_inadvertent_symbol_creation3 + feature5089 = '[ruby-core:38447]' + c = Class.new do + def self.alias_method(str) + super(:puts, str) + end + end + s = "gadzoooks" + {:alias_method => ["#{s}1", NameError], + :autoload? => ["#{s}2", nil], + :const_get => ["A#{s}3", NameError], + :private_class_method => ["#{s}4", NameError], + :private_constant => ["#{s}5", NameError], + :private => ["#{s}6", NameError], + :protected => ["#{s}7", NameError], + :public => ["#{s}8", NameError], + :public_class_method => ["#{s}9", NameError], + :public_constant => ["#{s}10", NameError], + :remove_method => ["#{s}11", NameError], + :undef_method => ["#{s}12", NameError], + :untrace_var => ["#{s}13", NameError], + }.each do |meth, arr| + str, ret = arr + msg = "#{meth}(#{str}) #{feature5089}" + if ret.is_a?(Class) && (ret < Exception) + assert_raises(ret){c.send(meth, str)} + else + assert(c.send(meth, str) == ret, msg) + end + assert !Symbol.all_symbols.any? {|sym| sym.to_s == str}, msg + end + end end |