From a16e0c29db3d5c7555362956ba62ea8f84f00cc7 Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 20 Apr 2008 03:51:57 +0000 Subject: * io.c (copy_stream_fallback): read directly (bypassing readpartial) if possible. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16088 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index d2292446fd..1fa164566b 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -417,9 +417,50 @@ class TestIO < Test::Unit::TestCase def test_copy_stream_strio_off src = StringIO.new("abcd") - dst = StringIO.new - assert_raise(ArgumentError) { - IO.copy_stream(src, dst, 3, 1) + with_pipe {|r, w| + assert_raise(ArgumentError) { + IO.copy_stream(src, w, 3, 1) + } + } + end + + def test_copy_stream_non_io + mkcdtmpdir {|d| + # filename to StringIO + File.open("foo", "w") {|f| f << "abcd" } + src = "foo" + dst = StringIO.new + ret = IO.copy_stream(src, dst, 3) + assert_equal(3, ret) + assert_equal("abc", dst.string) + + # StringIO to filename + src = StringIO.new("abcd") + ret = File.open("fooo", "w") {|dst| + IO.copy_stream(src, dst, 3) + } + assert_equal(3, ret) + assert_equal("abc", dst.string) + assert_equal(3, src.pos) + + # IO to StringIO + File.open("bar", "w") {|f| f << "abcd" } + File.open("bar") {|src| + dst = StringIO.new + ret = IO.copy_stream(src, dst, 3) + assert_equal(3, ret) + assert_equal("abc", dst.string) + assert_equal(3, src.pos) + } + + # StringIO to IO + src = StringIO.new("abcd") + ret = File.open("baz", "w") {|dst| + IO.copy_stream(src, dst, 3) + } + assert_equal(3, ret) + assert_equal("abc", File.read("baz")) + assert_equal(3, src.pos) } end -- cgit v1.2.3