aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_module.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-09 13:27:51 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-09 13:27:51 +0000
commite3a716a2ab831aff63a408e07a08e8d93a2fbb48 (patch)
tree44519591a556d4ff5c2afb12871c9e0e31c56b84 /test/ruby/test_module.rb
parent437cfad0715255ec2d2a9edd4cd0d3e1300d3c89 (diff)
downloadruby-e3a716a2ab831aff63a408e07a08e8d93a2fbb48.tar.gz
test_module.rb: quote name
* test/ruby/test_module.rb (test_bad_constants, test_invalid_attr): encode and quote name properly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43217 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_module.rb')
-rw-r--r--test/ruby/test_module.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 2847e9b5df..e8172d580c 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -247,9 +247,9 @@ class TestModule < Test::Unit::TestCase
"",
":",
["String::", "[Bug #7573]"],
- "\u{3042}",
+ "\u3042",
].each do |name, msg|
- expected = "wrong constant name %s" % name
+ expected = "wrong constant name %s" % quote(name)
msg = "#{msg}#{': ' if msg}wrong constant name #{name.dump}"
assert_raise_with_message(NameError, expected, msg) {
Object.const_get name
@@ -1659,14 +1659,19 @@ class TestModule < Test::Unit::TestCase
@foo
@@foo
$foo
- \u{3042}$
+ \u3042$
].each do |name|
- assert_raise_with_message(NameError, /#{Regexp.quote(name)}/) do
+ assert_raise_with_message(NameError, /#{Regexp.quote(quote(name))}/) do
Module.new { attr_accessor name.to_sym }
end
end
end
+ private def quote(name)
+ encoding = Encoding.default_internal || Encoding.default_external
+ (name.encoding == encoding || name.ascii_only?) ? name : name.inspect
+ end
+
class AttrTest
class << self
attr_accessor :cattr