summaryrefslogtreecommitdiffstats
path: root/test/ruby
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-20 03:51:57 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-20 03:51:57 +0000
commit2486fe540072d78ab04703dde94722dfdca618ae (patch)
treec1e4fdd6a6d87e317e93ac513f16a382ee5cd399 /test/ruby
parent62ecf80478cb6c5162d1445be6c2d1d1aac86171 (diff)
downloadruby-2486fe540072d78ab04703dde94722dfdca618ae.tar.gz
ruby-2486fe540072d78ab04703dde94722dfdca618ae.tar.xz
ruby-2486fe540072d78ab04703dde94722dfdca618ae.zip
* io.c (copy_stream_fallback): read directly (bypassing readpartial)
if possible. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16088 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_io.rb47
1 files changed, 44 insertions, 3 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index d2292446f..1fa164566 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