pr-zlib 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/{CHANGES → CHANGES.md} +19 -6
- data/Gemfile +6 -0
- data/MANIFEST.md +20 -0
- data/{README → README.md} +29 -12
- data/Rakefile +11 -61
- data/bin/{minizip.rb → minirbgzip} +77 -65
- data/lib/pr/rbzlib/bytef.rb +16 -0
- data/lib/pr/rbzlib/bytef_arr.rb +29 -0
- data/lib/pr/rbzlib/bytef_str.rb +52 -0
- data/lib/pr/rbzlib/posf.rb +33 -0
- data/lib/pr/rbzlib.rb +1758 -1855
- data/lib/pr/zlib/deflate.rb +99 -0
- data/lib/pr/zlib/errors.rb +27 -0
- data/lib/pr/zlib/gzipfile.rb +315 -0
- data/lib/pr/zlib/gzipfile_errors.rb +19 -0
- data/lib/pr/zlib/gzipreader.rb +338 -0
- data/lib/pr/zlib/gzipwriter.rb +167 -0
- data/lib/pr/zlib/inflate.rb +114 -0
- data/lib/pr/zlib/zstream.rb +417 -0
- data/lib/pr/zlib.rb +25 -1466
- data/pr-zlib.gemspec +15 -15
- data/profile/bench_pr_zlib.rb +7 -5
- data/profile/bench_zlib.rb +7 -5
- data/profile/profile_pr_zlib_read.rb +3 -3
- data/profile/profile_pr_zlib_write.rb +3 -3
- data/spec/README.md +46 -0
- data/spec/rbzlib/bytef_arr_spec.rb +82 -0
- data/spec/rbzlib/bytef_spec.rb +72 -0
- data/spec/rbzlib/bytef_str_spec.rb +113 -0
- data/spec/rbzlib/posf_spec.rb +83 -0
- data/spec/rbzlib_spec.rb +170 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/zlib/deflate_spec.rb +44 -0
- data/spec/zlib/gzip_file_spec.rb +86 -0
- data/spec/zlib/gzip_reader_spec.rb +276 -0
- data/spec/zlib/gzip_writer_spec.rb +275 -0
- data/spec/zlib/inflate_spec.rb +44 -0
- data/spec/zlib/zstream_spec.rb +156 -0
- data/spec/zlib_spec.rb +195 -0
- data.tar.gz.sig +0 -0
- metadata +68 -55
- metadata.gz.sig +0 -0
- data/MANIFEST +0 -20
- data/test/test_rbzlib.rb +0 -133
- data/test/test_rbzlib_bytef.rb +0 -76
- data/test/test_rbzlib_posf.rb +0 -56
- data/test/test_zlib.rb +0 -162
- data/test/test_zlib_deflate.rb +0 -55
- data/test/test_zlib_gzip_file.rb +0 -93
- data/test/test_zlib_gzip_reader.rb +0 -183
- data/test/test_zlib_gzip_writer.rb +0 -186
- data/test/test_zlib_inflate.rb +0 -55
- data/test/test_zlib_zstream.rb +0 -146
data/pr-zlib.gemspec
CHANGED
@@ -2,31 +2,31 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'pr-zlib'
|
5
|
-
spec.version = '1.0
|
5
|
+
spec.version = '1.1.0'
|
6
6
|
spec.authors = ['Park Heesob', 'Daniel Berger']
|
7
7
|
spec.email = ['phasis@gmail.com', 'djberg96@gmail.com'],
|
8
8
|
spec.homepage = 'https://github.com/djberg96/pr-zlib'
|
9
|
-
spec.license = '
|
9
|
+
spec.license = 'Zlib'
|
10
10
|
spec.summary = 'Pure Ruby version of the zlib library'
|
11
|
-
spec.test_files = Dir['
|
11
|
+
spec.test_files = Dir['spec/**/*_spec.rb']
|
12
12
|
spec.files = Dir["**/*"].reject{ |f| f.include?('git') }
|
13
|
-
spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
|
13
|
+
spec.extra_rdoc_files = ['README.md', 'CHANGES.md', 'MANIFEST.md']
|
14
14
|
spec.cert_chain = Dir['certs/*']
|
15
|
+
spec.executables = 'minirbgzip'
|
15
16
|
|
16
|
-
spec.add_development_dependency('
|
17
|
-
spec.add_development_dependency('
|
18
|
-
|
19
|
-
spec.required_ruby_version = '>= 2.2.0'
|
17
|
+
spec.add_development_dependency('rake')
|
18
|
+
spec.add_development_dependency('rspec', '~> 3.12')
|
20
19
|
|
21
20
|
spec.metadata = {
|
22
|
-
'homepage_uri'
|
23
|
-
'bug_tracker_uri'
|
24
|
-
'changelog_uri'
|
25
|
-
'documentation_uri'
|
26
|
-
'source_code_uri'
|
27
|
-
'wiki_uri'
|
21
|
+
'homepage_uri' => 'https://github.com/djberg96/pr-zlib',
|
22
|
+
'bug_tracker_uri' => 'https://github.com/djberg96/pr-zlib/issues',
|
23
|
+
'changelog_uri' => 'https://github.com/djberg96/pr-zlib/blob/main/CHANGES',
|
24
|
+
'documentation_uri' => 'https://github.com/djberg96/pr-zlib/wiki',
|
25
|
+
'source_code_uri' => 'https://github.com/djberg96/pr-zlib',
|
26
|
+
'wiki_uri' => 'https://github.com/djberg96/pr-zlib/wiki',
|
27
|
+
'rubygems_mfa_required' => 'true'
|
28
28
|
}
|
29
|
-
|
29
|
+
|
30
30
|
spec.description = <<-EOF
|
31
31
|
The pr-zlib library is a pure Ruby implementation of both the zlib C
|
32
32
|
library, and the Ruby zlib interface that ships as part of the standard
|
data/profile/bench_pr_zlib.rb
CHANGED
@@ -7,7 +7,9 @@
|
|
7
7
|
require 'pr/zlib'
|
8
8
|
require 'benchmark'
|
9
9
|
|
10
|
-
|
10
|
+
MAX = 50
|
11
|
+
|
12
|
+
print "\n\n== Running the benchmarks for pr-zlib using #{MAX} iterations ==\n\n"
|
11
13
|
|
12
14
|
# First, let's create a ~7 MB text file.
|
13
15
|
|
@@ -23,7 +25,7 @@ end
|
|
23
25
|
|
24
26
|
Benchmark.bm do |x|
|
25
27
|
x.report("write") do
|
26
|
-
|
28
|
+
MAX.times{
|
27
29
|
Zlib::GzipWriter.open(GZ_FILE_NAME) do |gz|
|
28
30
|
gz.write(File.read(FILE_NAME))
|
29
31
|
end
|
@@ -31,7 +33,7 @@ Benchmark.bm do |x|
|
|
31
33
|
end
|
32
34
|
|
33
35
|
x.report("read") do
|
34
|
-
|
36
|
+
MAX.times{
|
35
37
|
Zlib::GzipReader.open(GZ_FILE_NAME) do |gz|
|
36
38
|
gz.read
|
37
39
|
end
|
@@ -39,5 +41,5 @@ Benchmark.bm do |x|
|
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
|
-
File.delete(FILE_NAME) if File.
|
43
|
-
File.delete(GZ_FILE_NAME) if File.
|
44
|
+
File.delete(FILE_NAME) if File.exist?(FILE_NAME)
|
45
|
+
File.delete(GZ_FILE_NAME) if File.exist?(GZ_FILE_NAME)
|
data/profile/bench_zlib.rb
CHANGED
@@ -7,7 +7,9 @@
|
|
7
7
|
require 'zlib'
|
8
8
|
require 'benchmark'
|
9
9
|
|
10
|
-
|
10
|
+
MAX = 2000
|
11
|
+
|
12
|
+
print "\n\n== Running the benchmarks for zlib (stdlib) using #{MAX} iterations ==\n\n"
|
11
13
|
|
12
14
|
# First, let's create a ~7 MB text file.
|
13
15
|
|
@@ -23,7 +25,7 @@ end
|
|
23
25
|
|
24
26
|
Benchmark.bm do |x|
|
25
27
|
x.report("write") do
|
26
|
-
|
28
|
+
MAX.times{
|
27
29
|
Zlib::GzipWriter.open(GZ_FILE_NAME) do |gz|
|
28
30
|
gz.write(File.read(FILE_NAME))
|
29
31
|
end
|
@@ -31,7 +33,7 @@ Benchmark.bm do |x|
|
|
31
33
|
end
|
32
34
|
|
33
35
|
x.report("read") do
|
34
|
-
|
36
|
+
MAX.times{
|
35
37
|
Zlib::GzipReader.open(GZ_FILE_NAME) do |gz|
|
36
38
|
gz.read
|
37
39
|
end
|
@@ -39,5 +41,5 @@ Benchmark.bm do |x|
|
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
|
-
File.delete(FILE_NAME) if File.
|
43
|
-
File.delete(GZ_FILE_NAME) if File.
|
44
|
+
File.delete(FILE_NAME) if File.exist?(FILE_NAME)
|
45
|
+
File.delete(GZ_FILE_NAME) if File.exist?(GZ_FILE_NAME)
|
@@ -15,14 +15,14 @@ Zlib::GzipWriter.open(GZ_FILE_NAME){ |gz| gz.write(IO.read(FILE_NAME)) }
|
|
15
15
|
|
16
16
|
require 'ruby-prof'
|
17
17
|
|
18
|
-
result = RubyProf.profile do
|
18
|
+
result = RubyProf::Profile.profile do
|
19
19
|
Zlib::GzipReader.open(GZ_FILE_NAME) do |gz|
|
20
20
|
gz.read
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
File.delete(FILE_NAME) if File.
|
25
|
-
File.delete(GZ_FILE_NAME) if File.
|
24
|
+
File.delete(FILE_NAME) if File.exist?(FILE_NAME)
|
25
|
+
File.delete(GZ_FILE_NAME) if File.exist?(GZ_FILE_NAME)
|
26
26
|
|
27
27
|
printer = RubyProf::FlatPrinter.new(result)
|
28
28
|
printer.print(STDOUT)
|
@@ -13,14 +13,14 @@ end
|
|
13
13
|
|
14
14
|
require 'ruby-prof'
|
15
15
|
|
16
|
-
result = RubyProf.profile do
|
16
|
+
result = RubyProf::Profile.profile do
|
17
17
|
Zlib::GzipWriter.open(GZ_FILE_NAME) do |gz|
|
18
18
|
gz.write(File.read(FILE_NAME))
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
File.delete(FILE_NAME) if File.
|
23
|
-
File.delete(GZ_FILE_NAME) if File.
|
22
|
+
File.delete(FILE_NAME) if File.exist?(FILE_NAME)
|
23
|
+
File.delete(GZ_FILE_NAME) if File.exist?(GZ_FILE_NAME)
|
24
24
|
|
25
25
|
printer = RubyProf::FlatPrinter.new(result)
|
26
26
|
printer.print(STDOUT)
|
data/spec/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# RSpec Tests for pr-zlib
|
2
|
+
|
3
|
+
This directory contains RSpec specifications for the pr-zlib library, converted from the original test-unit tests.
|
4
|
+
|
5
|
+
## Running Tests
|
6
|
+
|
7
|
+
```bash
|
8
|
+
# Run all tests
|
9
|
+
bundle exec rspec
|
10
|
+
|
11
|
+
# Run tests via rake
|
12
|
+
bundle exec rake spec
|
13
|
+
|
14
|
+
# Run specific test file
|
15
|
+
bundle exec rspec spec/zlib_spec.rb
|
16
|
+
|
17
|
+
# Run with documentation format
|
18
|
+
bundle exec rspec --format documentation
|
19
|
+
```
|
20
|
+
|
21
|
+
## Test Structure
|
22
|
+
|
23
|
+
- `spec_helper.rb` - Common RSpec configuration
|
24
|
+
- `zlib_spec.rb` - Tests for the main Zlib module
|
25
|
+
- `rbzlib_spec.rb` - Tests for the Rbzlib module
|
26
|
+
- `rbzlib_bytef_spec.rb` - Tests for Rbzlib::Bytef class
|
27
|
+
- `rbzlib_posf_spec.rb` - Tests for Rbzlib::Posf class
|
28
|
+
- `zlib/` - Directory containing tests for Zlib subclasses
|
29
|
+
- `deflate_spec.rb` - Tests for Zlib::Deflate
|
30
|
+
- `inflate_spec.rb` - Tests for Zlib::Inflate
|
31
|
+
- `zstream_spec.rb` - Tests for Zlib::ZStream
|
32
|
+
- `gzip_file_spec.rb` - Tests for Zlib::GzipFile
|
33
|
+
- `gzip_reader_spec.rb` - Basic tests for Zlib::GzipReader
|
34
|
+
- `gzip_writer_spec.rb` - Basic tests for Zlib::GzipWriter
|
35
|
+
|
36
|
+
## Conversion Notes
|
37
|
+
|
38
|
+
The tests were converted from test-unit to RSpec format with the following changes:
|
39
|
+
|
40
|
+
- `assert_equal(expected, actual)` → `expect(actual).to eq(expected)`
|
41
|
+
- `assert_respond_to(object, method)` → `expect(object).to respond_to(method)`
|
42
|
+
- `assert_raise(exception)` → `expect { }.to raise_error(exception)`
|
43
|
+
- `assert_not_nil(value)` → `expect(value).not_to be_nil`
|
44
|
+
- `assert_nothing_raised` → `expect { }.not_to raise_error`
|
45
|
+
|
46
|
+
The basic interface tests have been preserved, though some complex file I/O tests for GzipReader and GzipWriter have been simplified to focus on the core interface verification.
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
########################################################################
|
4
|
+
# bytef_arr_spec.rb
|
5
|
+
#
|
6
|
+
# Spec for the Rbzlib::Bytef_arr class.
|
7
|
+
########################################################################
|
8
|
+
require 'spec_helper'
|
9
|
+
require 'pr/rbzlib/bytef_arr'
|
10
|
+
|
11
|
+
RSpec.describe Rbzlib::Bytef_arr do
|
12
|
+
let(:buffer) { Array.new(32, 0) }
|
13
|
+
let(:bytef) { described_class.new(buffer) }
|
14
|
+
|
15
|
+
describe 'inheritance' do
|
16
|
+
it 'inherits from Bytef_str' do
|
17
|
+
expect(described_class.superclass).to eq(Rbzlib::Bytef_str)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'array access' do
|
22
|
+
it 'responds to []' do
|
23
|
+
expect(bytef).to respond_to(:[])
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'reads from the buffer' do
|
27
|
+
expect { bytef[0] }.not_to raise_error
|
28
|
+
expect(bytef[0]).to eq(0)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'responds to []=' do
|
32
|
+
expect(bytef).to respond_to(:[]=)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'writes to the buffer' do
|
36
|
+
expect { bytef[0] = 65 }.not_to raise_error
|
37
|
+
expect(bytef[0]).to eq(65)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#get' do
|
42
|
+
it 'responds to get' do
|
43
|
+
expect(bytef).to respond_to(:get)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'gets the current value' do
|
47
|
+
expect(bytef.get).to eq(0)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#set' do
|
52
|
+
it 'responds to set' do
|
53
|
+
expect(bytef).to respond_to(:set)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'sets the current value' do
|
57
|
+
expect { bytef.set(42) }.not_to raise_error
|
58
|
+
expect(bytef.get).to eq(42)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'arithmetic operations' do
|
63
|
+
it 'responds to +' do
|
64
|
+
expect(bytef).to respond_to(:+)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'increments the offset' do
|
68
|
+
expect { bytef + 4 }.not_to raise_error
|
69
|
+
expect(bytef.offset).to eq(4)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'responds to -' do
|
73
|
+
expect(bytef).to respond_to(:-)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'decrements the offset' do
|
77
|
+
bytef + 8
|
78
|
+
bytef - 4
|
79
|
+
expect(bytef.offset).to eq(4)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
########################################################################
|
4
|
+
# bytef_spec.rb
|
5
|
+
#
|
6
|
+
# Spec for the Rbzlib::Bytef factory class.
|
7
|
+
########################################################################
|
8
|
+
require 'spec_helper'
|
9
|
+
require 'pr/rbzlib/bytef'
|
10
|
+
|
11
|
+
RSpec.describe Rbzlib::Bytef do
|
12
|
+
describe '.new' do
|
13
|
+
context 'with string buffer' do
|
14
|
+
let(:string_buffer) { +'hello world' } # Make string mutable
|
15
|
+
|
16
|
+
it 'returns a Bytef_str instance' do
|
17
|
+
result = described_class.new(string_buffer)
|
18
|
+
expect(result).to be_a(Rbzlib::Bytef_str)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'initializes with the correct buffer' do
|
22
|
+
result = described_class.new(string_buffer)
|
23
|
+
expect(result.buffer).to eq(string_buffer)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'initializes with default offset 0' do
|
27
|
+
result = described_class.new(string_buffer)
|
28
|
+
expect(result.offset).to eq(0)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'initializes with custom offset' do
|
32
|
+
result = described_class.new(string_buffer, 5)
|
33
|
+
expect(result.offset).to eq(5)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with array buffer' do
|
38
|
+
let(:array_buffer) { [65, 66, 67, 68, 69] }
|
39
|
+
|
40
|
+
it 'returns a Bytef_arr instance' do
|
41
|
+
result = described_class.new(array_buffer)
|
42
|
+
expect(result).to be_a(Rbzlib::Bytef_arr)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'initializes with the correct buffer' do
|
46
|
+
result = described_class.new(array_buffer)
|
47
|
+
expect(result.buffer).to eq(array_buffer)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'initializes with default offset 0' do
|
51
|
+
result = described_class.new(array_buffer)
|
52
|
+
expect(result.offset).to eq(0)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'initializes with custom offset' do
|
56
|
+
result = described_class.new(array_buffer, 3)
|
57
|
+
expect(result.offset).to eq(3)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'factory behavior' do
|
62
|
+
it 'creates appropriate instance based on buffer type' do
|
63
|
+
string_result = described_class.new(+'test') # Make string mutable
|
64
|
+
array_result = described_class.new([1, 2, 3])
|
65
|
+
|
66
|
+
expect(string_result.class).not_to eq(array_result.class)
|
67
|
+
expect(string_result).to be_a(Rbzlib::Bytef_str)
|
68
|
+
expect(array_result).to be_a(Rbzlib::Bytef_arr)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
########################################################################
|
4
|
+
# bytef_str_spec.rb
|
5
|
+
#
|
6
|
+
# Spec for the Rbzlib::Bytef_str class.
|
7
|
+
########################################################################
|
8
|
+
require 'spec_helper'
|
9
|
+
require 'pr/rbzlib/bytef_str'
|
10
|
+
|
11
|
+
RSpec.describe Rbzlib::Bytef_str do
|
12
|
+
let(:buffer) { 0.chr * 32 }
|
13
|
+
let(:bytef) { described_class.new(buffer) }
|
14
|
+
|
15
|
+
describe '#buffer' do
|
16
|
+
it 'responds to buffer getter' do
|
17
|
+
expect(bytef).to respond_to(:buffer)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns the buffer' do
|
21
|
+
expect(bytef.buffer).to eq(buffer)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'responds to buffer setter' do
|
25
|
+
expect(bytef).to respond_to(:buffer=)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'sets the buffer' do
|
29
|
+
new_buffer = 0.chr * 8
|
30
|
+
expect { bytef.buffer = new_buffer }.not_to raise_error
|
31
|
+
expect(bytef.buffer).to eq(new_buffer)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#length' do
|
36
|
+
it 'responds to length' do
|
37
|
+
expect(bytef).to respond_to(:length)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns the correct length' do
|
41
|
+
expect(bytef.length).to eq(32)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'arithmetic operations' do
|
46
|
+
it 'responds to +' do
|
47
|
+
expect(bytef).to respond_to(:+)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'increments the offset' do
|
51
|
+
expect { bytef + 4 }.not_to raise_error
|
52
|
+
expect(bytef.offset).to eq(4)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'responds to -' do
|
56
|
+
expect(bytef).to respond_to(:-)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'decrements the offset' do
|
60
|
+
bytef + 8
|
61
|
+
bytef - 4
|
62
|
+
expect(bytef.offset).to eq(4)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'array access' do
|
67
|
+
it 'responds to []' do
|
68
|
+
expect(bytef).to respond_to(:[])
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'reads from the buffer' do
|
72
|
+
expect { bytef[0] }.not_to raise_error
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'responds to []=' do
|
76
|
+
expect(bytef).to respond_to(:[]=)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'writes to the buffer' do
|
80
|
+
expect { bytef[0] = 'A' }.not_to raise_error
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#get' do
|
85
|
+
it 'responds to get' do
|
86
|
+
expect(bytef).to respond_to(:get)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'gets the current value' do
|
90
|
+
expect { bytef.get }.not_to raise_error
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#set' do
|
95
|
+
it 'responds to set' do
|
96
|
+
expect(bytef).to respond_to(:set)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'sets the current value' do
|
100
|
+
expect { bytef.set('A') }.not_to raise_error
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#current' do
|
105
|
+
it 'responds to current' do
|
106
|
+
expect(bytef).to respond_to(:current)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'returns the current buffer' do
|
110
|
+
expect(bytef.current).to eq(buffer)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
########################################################################
|
4
|
+
# posf_spec.rb
|
5
|
+
#
|
6
|
+
# Spec for the Rbzlib::Posf class.
|
7
|
+
########################################################################
|
8
|
+
require 'spec_helper'
|
9
|
+
require 'pr/rbzlib/posf'
|
10
|
+
|
11
|
+
RSpec.describe Rbzlib::Posf do
|
12
|
+
let(:buffer) { 0.chr * 32 }
|
13
|
+
let(:posf) { described_class.new(buffer) }
|
14
|
+
|
15
|
+
describe 'inheritance' do
|
16
|
+
it 'inherits from Bytef_str' do
|
17
|
+
expect(described_class.superclass).to eq(Rbzlib::Bytef_str)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'arithmetic operations' do
|
22
|
+
it 'responds to +' do
|
23
|
+
expect(posf).to respond_to(:+)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'increments the offset by 2x the value' do
|
27
|
+
expect { posf + 4 }.not_to raise_error
|
28
|
+
expect(posf.offset).to eq(8)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'responds to -' do
|
32
|
+
expect(posf).to respond_to(:-)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'decrements the offset by 2x the value' do
|
36
|
+
expect { posf - 4 }.not_to raise_error
|
37
|
+
expect(posf.offset).to eq(-8)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'array access' do
|
42
|
+
it 'responds to []' do
|
43
|
+
expect(posf).to respond_to(:[])
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'reads from the buffer' do
|
47
|
+
expect { posf[2] }.not_to raise_error
|
48
|
+
expect(posf[2]).to eq(0)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'responds to []=' do
|
52
|
+
expect(posf).to respond_to(:[]=)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'writes to the buffer' do
|
56
|
+
expect { posf[2] = 7 }.not_to raise_error
|
57
|
+
expect(posf[2]).to eq(7)
|
58
|
+
expect(posf.buffer[4, 2]).to eq("\a\000")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#get' do
|
63
|
+
it 'responds to get' do
|
64
|
+
expect(posf).to respond_to(:get)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'gets the current value' do
|
68
|
+
expect { posf.get }.not_to raise_error
|
69
|
+
expect(posf.get).to eq(0)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#set' do
|
74
|
+
it 'responds to set' do
|
75
|
+
expect(posf).to respond_to(:set)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'sets the current value' do
|
79
|
+
expect { posf.set(4) }.not_to raise_error
|
80
|
+
expect(posf.buffer[0, 2]).to eq("\004\000")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|