summaryrefslogtreecommitdiff
path: root/test/zlib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-25 02:02:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-25 02:02:55 +0000
commit91c6ba23336789f340878f69b5fee1defe0fa5d5 (patch)
tree0f6d71a98c547ef6b7886a99d242f3080aed1780 /test/zlib
parentaeb8d7f5e591915d7c4e290a3bee3185c84f0630 (diff)
* ext/zlib/zlib.c (gzreader_gets): support optional length
parameter. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30341 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/zlib')
-rw-r--r--test/zlib/test_zlib.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb
index 746dfba..68b44a1 100644
--- a/test/zlib/test_zlib.rb
+++ b/test/zlib/test_zlib.rb
@@ -588,6 +588,40 @@ if defined? Zlib
Zlib::GzipReader.open(t.path) do |f|
assert_equal("foo\nbar\nbaz\n", f.gets(nil))
end
+
+ Zlib::GzipReader.open(t.path) do |f|
+ assert_equal("foo\n", f.gets(10))
+ assert_equal("ba", f.gets(2))
+ assert_equal("r\nb", f.gets(nil, 3))
+ assert_equal("az\n", f.gets(nil, 10))
+ assert_nil(f.gets)
+ end
+ end
+
+ def test_gets2
+ t = Tempfile.new("test_zlib_gzip_reader_gets2")
+ t.close
+ ustrs = %W"\u{3042 3044 3046}\n \u{304b 304d 304f}\n \u{3055 3057 3059}\n"
+ Zlib::GzipWriter.open(t.path) {|gz| gz.print(*ustrs) }
+
+ Zlib::GzipReader.open(t.path, encoding: "UTF-8") do |f|
+ assert_equal(ustrs[0], f.gets)
+ assert_equal(ustrs[1], f.gets)
+ assert_equal(ustrs[2], f.gets)
+ assert_nil(f.gets)
+ end
+
+ Zlib::GzipReader.open(t.path, encoding: "UTF-8") do |f|
+ assert_equal(ustrs.join(''), f.gets(nil))
+ end
+
+ Zlib::GzipReader.open(t.path, encoding: "UTF-8") do |f|
+ assert_equal(ustrs[0], f.gets(20))
+ assert_equal(ustrs[1][0,2], f.gets(5))
+ assert_equal(ustrs[1][2..-1]+ustrs[2][0,1], f.gets(nil, 5))
+ assert_equal(ustrs[2][1..-1], f.gets(nil, 20))
+ assert_nil(f.gets)
+ end
end
def test_readline