diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-13 05:30:42 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-13 05:30:42 +0000 |
commit | 74a2a7bdbfbf70febab024354fe0b7fb26300704 (patch) | |
tree | 4b4ca9d7d11fe733e5ca1ec4cf78f372050a1636 /test/ruby/test_econv.rb | |
parent | ab0ee1d5e98183e0994765352998b5543cd7f02f (diff) | |
download | ruby-74a2a7bdbfbf70febab024354fe0b7fb26300704.tar.gz |
* enc/trans/newline.trans: new file.
* transcode_data.h (rb_trans_t): add last_tc field.
* transcode.c (UNIVERSAL_NEWLINE): defined.
(CRLF_NEWLINE): defined.
(CR_NEWLINE): defined.
(rb_trans_open_by_transcoder_entries): initialize last_tc.
(trans_open_i): allocate one more room for newline converter.
(rb_trans_open): universal newline implemented.
(more_output_buffer): take max_output argument instead ts.
(output_replacement_character): take tc argument instead of ts.
(transcode_loop): use last_tc field.
(econv_init): add flags argument for rb_trans_open.
(Init_transcode): Encoding::Converter::UNIVERSAL_NEWLINE defined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_econv.rb')
-rw-r--r-- | test/ruby/test_econv.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb index a4f86d1c93..8a09f1e9bb 100644 --- a/test/ruby/test_econv.rb +++ b/test/ruby/test_econv.rb @@ -4,7 +4,7 @@ class TestEncodingConverter < Test::Unit::TestCase def assert_econv(ret_expected, dst_expected, src_expected, to, from, src, opt={}) opt[:obuf_len] ||= 100 src = src.dup - ec = Encoding::Converter.new(from, to) + ec = Encoding::Converter.new(from, to, 0) dst = '' while true ret = ec.primitive_convert(src, dst2="", opt[:obuf_len], 0) @@ -35,7 +35,7 @@ class TestEncodingConverter < Test::Unit::TestCase end def test_errors - ec = Encoding::Converter.new("UTF-16BE", "EUC-JP") + ec = Encoding::Converter.new("UTF-16BE", "EUC-JP", 0) src = "\xFF\xFE\x00A\xDC\x00" ret = ec.primitive_convert(src, dst="", 10, 0) assert_equal("", src) @@ -50,4 +50,18 @@ class TestEncodingConverter < Test::Unit::TestCase assert_equal("", dst) assert_equal(:finished, ret) end + + def test_universal_newline + ec = Encoding::Converter.new("UTF-8", "EUC-JP", Encoding::Converter::UNIVERSAL_NEWLINE) + ret = ec.primitive_convert(src="abc\r\ndef", dst="", 50, Encoding::Converter::PARTIAL_INPUT) + assert_equal([:ibuf_empty, "", "abc\ndef"], [ret, src, dst]) + ret = ec.primitive_convert(src="ghi\njkl", dst="", 50, Encoding::Converter::PARTIAL_INPUT) + assert_equal([:ibuf_empty, "", "ghi\njkl"], [ret, src, dst]) + ret = ec.primitive_convert(src="mno\rpqr", dst="", 50, Encoding::Converter::PARTIAL_INPUT) + assert_equal([:ibuf_empty, "", "mno\npqr"], [ret, src, dst]) + ret = ec.primitive_convert(src="stu\r", dst="", 50, Encoding::Converter::PARTIAL_INPUT) + assert_equal([:ibuf_empty, "", "stu\n"], [ret, src, dst]) + ret = ec.primitive_convert(src="\nvwx", dst="", 50, Encoding::Converter::PARTIAL_INPUT) + assert_equal([:ibuf_empty, "", "vwx"], [ret, src, dst]) + end end |