diff options
Diffstat (limited to 'spec/ruby/library/zlib/gzipreader')
23 files changed, 184 insertions, 136 deletions
diff --git a/spec/ruby/library/zlib/gzipreader/each_byte_spec.rb b/spec/ruby/library/zlib/gzipreader/each_byte_spec.rb index d2c43ecaa4..48821dc833 100644 --- a/spec/ruby/library/zlib/gzipreader/each_byte_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/each_byte_spec.rb @@ -2,7 +2,7 @@ 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 b576788e27..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 "GzipReader#each_line" do - it_behaves_like :gzipreader_each, :each_line +describe "Zlib::GzipReader#each_line" do + 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 f9b90be316..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 "GzipReader#each" do - it_behaves_like :gzipreader_each, :each +describe "Zlib::GzipReader#each" 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.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 e33d8e3133..434e716b64 100644 --- a/spec/ruby/library/zlib/gzipreader/eof_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/eof_spec.rb @@ -2,8 +2,7 @@ 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,18 @@ 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 +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 90b5ffe37a..be13592189 100644 --- a/spec/ruby/library/zlib/gzipreader/getc_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/getc_spec.rb @@ -2,8 +2,7 @@ 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 8e4465e49c..5d0809f833 100644 --- a/spec/ruby/library/zlib/gzipreader/gets_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/gets_spec.rb @@ -2,7 +2,7 @@ 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 e15f14f95f..0000000000 --- a/spec/ruby/library/zlib/gzipreader/lineno_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../../spec_helper' 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/open_spec.rb b/spec/ruby/library/zlib/gzipreader/open_spec.rb deleted file mode 100644 index e15f14f95f..0000000000 --- a/spec/ruby/library/zlib/gzipreader/open_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../../spec_helper' diff --git a/spec/ruby/library/zlib/gzipreader/pos_spec.rb b/spec/ruby/library/zlib/gzipreader/pos_spec.rb index df7c78ad8f..8586faec92 100644 --- a/spec/ruby/library/zlib/gzipreader/pos_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/pos_spec.rb @@ -2,8 +2,7 @@ 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,5 +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 a90b2bf498..b07d433bdd 100644 --- a/spec/ruby/library/zlib/gzipreader/read_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/read_spec.rb @@ -2,8 +2,7 @@ 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 e15f14f95f..0000000000 --- a/spec/ruby/library/zlib/gzipreader/readchar_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../../spec_helper' 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 e15f14f95f..0000000000 --- a/spec/ruby/library/zlib/gzipreader/readline_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../../spec_helper' 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 e15f14f95f..0000000000 --- a/spec/ruby/library/zlib/gzipreader/readlines_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../../spec_helper' diff --git a/spec/ruby/library/zlib/gzipreader/readpartial_spec.rb b/spec/ruby/library/zlib/gzipreader/readpartial_spec.rb index a367e5b856..559ce9f841 100644 --- a/spec/ruby/library/zlib/gzipreader/readpartial_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/readpartial_spec.rb @@ -2,7 +2,7 @@ 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 2e22458b43..b31abb6abf 100644 --- a/spec/ruby/library/zlib/gzipreader/rewind_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/rewind_spec.rb @@ -2,8 +2,7 @@ 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 deleted file mode 100644 index 11c15d8a66..0000000000 --- a/spec/ruby/library/zlib/gzipreader/shared/each.rb +++ /dev/null @@ -1,51 +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 index e15f14f95f..cc103e57b4 100644 --- a/spec/ruby/library/zlib/gzipreader/tell_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/tell_spec.rb @@ -1 +1,9 @@ -require_relative '../../../spec_helper' +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 f29927e20b..53870b9177 100644 --- a/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb @@ -2,7 +2,7 @@ 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 d749d58cca..46dcfde989 100644 --- a/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb +++ b/spec/ruby/library/zlib/gzipreader/ungetc_spec.rb @@ -2,7 +2,7 @@ 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 e15f14f95f..0000000000 --- a/spec/ruby/library/zlib/gzipreader/unused_spec.rb +++ /dev/null @@ -1 +0,0 @@ -require_relative '../../../spec_helper' |
