summaryrefslogtreecommitdiff
path: root/spec/ruby/library/zlib/gzipreader
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/zlib/gzipreader')
-rw-r--r--spec/ruby/library/zlib/gzipreader/each_char_spec.rb51
-rw-r--r--spec/ruby/library/zlib/gzipreader/each_line_spec.rb8
-rw-r--r--spec/ruby/library/zlib/gzipreader/each_spec.rb48
-rw-r--r--spec/ruby/library/zlib/gzipreader/eof_spec.rb29
-rw-r--r--spec/ruby/library/zlib/gzipreader/getc_spec.rb2
-rw-r--r--spec/ruby/library/zlib/gzipreader/gets_spec.rb2
-rw-r--r--spec/ruby/library/zlib/gzipreader/mtime_spec.rb11
-rw-r--r--spec/ruby/library/zlib/gzipreader/new_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipreader/read_spec.rb6
-rw-r--r--spec/ruby/library/zlib/gzipreader/shared/each.rb49
-rw-r--r--spec/ruby/library/zlib/gzipreader/tell_spec.rb9
-rw-r--r--spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb4
-rw-r--r--spec/ruby/library/zlib/gzipreader/ungetc_spec.rb12
13 files changed, 154 insertions, 78 deletions
diff --git a/spec/ruby/library/zlib/gzipreader/each_char_spec.rb b/spec/ruby/library/zlib/gzipreader/each_char_spec.rb
new file mode 100644
index 0000000000..de6396da7e
--- /dev/null
+++ b/spec/ruby/library/zlib/gzipreader/each_char_spec.rb
@@ -0,0 +1,51 @@
+require_relative '../../../spec_helper'
+require 'stringio'
+require 'zlib'
+
+describe "Zlib::GzipReader#each_char" do
+
+ before :each do
+ @data = '12345abcde'
+ @zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77,
+ 76, 74, 78, 73, 5, 0, 157, 5, 0, 36, 10, 0, 0, 0].pack('C*')
+
+ @io = StringIO.new @zip
+ ScratchPad.clear
+ end
+
+ it "calls the given block for each char in the stream, passing the char as an argument" do
+ gz = Zlib::GzipReader.new @io
+
+ ScratchPad.record []
+ gz.each_char { |b| ScratchPad << b }
+
+ ScratchPad.recorded.should == ["1", "2", "3", "4", "5", "a", "b", "c", "d", "e"]
+ end
+
+ it "returns an enumerator, which yields each char in the stream, when no block is passed" do
+ gz = Zlib::GzipReader.new @io
+ enum = gz.each_char
+
+ ScratchPad.record []
+ while true
+ begin
+ ScratchPad << enum.next
+ rescue StopIteration
+ break
+ end
+ end
+
+ ScratchPad.recorded.should == ["1", "2", "3", "4", "5", "a", "b", "c", "d", "e"]
+ end
+
+ it "increments position before calling the block" do
+ gz = Zlib::GzipReader.new @io
+
+ i = 1
+ gz.each_char do |ignore|
+ gz.pos.should == i
+ i += 1
+ end
+ end
+
+end
diff --git a/spec/ruby/library/zlib/gzipreader/each_line_spec.rb b/spec/ruby/library/zlib/gzipreader/each_line_spec.rb
index efaf27d6bb..97f24d410f 100644
--- a/spec/ruby/library/zlib/gzipreader/each_line_spec.rb
+++ b/spec/ruby/library/zlib/gzipreader/each_line_spec.rb
@@ -1,5 +1,9 @@
-require_relative 'shared/each'
+require_relative "../../../spec_helper"
+require 'zlib'
describe "Zlib::GzipReader#each_line" do
- it_behaves_like :gzipreader_each, :each_line
+ it "is an alias of Zlib::GzipReader#each" do
+ Zlib::GzipReader.instance_method(:each_line).should ==
+ Zlib::GzipReader.instance_method(:each)
+ end
end
diff --git a/spec/ruby/library/zlib/gzipreader/each_spec.rb b/spec/ruby/library/zlib/gzipreader/each_spec.rb
index 59aa63e52c..75fd7e6bae 100644
--- a/spec/ruby/library/zlib/gzipreader/each_spec.rb
+++ b/spec/ruby/library/zlib/gzipreader/each_spec.rb
@@ -1,5 +1,49 @@
-require_relative 'shared/each'
+require_relative "../../../spec_helper"
+require 'stringio'
+require 'zlib'
describe "Zlib::GzipReader#each" do
- it_behaves_like :gzipreader_each, :each
+ before :each do
+ @data = "firstline\nsecondline\n\nforthline"
+ @zip = [31, 139, 8, 0, 244, 125, 128, 88, 2, 255, 75, 203, 44, 42, 46, 201,
+ 201, 204, 75, 229, 42, 78, 77, 206, 207, 75, 1, 51, 185, 210,242,
+ 139, 74, 50, 64, 76, 0, 180, 54, 61, 111, 31, 0, 0, 0].pack('C*')
+
+ @io = StringIO.new @zip
+ @gzreader = Zlib::GzipReader.new @io
+ end
+
+ after :each do
+ ScratchPad.clear
+ end
+
+ it "calls the given block for each line in the stream, passing the line as an argument" do
+ ScratchPad.record []
+ @gzreader.each { |b| ScratchPad << b }
+
+ ScratchPad.recorded.should == ["firstline\n", "secondline\n", "\n", "forthline"]
+ end
+
+ it "returns an enumerator, which yields each byte in the stream, when no block is passed" do
+ enum = @gzreader.each
+
+ ScratchPad.record []
+ while true
+ begin
+ ScratchPad << enum.next
+ rescue StopIteration
+ break
+ end
+ end
+
+ ScratchPad.recorded.should == ["firstline\n", "secondline\n", "\n", "forthline"]
+ end
+
+ it "increments position before calling the block" do
+ i = 0
+ @gzreader.each do |line|
+ i += line.length
+ @gzreader.pos.should == i
+ end
+ end
end
diff --git a/spec/ruby/library/zlib/gzipreader/eof_spec.rb b/spec/ruby/library/zlib/gzipreader/eof_spec.rb
index 673220fdfd..434e716b64 100644
--- a/spec/ruby/library/zlib/gzipreader/eof_spec.rb
+++ b/spec/ruby/library/zlib/gzipreader/eof_spec.rb
@@ -12,31 +12,31 @@ describe "Zlib::GzipReader#eof?" do
it "returns true when at EOF" do
gz = Zlib::GzipReader.new @io
- gz.eof?.should be_false
+ gz.eof?.should == false
gz.read
- gz.eof?.should be_true
+ gz.eof?.should == true
end
it "returns true when at EOF with the exact length of uncompressed data" do
gz = Zlib::GzipReader.new @io
- gz.eof?.should be_false
+ gz.eof?.should == false
gz.read(10)
- gz.eof?.should be_true
+ gz.eof?.should == true
end
it "returns true when at EOF with a length greater than the size of uncompressed data" do
gz = Zlib::GzipReader.new @io
- gz.eof?.should be_false
+ gz.eof?.should == false
gz.read(11)
- gz.eof?.should be_true
+ gz.eof?.should == true
end
it "returns false when at EOF when there's data left in the buffer to read" do
gz = Zlib::GzipReader.new @io
gz.read(9)
- gz.eof?.should be_false
+ gz.eof?.should == false
gz.read
- gz.eof?.should be_true
+ gz.eof?.should == true
end
# This is especially important for JRuby, since eof? there
@@ -44,11 +44,18 @@ describe "Zlib::GzipReader#eof?" do
it "does not affect the reading data" do
gz = Zlib::GzipReader.new @io
0.upto(9) do |i|
- gz.eof?.should be_false
+ gz.eof?.should == false
gz.read(1).should == @data[i, 1]
end
- gz.eof?.should be_true
+ gz.eof?.should == true
gz.read.should == ""
- gz.eof?.should be_true
+ gz.eof?.should == true
+ end
+end
+
+describe "Zlib::GzipReader#eof" do
+ it "is an alias of Zlib::GzipReader#eof?" do
+ Zlib::GzipReader.instance_method(:eof).should ==
+ Zlib::GzipReader.instance_method(:eof?)
end
end
diff --git a/spec/ruby/library/zlib/gzipreader/getc_spec.rb b/spec/ruby/library/zlib/gzipreader/getc_spec.rb
index e567231940..be13592189 100644
--- a/spec/ruby/library/zlib/gzipreader/getc_spec.rb
+++ b/spec/ruby/library/zlib/gzipreader/getc_spec.rb
@@ -33,7 +33,7 @@ describe "Zlib::GzipReader#getc" do
gz = Zlib::GzipReader.new @io
gz.read
pos = gz.pos
- gz.getc.should be_nil
+ gz.getc.should == nil
gz.pos.should == pos
end
end
diff --git a/spec/ruby/library/zlib/gzipreader/gets_spec.rb b/spec/ruby/library/zlib/gzipreader/gets_spec.rb
index d3a2e7d263..5d0809f833 100644
--- a/spec/ruby/library/zlib/gzipreader/gets_spec.rb
+++ b/spec/ruby/library/zlib/gzipreader/gets_spec.rb
@@ -16,7 +16,7 @@ describe 'Zlib::GzipReader#gets' do
gz.gets('').should == "123\n45\n\n"
gz.gets('').should == "abc\nde\n\n"
- gz.eof?.should be_true
+ gz.eof?.should == true
end
end
end
diff --git a/spec/ruby/library/zlib/gzipreader/mtime_spec.rb b/spec/ruby/library/zlib/gzipreader/mtime_spec.rb
new file mode 100644
index 0000000000..e8e71fa72e
--- /dev/null
+++ b/spec/ruby/library/zlib/gzipreader/mtime_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../../spec_helper'
+require 'zlib'
+require 'stringio'
+
+describe "Zlib::GzipReader#mtime" do
+ it "returns the timestamp from the Gzip header" do
+ io = StringIO.new "\x1f\x8b\x08\x00\x44\x33\x22\x11\x00\xff\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+ gz = Zlib::GzipReader.new(io)
+ gz.mtime.to_i.should == 0x11223344
+ end
+end
diff --git a/spec/ruby/library/zlib/gzipreader/new_spec.rb b/spec/ruby/library/zlib/gzipreader/new_spec.rb
deleted file mode 100644
index e15f14f95f..0000000000
--- a/spec/ruby/library/zlib/gzipreader/new_spec.rb
+++ /dev/null
@@ -1 +0,0 @@
-require_relative '../../../spec_helper'
diff --git a/spec/ruby/library/zlib/gzipreader/read_spec.rb b/spec/ruby/library/zlib/gzipreader/read_spec.rb
index b81954b5ce..b07d433bdd 100644
--- a/spec/ruby/library/zlib/gzipreader/read_spec.rb
+++ b/spec/ruby/library/zlib/gzipreader/read_spec.rb
@@ -30,7 +30,7 @@ describe "Zlib::GzipReader#read" do
gz = Zlib::GzipReader.new @io
-> {
gz.read(-1)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "returns an empty string if a 0 length is given" do
@@ -59,8 +59,8 @@ describe "Zlib::GzipReader#read" do
it "returns nil if length parameter is positive" do
gz = Zlib::GzipReader.new @io
gz.read # read till the end
- gz.read(1).should be_nil
- gz.read(2**16).should be_nil
+ gz.read(1).should == nil
+ gz.read(2**16).should == nil
end
end
end
diff --git a/spec/ruby/library/zlib/gzipreader/shared/each.rb b/spec/ruby/library/zlib/gzipreader/shared/each.rb
deleted file mode 100644
index 71608e04ab..0000000000
--- a/spec/ruby/library/zlib/gzipreader/shared/each.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-require_relative '../../../../spec_helper'
-require 'stringio'
-require 'zlib'
-
-describe :gzipreader_each, shared: true do
- before :each do
- @data = "firstline\nsecondline\n\nforthline"
- @zip = [31, 139, 8, 0, 244, 125, 128, 88, 2, 255, 75, 203, 44, 42, 46, 201,
- 201, 204, 75, 229, 42, 78, 77, 206, 207, 75, 1, 51, 185, 210,242,
- 139, 74, 50, 64, 76, 0, 180, 54, 61, 111, 31, 0, 0, 0].pack('C*')
-
- @io = StringIO.new @zip
- @gzreader = Zlib::GzipReader.new @io
- end
-
- after :each do
- ScratchPad.clear
- end
-
- it "calls the given block for each line in the stream, passing the line as an argument" do
- ScratchPad.record []
- @gzreader.send(@method) { |b| ScratchPad << b }
-
- ScratchPad.recorded.should == ["firstline\n", "secondline\n", "\n", "forthline"]
- end
-
- it "returns an enumerator, which yields each byte in the stream, when no block is passed" do
- enum = @gzreader.send(@method)
-
- ScratchPad.record []
- while true
- begin
- ScratchPad << enum.next
- rescue StopIteration
- break
- end
- end
-
- ScratchPad.recorded.should == ["firstline\n", "secondline\n", "\n", "forthline"]
- end
-
- it "increments position before calling the block" do
- i = 0
- @gzreader.send(@method) do |line|
- i += line.length
- @gzreader.pos.should == i
- end
- end
-end
diff --git a/spec/ruby/library/zlib/gzipreader/tell_spec.rb b/spec/ruby/library/zlib/gzipreader/tell_spec.rb
new file mode 100644
index 0000000000..cc103e57b4
--- /dev/null
+++ b/spec/ruby/library/zlib/gzipreader/tell_spec.rb
@@ -0,0 +1,9 @@
+require_relative "../../../spec_helper"
+require 'zlib'
+
+describe "Zlib::GzipReader#tell" do
+ it "is an alias of Zlib::GzipReader#pos" do
+ Zlib::GzipReader.instance_method(:tell).should ==
+ Zlib::GzipReader.instance_method(:pos)
+ end
+end
diff --git a/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb b/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb
index 7fa0608f9f..53870b9177 100644
--- a/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb
+++ b/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb
@@ -94,7 +94,7 @@ describe "Zlib::GzipReader#ungetbyte" do
it 'makes eof? false' do
@gz.ungetbyte 0x21
- @gz.eof?.should be_false
+ @gz.eof?.should == false
end
end
@@ -112,7 +112,7 @@ describe "Zlib::GzipReader#ungetbyte" do
it 'does not make eof? false' do
@gz.ungetbyte nil
- @gz.eof?.should be_true
+ @gz.eof?.should == true
end
end
end
diff --git a/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb b/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb
index 34f2a1a2ca..46dcfde989 100644
--- a/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb
+++ b/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb
@@ -190,7 +190,7 @@ describe "Zlib::GzipReader#ungetc" do
it 'makes eof? false' do
@gz.ungetc 'x'
- @gz.eof?.should be_false
+ @gz.eof?.should == false
end
end
@@ -207,7 +207,7 @@ describe "Zlib::GzipReader#ungetc" do
it 'makes eof? false' do
@gz.ungetc 'ŷ'
- @gz.eof?.should be_false
+ @gz.eof?.should == false
end
end
@@ -224,7 +224,7 @@ describe "Zlib::GzipReader#ungetc" do
it 'makes eof? false' do
@gz.ungetc 'xŷž'
- @gz.eof?.should be_false
+ @gz.eof?.should == false
end
end
@@ -241,7 +241,7 @@ describe "Zlib::GzipReader#ungetc" do
it 'makes eof? false' do
@gz.ungetc 0x21
- @gz.eof?.should be_false
+ @gz.eof?.should == false
end
end
@@ -258,7 +258,7 @@ describe "Zlib::GzipReader#ungetc" do
it 'does not make eof? false' do
@gz.ungetc ''
- @gz.eof?.should be_true
+ @gz.eof?.should == true
end
end
@@ -276,7 +276,7 @@ describe "Zlib::GzipReader#ungetc" do
it 'does not make eof? false' do
@gz.ungetc nil
- @gz.eof?.should be_true
+ @gz.eof?.should == true
end
end
end