diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-15 09:12:56 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-15 09:12:56 +0000 |
commit | 131e194cec5a36ac18d6c9abcae6aad6ccd5fd1d (patch) | |
tree | 46cafdd93d913930e75e194e7f43b8b207248243 /test/ruby/test_econv.rb | |
parent | d6d2eed78ef765f321b33ebdd2bdd9901dd5a39f (diff) | |
download | ruby-131e194cec5a36ac18d6c9abcae6aad6ccd5fd1d.tar.gz |
* include/ruby/encoding.h (rb_econv_t): new field: last_error.
* transcode.c (rb_trans_conv): new argument: result_position_ptr.
(rb_econv_convert): fill last_error.
(econv_result_to_symbol): extracted from econv_primitive_convert.
(econv_primitive_errinfo): new method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_econv.rb')
-rw-r--r-- | test/ruby/test_econv.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb index 3ae46b184c..0a797aecd6 100644 --- a/test/ruby/test_econv.rb +++ b/test/ruby/test_econv.rb @@ -20,6 +20,14 @@ class TestEncodingConverter < Test::Unit::TestCase [o, ret, i]) end + def assert_errinfo(e_res, e_enc1, e_enc2, e_error_bytes, e_readagain_bytes, e_partial_input, ec) + assert_equal([e_res, e_enc1, e_enc2, + e_error_bytes && e_error_bytes.dup.force_encoding("ASCII-8BIT"), + e_readagain_bytes && e_readagain_bytes.dup.force_encoding("ASCII-8BIT"), + e_partial_input], + ec.primitive_errinfo) + end + def test_new assert_kind_of(Encoding::Converter, Encoding::Converter.new("UTF-8", "EUC-JP")) assert_kind_of(Encoding::Converter, Encoding::Converter.new(Encoding::UTF_8, Encoding::EUC_JP)) @@ -319,4 +327,42 @@ class TestEncodingConverter < Test::Unit::TestCase check_ec("abc\xA4\xA2def", "", :output_followed_by_input, *a) check_ec("abc\xA4\xA2def", "", :finished, *a) end + + def test_errinfo_invalid_euc_jp + ec = Encoding::Converter.new("EUC-JP", "Shift_JIS") + ec.primitive_convert(src="\xff", dst="", nil, 10) + assert_errinfo(:invalid_byte_sequence, "EUC-JP", "UTF-8", "\xFF", "", nil, ec) + end + + def test_errinfo_undefined_hiragana + ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1") + ec.primitive_convert(src="\xa4\xa2", dst="", nil, 10) + assert_errinfo(:undefined_conversion, "UTF-8", "ISO-8859-1", "\xE3\x81\x82", "", nil, ec) + end + + def test_errinfo_invalid_partial_character + ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1") + ec.primitive_convert(src="\xa4", dst="", nil, 10) + assert_errinfo(:invalid_byte_sequence, "EUC-JP", "UTF-8", "\xA4", "", nil, ec) + end + + def test_errinfo_valid_partial_character + ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1") + ec.primitive_convert(src="\xa4", dst="", nil, 10, Encoding::Converter::PARTIAL_INPUT) + assert_errinfo(:source_buffer_empty, nil, nil, nil, nil, :partial_input, ec) + end + + def test_errinfo_invalid_utf16be + ec = Encoding::Converter.new("UTF-16BE", "UTF-8") + ec.primitive_convert(src="\xd8\x00\x00@", dst="", nil, 10) + assert_errinfo(:invalid_byte_sequence, "UTF-16BE", "UTF-8", "\xD8\x00", "\x00", nil, ec) + assert_equal("@", src) + end + + def test_errinfo_invalid_utf16le + ec = Encoding::Converter.new("UTF-16LE", "UTF-8") + ec.primitive_convert(src="\x00\xd8@\x00", dst="", nil, 10) + assert_errinfo(:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "@\x00", nil, ec) + assert_equal("", src) + end end |