From 071319fde18d319cf5c66702aeaf66ca1a880a2f Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 24 Aug 2008 09:40:31 +0000 Subject: * io.c (rb_io_s_pipe): accept optional hash. (rb_io_set_encoding): ditto. (rb_io_extract_modeenc): use rb_econv_opts to initialize ecopts. (rb_file_open_generic): ditto. (rb_file_open_internal): ditto. (io_encoding_set): new argument: opt. (argf_set_encoding): copy fptr->encs.opts to argf_ecopts. * transcode.c (rb_econv_opts): accept Qnil for initialization. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io_m17n.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/ruby/test_io_m17n.rb') diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index 93b6de0341..c2254545f3 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -219,6 +219,26 @@ EOT } end + def test_s_pipe_invalid + r, w = IO.pipe("utf-8", "euc-jp", :invalid=>:replace) + w << "\x80" + w.close + assert_equal("?", r.read) + ensure + r.close if r && !r.closed? + w.close if w && !w.closed? + end + + def test_s_pipe_undef + r, w = IO.pipe("utf-8:euc-jp", :undef=>:replace) + w << "\ufffd" + w.close + assert_equal("?", r.read) + ensure + r.close if r && !r.closed? + w.close if w && !w.closed? + end + def test_stdin assert_equal(Encoding.default_external, STDIN.external_encoding) assert_equal(nil, STDIN.internal_encoding) @@ -716,6 +736,24 @@ EOT } end + def test_set_encoding_invalid + with_pipe {|r, w| + w << "\x80" + w.close + r.set_encoding("utf-8:euc-jp", :invalid=>:replace) + assert_equal("?", r.read) + } + end + + def test_set_encoding_undef + with_pipe {|r, w| + w << "\ufffd" + w.close + r.set_encoding("utf-8", "euc-jp", :undef=>:replace) + assert_equal("?", r.read) + } + end + def test_write_conversion_fixenc with_pipe {|r, w| w.set_encoding("iso-2022-jp:utf-8") -- cgit v1.2.3