From 89c2ab70a44914663d1d1e3b4f0579f30cbdb4b7 Mon Sep 17 00:00:00 2001 From: yugui Date: Thu, 1 Jan 2009 06:42:23 +0000 Subject: merges r21209 from trunk into ruby_1_9_1. * io.c (copy_stream_body): don't check to_io because Zlib::GzipWriter#to_io returns the underlying IO. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@21229 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'test') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 40808da772..073ca20314 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -526,6 +526,69 @@ class TestIO < Test::Unit::TestCase } end + class Rot13IO + def initialize(io) + @io = io + end + + def readpartial(*args) + ret = @io.readpartial(*args) + ret.tr!('a-zA-Z', 'n-za-mN-ZA-M') + ret + end + + def write(str) + @io.write(str.tr('a-zA-Z', 'n-za-mN-ZA-M')) + end + + def to_io + @io + end + end + + def test_copy_stream_io_to_rot13 + mkcdtmpdir { + File.open("bar", "w") {|f| f << "vex" } + File.open("bar") {|src| + File.open("baz", "w") {|dst0| + dst = Rot13IO.new(dst0) + ret = IO.copy_stream(src, dst, 3) + assert_equal(3, ret) + } + assert_equal("irk", File.read("baz")) + } + } + end + + def test_copy_stream_rot13_to_io + mkcdtmpdir { + File.open("bar", "w") {|f| f << "flap" } + File.open("bar") {|src0| + src = Rot13IO.new(src0) + File.open("baz", "w") {|dst| + ret = IO.copy_stream(src, dst, 4) + assert_equal(4, ret) + } + } + assert_equal("sync", File.read("baz")) + } + end + + def test_copy_stream_rot13_to_rot13 + mkcdtmpdir { + File.open("bar", "w") {|f| f << "bin" } + File.open("bar") {|src0| + src = Rot13IO.new(src0) + File.open("baz", "w") {|dst0| + dst = Rot13IO.new(dst0) + ret = IO.copy_stream(src, dst, 3) + assert_equal(3, ret) + } + } + assert_equal("bin", File.read("baz")) + } + end + def test_copy_stream_strio_flush with_pipe {|r, w| w.sync = false -- cgit v1.2.3