* transcode.c: add "Error" suffix for Encoding exception classes.

a patch from Tadashi Saito <shiba at mail2.accsnet.ne.jp> in
  [ruby-dev:36346].

* encoding.c (Init_Encoding): rename EncodingCompatibilityError to
  Encoding::CompatibilityError.  [ruby-dev:36366]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-09-18 08:57:33 +00:00
Родитель 45ee7d2e78
Коммит d5ec36c486
11 изменённых файлов: 230 добавлений и 220 удалений

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

@ -1,3 +1,12 @@
Thu Sep 18 17:32:44 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* transcode.c: add "Error" suffix for Encoding exception classes.
a patch from Tadashi Saito <shiba at mail2.accsnet.ne.jp> in
[ruby-dev:36346].
* encoding.c (Init_Encoding): rename EncodingCompatibilityError to
Encoding::CompatibilityError. [ruby-dev:36366]
Thu Sep 18 17:18:35 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* transcode.c (enc_arg): revert last change. too early exception

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

@ -323,12 +323,12 @@ VALUE rb_eIndexError;
VALUE rb_eKeyError;
VALUE rb_eRangeError;
VALUE rb_eNameError;
VALUE rb_eEncCompatError;
VALUE rb_eNoMethodError;
VALUE rb_eSecurityError;
VALUE rb_eNotImpError;
VALUE rb_eNoMemError;
VALUE rb_cNameErrorMesg;
VALUE rb_eEncCompatError;
VALUE rb_eScriptError;
VALUE rb_eSyntaxError;
@ -1033,7 +1033,6 @@ Init_Exception(void)
rb_eIndexError = rb_define_class("IndexError", rb_eStandardError);
rb_eKeyError = rb_define_class("KeyError", rb_eIndexError);
rb_eRangeError = rb_define_class("RangeError", rb_eStandardError);
rb_eEncCompatError = rb_define_class("EncodingCompatibilityError", rb_eStandardError);
rb_eScriptError = rb_define_class("ScriptError", rb_eException);
rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError);
@ -1057,6 +1056,7 @@ Init_Exception(void)
rb_eRuntimeError = rb_define_class("RuntimeError", rb_eStandardError);
rb_eSecurityError = rb_define_class("SecurityError", rb_eException);
rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException);
rb_eEncCompatError = rb_define_class_under(rb_cEncoding, "CompatibilityError", rb_eStandardError);
syserr_tbl = st_init_numtable();
rb_eSystemCallError = rb_define_class("SystemCallError", rb_eStandardError);

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

@ -982,6 +982,7 @@ RUBY_EXTERN VALUE rb_cCont;
RUBY_EXTERN VALUE rb_cDir;
RUBY_EXTERN VALUE rb_cData;
RUBY_EXTERN VALUE rb_cFalseClass;
RUBY_EXTERN VALUE rb_cEncoding;
RUBY_EXTERN VALUE rb_cEnumerator;
RUBY_EXTERN VALUE rb_cFile;
RUBY_EXTERN VALUE rb_cFixnum;

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

@ -144,19 +144,19 @@ EOT
end
def test_hex
assert_raise(EncodingCompatibilityError) {
assert_raise(Encoding::CompatibilityError) {
"ff".encode("utf-16le").hex
}
assert_raise(EncodingCompatibilityError) {
assert_raise(Encoding::CompatibilityError) {
"ff".encode("utf-16be").hex
}
end
def test_oct
assert_raise(EncodingCompatibilityError) {
assert_raise(Encoding::CompatibilityError) {
"77".encode("utf-16le").oct
}
assert_raise(EncodingCompatibilityError) {
assert_raise(Encoding::CompatibilityError) {
"77".encode("utf-16be").oct
}
end
@ -164,7 +164,7 @@ EOT
def test_count
s1 = "aa".force_encoding("utf-16be")
s2 = "aa"
assert_raise(EncodingCompatibilityError, "#{encdump s1}.count(#{encdump s2})") {
assert_raise(Encoding::CompatibilityError, "#{encdump s1}.count(#{encdump s2})") {
s1.count(s2)
}
end
@ -172,7 +172,7 @@ EOT
def test_plus
s1 = "a".force_encoding("us-ascii")
s2 = "aa".force_encoding("utf-16be")
assert_raise(EncodingCompatibilityError, "#{encdump s1} + #{encdump s2}") {
assert_raise(Encoding::CompatibilityError, "#{encdump s1} + #{encdump s2}") {
s1 + s2
}
end
@ -185,7 +185,7 @@ EOT
def test_interpolation
s = "aa".force_encoding("utf-16be")
assert_raise(EncodingCompatibilityError, "\"a\#{#{encdump s}}\"") {
assert_raise(Encoding::CompatibilityError, "\"a\#{#{encdump s}}\"") {
"a#{s}"
}
end
@ -213,7 +213,7 @@ EOT
def test_plus_nonempty
s1 = "aa"
s2 = "bb".force_encoding("utf-16be")
assert_raise(EncodingCompatibilityError, "#{encdump s1} << #{encdump s2}") {
assert_raise(Encoding::CompatibilityError, "#{encdump s1} << #{encdump s2}") {
s1 + s2
}
end
@ -237,7 +237,7 @@ EOT
def test_concat_nonempty
s1 = "aa"
s2 = "bb".force_encoding("utf-16be")
assert_raise(EncodingCompatibilityError, "#{encdump s1} << #{encdump s2}") {
assert_raise(Encoding::CompatibilityError, "#{encdump s1} << #{encdump s2}") {
s1 << s2
}
end
@ -279,7 +279,7 @@ EOT
s.gsub(Regexp.new(".".encode("utf-16be")), "xy")
}
s = "ab\0\ncd".force_encoding("utf-16be")
assert_raise(EncodingCompatibilityError) {
assert_raise(Encoding::CompatibilityError) {
s.gsub(Regexp.new(".".encode("utf-16be")), "xy")
}
end

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

@ -80,7 +80,7 @@ class TestEncodingConverter < Test::Unit::TestCase
name1 = "encoding-which-is-not-exist-1"
name2 = "encoding-which-is-not-exist-2"
assert_raise(Encoding::NoConverter) {
assert_raise(Encoding::NoConverterError) {
Encoding::Converter.new(name1, name2)
}
@ -513,7 +513,7 @@ class TestEncodingConverter < Test::Unit::TestCase
ec.primitive_convert("", dst, nil, 10, :partial_input=>true)
assert_equal("\e$B!!\e(B???\e$B!\"!!!\#$\"".force_encoding("ISO-2022-JP"), dst)
assert_raise(Encoding::ConversionUndefined) {
assert_raise(Encoding::ConversionUndefinedError) {
ec.insert_output("\uFFFD")
}
@ -524,7 +524,7 @@ class TestEncodingConverter < Test::Unit::TestCase
end
def test_exc_invalid
err = assert_raise(Encoding::InvalidByteSequence) {
err = assert_raise(Encoding::InvalidByteSequenceError) {
"abc\xa4def".encode("ISO-8859-1", "EUC-JP")
}
assert_equal("EUC-JP", err.source_encoding_name)
@ -537,7 +537,7 @@ class TestEncodingConverter < Test::Unit::TestCase
end
def test_exc_incomplete
err = assert_raise(Encoding::InvalidByteSequence) {
err = assert_raise(Encoding::InvalidByteSequenceError) {
"abc\xa4".encode("ISO-8859-1", "EUC-JP")
}
assert_equal("EUC-JP", err.source_encoding_name)
@ -550,7 +550,7 @@ class TestEncodingConverter < Test::Unit::TestCase
end
def test_exc_undef
err = assert_raise(Encoding::ConversionUndefined) {
err = assert_raise(Encoding::ConversionUndefinedError) {
"abc\xa4\xa2def".encode("ISO-8859-1", "EUC-JP")
}
assert_equal("UTF-8", err.source_encoding_name)
@ -657,8 +657,8 @@ class TestEncodingConverter < Test::Unit::TestCase
def test_convert
ec = Encoding::Converter.new("utf-8", "euc-jp")
assert_raise(Encoding::InvalidByteSequence) { ec.convert("a\x80") }
assert_raise(Encoding::ConversionUndefined) { ec.convert("\ufffd") }
assert_raise(Encoding::InvalidByteSequenceError) { ec.convert("a\x80") }
assert_raise(Encoding::ConversionUndefinedError) { ec.convert("\ufffd") }
ret = ec.primitive_convert(nil, "", nil, nil)
assert_equal(:finished, ret)
assert_raise(ArgumentError) { ec.convert("a") }
@ -674,28 +674,28 @@ class TestEncodingConverter < Test::Unit::TestCase
def test_finish_incomplete_error
ec = Encoding::Converter.new("utf-8", "euc-jp")
ec.convert("\xEF")
assert_raise(Encoding::InvalidByteSequence) { ec.finish }
assert_raise(Encoding::InvalidByteSequenceError) { ec.finish }
end
def test_last_error1
ec = Encoding::Converter.new("sjis", "euc-jp")
assert_equal(nil, ec.last_error)
assert_equal(:incomplete_input, ec.primitive_convert(src="fo\x81", dst="", nil, nil))
assert_kind_of(Encoding::InvalidByteSequence, ec.last_error)
assert_kind_of(Encoding::InvalidByteSequenceError, ec.last_error)
end
def test_last_error2
ec = Encoding::Converter.new("sjis", "euc-jp")
assert_equal("fo", ec.convert(src="fo\x81"))
assert_raise(Encoding::InvalidByteSequence) { ec.finish }
assert_kind_of(Encoding::InvalidByteSequence, ec.last_error)
assert_raise(Encoding::InvalidByteSequenceError) { ec.finish }
assert_kind_of(Encoding::InvalidByteSequenceError, ec.last_error)
end
def test_us_ascii
ec = Encoding::Converter.new("UTF-8", "US-ASCII")
ec.primitive_convert(src="\u{3042}", dst="")
err = ec.last_error
assert_kind_of(Encoding::ConversionUndefined, err)
assert_kind_of(Encoding::ConversionUndefinedError, err)
assert_equal("\u{3042}", err.error_char)
end
@ -703,7 +703,7 @@ class TestEncodingConverter < Test::Unit::TestCase
ec = Encoding::Converter.new("UTF-8", "ISO-8859-1")
ec.primitive_convert(src="\u{3042}", dst="")
err = ec.last_error
assert_kind_of(Encoding::ConversionUndefined, err)
assert_kind_of(Encoding::ConversionUndefinedError, err)
assert_equal("\u{3042}", err.error_char)
end

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

@ -374,7 +374,7 @@ EOT
with_pipe("euc-jp:utf-8") {|r, w|
w << "\xa1xyz"
w.close
err = assert_raise(Encoding::InvalidByteSequence) { r.getc }
err = assert_raise(Encoding::InvalidByteSequenceError) { r.getc }
assert_equal("\xA1".force_encoding("ascii-8bit"), err.error_bytes)
assert_equal("xyz", r.read(10))
}
@ -652,7 +652,7 @@ EOT
after = "\u{3046}\u{3048}"
w << before + invalid + after
w.close
err = assert_raise(Encoding::InvalidByteSequence) { r.gets }
err = assert_raise(Encoding::InvalidByteSequenceError) { r.gets }
assert_equal(invalid.force_encoding("ascii-8bit"), err.error_bytes)
assert_equal(after.encode("euc-jp"), r.gets)
}
@ -669,7 +669,7 @@ EOT
w.close
assert_equal(before1.encode("euc-jp"), r.getc)
assert_equal(before2.encode("euc-jp"), r.getc)
err = assert_raise(Encoding::InvalidByteSequence) { r.getc }
err = assert_raise(Encoding::InvalidByteSequenceError) { r.getc }
assert_equal(invalid.force_encoding("ascii-8bit"), err.error_bytes)
assert_equal(after1.encode("euc-jp"), r.getc)
assert_equal(after2.encode("euc-jp"), r.getc)
@ -688,7 +688,7 @@ EOT
w.close
assert_equal(before1.encode("euc-jp"), r.getc)
assert_equal(before2.encode("euc-jp"), r.getc)
err = assert_raise(Encoding::InvalidByteSequence) { r.getc }
err = assert_raise(Encoding::InvalidByteSequenceError) { r.getc }
assert_equal(invalid.force_encoding("ascii-8bit"), err.error_bytes)
assert_equal(after1.encode("euc-jp"), r.getc)
assert_equal(after2.encode("euc-jp"), r.getc)
@ -711,7 +711,7 @@ EOT
after = "\u{3046}\u{3048}"
w << before + invalid + after
w.close
err = assert_raise(Encoding::InvalidByteSequence) { r.read }
err = assert_raise(Encoding::InvalidByteSequenceError) { r.read }
assert_equal(invalid.force_encoding("ascii-8bit"), err.error_bytes)
assert_equal(after.encode("euc-jp"), r.read)
}
@ -1549,11 +1549,11 @@ EOT
assert_equal("ab", f.read)
}
open("t.txt", "r:utf-8:euc-jp", :undef => :replace) {|f|
assert_raise(Encoding::InvalidByteSequence) { f.read }
assert_raise(Encoding::InvalidByteSequenceError) { f.read }
assert_equal("b", f.read)
}
open("t.txt", "r:utf-8:euc-jp", :undef => :replace, :replace => "") {|f|
assert_raise(Encoding::InvalidByteSequence) { f.read }
assert_raise(Encoding::InvalidByteSequenceError) { f.read }
assert_equal("b", f.read)
}
}
@ -1569,11 +1569,11 @@ EOT
assert_equal("ab", f.read)
}
open("t.txt", "r:utf-8:euc-jp", :invalid => :replace) {|f|
assert_raise(Encoding::ConversionUndefined) { f.read }
assert_raise(Encoding::ConversionUndefinedError) { f.read }
assert_equal("b", f.read)
}
open("t.txt", "r:utf-8:euc-jp", :invalid => :replace, :replace => "") {|f|
assert_raise(Encoding::ConversionUndefined) { f.read }
assert_raise(Encoding::ConversionUndefinedError) { f.read }
assert_equal("b", f.read)
}
}
@ -1593,10 +1593,10 @@ EOT
assert_equal("ab", File.read("t.txt"))
open("t.txt", "w:euc-jp", :undef => :replace) {|f|
assert_raise(Encoding::InvalidByteSequence) { f.write invalid_utf8 }
assert_raise(Encoding::InvalidByteSequenceError) { f.write invalid_utf8 }
}
open("t.txt", "w:euc-jp", :undef => :replace, :replace => "") {|f|
assert_raise(Encoding::InvalidByteSequence) { f.write invalid_utf8 }
assert_raise(Encoding::InvalidByteSequenceError) { f.write invalid_utf8 }
}
}
end
@ -1613,10 +1613,10 @@ EOT
}
assert_equal("ab", File.read("t.txt"))
open("t.txt", "w:euc-jp:utf-8", :invalid => :replace) {|f|
assert_raise(Encoding::ConversionUndefined) { f.write "a\uFFFDb" }
assert_raise(Encoding::ConversionUndefinedError) { f.write "a\uFFFDb" }
}
open("t.txt", "w:euc-jp:utf-8", :invalid => :replace, :replace => "") {|f|
assert_raise(Encoding::ConversionUndefined) { f.write "a\uFFFDb" }
assert_raise(Encoding::ConversionUndefinedError) { f.write "a\uFFFDb" }
}
}
end
@ -1633,10 +1633,10 @@ EOT
}
assert_equal("ab", File.read("t.txt"))
open("t.txt", "w:iso-2022-jp:utf-8", :invalid => :replace) {|f|
assert_raise(Encoding::ConversionUndefined) { f.write "a\uFFFDb" }
assert_raise(Encoding::ConversionUndefinedError) { f.write "a\uFFFDb" }
}
open("t.txt", "w:iso-2022-jp:utf-8", :invalid => :replace, :replace => "") {|f|
assert_raise(Encoding::ConversionUndefined) { f.write "a\uFFFDb" }
assert_raise(Encoding::ConversionUndefinedError) { f.write "a\uFFFDb" }
}
}
end

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

@ -746,7 +746,7 @@ class TestM17N < Test::Unit::TestCase
#assert_raise(ArgumentError) { s("%c") % 0xc2a1 }
assert_strenc("\u{c2a1}", 'UTF-8', u("%c") % 0xc2a1)
assert_strenc("\u{c2}", 'UTF-8', u("%c") % 0xc2)
assert_raise(EncodingCompatibilityError) {
assert_raise(Encoding::CompatibilityError) {
"%s%s" % [s("\xc2\xa1"), e("\xc2\xa1")]
}
end
@ -866,22 +866,22 @@ class TestM17N < Test::Unit::TestCase
def test_str_aref_substr
assert_equal(a("\xa1\xc2"), a("\xc2\xa1\xc2\xa2\xc2\xa3")[a("\xa1\xc2")])
assert_raise(EncodingCompatibilityError) { a("\xc2\xa1\xc2\xa2\xc2\xa3")[e("\xa1\xc2")] }
assert_raise(Encoding::CompatibilityError) { a("\xc2\xa1\xc2\xa2\xc2\xa3")[e("\xa1\xc2")] }
assert_equal(nil, e("\xc2\xa1\xc2\xa2\xc2\xa3")[e("\xa1\xc2")])
assert_raise(EncodingCompatibilityError) { e("\xc2\xa1\xc2\xa2\xc2\xa3")[s("\xa1\xc2")] }
assert_raise(Encoding::CompatibilityError) { e("\xc2\xa1\xc2\xa2\xc2\xa3")[s("\xa1\xc2")] }
assert_equal(s("\xa1\xc2"), s("\xc2\xa1\xc2\xa2\xc2\xa3")[s("\xa1\xc2")])
assert_raise(EncodingCompatibilityError) { s("\xc2\xa1\xc2\xa2\xc2\xa3")[u("\xa1\xc2")] }
assert_raise(Encoding::CompatibilityError) { s("\xc2\xa1\xc2\xa2\xc2\xa3")[u("\xa1\xc2")] }
assert_equal(nil, u("\xc2\xa1\xc2\xa2\xc2\xa3")[u("\xa1\xc2")])
assert_raise(EncodingCompatibilityError) { u("\xc2\xa1\xc2\xa2\xc2\xa3")[a("\xa1\xc2")] }
assert_raise(Encoding::CompatibilityError) { u("\xc2\xa1\xc2\xa2\xc2\xa3")[a("\xa1\xc2")] }
assert_nil(e("\xa1\xa2\xa3\xa4")[e("\xa2\xa3")])
end
def test_aset
s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4")
assert_raise(EncodingCompatibilityError){s["\xb0\xa3"] = "foo"}
assert_raise(Encoding::CompatibilityError){s["\xb0\xa3"] = "foo"}
end
def test_str_center
@ -917,13 +917,13 @@ class TestM17N < Test::Unit::TestCase
def test_count
assert_equal(0, e("\xa1\xa2").count("z"))
s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4")
assert_raise(EncodingCompatibilityError){s.count(a("\xa3\xb0"))}
assert_raise(Encoding::CompatibilityError){s.count(a("\xa3\xb0"))}
end
def test_delete
assert_equal(1, e("\xa1\xa2").delete("z").length)
s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4")
assert_raise(EncodingCompatibilityError){s.delete(a("\xa3\xb2"))}
assert_raise(Encoding::CompatibilityError){s.delete(a("\xa3\xb2"))}
a = "\u3042\u3044\u3046\u3042\u3044\u3046"
a.delete!("\u3042\u3044", "^\u3044")
@ -942,7 +942,7 @@ class TestM17N < Test::Unit::TestCase
assert_nil(e("\xa1\xa2\xa3\xa4").index(e("\xa3")))
assert_nil(e("\xa1\xa2\xa3\xa4").rindex(e("\xa3")))
s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4")
assert_raise(EncodingCompatibilityError){s.rindex(a("\xb1\xa3"))}
assert_raise(Encoding::CompatibilityError){s.rindex(a("\xb1\xa3"))}
end
def test_next
@ -985,7 +985,7 @@ class TestM17N < Test::Unit::TestCase
def test_upto
s1 = e("\xa1\xa2")
s2 = s("\xa1\xa2")
assert_raise(EncodingCompatibilityError){s1.upto(s2) {|x| break }}
assert_raise(Encoding::CompatibilityError){s1.upto(s2) {|x| break }}
end
def test_casecmp
@ -1005,12 +1005,12 @@ class TestM17N < Test::Unit::TestCase
end
def test_plus
assert_raise(EncodingCompatibilityError){u("\xe3\x81\x82") + a("\xa1")}
assert_raise(Encoding::CompatibilityError){u("\xe3\x81\x82") + a("\xa1")}
end
def test_chomp
s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4")
assert_raise(EncodingCompatibilityError){s.chomp(s("\xa3\xb4"))}
assert_raise(Encoding::CompatibilityError){s.chomp(s("\xa3\xb4"))}
end
def test_gsub
@ -1023,7 +1023,7 @@ class TestM17N < Test::Unit::TestCase
t = s.gsub(/b/, "\xa1\xa1".force_encoding("euc-jp"))
assert_equal(Encoding::ASCII_8BIT, s.encoding)
assert_raise(EncodingCompatibilityError) {
assert_raise(Encoding::CompatibilityError) {
"abc".gsub(/[ac]/) {
$& == "a" ? "\xc2\xa1".force_encoding("euc-jp") :
"\xc2\xa1".force_encoding("utf-8")
@ -1044,7 +1044,7 @@ class TestM17N < Test::Unit::TestCase
def test_each_line
s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4")
assert_raise(EncodingCompatibilityError){s.each_line(a("\xa3\xb1")) {|l| }}
assert_raise(Encoding::CompatibilityError){s.each_line(a("\xa3\xb1")) {|l| }}
s = e("\xa4\xa2\nfoo")
actual = []

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

@ -261,7 +261,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_plus
combination(STRINGS, STRINGS) {|s1, s2|
if s1.encoding != s2.encoding && !s1.ascii_only? && !s2.ascii_only?
assert_raise(EncodingCompatibilityError) { s1 + s2 }
assert_raise(Encoding::CompatibilityError) { s1 + s2 }
else
t = enccall(s1, :+, s2)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
@ -344,7 +344,7 @@ class TestM17NComb < Test::Unit::TestCase
assert_equal(a(s), a(s1) + a(s2))
assert_str_enc_propagation(s, s1, s2)
else
assert_raise(EncodingCompatibilityError) { s << s2 }
assert_raise(Encoding::CompatibilityError) { s << s2 }
end
}
end
@ -396,7 +396,7 @@ class TestM17NComb < Test::Unit::TestCase
end
end
else
assert_raise(EncodingCompatibilityError) { s1[s2] }
assert_raise(Encoding::CompatibilityError) { s1[s2] }
end
}
end
@ -481,7 +481,7 @@ class TestM17NComb < Test::Unit::TestCase
end
end
else
assert_raise(EncodingCompatibilityError) { t[i] = s2 }
assert_raise(Encoding::CompatibilityError) { t[i] = s2 }
end
}
}
@ -513,7 +513,7 @@ class TestM17NComb < Test::Unit::TestCase
end
end
else
assert_raise(EncodingCompatibilityError) { t[i,len] = s2 }
assert_raise(Encoding::CompatibilityError) { t[i,len] = s2 }
end
}
end
@ -526,7 +526,7 @@ class TestM17NComb < Test::Unit::TestCase
!s2.ascii_only? ? s2.encoding : nil,
!s3.ascii_only? ? s3.encoding : nil].uniq.compact
if 1 < encs.length
assert_raise(EncodingCompatibilityError, IndexError) { t[s2] = s3 }
assert_raise(Encoding::CompatibilityError, IndexError) { t[s2] = s3 }
else
if encs.empty?
encs = [
@ -565,7 +565,7 @@ class TestM17NComb < Test::Unit::TestCase
end
end
else
assert_raise(EncodingCompatibilityError, RangeError,
assert_raise(Encoding::CompatibilityError, RangeError,
"t=#{encdump(s1)};t[#{first}..#{last}]=#{encdump(s2)}") {
t[first..last] = s2
}
@ -592,7 +592,7 @@ class TestM17NComb < Test::Unit::TestCase
end
end
else
assert_raise(EncodingCompatibilityError, RangeError,
assert_raise(Encoding::CompatibilityError, RangeError,
"t=#{encdump(s1)};t[#{first}...#{last}]=#{encdump(s2)}") {
t[first...last] = s2
}
@ -655,7 +655,7 @@ class TestM17NComb < Test::Unit::TestCase
next
end
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
assert_raise(EncodingCompatibilityError) { s1.center(width, s2) }
assert_raise(Encoding::CompatibilityError) { s1.center(width, s2) }
next
end
t = enccall(s1, :center, width, s2)
@ -676,7 +676,7 @@ class TestM17NComb < Test::Unit::TestCase
next
end
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
assert_raise(EncodingCompatibilityError) { s1.ljust(width, s2) }
assert_raise(Encoding::CompatibilityError) { s1.ljust(width, s2) }
next
end
t = enccall(s1, :ljust, width, s2)
@ -697,7 +697,7 @@ class TestM17NComb < Test::Unit::TestCase
next
end
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
assert_raise(EncodingCompatibilityError) { s1.rjust(width, s2) }
assert_raise(Encoding::CompatibilityError) { s1.rjust(width, s2) }
next
end
t = enccall(s1, :rjust, width, s2)
@ -711,7 +711,7 @@ class TestM17NComb < Test::Unit::TestCase
combination(STRINGS, STRINGS) {|s1, s2|
if !s1.ascii_only? && !s2.ascii_only? && !Encoding.compatible?(s1,s2)
if s1.bytesize > s2.bytesize
assert_raise(EncodingCompatibilityError) { s1.chomp(s2) }
assert_raise(Encoding::CompatibilityError) { s1.chomp(s2) }
end
next
end
@ -777,11 +777,11 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_count
combination(STRINGS, STRINGS) {|s1, s2|
if !s1.valid_encoding? || !s2.valid_encoding?
assert_raise(ArgumentError, EncodingCompatibilityError) { s1.count(s2) }
assert_raise(ArgumentError, Encoding::CompatibilityError) { s1.count(s2) }
next
end
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
assert_raise(EncodingCompatibilityError) { s1.count(s2) }
assert_raise(Encoding::CompatibilityError) { s1.count(s2) }
next
end
n = enccall(s1, :count, s2)
@ -809,11 +809,11 @@ class TestM17NComb < Test::Unit::TestCase
next
end
if !s1.valid_encoding? || !s2.valid_encoding?
assert_raise(ArgumentError, EncodingCompatibilityError) { s1.delete(s2) }
assert_raise(ArgumentError, Encoding::CompatibilityError) { s1.delete(s2) }
next
end
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
assert_raise(EncodingCompatibilityError) { s1.delete(s2) }
assert_raise(Encoding::CompatibilityError) { s1.delete(s2) }
next
end
t = enccall(s1, :delete, s2)
@ -855,11 +855,11 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_each_line
combination(STRINGS, STRINGS) {|s1, s2|
if !s1.valid_encoding? || !s2.valid_encoding?
assert_raise(ArgumentError, EncodingCompatibilityError) { s1.each_line(s2) {} }
assert_raise(ArgumentError, Encoding::CompatibilityError) { s1.each_line(s2) {} }
next
end
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
assert_raise(EncodingCompatibilityError) { s1.each_line(s2) {} }
assert_raise(Encoding::CompatibilityError) { s1.each_line(s2) {} }
next
end
lines = []
@ -908,9 +908,9 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_include?
combination(STRINGS, STRINGS) {|s1, s2|
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
assert_raise(EncodingCompatibilityError) { s1.include?(s2) }
assert_raise(EncodingCompatibilityError) { s1.index(s2) }
assert_raise(EncodingCompatibilityError) { s1.rindex(s2) }
assert_raise(Encoding::CompatibilityError) { s1.include?(s2) }
assert_raise(Encoding::CompatibilityError) { s1.index(s2) }
assert_raise(Encoding::CompatibilityError) { s1.rindex(s2) }
next
end
t = enccall(s1, :include?, s2)
@ -941,7 +941,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_index
combination(STRINGS, STRINGS, -2..2) {|s1, s2, pos|
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
assert_raise(EncodingCompatibilityError) { s1.index(s2) }
assert_raise(Encoding::CompatibilityError) { s1.index(s2) }
next
end
t = enccall(s1, :index, s2, pos)
@ -974,7 +974,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_rindex
combination(STRINGS, STRINGS, -2..2) {|s1, s2, pos|
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
assert_raise(EncodingCompatibilityError) { s1.rindex(s2) }
assert_raise(Encoding::CompatibilityError) { s1.rindex(s2) }
next
end
t = enccall(s1, :rindex, s2, pos)
@ -1023,11 +1023,11 @@ class TestM17NComb < Test::Unit::TestCase
t2 = s1.dup
begin
t1[nth, 0] = s2
rescue EncodingCompatibilityError, IndexError => e1
rescue Encoding::CompatibilityError, IndexError => e1
end
begin
t2.insert(nth, s2)
rescue EncodingCompatibilityError, IndexError => e2
rescue Encoding::CompatibilityError, IndexError => e2
end
assert_equal(t1, t2, "t=#{encdump s1}; t.insert(#{nth},#{encdump s2}); t")
assert_equal(e1.class, e2.class, "begin #{encdump s1}.insert(#{nth},#{encdump s2}); rescue ArgumentError, IndexError => e; e end")
@ -1041,7 +1041,7 @@ class TestM17NComb < Test::Unit::TestCase
t1.insert(nth, s2)
slen = s2.length
assert_equal(t1[nth-slen+1,slen], s2, "t=#{encdump s1}; t.insert(#{nth},#{encdump s2}); t")
rescue EncodingCompatibilityError, IndexError => e
rescue Encoding::CompatibilityError, IndexError => e
end
}
end
@ -1162,7 +1162,7 @@ class TestM17NComb < Test::Unit::TestCase
next
end
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
assert_raise(ArgumentError, EncodingCompatibilityError) { s1.split(s2) }
assert_raise(ArgumentError, Encoding::CompatibilityError) { s1.split(s2) }
next
end
if !s1.valid_encoding?
@ -1186,11 +1186,11 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_squeeze
combination(STRINGS, STRINGS) {|s1, s2|
if !s1.valid_encoding? || !s2.valid_encoding?
assert_raise(ArgumentError, EncodingCompatibilityError, "#{encdump s1}.squeeze(#{encdump s2})") { s1.squeeze(s2) }
assert_raise(ArgumentError, Encoding::CompatibilityError, "#{encdump s1}.squeeze(#{encdump s2})") { s1.squeeze(s2) }
next
end
if !s1.ascii_only? && !s2.ascii_only? && s1.encoding != s2.encoding
assert_raise(EncodingCompatibilityError) { s1.squeeze(s2) }
assert_raise(Encoding::CompatibilityError) { s1.squeeze(s2) }
next
end
t = enccall(s1, :squeeze, s2)
@ -1280,7 +1280,7 @@ class TestM17NComb < Test::Unit::TestCase
next
end
if !str_enc_compatible?(s1, s2, s3)
assert_raise(EncodingCompatibilityError, desc) { s1.tr(s2, s3) }
assert_raise(Encoding::CompatibilityError, desc) { s1.tr(s2, s3) }
next
end
if !s1.valid_encoding?
@ -1309,11 +1309,11 @@ class TestM17NComb < Test::Unit::TestCase
next
end
if !s1.valid_encoding?
assert_raise(ArgumentError, EncodingCompatibilityError, desc) { s1.tr_s(s2, s3) }
assert_raise(ArgumentError, Encoding::CompatibilityError, desc) { s1.tr_s(s2, s3) }
next
end
if !str_enc_compatible?(s1, s2, s3)
assert_raise(EncodingCompatibilityError, desc) { s1.tr(s2, s3) }
assert_raise(Encoding::CompatibilityError, desc) { s1.tr(s2, s3) }
next
end
if s2.empty?
@ -1423,7 +1423,7 @@ class TestM17NComb < Test::Unit::TestCase
next
end
if !str_enc_compatible?(s1.gsub(r2, ''), s3)
assert_raise(EncodingCompatibilityError, desc) { doit.call }
assert_raise(Encoding::CompatibilityError, desc) { doit.call }
next
end
t = nil
@ -1477,7 +1477,7 @@ class TestM17NComb < Test::Unit::TestCase
next
end
if !str_enc_compatible?(s1.gsub(r2, ''), s3)
assert_raise(EncodingCompatibilityError, desc) { doit.call }
assert_raise(Encoding::CompatibilityError, desc) { doit.call }
next
end
t = ret = nil
@ -1538,7 +1538,7 @@ class TestM17NComb < Test::Unit::TestCase
combination(STRINGS, STRINGS) {|s1, s2|
desc = "#{encdump s1}.end_with?(#{encdump s2})"
if !str_enc_compatible?(s1, s2)
assert_raise(EncodingCompatibilityError, desc) { s1.end_with?(s2) }
assert_raise(Encoding::CompatibilityError, desc) { s1.end_with?(s2) }
next
end
if s1.length < s2.length
@ -1557,7 +1557,7 @@ class TestM17NComb < Test::Unit::TestCase
combination(STRINGS, STRINGS) {|s1, s2|
desc = "#{encdump s1}.start_with?(#{encdump s2})"
if !str_enc_compatible?(s1, s2)
assert_raise(EncodingCompatibilityError, desc) { s1.start_with?(s2) }
assert_raise(Encoding::CompatibilityError, desc) { s1.start_with?(s2) }
next
end
s1 = s1.dup.force_encoding("ASCII-8BIT")
@ -1592,7 +1592,7 @@ class TestM17NComb < Test::Unit::TestCase
combination(STRINGS, STRINGS) {|s1, s2|
desc = "#{encdump s1}.partition(#{encdump s2})"
if !str_enc_compatible?(s1, s2)
assert_raise(EncodingCompatibilityError, desc) { s1.partition(s2) }
assert_raise(Encoding::CompatibilityError, desc) { s1.partition(s2) }
next
end
i = enccall(s1, :index, s2)
@ -1608,7 +1608,7 @@ class TestM17NComb < Test::Unit::TestCase
combination(STRINGS, STRINGS) {|s1, s2|
desc = "#{encdump s1}.rpartition(#{encdump s2})"
if !str_enc_compatible?(s1, s2)
assert_raise(EncodingCompatibilityError, desc) { s1.rpartition(s2) }
assert_raise(Encoding::CompatibilityError, desc) { s1.rpartition(s2) }
next
end
i = enccall(s1, :rindex, s2)

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

@ -1,4 +1,4 @@
# -*- coding: sjis -*-
# -*- coding: cp932 -*-
# This test is in a differnt file than TestUnicodeEscapes
# So that we can have a different coding comment above
@ -18,8 +18,8 @@ class TestMixedUnicodeEscape < Test::Unit::TestCase
# String interpolation turns into an expression and we get
# a different kind of error, but we still can't mix these
assert_raise(EncodingCompatibilityError) { eval %q("\u{1234}#{nil}é<>")}
assert_raise(EncodingCompatibilityError) { eval %q(<>#{nil}\u1234")}
assert_raise(Encoding::CompatibilityError) { eval %q("\u{1234}#{nil}é<>")}
assert_raise(Encoding::CompatibilityError) { eval %q(<>#{nil}\u1234")}
end
end

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

@ -21,13 +21,13 @@ class TestTranscode < Test::Unit::TestCase
def test_errors
assert_raise(ArgumentError) { 'abc'.encode }
assert_raise(ArgumentError) { 'abc'.encode! }
assert_raise(Encoding::NoConverter) { 'abc'.encode('foo', 'bar') }
assert_raise(Encoding::NoConverter) { 'abc'.encode!('foo', 'bar') }
assert_raise(Encoding::NoConverter) { 'abc'.force_encoding('utf-8').encode('foo') }
assert_raise(Encoding::NoConverter) { 'abc'.force_encoding('utf-8').encode!('foo') }
assert_raise(Encoding::ConversionUndefined) { "\x80".encode('utf-8','ASCII-8BIT') }
assert_raise(Encoding::InvalidByteSequence) { "\x80".encode('utf-8','US-ASCII') }
assert_raise(Encoding::ConversionUndefined) { "\xA5".encode('utf-8','iso-8859-3') }
assert_raise(Encoding::NoConverterError) { 'abc'.encode('foo', 'bar') }
assert_raise(Encoding::NoConverterError) { 'abc'.encode!('foo', 'bar') }
assert_raise(Encoding::NoConverterError) { 'abc'.force_encoding('utf-8').encode('foo') }
assert_raise(Encoding::NoConverterError) { 'abc'.force_encoding('utf-8').encode!('foo') }
assert_raise(Encoding::ConversionUndefinedError) { "\x80".encode('utf-8','ASCII-8BIT') }
assert_raise(Encoding::InvalidByteSequenceError) { "\x80".encode('utf-8','US-ASCII') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA5".encode('utf-8','iso-8859-3') }
end
def test_arguments
@ -355,24 +355,24 @@ class TestTranscode < Test::Unit::TestCase
check_both_ways("\u71FC", "\xE0\x9E", 'shift_jis') # 燼
check_both_ways("\u71F9", "\xE0\x9F", 'shift_jis') # 燹
check_both_ways("\u73F1", "\xE0\xFC", 'shift_jis') # 珱
assert_raise(Encoding::ConversionUndefined) { "\xEF\x40".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xEF\x7E".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xEF\x80".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xEF\x9E".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xEF\x9F".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xEF\xFC".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xF0\x40".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xF0\x7E".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xF0\x80".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xF0\x9E".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xF0\x9F".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xF0\xFC".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xEF\x40".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xEF\x7E".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xEF\x80".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xEF\x9E".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xEF\x9F".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xEF\xFC".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xF0\x40".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xF0\x7E".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xF0\x80".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xF0\x9E".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xF0\x9F".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xF0\xFC".encode("utf-8", 'shift_jis') }
#check_both_ways("\u9ADC", "\xFC\x40", 'shift_jis') # 髜 (IBM extended)
assert_raise(Encoding::ConversionUndefined) { "\xFC\x7E".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xFC\x80".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xFC\x9E".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xFC\x9F".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefined) { "\xFC\xFC".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xFC\x7E".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xFC\x80".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xFC\x9E".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xFC\x9F".encode("utf-8", 'shift_jis') }
assert_raise(Encoding::ConversionUndefinedError) { "\xFC\xFC".encode("utf-8", 'shift_jis') }
check_both_ways("\u677E\u672C\u884C\u5F18", "\x8f\xbc\x96\x7b\x8d\x73\x8d\x4f", 'shift_jis') # 松本行弘
check_both_ways("\u9752\u5C71\u5B66\u9662\u5927\u5B66", "\x90\xC2\x8E\x52\x8A\x77\x89\x40\x91\xE5\x8A\x77", 'shift_jis') # 青山学院大学
check_both_ways("\u795E\u6797\u7FA9\u535A", "\x90\x5F\x97\xD1\x8B\x60\x94\x8E", 'shift_jis') # 神林義博
@ -392,34 +392,34 @@ class TestTranscode < Test::Unit::TestCase
check_both_ways("\u00F7", "\xA1\xE0", 'euc-jp') # ÷
check_both_ways("\u25C7", "\xA1\xFE", 'euc-jp') # ◇
check_both_ways("\u25C6", "\xA2\xA1", 'euc-jp') # ◆
assert_raise(Encoding::ConversionUndefined) { "\xA2\xAF".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA2\xB9".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA2\xC2".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA2\xC9".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA2\xD1".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA2\xDB".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA2\xEB".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA2\xF1".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA2\xFA".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA2\xFD".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA2\xAF".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA2\xB9".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA2\xC2".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA2\xC9".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA2\xD1".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA2\xDB".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA2\xEB".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA2\xF1".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA2\xFA".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA2\xFD".encode("utf-8", 'euc-jp') }
check_both_ways("\u25EF", "\xA2\xFE", 'euc-jp') # ◯
assert_raise(Encoding::ConversionUndefined) { "\xA3\xAF".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA3\xBA".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA3\xC0".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA3\xDB".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA3\xE0".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA3\xFB".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA4\xF4".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA5\xF7".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA6\xB9".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA6\xC0".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA6\xD9".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA7\xC2".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA7\xD0".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA7\xF2".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xA8\xC1".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xCF\xD4".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefined) { "\xCF\xFE".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA3\xAF".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA3\xBA".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA3\xC0".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA3\xDB".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA3\xE0".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA3\xFB".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA4\xF4".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA5\xF7".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA6\xB9".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA6\xC0".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA6\xD9".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA7\xC2".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA7\xD0".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA7\xF2".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xA8\xC1".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xCF\xD4".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xCF\xFE".encode("utf-8", 'euc-jp') }
check_both_ways("\u6A97", "\xDD\xA1", 'euc-jp') # 檗
check_both_ways("\u6BEF", "\xDD\xDF", 'euc-jp') # 毯
check_both_ways("\u9EBE", "\xDD\xE0", 'euc-jp') # 麾
@ -432,7 +432,7 @@ class TestTranscode < Test::Unit::TestCase
check_both_ways("\u71FC", "\xDF\xFE", 'euc-jp') # 燼
check_both_ways("\u71F9", "\xE0\xA1", 'euc-jp') # 燹
check_both_ways("\u73F1", "\xE0\xFE", 'euc-jp') # 珱
assert_raise(Encoding::ConversionUndefined) { "\xF4\xA7".encode("utf-8", 'euc-jp') }
assert_raise(Encoding::ConversionUndefinedError) { "\xF4\xA7".encode("utf-8", 'euc-jp') }
#check_both_ways("\u9ADC", "\xFC\xE3", 'euc-jp') # 髜 (IBM extended)
check_both_ways("\u677E\u672C\u884C\u5F18", "\xBE\xBE\xCB\xDC\xB9\xD4\xB9\xB0", 'euc-jp') # 松本行弘
@ -491,33 +491,33 @@ class TestTranscode < Test::Unit::TestCase
end
def test_eucjp_sjis_undef
assert_raise(Encoding::ConversionUndefined) { "\x8e\xe0".encode("Shift_JIS", "EUC-JP") }
assert_raise(Encoding::ConversionUndefined) { "\x8e\xfe".encode("Shift_JIS", "EUC-JP") }
assert_raise(Encoding::ConversionUndefined) { "\x8f\xa1\xa1".encode("Shift_JIS", "EUC-JP") }
assert_raise(Encoding::ConversionUndefined) { "\x8f\xa1\xfe".encode("Shift_JIS", "EUC-JP") }
assert_raise(Encoding::ConversionUndefined) { "\x8f\xfe\xa1".encode("Shift_JIS", "EUC-JP") }
assert_raise(Encoding::ConversionUndefined) { "\x8f\xfe\xfe".encode("Shift_JIS", "EUC-JP") }
assert_raise(Encoding::ConversionUndefinedError) { "\x8e\xe0".encode("Shift_JIS", "EUC-JP") }
assert_raise(Encoding::ConversionUndefinedError) { "\x8e\xfe".encode("Shift_JIS", "EUC-JP") }
assert_raise(Encoding::ConversionUndefinedError) { "\x8f\xa1\xa1".encode("Shift_JIS", "EUC-JP") }
assert_raise(Encoding::ConversionUndefinedError) { "\x8f\xa1\xfe".encode("Shift_JIS", "EUC-JP") }
assert_raise(Encoding::ConversionUndefinedError) { "\x8f\xfe\xa1".encode("Shift_JIS", "EUC-JP") }
assert_raise(Encoding::ConversionUndefinedError) { "\x8f\xfe\xfe".encode("Shift_JIS", "EUC-JP") }
assert_raise(Encoding::ConversionUndefined) { "\xf0\x40".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefined) { "\xf0\x7e".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefined) { "\xf0\x80".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefined) { "\xf0\xfc".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefined) { "\xfc\x40".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefined) { "\xfc\x7e".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefined) { "\xfc\x80".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefined) { "\xfc\xfc".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefinedError) { "\xf0\x40".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefinedError) { "\xf0\x7e".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefinedError) { "\xf0\x80".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefinedError) { "\xf0\xfc".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefinedError) { "\xfc\x40".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefinedError) { "\xfc\x7e".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefinedError) { "\xfc\x80".encode("EUC-JP", "Shift_JIS") }
assert_raise(Encoding::ConversionUndefinedError) { "\xfc\xfc".encode("EUC-JP", "Shift_JIS") }
end
def test_iso_2022_jp
assert_raise(Encoding::InvalidByteSequence) { "\x1b(A".encode("utf-8", "iso-2022-jp") }
assert_raise(Encoding::InvalidByteSequence) { "\x1b$(A".encode("utf-8", "iso-2022-jp") }
assert_raise(Encoding::InvalidByteSequence) { "\x1b$C".encode("utf-8", "iso-2022-jp") }
assert_raise(Encoding::InvalidByteSequence) { "\x0e".encode("utf-8", "iso-2022-jp") }
assert_raise(Encoding::InvalidByteSequence) { "\x80".encode("utf-8", "iso-2022-jp") }
assert_raise(Encoding::InvalidByteSequence) { "\x1b$(Dd!\x1b(B".encode("utf-8", "iso-2022-jp") }
assert_raise(Encoding::ConversionUndefined) { "\u9299".encode("iso-2022-jp") }
assert_raise(Encoding::ConversionUndefined) { "\uff71\uff72\uff73\uff74\uff75".encode("iso-2022-jp") }
assert_raise(Encoding::InvalidByteSequence) { "\x1b(I12345\x1b(B".encode("utf-8", "iso-2022-jp") }
assert_raise(Encoding::InvalidByteSequenceError) { "\x1b(A".encode("utf-8", "iso-2022-jp") }
assert_raise(Encoding::InvalidByteSequenceError) { "\x1b$(A".encode("utf-8", "iso-2022-jp") }
assert_raise(Encoding::InvalidByteSequenceError) { "\x1b$C".encode("utf-8", "iso-2022-jp") }
assert_raise(Encoding::InvalidByteSequenceError) { "\x0e".encode("utf-8", "iso-2022-jp") }
assert_raise(Encoding::InvalidByteSequenceError) { "\x80".encode("utf-8", "iso-2022-jp") }
assert_raise(Encoding::InvalidByteSequenceError) { "\x1b$(Dd!\x1b(B".encode("utf-8", "iso-2022-jp") }
assert_raise(Encoding::ConversionUndefinedError) { "\u9299".encode("iso-2022-jp") }
assert_raise(Encoding::ConversionUndefinedError) { "\uff71\uff72\uff73\uff74\uff75".encode("iso-2022-jp") }
assert_raise(Encoding::InvalidByteSequenceError) { "\x1b(I12345\x1b(B".encode("utf-8", "iso-2022-jp") }
assert_equal("\xA1\xA1".force_encoding("euc-jp"),
"\e$B!!\e(B".encode("EUC-JP", "ISO-2022-JP"))
assert_equal("\e$B!!\e(B".force_encoding("ISO-2022-JP"),
@ -550,11 +550,11 @@ class TestTranscode < Test::Unit::TestCase
assert_equal("\u005C", "\e(J\x5C\e(B".encode("UTF-8", "ISO-2022-JP"))
assert_equal("\u005C", "\x5C".encode("stateless-ISO-2022-JP", "ISO-2022-JP"))
assert_equal("\u005C", "\e(J\x5C\e(B".encode("stateless-ISO-2022-JP", "ISO-2022-JP"))
assert_raise(Encoding::ConversionUndefined) { "\u00A5".encode("Shift_JIS") }
assert_raise(Encoding::ConversionUndefined) { "\u00A5".encode("Windows-31J") }
assert_raise(Encoding::ConversionUndefined) { "\u00A5".encode("EUC-JP") }
assert_raise(Encoding::ConversionUndefined) { "\u00A5".encode("eucJP-ms") }
assert_raise(Encoding::ConversionUndefined) { "\u00A5".encode("CP51932") }
assert_raise(Encoding::ConversionUndefinedError) { "\u00A5".encode("Shift_JIS") }
assert_raise(Encoding::ConversionUndefinedError) { "\u00A5".encode("Windows-31J") }
assert_raise(Encoding::ConversionUndefinedError) { "\u00A5".encode("EUC-JP") }
assert_raise(Encoding::ConversionUndefinedError) { "\u00A5".encode("eucJP-ms") }
assert_raise(Encoding::ConversionUndefinedError) { "\u00A5".encode("CP51932") }
# FULLWIDTH REVERSE SOLIDUS
check_both_ways("\uFF3C", "\x81\x5F", "Shift_JIS")
@ -575,11 +575,11 @@ class TestTranscode < Test::Unit::TestCase
assert_equal("\u007E", "\e(J\x7E\e(B".encode("UTF-8", "ISO-2022-JP"))
assert_equal("\u007E", "\x7E".encode("stateless-ISO-2022-JP", "ISO-2022-JP"))
assert_equal("\u007E", "\e(J\x7E\e(B".encode("stateless-ISO-2022-JP", "ISO-2022-JP"))
assert_raise(Encoding::ConversionUndefined) { "\u203E".encode("Shift_JIS") }
assert_raise(Encoding::ConversionUndefined) { "\u203E".encode("Windows-31J") }
assert_raise(Encoding::ConversionUndefined) { "\u203E".encode("EUC-JP") }
assert_raise(Encoding::ConversionUndefined) { "\u203E".encode("eucJP-ms") }
assert_raise(Encoding::ConversionUndefined) { "\u203E".encode("CP51932") }
assert_raise(Encoding::ConversionUndefinedError) { "\u203E".encode("Shift_JIS") }
assert_raise(Encoding::ConversionUndefinedError) { "\u203E".encode("Windows-31J") }
assert_raise(Encoding::ConversionUndefinedError) { "\u203E".encode("EUC-JP") }
assert_raise(Encoding::ConversionUndefinedError) { "\u203E".encode("eucJP-ms") }
assert_raise(Encoding::ConversionUndefinedError) { "\u203E".encode("CP51932") }
end
def test_nothing_changed

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

@ -14,9 +14,9 @@
#include "transcode_data.h"
#include <ctype.h>
VALUE rb_eConversionUndefined;
VALUE rb_eInvalidByteSequence;
VALUE rb_eNoConverter;
VALUE rb_eConversionUndefinedError;
VALUE rb_eInvalidByteSequenceError;
VALUE rb_eNoConverterError;
VALUE rb_cEncodingConverter;
@ -1960,7 +1960,7 @@ rb_econv_open_exc(const char *sname, const char *dname, int ecflags)
mesg = rb_str_new_cstr("code converter not found (");
econv_description(sname, dname, ecflags, mesg);
rb_str_cat2(mesg, ")");
exc = rb_exc_new3(rb_eNoConverter, mesg);
exc = rb_exc_new3(rb_eNoConverterError, mesg);
return exc;
}
@ -1997,7 +1997,7 @@ make_econv_exception(rb_econv_t *ec)
ec->last_error.source_encoding);
}
exc = rb_exc_new3(rb_eInvalidByteSequence, mesg);
exc = rb_exc_new3(rb_eInvalidByteSequenceError, mesg);
rb_ivar_set(exc, rb_intern("error_bytes"), bytes);
rb_ivar_set(exc, rb_intern("readagain_bytes"), bytes2);
rb_ivar_set(exc, rb_intern("incomplete_input"), ec->last_error.result == econv_incomplete_input ? Qtrue : Qfalse);
@ -2023,7 +2023,7 @@ make_econv_exception(rb_econv_t *ec)
StringValueCStr(dumped),
ec->last_error.source_encoding,
ec->last_error.destination_encoding);
exc = rb_exc_new3(rb_eConversionUndefined, mesg);
exc = rb_exc_new3(rb_eConversionUndefinedError, mesg);
idx = rb_enc_find_index(ec->last_error.source_encoding);
if (0 <= idx)
rb_enc_associate_index(bytes, idx);
@ -3381,8 +3381,8 @@ econv_primitive_convert(int argc, VALUE *argv, VALUE self)
* puts ec.finish.dump #=> "\e(B".force_encoding("ISO-2022-JP")
*
* If a conversion error occur,
* Encoding::ConversionUndefined or
* Encoding::InvalidByteSequence is raised.
* Encoding::ConversionUndefinedError or
* Encoding::InvalidByteSequenceError is raised.
*
*/
static VALUE
@ -3634,7 +3634,7 @@ econv_insert_output(VALUE self, VALUE string)
* some bytes are buffered to be converted later.
* The latter bytes can be put back.
* It can be observed by
* Encoding::InvalidByteSequence#readagain_bytes and
* Encoding::InvalidByteSequenceError#readagain_bytes and
* Encoding::Converter#primitive_errinfo.
*
* ec = Encoding::Converter.new("utf-16le", "iso-8859-1")
@ -3683,14 +3683,14 @@ econv_putback(int argc, VALUE *argv, VALUE self)
* It returns nil if the last conversion is not an error.
*
* "error" means that
* Encoding::InvalidByteSequence and Encoding::ConversionUndefined for
* Encoding::InvalidByteSequenceError and Encoding::ConversionUndefinedError for
* Encoding::Converter#convert and
* :invalid_byte_sequence, :incomplete_input and :undefined_conversion for
* Encoding::Converter#primitive_convert.
*
* ec = Encoding::Converter.new("utf-8", "iso-8859-1")
* p ec.primitive_convert(src="\xf1abcd", dst="") #=> :invalid_byte_sequence
* p ec.last_error #=> #<Encoding::InvalidByteSequence: "\xF1" followed by "a" on UTF-8>
* p ec.last_error #=> #<Encoding::InvalidByteSequenceError: "\xF1" followed by "a" on UTF-8>
* p ec.primitive_convert(src, dst, nil, 1) #=> :destination_buffer_full
* p ec.last_error #=> nil
*
@ -3728,7 +3728,7 @@ econv_get_replacement(VALUE self)
ret = make_replacement(ec);
if (ret == -1) {
rb_raise(rb_eConversionUndefined, "replacement character setup failed");
rb_raise(rb_eConversionUndefinedError, "replacement character setup failed");
}
enc = rb_enc_find(ec->replacement_enc);
@ -3762,8 +3762,8 @@ econv_set_replacement(VALUE self, VALUE arg)
rb_enc_name(enc));
if (ret == -1) {
/* xxx: rb_eInvalidByteSequence? */
rb_raise(rb_eConversionUndefined, "replacement character setup failed");
/* xxx: rb_eInvalidByteSequenceError? */
rb_raise(rb_eConversionUndefinedError, "replacement character setup failed");
}
return arg;
@ -3804,7 +3804,7 @@ ecerr_source_encoding_name(VALUE self)
* ec = Encoding::Converter.new("ISO-8859-1", "EUC-JP") # ISO-8859-1 -> UTF-8 -> EUC-JP
* begin
* ec.convert("\xa0") # NO-BREAK SPACE, which is available in UTF-8 but not in EUC-JP.
* rescue Encoding::ConversionUndefined
* rescue Encoding::ConversionUndefinedError
* p $!.source_encoding #=> #<Encoding:UTF-8>
* p $!.destination_encoding #=> #<Encoding:EUC-JP>
* p $!.source_encoding_name #=> "UTF-8"
@ -3846,12 +3846,12 @@ ecerr_destination_encoding(VALUE self)
* call-seq:
* ecerr.error_char -> string
*
* returns the one-character string which cause Encoding::ConversionUndefined.
* returns the one-character string which cause Encoding::ConversionUndefinedError.
*
* ec = Encoding::Converter.new("ISO-8859-1", "EUC-JP")
* begin
* ec.convert("\xa0")
* rescue Encoding::ConversionUndefined
* rescue Encoding::ConversionUndefinedError
* puts $!.error_char.dump #=> "\xC2\xA0"
* p $!.error_char.encoding #=> #<Encoding:UTF-8>
* end
@ -3867,13 +3867,13 @@ ecerr_error_char(VALUE self)
* call-seq:
* ecerr.error_bytes -> string
*
* returns the discarded bytes when Encoding::InvalidByteSequence occur.
* returns the discarded bytes when Encoding::InvalidByteSequenceError occur.
*
* ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
* begin
* ec.convert("abc\xA1\xFFdef")
* rescue Encoding::InvalidByteSequence
* p $! #=> #<Encoding::InvalidByteSequence: "\xA1" followed by "\xFF" on EUC-JP>
* rescue Encoding::InvalidByteSequenceError
* p $! #=> #<Encoding::InvalidByteSequenceError: "\xA1" followed by "\xFF" on EUC-JP>
* puts $!.error_bytes.dump #=> "\xA1"
* puts $!.readagain_bytes.dump #=> "\xFF"
* end
@ -3888,7 +3888,7 @@ ecerr_error_bytes(VALUE self)
* call-seq:
* ecerr.readagain_bytes -> string
*
* returns the bytes to be read again when Encoding::InvalidByteSequence occur.
* returns the bytes to be read again when Encoding::InvalidByteSequenceError occur.
*/
static VALUE
ecerr_readagain_bytes(VALUE self)
@ -3907,16 +3907,16 @@ ecerr_readagain_bytes(VALUE self)
*
* begin
* ec.convert("abc\xA1z")
* rescue Encoding::InvalidByteSequence
* p $! #=> #<Encoding::InvalidByteSequence: "\xA1" followed by "z" on EUC-JP>
* rescue Encoding::InvalidByteSequenceError
* p $! #=> #<Encoding::InvalidByteSequenceError: "\xA1" followed by "z" on EUC-JP>
* p $!.incomplete_input? #=> false
* end
*
* begin
* ec.convert("abc\xA1")
* ec.finish
* rescue Encoding::InvalidByteSequence
* p $! #=> #<Encoding::InvalidByteSequence: incomplete "\xA1" on EUC-JP>
* rescue Encoding::InvalidByteSequenceError
* p $! #=> #<Encoding::InvalidByteSequenceError: incomplete "\xA1" on EUC-JP>
* p $!.incomplete_input? #=> true
* end
*/
@ -3931,9 +3931,9 @@ extern void Init_newline(void);
void
Init_transcode(void)
{
rb_eConversionUndefined = rb_define_class_under(rb_cEncoding, "ConversionUndefined", rb_eStandardError);
rb_eInvalidByteSequence = rb_define_class_under(rb_cEncoding, "InvalidByteSequence", rb_eStandardError);
rb_eNoConverter = rb_define_class_under(rb_cEncoding, "NoConverter", rb_eStandardError);
rb_eConversionUndefinedError = rb_define_class_under(rb_cEncoding, "ConversionUndefinedError", rb_eStandardError);
rb_eInvalidByteSequenceError = rb_define_class_under(rb_cEncoding, "InvalidByteSequenceError", rb_eStandardError);
rb_eNoConverterError = rb_define_class_under(rb_cEncoding, "NoConverterError", rb_eStandardError);
transcoder_table = st_init_strcasetable();
@ -3993,19 +3993,19 @@ Init_transcode(void)
rb_define_const(rb_cEncodingConverter, "XML_ATTR_CONTENT_DECORATOR", INT2FIX(ECONV_XML_ATTR_CONTENT_DECORATOR));
rb_define_const(rb_cEncodingConverter, "XML_ATTR_QUOTE_DECORATOR", INT2FIX(ECONV_XML_ATTR_QUOTE_DECORATOR));
rb_define_method(rb_eConversionUndefined, "source_encoding_name", ecerr_source_encoding_name, 0);
rb_define_method(rb_eConversionUndefined, "destination_encoding_name", ecerr_destination_encoding_name, 0);
rb_define_method(rb_eConversionUndefined, "source_encoding", ecerr_source_encoding, 0);
rb_define_method(rb_eConversionUndefined, "destination_encoding", ecerr_destination_encoding, 0);
rb_define_method(rb_eConversionUndefined, "error_char", ecerr_error_char, 0);
rb_define_method(rb_eConversionUndefinedError, "source_encoding_name", ecerr_source_encoding_name, 0);
rb_define_method(rb_eConversionUndefinedError, "destination_encoding_name", ecerr_destination_encoding_name, 0);
rb_define_method(rb_eConversionUndefinedError, "source_encoding", ecerr_source_encoding, 0);
rb_define_method(rb_eConversionUndefinedError, "destination_encoding", ecerr_destination_encoding, 0);
rb_define_method(rb_eConversionUndefinedError, "error_char", ecerr_error_char, 0);
rb_define_method(rb_eInvalidByteSequence, "source_encoding_name", ecerr_source_encoding_name, 0);
rb_define_method(rb_eInvalidByteSequence, "destination_encoding_name", ecerr_destination_encoding_name, 0);
rb_define_method(rb_eInvalidByteSequence, "source_encoding", ecerr_source_encoding, 0);
rb_define_method(rb_eInvalidByteSequence, "destination_encoding", ecerr_destination_encoding, 0);
rb_define_method(rb_eInvalidByteSequence, "error_bytes", ecerr_error_bytes, 0);
rb_define_method(rb_eInvalidByteSequence, "readagain_bytes", ecerr_readagain_bytes, 0);
rb_define_method(rb_eInvalidByteSequence, "incomplete_input?", ecerr_incomplete_input, 0);
rb_define_method(rb_eInvalidByteSequenceError, "source_encoding_name", ecerr_source_encoding_name, 0);
rb_define_method(rb_eInvalidByteSequenceError, "destination_encoding_name", ecerr_destination_encoding_name, 0);
rb_define_method(rb_eInvalidByteSequenceError, "source_encoding", ecerr_source_encoding, 0);
rb_define_method(rb_eInvalidByteSequenceError, "destination_encoding", ecerr_destination_encoding, 0);
rb_define_method(rb_eInvalidByteSequenceError, "error_bytes", ecerr_error_bytes, 0);
rb_define_method(rb_eInvalidByteSequenceError, "readagain_bytes", ecerr_readagain_bytes, 0);
rb_define_method(rb_eInvalidByteSequenceError, "incomplete_input?", ecerr_incomplete_input, 0);
Init_newline();
}