diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-14 06:12:27 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-14 06:12:27 +0000 |
commit | bea2fa9b48b47e9eb49d80d33cd40a907a146bf6 (patch) | |
tree | 2d863ac9d8e89479dd6b0c476935f642c616376a /test/ruby | |
parent | 4b514ef442fe3e1cd2a456824155606a80ff807a (diff) | |
download | ruby-bea2fa9b48b47e9eb49d80d33cd40a907a146bf6.tar.gz ruby-bea2fa9b48b47e9eb49d80d33cd40a907a146bf6.tar.xz ruby-bea2fa9b48b47e9eb49d80d33cd40a907a146bf6.zip |
* transcode_data.h (rb_trans_result_t): new enumeration constant:
transcode_output_followed_by_input.
* transcode.c (OUTPUT_FOLLOWED_BY_INPUT): new flag.
(transcode_restartable0): suspend when output followed by input if
OUTPUT_FOLLOWED_BY_INPUT is specified.
(trans_sweep): check OUTPUT_FOLLOWED_BY_INPUT.
(rb_trans_conv): support OUTPUT_FOLLOWED_BY_INPUT.
(econv_primitive_convert): return :output_followed_by_input for
transcode_output_followed_by_input.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_econv.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb index 3061f8ea1..44cc12035 100644 --- a/test/ruby/test_econv.rb +++ b/test/ruby/test_econv.rb @@ -70,6 +70,19 @@ class TestEncodingConverter < Test::Unit::TestCase assert_econv("", :finished, 100, ["Shift_JIS", "ISO-2022-JP"], "", "") end + def test_iso2022jp_outstream + ec = Encoding::Converter.new("EUC-JP", "ISO-2022-JP") + a = ["", src="", ec, nil, 50, Encoding::Converter::PARTIAL_INPUT] + src << "a"; check_ec("a", "", :ibuf_empty, *a) + src << "\xA2"; check_ec("a", "", :ibuf_empty, *a) + src << "\xA4"; check_ec("a\e$B\"$", "", :ibuf_empty, *a) + src << "\xA1"; check_ec("a\e$B\"$", "", :ibuf_empty, *a) + src << "\xA2"; check_ec("a\e$B\"$!\"", "", :ibuf_empty, *a) + src << "b"; check_ec("a\e$B\"$!\"\e(Bb", "", :ibuf_empty, *a) + src << "\xA2\xA6"; check_ec("a\e$B\"$!\"\e(Bb\e$B\"&", "", :ibuf_empty, *a) + a[-1] = 0; check_ec("a\e$B\"$!\"\e(Bb\e$B\"&\e(B", "", :finished, *a) + end + def test_invalid assert_econv("", :invalid_input, 100, ["UTF-8", "EUC-JP"], "\x80", "") assert_econv("a", :invalid_input, 100, ["UTF-8", "EUC-JP"], "a\x80", "") @@ -98,6 +111,16 @@ class TestEncodingConverter < Test::Unit::TestCase check_ec("AB", "", :finished, *a) end + def test_errors2 + ec = Encoding::Converter.new("UTF-16BE", "EUC-JP") + a = ["", "\xFF\xFE\x00A\xDC\x00\x00B", ec, nil, 10, Encoding::Converter::OUTPUT_FOLLOWED_BY_INPUT] + check_ec("", "\x00A\xDC\x00\x00B", :undefined_conversion, *a) + check_ec("A", "\xDC\x00\x00B", :output_followed_by_input, *a) + check_ec("A", "\x00B", :invalid_input, *a) + check_ec("AB", "", :output_followed_by_input, *a) + check_ec("AB", "", :finished, *a) + end + def test_universal_newline ec = Encoding::Converter.new("UTF-8", "EUC-JP", Encoding::Converter::UNIVERSAL_NEWLINE) a = ["", src="", ec, nil, 50, Encoding::Converter::PARTIAL_INPUT] @@ -118,4 +141,17 @@ class TestEncodingConverter < Test::Unit::TestCase ec = Encoding::Converter.new("UTF-8", "EUC-JP", Encoding::Converter::CR_NEWLINE) assert_econv("abc\rdef", :finished, 50, ec, "abc\ndef", "") end + + def test_output_followed_by_input + ec = Encoding::Converter.new("UTF-8", "EUC-JP") + a = ["", "abc\u{3042}def", ec, nil, 100, Encoding::Converter::OUTPUT_FOLLOWED_BY_INPUT] + check_ec("a", "bc\u{3042}def", :output_followed_by_input, *a) + check_ec("ab", "c\u{3042}def", :output_followed_by_input, *a) + check_ec("abc", "\u{3042}def", :output_followed_by_input, *a) + check_ec("abc\xA4\xA2", "def", :output_followed_by_input, *a) + check_ec("abc\xA4\xA2d", "ef", :output_followed_by_input, *a) + check_ec("abc\xA4\xA2de", "f", :output_followed_by_input, *a) + check_ec("abc\xA4\xA2def", "", :output_followed_by_input, *a) + check_ec("abc\xA4\xA2def", "", :finished, *a) + end end |