From 91c6ba23336789f340878f69b5fee1defe0fa5d5 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 25 Dec 2010 02:02:55 +0000 Subject: * 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 --- test/zlib/test_zlib.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'test/zlib/test_zlib.rb') diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb index 746dfba844..68b44a1c32 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 -- cgit v1.2.3