зеркало из https://github.com/github/ruby.git
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:
Родитель
edacc7d236
Коммит
caa0e40f4d
|
@ -195,31 +195,35 @@ class TestM17N < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_string_inspect_encoding
|
def test_string_inspect_encoding
|
||||||
orig_int = Encoding.default_internal
|
EnvUtil.suppress_warning do
|
||||||
orig_ext = Encoding.default_external
|
begin
|
||||||
Encoding.default_internal = nil
|
orig_int = Encoding.default_internal
|
||||||
[Encoding::UTF_8, Encoding::EUC_JP, Encoding::Windows_31J, Encoding::GB18030].
|
orig_ext = Encoding.default_external
|
||||||
each do |e|
|
Encoding.default_internal = nil
|
||||||
Encoding.default_external = e
|
[Encoding::UTF_8, Encoding::EUC_JP, Encoding::Windows_31J, Encoding::GB18030].
|
||||||
str = "\x81\x30\x81\x30".force_encoding('GB18030')
|
each do |e|
|
||||||
assert_equal(Encoding::GB18030 == e ? %{"#{str}"} : '"\x{81308130}"', str.inspect)
|
Encoding.default_external = e
|
||||||
str = e("\xa1\x8f\xa1\xa1")
|
str = "\x81\x30\x81\x30".force_encoding('GB18030')
|
||||||
expected = "\"\\xA1\x8F\xA1\xA1\"".force_encoding("EUC-JP")
|
assert_equal(Encoding::GB18030 == e ? %{"#{str}"} : '"\x{81308130}"', str.inspect)
|
||||||
assert_equal(Encoding::EUC_JP == e ? expected : "\"\\xA1\\x{8FA1A1}\"", str.inspect)
|
str = e("\xa1\x8f\xa1\xa1")
|
||||||
str = s("\x81@")
|
expected = "\"\\xA1\x8F\xA1\xA1\"".force_encoding("EUC-JP")
|
||||||
assert_equal(Encoding::Windows_31J == e ? %{"#{str}"} : '"\x{8140}"', str.inspect)
|
assert_equal(Encoding::EUC_JP == e ? expected : "\"\\xA1\\x{8FA1A1}\"", str.inspect)
|
||||||
str = "\u3042\u{10FFFD}"
|
str = s("\x81@")
|
||||||
assert_equal(Encoding::UTF_8 == e ? %{"#{str}"} : '"\u3042\u{10FFFD}"', str.inspect)
|
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
|
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
|
||||||
|
|
||||||
def test_utf_16_32_inspect
|
def test_utf_16_32_inspect
|
||||||
|
@ -247,18 +251,22 @@ class TestM17N < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_object_utf16_32_inspect
|
def test_object_utf16_32_inspect
|
||||||
orig_int = Encoding.default_internal
|
EnvUtil.suppress_warning do
|
||||||
orig_ext = Encoding.default_external
|
begin
|
||||||
Encoding.default_internal = nil
|
orig_int = Encoding.default_internal
|
||||||
Encoding.default_external = Encoding::UTF_8
|
orig_ext = Encoding.default_external
|
||||||
o = Object.new
|
Encoding.default_internal = nil
|
||||||
[Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE].each do |e|
|
Encoding.default_external = Encoding::UTF_8
|
||||||
o.instance_eval "undef inspect;def inspect;'abc'.encode('#{e}');end"
|
o = Object.new
|
||||||
assert_raise(Encoding::CompatibilityError) { [o].inspect }
|
[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
|
end
|
||||||
ensure
|
|
||||||
Encoding.default_internal = orig_int
|
|
||||||
Encoding.default_external = orig_ext
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_object_inspect_external
|
def test_object_inspect_external
|
||||||
|
|
Загрузка…
Ссылка в новой задаче