diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/library/zlib/deflate | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) |
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
[Misc #13792] [ruby-core:82287]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/zlib/deflate')
-rw-r--r-- | spec/ruby/library/zlib/deflate/append_spec.rb | 1 | ||||
-rw-r--r-- | spec/ruby/library/zlib/deflate/deflate_spec.rb | 128 | ||||
-rw-r--r-- | spec/ruby/library/zlib/deflate/flush_spec.rb | 1 | ||||
-rw-r--r-- | spec/ruby/library/zlib/deflate/new_spec.rb | 1 | ||||
-rw-r--r-- | spec/ruby/library/zlib/deflate/params_spec.rb | 17 | ||||
-rw-r--r-- | spec/ruby/library/zlib/deflate/set_dictionary_spec.rb | 15 |
6 files changed, 163 insertions, 0 deletions
diff --git a/spec/ruby/library/zlib/deflate/append_spec.rb b/spec/ruby/library/zlib/deflate/append_spec.rb new file mode 100644 index 0000000000..6a4c1dadb4 --- /dev/null +++ b/spec/ruby/library/zlib/deflate/append_spec.rb @@ -0,0 +1 @@ +require File.expand_path('../../../../spec_helper', __FILE__) diff --git a/spec/ruby/library/zlib/deflate/deflate_spec.rb b/spec/ruby/library/zlib/deflate/deflate_spec.rb new file mode 100644 index 0000000000..44b3389701 --- /dev/null +++ b/spec/ruby/library/zlib/deflate/deflate_spec.rb @@ -0,0 +1,128 @@ +require 'zlib' +require File.expand_path('../../../../spec_helper', __FILE__) + +describe "Zlib::Deflate.deflate" do + it "deflates some data" do + data = Array.new(10,0).pack('C*') + + zipped = Zlib::Deflate.deflate data + + zipped.should == [120, 156, 99, 96, 128, 1, 0, 0, 10, 0, 1].pack('C*') + end + + it "deflates lots of data" do + data = "\000" * 32 * 1024 + + zipped = Zlib::Deflate.deflate data + + zipped.should == ([120, 156, 237, 193, 1, 1, 0, 0] + + [0, 128, 144, 254, 175, 238, 8, 10] + + Array.new(31, 0) + + [24, 128, 0, 0, 1]).pack('C*') + end + + it "deflates chunked data" do + random_generator = Random.new(0) + deflated = '' + + Zlib.deflate(random_generator.bytes(20000)) do |chunk| + deflated << chunk + end + + deflated.length.should == 20016 + end +end + +describe "Zlib::Deflate#deflate" do + before :each do + @deflator = Zlib::Deflate.new + end + + it "deflates some data" do + data = "\000" * 10 + + zipped = @deflator.deflate data, Zlib::FINISH + @deflator.finish + + zipped.should == [120, 156, 99, 96, 128, 1, 0, 0, 10, 0, 1].pack('C*') + end + + it "deflates lots of data" do + data = "\000" * 32 * 1024 + + zipped = @deflator.deflate data, Zlib::FINISH + @deflator.finish + + zipped.should == ([120, 156, 237, 193, 1, 1, 0, 0] + + [0, 128, 144, 254, 175, 238, 8, 10] + + Array.new(31, 0) + + [24, 128, 0, 0, 1]).pack('C*') + end +end + +describe "Zlib::Deflate#deflate" do + + before :each do + @deflator = Zlib::Deflate.new + @random_generator = Random.new(0) + @original = '' + @chunks = [] + end + + describe "without break" do + + before do + 2.times do + @input = @random_generator.bytes(20000) + @original << @input + @deflator.deflate(@input) do |chunk| + @chunks << chunk + end + end + end + + it "deflates chunked data" do + @deflator.finish + @chunks.map { |chunk| chunk.length }.should == [16384, 16384] + end + + it "deflates chunked data with final chunk" do + final = @deflator.finish + final.length.should == 7253 + end + + it "deflates chunked data without errors" do + final = @deflator.finish + @chunks << final + @original.should == Zlib.inflate(@chunks.join) + end + + end + + describe "with break" do + before :each do + @input = @random_generator.bytes(20000) + @deflator.deflate(@input) do |chunk| + @chunks << chunk + break + end + end + + it "deflates only first chunk" do + @deflator.finish + @chunks.map { |chunk| chunk.length }.should == [16384] + end + + it "deflates chunked data with final chunk" do + final = @deflator.finish + final.length.should == 3632 + end + + it "deflates chunked data without errors" do + final = @deflator.finish + @chunks << final + @input.should == Zlib.inflate(@chunks.join) + end + + end +end diff --git a/spec/ruby/library/zlib/deflate/flush_spec.rb b/spec/ruby/library/zlib/deflate/flush_spec.rb new file mode 100644 index 0000000000..6a4c1dadb4 --- /dev/null +++ b/spec/ruby/library/zlib/deflate/flush_spec.rb @@ -0,0 +1 @@ +require File.expand_path('../../../../spec_helper', __FILE__) diff --git a/spec/ruby/library/zlib/deflate/new_spec.rb b/spec/ruby/library/zlib/deflate/new_spec.rb new file mode 100644 index 0000000000..6a4c1dadb4 --- /dev/null +++ b/spec/ruby/library/zlib/deflate/new_spec.rb @@ -0,0 +1 @@ +require File.expand_path('../../../../spec_helper', __FILE__) diff --git a/spec/ruby/library/zlib/deflate/params_spec.rb b/spec/ruby/library/zlib/deflate/params_spec.rb new file mode 100644 index 0000000000..59b1353c07 --- /dev/null +++ b/spec/ruby/library/zlib/deflate/params_spec.rb @@ -0,0 +1,17 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'zlib' + +describe "Zlib::Deflate#params" do + it "changes the deflate parameters" do + data = 'abcdefghijklm' + + d = Zlib::Deflate.new Zlib::NO_COMPRESSION, Zlib::MAX_WBITS, + Zlib::DEF_MEM_LEVEL, Zlib::DEFAULT_STRATEGY + + d << data.slice!(0..10) + d.params Zlib::BEST_COMPRESSION, Zlib::DEFAULT_STRATEGY + d << data + + Zlib::Inflate.inflate(d.finish).should == 'abcdefghijklm' + end +end diff --git a/spec/ruby/library/zlib/deflate/set_dictionary_spec.rb b/spec/ruby/library/zlib/deflate/set_dictionary_spec.rb new file mode 100644 index 0000000000..c5c62d9529 --- /dev/null +++ b/spec/ruby/library/zlib/deflate/set_dictionary_spec.rb @@ -0,0 +1,15 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'zlib' + +describe "Zlib::Deflate#set_dictionary" do + it "sets the dictionary" do + d = Zlib::Deflate.new + d.set_dictionary 'aaaaaaaaaa' + d << 'abcdefghij' + + d.finish.should == [120, 187, 20, 225, 3, 203, 75, 76, + 74, 78, 73, 77, 75, 207, 200, 204, + 2, 0, 21, 134, 3, 248].pack('C*') + end +end + |