ruby-changes:27158
From: naruse <ko1@a...>
Date: Tue, 12 Feb 2013 12:24:35 +0900 (JST)
Subject: [ruby-changes:27158] naruse:r39210 (trunk): Suppress warnings: setting Encoding.default_external
naruse 2013-02-12 12:22:33 +0900 (Tue, 12 Feb 2013) New Revision: 39210 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39210 Log: Suppress warnings: setting Encoding.default_external Modified files: trunk/test/ruby/test_m17n.rb Index: test/ruby/test_m17n.rb =================================================================== --- test/ruby/test_m17n.rb (revision 39209) +++ test/ruby/test_m17n.rb (revision 39210) @@ -195,31 +195,35 @@ class TestM17N < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_m17n.rb#L195 end def test_string_inspect_encoding - orig_int = Encoding.default_internal - orig_ext = Encoding.default_external - Encoding.default_internal = nil - [Encoding::UTF_8, Encoding::EUC_JP, Encoding::Windows_31J, Encoding::GB18030]. - each do |e| - Encoding.default_external = e - str = "\x81\x30\x81\x30".force_encoding('GB18030') - assert_equal(Encoding::GB18030 == e ? %{"#{str}"} : '"\x{81308130}"', str.inspect) - str = e("\xa1\x8f\xa1\xa1") - expected = "\"\\xA1\x8F\xA1\xA1\"".force_encoding("EUC-JP") - assert_equal(Encoding::EUC_JP == e ? expected : "\"\\xA1\\x{8FA1A1}\"", str.inspect) - str = s("\x81@") - assert_equal(Encoding::Windows_31J == e ? %{"#{str}"} : '"\x{8140}"', str.inspect) - str = "\u3042\u{10FFFD}" - assert_equal(Encoding::UTF_8 == e ? %{"#{str}"} : '"\u3042\u{10FFFD}"', str.inspect) - end - Encoding.default_external = Encoding::UTF_8 - [Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE, - Encoding::UTF8_SOFTBANK].each do |e| - str = "abc".encode(e) - assert_equal('"abc"', str.inspect) + EnvUtil.suppress_warning do + begin + orig_int = Encoding.default_internal + orig_ext = Encoding.default_external + Encoding.default_internal = nil + [Encoding::UTF_8, Encoding::EUC_JP, Encoding::Windows_31J, Encoding::GB18030]. + each do |e| + Encoding.default_external = e + str = "\x81\x30\x81\x30".force_encoding('GB18030') + assert_equal(Encoding::GB18030 == e ? %{"#{str}"} : '"\x{81308130}"', str.inspect) + str = e("\xa1\x8f\xa1\xa1") + expected = "\"\\xA1\x8F\xA1\xA1\"".force_encoding("EUC-JP") + assert_equal(Encoding::EUC_JP == e ? expected : "\"\\xA1\\x{8FA1A1}\"", str.inspect) + str = s("\x81@") + assert_equal(Encoding::Windows_31J == e ? %{"#{str}"} : '"\x{8140}"', str.inspect) + str = "\u3042\u{10FFFD}" + assert_equal(Encoding::UTF_8 == e ? %{"#{str}"} : '"\u3042\u{10FFFD}"', str.inspect) + end + Encoding.default_external = Encoding::UTF_8 + [Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE, + Encoding::UTF8_SOFTBANK].each do |e| + str = "abc".encode(e) + assert_equal('"abc"', str.inspect) + end + ensure + Encoding.default_internal = orig_int + Encoding.default_external = orig_ext + end end - ensure - Encoding.default_internal = orig_int - Encoding.default_external = orig_ext end def test_utf_16_32_inspect @@ -247,18 +251,22 @@ class TestM17N < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_m17n.rb#L251 end def test_object_utf16_32_inspect - orig_int = Encoding.default_internal - orig_ext = Encoding.default_external - Encoding.default_internal = nil - Encoding.default_external = Encoding::UTF_8 - o = Object.new - [Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE].each do |e| - o.instance_eval "undef inspect;def inspect;'abc'.encode('#{e}');end" - assert_raise(Encoding::CompatibilityError) { [o].inspect } + EnvUtil.suppress_warning do + begin + orig_int = Encoding.default_internal + orig_ext = Encoding.default_external + Encoding.default_internal = nil + Encoding.default_external = Encoding::UTF_8 + o = Object.new + [Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE].each do |e| + o.instance_eval "undef inspect;def inspect;'abc'.encode('#{e}');end" + assert_raise(Encoding::CompatibilityError) { [o].inspect } + end + ensure + Encoding.default_internal = orig_int + Encoding.default_external = orig_ext + end end - ensure - Encoding.default_internal = orig_int - Encoding.default_external = orig_ext end def test_object_inspect_external -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/