mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
437cfad071
commit
e3a716a2ab
1 changed files with 9 additions and 4 deletions
|
@ -247,9 +247,9 @@ class TestModule < Test::Unit::TestCase
|
||||||
"",
|
"",
|
||||||
":",
|
":",
|
||||||
["String::", "[Bug #7573]"],
|
["String::", "[Bug #7573]"],
|
||||||
"\u{3042}",
|
"\u3042",
|
||||||
].each do |name, msg|
|
].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}"
|
msg = "#{msg}#{': ' if msg}wrong constant name #{name.dump}"
|
||||||
assert_raise_with_message(NameError, expected, msg) {
|
assert_raise_with_message(NameError, expected, msg) {
|
||||||
Object.const_get name
|
Object.const_get name
|
||||||
|
@ -1659,14 +1659,19 @@ class TestModule < Test::Unit::TestCase
|
||||||
@foo
|
@foo
|
||||||
@@foo
|
@@foo
|
||||||
$foo
|
$foo
|
||||||
\u{3042}$
|
\u3042$
|
||||||
].each do |name|
|
].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 }
|
Module.new { attr_accessor name.to_sym }
|
||||||
end
|
end
|
||||||
end
|
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 AttrTest
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :cattr
|
attr_accessor :cattr
|
||||||
|
|
Loading…
Add table
Reference in a new issue