diff options
Diffstat (limited to 'spec/ruby/library/zlib/gzipreader')
23 files changed, 132 insertions, 98 deletions
diff --git a/spec/ruby/library/zlib/gzipreader/each_byte_spec.rb b/spec/ruby/library/zlib/gzipreader/each_byte_spec.rb index 6da9ac8323..48821dc833 100644 --- a/spec/ruby/library/zlib/gzipreader/each_byte_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/each_byte_spec.rb @@ -1,8 +1,8 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'stringio' require 'zlib' -describe "GzipReader#each_byte" do +describe "Zlib::GzipReader#each_byte" do before :each do @data = '12345abcde' 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 7ff116a258..6f17365879 100644 --- a/spec/ruby/library/zlib/gzipreader/each_line_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/each_line_spec.rb @@ -1,5 +1,6 @@ -require File.expand_path('../shared/each', __FILE__) +require_relative "../../../spec_helper" +require_relative 'shared/each' -describe "GzipReader#each_line" do +describe "Zlib::GzipReader#each_line" do it_behaves_like :gzipreader_each, :each_line end diff --git a/spec/ruby/library/zlib/gzipreader/each_spec.rb b/spec/ruby/library/zlib/gzipreader/each_spec.rb index dd780e4083..3b98391a87 100644 --- a/spec/ruby/library/zlib/gzipreader/each_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/each_spec.rb @@ -1,5 +1,6 @@ -require File.expand_path('../shared/each', __FILE__) +require_relative "../../../spec_helper" +require_relative 'shared/each' -describe "GzipReader#each" do +describe "Zlib::GzipReader#each" do it_behaves_like :gzipreader_each, :each end diff --git a/spec/ruby/library/zlib/gzipreader/eof_spec.rb b/spec/ruby/library/zlib/gzipreader/eof_spec.rb index 446cbfec37..a38e144c72 100644 --- a/spec/ruby/library/zlib/gzipreader/eof_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/eof_spec.rb @@ -1,9 +1,8 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'stringio' require 'zlib' -describe "GzipReader#eof?" do - +describe "Zlib::GzipReader#eof?" do before :each do @data = '{"a":1234}' @zip = [31, 139, 8, 0, 0, 0, 0, 0, 0, 3, 171, 86, 74, 84, 178, 50, @@ -13,31 +12,31 @@ describe "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 @@ -45,12 +44,11 @@ describe "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.read().should == "" - gz.eof?.should be_true + gz.eof?.should == true + gz.read.should == "" + 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 a3c4aecf76..be13592189 100644 --- a/spec/ruby/library/zlib/gzipreader/getc_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/getc_spec.rb @@ -1,9 +1,8 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'stringio' require 'zlib' -describe "GzipReader#getc" do - +describe "Zlib::GzipReader#getc" do before :each do @data = '12345abcde' @zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77, @@ -34,8 +33,7 @@ describe "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 d49adc2850..5d0809f833 100644 --- a/spec/ruby/library/zlib/gzipreader/gets_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/gets_spec.rb @@ -1,8 +1,8 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'zlib' require 'stringio' -describe 'GzipReader#gets' do +describe 'Zlib::GzipReader#gets' do describe 'with "" separator' do it 'reads paragraphs skipping newlines' do # gz contains "\n\n\n\n\n123\n45\n\n\n\n\nabc\nde\n\n\n\n\n" @@ -16,7 +16,7 @@ describe '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/lineno_spec.rb b/spec/ruby/library/zlib/gzipreader/lineno_spec.rb deleted file mode 100644 index 6a4c1dadb4..0000000000 --- a/spec/ruby/library/zlib/gzipreader/lineno_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require File.expand_path('../../../../spec_helper', __FILE__) 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 6a4c1dadb4..0000000000 --- a/spec/ruby/library/zlib/gzipreader/new_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require File.expand_path('../../../../spec_helper', __FILE__) diff --git a/spec/ruby/library/zlib/gzipreader/open_spec.rb b/spec/ruby/library/zlib/gzipreader/open_spec.rb deleted file mode 100644 index 6a4c1dadb4..0000000000 --- a/spec/ruby/library/zlib/gzipreader/open_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require File.expand_path('../../../../spec_helper', __FILE__) diff --git a/spec/ruby/library/zlib/gzipreader/pos_spec.rb b/spec/ruby/library/zlib/gzipreader/pos_spec.rb index 66fbf388d8..8586faec92 100644 --- a/spec/ruby/library/zlib/gzipreader/pos_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/pos_spec.rb @@ -1,9 +1,8 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'stringio' require 'zlib' -describe "GzipReader#pos" do - +describe "Zlib::GzipReader#pos" do before :each do @data = '12345abcde' @zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77, @@ -22,6 +21,4 @@ describe "GzipReader#pos" do gz.read gz.pos.should == @data.length end - end - diff --git a/spec/ruby/library/zlib/gzipreader/read_spec.rb b/spec/ruby/library/zlib/gzipreader/read_spec.rb index 337f507502..b07d433bdd 100644 --- a/spec/ruby/library/zlib/gzipreader/read_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/read_spec.rb @@ -1,9 +1,8 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'stringio' require 'zlib' -describe "GzipReader#read" do - +describe "Zlib::GzipReader#read" do before :each do @data = '12345abcde' @zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77, @@ -29,9 +28,9 @@ describe "GzipReader#read" do it "does not accept a negative length to read" do gz = Zlib::GzipReader.new @io - lambda { + -> { gz.read(-1) - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "returns an empty string if a 0 length is given" do @@ -49,7 +48,7 @@ describe "GzipReader#read" do end describe "at the end of data" do - it "returns empty string if length prameter is not specified or 0" do + it "returns empty string if length parameter is not specified or 0" do gz = Zlib::GzipReader.new @io gz.read # read till the end gz.read(0).should == "" @@ -57,12 +56,11 @@ describe "GzipReader#read" do gz.read(nil).should == "" end - it "returns nil if length prameter is positive" 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/readchar_spec.rb b/spec/ruby/library/zlib/gzipreader/readchar_spec.rb deleted file mode 100644 index 6a4c1dadb4..0000000000 --- a/spec/ruby/library/zlib/gzipreader/readchar_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require File.expand_path('../../../../spec_helper', __FILE__) diff --git a/spec/ruby/library/zlib/gzipreader/readline_spec.rb b/spec/ruby/library/zlib/gzipreader/readline_spec.rb deleted file mode 100644 index 6a4c1dadb4..0000000000 --- a/spec/ruby/library/zlib/gzipreader/readline_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require File.expand_path('../../../../spec_helper', __FILE__) diff --git a/spec/ruby/library/zlib/gzipreader/readlines_spec.rb b/spec/ruby/library/zlib/gzipreader/readlines_spec.rb deleted file mode 100644 index 6a4c1dadb4..0000000000 --- a/spec/ruby/library/zlib/gzipreader/readlines_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require File.expand_path('../../../../spec_helper', __FILE__) diff --git a/spec/ruby/library/zlib/gzipreader/readpartial_spec.rb b/spec/ruby/library/zlib/gzipreader/readpartial_spec.rb index 2cdef54fd1..559ce9f841 100644 --- a/spec/ruby/library/zlib/gzipreader/readpartial_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/readpartial_spec.rb @@ -1,8 +1,8 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'stringio' require 'zlib' -describe 'GzipReader#readpartial' do +describe "Zlib::GzipReader#readpartial" do before :each do @data = '12345abcde' @zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77, diff --git a/spec/ruby/library/zlib/gzipreader/rewind_spec.rb b/spec/ruby/library/zlib/gzipreader/rewind_spec.rb index 70bee3372d..b31abb6abf 100644 --- a/spec/ruby/library/zlib/gzipreader/rewind_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/rewind_spec.rb @@ -1,9 +1,8 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'stringio' require 'zlib' -describe "GzipReader#rewind" do - +describe "Zlib::GzipReader#rewind" do before :each do @data = '12345abcde' @zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77, diff --git a/spec/ruby/library/zlib/gzipreader/shared/each.rb b/spec/ruby/library/zlib/gzipreader/shared/each.rb index 47cd284b6a..71608e04ab 100644 --- a/spec/ruby/library/zlib/gzipreader/shared/each.rb +++ b/spec/ruby/library/zlib/gzipreader/shared/each.rb @@ -1,9 +1,8 @@ -require File.expand_path('../../../../../spec_helper', __FILE__) +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, @@ -47,5 +46,4 @@ describe :gzipreader_each, shared: true do @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 deleted file mode 100644 index 6a4c1dadb4..0000000000 --- a/spec/ruby/library/zlib/gzipreader/tell_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require File.expand_path('../../../../spec_helper', __FILE__) diff --git a/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb b/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb index 16f1c12272..53870b9177 100644 --- a/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb @@ -1,8 +1,8 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'stringio' require 'zlib' -describe 'GzipReader#ungetbyte' do +describe "Zlib::GzipReader#ungetbyte" do before :each do @data = '12345abcde' @zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77, @@ -21,11 +21,9 @@ describe 'GzipReader#ungetbyte' do @gz.read.should == '!12345abcde' end - ruby_bug "#13616", ""..."2.6" do - it 'decrements pos' do - @gz.ungetbyte 0x21 - @gz.pos.should == -1 - end + it 'decrements pos' do + @gz.ungetbyte 0x21 + @gz.pos.should == -1 end end @@ -96,7 +94,7 @@ describe 'GzipReader#ungetbyte' do it 'makes eof? false' do @gz.ungetbyte 0x21 - @gz.eof?.should be_false + @gz.eof?.should == false end end @@ -114,7 +112,7 @@ describe '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 2d218e8d19..46dcfde989 100644 --- a/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb @@ -1,8 +1,8 @@ -require File.expand_path('../../../../spec_helper', __FILE__) +require_relative '../../../spec_helper' require 'stringio' require 'zlib' -describe 'GzipReader#ungetc' do +describe "Zlib::GzipReader#ungetc" do before :each do @data = '12345abcde' @zip = [31, 139, 8, 0, 44, 220, 209, 71, 0, 3, 51, 52, 50, 54, 49, 77, @@ -21,11 +21,9 @@ describe 'GzipReader#ungetc' do @gz.read.should == 'x12345abcde' end - ruby_bug "#13616", ""..."2.6" do - it 'decrements pos' do - @gz.ungetc 'x' - @gz.pos.should == -1 - end + it 'decrements pos' do + @gz.ungetc 'x' + @gz.pos.should == -1 end end @@ -35,11 +33,9 @@ describe 'GzipReader#ungetc' do @gz.read.should == 'ŷ12345abcde' end - ruby_bug "#13616", ""..."2.6" do - it 'decrements pos' do - @gz.ungetc 'ŷ' - @gz.pos.should == -2 - end + it 'decrements pos' do + @gz.ungetc 'ŷ' + @gz.pos.should == -2 end end @@ -49,11 +45,9 @@ describe 'GzipReader#ungetc' do @gz.read.should == 'xŷž12345abcde' end - ruby_bug "#13616", ""..."2.6" do - it 'decrements pos' do - @gz.ungetc 'xŷž' - @gz.pos.should == -5 - end + it 'decrements pos' do + @gz.ungetc 'xŷž' + @gz.pos.should == -5 end end @@ -63,11 +57,9 @@ describe 'GzipReader#ungetc' do @gz.read.should == '!12345abcde' end - ruby_bug "#13616", ""..."2.6" do - it 'decrements pos' do - @gz.ungetc 0x21 - @gz.pos.should == -1 - end + it 'decrements pos' do + @gz.ungetc 0x21 + @gz.pos.should == -1 end end @@ -198,7 +190,7 @@ describe 'GzipReader#ungetc' do it 'makes eof? false' do @gz.ungetc 'x' - @gz.eof?.should be_false + @gz.eof?.should == false end end @@ -215,7 +207,7 @@ describe 'GzipReader#ungetc' do it 'makes eof? false' do @gz.ungetc 'ŷ' - @gz.eof?.should be_false + @gz.eof?.should == false end end @@ -232,7 +224,7 @@ describe 'GzipReader#ungetc' do it 'makes eof? false' do @gz.ungetc 'xŷž' - @gz.eof?.should be_false + @gz.eof?.should == false end end @@ -249,7 +241,7 @@ describe 'GzipReader#ungetc' do it 'makes eof? false' do @gz.ungetc 0x21 - @gz.eof?.should be_false + @gz.eof?.should == false end end @@ -266,7 +258,7 @@ describe 'GzipReader#ungetc' do it 'does not make eof? false' do @gz.ungetc '' - @gz.eof?.should be_true + @gz.eof?.should == true end end @@ -284,7 +276,7 @@ describe '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 diff --git a/spec/ruby/library/zlib/gzipreader/unused_spec.rb b/spec/ruby/library/zlib/gzipreader/unused_spec.rb deleted file mode 100644 index 6a4c1dadb4..0000000000 --- a/spec/ruby/library/zlib/gzipreader/unused_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require File.expand_path('../../../../spec_helper', __FILE__) |
