summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-18 23:48:27 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-18 23:48:27 +0000
commitab0eb272f9e73123211574081aa8a0943678d80d (patch)
tree5fd6a149c40d1ffd25eb2531beb30fa17566a6d8 /test
parentaa883f84da4f3e4e82ecf2feaddca31d015f590e (diff)
* io.c (io_readpartial): Document the output buffer parameter is
overwritten with the read contents even when non-empty. Patch by yu nobuoka. [ruby-trunk - Bug #6285] * io.c (io_read_nonblock): ditto. * io.c (io_read): ditto. * io.c (rb_io_sysread): ditto. * io.c (argf_read): ditto. * io.c (argf_readpartial): ditto. * ext/stringio/stringio.c (strio_read): ditto. * test/ruby/test_argf.rb (class TestArgf): Add test for existing behavior of read outbuf. * test/ruby/test_io.rb (class TestIO): ditto. * test/stringio/test_stringio.rb (class TestStringIO): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_argf.rb12
-rw-r--r--test/ruby/test_io.rb41
-rw-r--r--test/stringio/test_stringio.rb13
3 files changed, 66 insertions, 0 deletions
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index 2f1ddf5391..284f34259e 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -446,6 +446,16 @@ class TestArgf < Test::Unit::TestCase
end
end
+ def test_read2_with_not_empty_buffer
+ ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+ s = "0123456789"
+ ARGF.read(8, s)
+ p s
+ SRC
+ assert_equal("\"1\\n2\\n3\\n4\\n\"\n", f.read)
+ end
+ end
+
def test_read3
ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
nil while ARGF.gets
@@ -463,6 +473,8 @@ class TestArgf < Test::Unit::TestCase
loop do
s << ARGF.readpartial(1)
t = ""; ARGF.readpartial(1, t); s << t
+ # not empty buffer
+ u = "abcdef"; ARGF.readpartial(1, u); s << u
end
rescue EOFError
puts s
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 0f4d5234a0..d984252cb5 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -991,6 +991,16 @@ class TestIO < Test::Unit::TestCase
}
end
+ def test_readpartial_with_not_empty_buffer
+ pipe(proc do |w|
+ w.write "foob"
+ w.close
+ end, proc do |r|
+ r.readpartial(5, s = "01234567")
+ assert_equal("foob", s)
+ end)
+ end
+
def test_readpartial_buffer_error
with_pipe do |r, w|
s = ""
@@ -1026,6 +1036,16 @@ class TestIO < Test::Unit::TestCase
end
end
+ def test_read_with_not_empty_buffer
+ pipe(proc do |w|
+ w.write "foob"
+ w.close
+ end, proc do |r|
+ r.read(nil, s = "01234567")
+ assert_equal("foob", s)
+ end)
+ end
+
def test_read_buffer_error
with_pipe do |r, w|
s = ""
@@ -1047,6 +1067,17 @@ class TestIO < Test::Unit::TestCase
end)
end
+ def test_read_nonblock_with_not_empty_buffer
+ skip "IO#read_nonblock is not supported on file/pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
+ pipe(proc do |w|
+ w.write "foob"
+ w.close
+ end, proc do |r|
+ r.read_nonblock(5, s = "01234567")
+ assert_equal("foob", s)
+ end)
+ end
+
def test_read_nonblock_error
return if !have_nonblock?
skip "IO#read_nonblock is not supported on file/pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
@@ -1417,6 +1448,16 @@ class TestIO < Test::Unit::TestCase
end
end
+ def test_sysread_with_not_empty_buffer
+ pipe(proc do |w|
+ w.write "foob"
+ w.close
+ end, proc do |r|
+ r.sysread( 5, s = "01234567" )
+ assert_equal( "foob", s )
+ end)
+ end
+
def test_flag
t = make_tempfile
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index 26fcc624e2..22cba382fb 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -426,6 +426,11 @@ class TestStringIO < Test::Unit::TestCase
s = ""
f.read(nil, s)
assert_equal("\u3042\u3044", s, bug5207)
+ f.rewind
+ # not empty buffer
+ s = "0123456789"
+ f.read(nil, s)
+ assert_equal("\u3042\u3044", s)
end
def test_readpartial
@@ -435,6 +440,10 @@ class TestStringIO < Test::Unit::TestCase
assert_equal("\u3042\u3044", f.readpartial)
f.rewind
assert_equal("\u3042\u3044".force_encoding(Encoding::ASCII_8BIT), f.readpartial(f.size))
+ f.rewind
+ # not empty buffer
+ s = '0123456789'
+ assert_equal("\u3042\u3044".force_encoding(Encoding::ASCII_8BIT), f.readpartial(f.size, s))
end
def test_read_nonblock
@@ -444,6 +453,10 @@ class TestStringIO < Test::Unit::TestCase
assert_equal("\u3042\u3044", f.read_nonblock)
f.rewind
assert_equal("\u3042\u3044".force_encoding(Encoding::ASCII_8BIT), f.read_nonblock(f.size))
+ f.rewind
+ # not empty buffer
+ s = '0123456789'
+ assert_equal("\u3042\u3044".force_encoding(Encoding::ASCII_8BIT), f.read_nonblock(f.size, s))
end
def test_size