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/eof_spec.rb22
-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/read_spec.rb6
-rw-r--r--spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb4
-rw-r--r--spec/ruby/library/zlib/gzipreader/ungetc_spec.rb12
7 files changed, 75 insertions, 24 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/eof_spec.rb b/spec/ruby/library/zlib/gzipreader/eof_spec.rb
index 673220fdfd..a38e144c72 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,11 @@ 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
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/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/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