diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-20 03:51:57 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-20 03:51:57 +0000 |
commit | a16e0c29db3d5c7555362956ba62ea8f84f00cc7 (patch) | |
tree | c1e4fdd6a6d87e317e93ac513f16a382ee5cd399 /test | |
parent | 9579647fe18b29d946d7905f0d233bd37463a504 (diff) | |
download | ruby-a16e0c29db3d5c7555362956ba62ea8f84f00cc7.tar.gz |
* 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
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_io.rb | 47 |
1 files changed, 44 insertions, 3 deletions
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 |