From 790a018902aa6d6aaa2a327875ee314ec219c97c Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 18 Aug 2008 12:06:42 +0000 Subject: * include/ruby/io.h (rb_io_t): new fields: writeconv, writeconv_stateless and writeconv_initialized. (MakeOpenFile): initialize them. * include/ruby/encoding.h (rb_econv_stateless_encoding): declared. (rb_econv_string): declared. * io.c (make_writeconv): new function. (io_fwrite): use econv. (make_readconv): fix error message. (finish_writeconv): new function. (fptr_finalize): call finish_writeconv. (clear_writeconv): new function. (clear_codeconv): new function to call both clear_readconv and clear_writeconv. (rb_io_fptr_finalize): call clear_codeconv instead of clear_readconv. (mode_enc): ditto. (io_set_encoding): ditto. (argf_next_argv): ditto. (io_encoding_set): ditto. * gc.c (gc_mark_children): mark writeconv_stateless in T_FILE. * transcode.c (stateless_encoding_i): new function. (rb_econv_stateless_encoding): ditto. (rb_econv_string): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io_m17n.rb | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index e982722cf..070987ad3 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -601,5 +601,50 @@ EOT } end + def test_write_conversion_fixenc + with_pipe {|r, w| + w.set_encoding("iso-2022-jp:utf-8") + t = Thread.new { r.read.force_encoding("ascii-8bit") } + w << "\u3042" + w << "\u3044" + w.close + assert_equal("\e$B$\"$$\e(B".force_encoding("ascii-8bit"), t.value) + } + end + + def test_write_conversion_anyenc_stateful + with_pipe {|r, w| + w.set_encoding("iso-2022-jp") + t = Thread.new { r.read.force_encoding("ascii-8bit") } + w << "\u3042" + w << "\x82\xa2".force_encoding("sjis") + w.close + assert_equal("\e$B$\"$$\e(B".force_encoding("ascii-8bit"), t.value) + } + end + + def test_write_conversion_anyenc_stateless + with_pipe {|r, w| + w.set_encoding("euc-jp") + t = Thread.new { r.read.force_encoding("ascii-8bit") } + w << "\u3042" + w << "\x82\xa2".force_encoding("sjis") + w.close + assert_equal("\xa4\xa2\xa4\xa4".force_encoding("ascii-8bit"), t.value) + } + end + + def test_write_conversion_anyenc_stateful_nosync + with_pipe {|r, w| + w.sync = false + w.set_encoding("iso-2022-jp") + t = Thread.new { r.read.force_encoding("ascii-8bit") } + w << "\u3042" + w << "\x82\xa2".force_encoding("sjis") + w.close + assert_equal("\e$B$\"$$\e(B".force_encoding("ascii-8bit"), t.value) + } + end + end -- cgit