summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-07 17:48:11 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-07 17:48:11 +0000
commitadd77a592bee645aa6787130db384afc11482a04 (patch)
treeab6fe0e36968c1048a5622691cfca98b1752ef02 /test
parent4764756497ace72f8578ab886ae1e8b45c2def7c (diff)
* include/ruby/encoding.h (ECONV_NEWLINE_DECORATOR_READ_MASK,
ECONV_NEWLINE_DECORATOR_WRITE_MASK): new macro. * io.c (rb_io_extract_modeenc, pipe_open, prep_stdio, argf_next_argv): set TEXTMODE_NEWLINE_DECORATOR_ON_WRITE for textmode on creating IO if the flag is available. * io.c (make_writeconv): drop decorators for reading. * io.c (make_readconv): drop decorators for writing. * io.c (do_writeconv): existing writeconv is not the condition to raise ArgumentError. should check textmode or not. * test/ruby/test_io_m17n.rb (TestIO_M17N#test_{cr,lf,crlf}_decorator_on_stdout): test above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_io_m17n.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index ecf34c793f..18f84c6253 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -2117,4 +2117,61 @@ EOT
end
end
end if /mswin|mingw/ =~ RUBY_PLATFORM
+
+ def test_cr_decorator_on_stdout
+ with_pipe do |in_r, in_w|
+ with_pipe do |out_r, out_w|
+ pid = Process.spawn({}, EnvUtil.rubybin, in: in_r, out: out_w)
+ in_r.close
+ out_w.close
+ in_w.write <<-EOS
+ STDOUT.set_encoding('locale', nil, newline: :cr)
+ STDOUT.puts "abc"
+ STDOUT.flush
+ EOS
+ in_w.close
+ Process.wait pid
+ assert_equal "abc\r", out_r.binmode.read
+ out_r.close
+ end
+ end
+ end
+
+ def test_lf_decorator_on_stdout
+ with_pipe do |in_r, in_w|
+ with_pipe do |out_r, out_w|
+ pid = Process.spawn({}, EnvUtil.rubybin, in: in_r, out: out_w)
+ in_r.close
+ out_w.close
+ in_w.write <<-EOS
+ STDOUT.set_encoding('locale', nil, newline: :lf)
+ STDOUT.puts "abc"
+ STDOUT.flush
+ EOS
+ in_w.close
+ Process.wait pid
+ assert_equal "abc\n", out_r.binmode.read
+ out_r.close
+ end
+ end
+ end
+
+ def test_crlf_decorator_on_stdout
+ with_pipe do |in_r, in_w|
+ with_pipe do |out_r, out_w|
+ pid = Process.spawn({}, EnvUtil.rubybin, in: in_r, out: out_w)
+ in_r.close
+ out_w.close
+ in_w.write <<-EOS
+ STDOUT.set_encoding('locale', nil, newline: :crlf)
+ STDOUT.puts "abc"
+ STDOUT.flush
+ EOS
+ in_w.close
+ Process.wait pid
+ assert_equal "abc\r\n", out_r.binmode.read
+ out_r.close
+ end
+ end
+ end
end