Suppress warnings: setting Encoding.default_external

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2013-02-12 03:22:33 +00:00
Родитель edacc7d236
Коммит caa0e40f4d
1 изменённых файлов: 43 добавлений и 35 удалений

Просмотреть файл

@ -195,31 +195,35 @@ class TestM17N < Test::Unit::TestCase
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)
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
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
def test_utf_16_32_inspect
@ -247,18 +251,22 @@ class TestM17N < Test::Unit::TestCase
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