[前][次][番号順一覧][スレッド一覧]

ruby-changes:31138

From: nobu <ko1@a...>
Date: Wed, 9 Oct 2013 22:28:04 +0900 (JST)
Subject: [ruby-changes:31138] nobu:r43217 (trunk): test_module.rb: quote name

nobu	2013-10-09 22:27:51 +0900 (Wed, 09 Oct 2013)

  New Revision: 43217

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43217

  Log:
    test_module.rb: quote name
    
    * test/ruby/test_module.rb (test_bad_constants, test_invalid_attr):
      encode and quote name properly.

  Modified files:
    trunk/test/ruby/test_module.rb
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 43216)
+++ test/ruby/test_module.rb	(revision 43217)
@@ -247,9 +247,9 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L247
       "",
       ":",
       ["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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1659
       @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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]