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/spec/rbzlib_spec.rb
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
########################################################################
|
4
|
+
# rbzlib_spec.rb
|
5
|
+
#
|
6
|
+
# Spec for the Rbzlib module.
|
7
|
+
########################################################################
|
8
|
+
require 'spec_helper'
|
9
|
+
|
10
|
+
RSpec.describe Rbzlib do
|
11
|
+
include described_class
|
12
|
+
|
13
|
+
let(:fixnum) { 7 }
|
14
|
+
let(:buffer) { 0.chr * 16 }
|
15
|
+
|
16
|
+
describe 'version' do
|
17
|
+
it 'has the correct version' do
|
18
|
+
expect(ZLIB_VERSION).to eq('1.2.3')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'Fixnum#ord' do
|
23
|
+
it 'responds to ord' do
|
24
|
+
expect(7).to respond_to(:ord)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns the number itself' do
|
28
|
+
expect(7.ord).to eq(7)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'miscellaneous constants' do
|
33
|
+
it 'has the correct values' do
|
34
|
+
expect(MAX_MEM_LEVEL).to eq(9)
|
35
|
+
expect(DEF_MEM_LEVEL).to eq(8)
|
36
|
+
expect(MAX_WBITS).to eq(15)
|
37
|
+
expect(DEF_WBITS).to eq(MAX_WBITS)
|
38
|
+
expect(STORED_BLOCK).to eq(0)
|
39
|
+
expect(STATIC_TREES).to eq(1)
|
40
|
+
expect(DYN_TREES).to eq(2)
|
41
|
+
expect(MIN_MATCH).to eq(3)
|
42
|
+
expect(MAX_MATCH).to eq(258)
|
43
|
+
expect(PRESET_DICT).to eq(0x20)
|
44
|
+
expect(BASE).to eq(65521)
|
45
|
+
expect(NMAX).to eq(5552)
|
46
|
+
expect(OS_CODE).to eq(0)
|
47
|
+
expect(SEEK_CUR).to eq(1)
|
48
|
+
expect(SEEK_END).to eq(2)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'sync constants' do
|
53
|
+
it 'has the correct values' do
|
54
|
+
expect(Z_NO_FLUSH).to eq(0)
|
55
|
+
expect(Z_PARTIAL_FLUSH).to eq(1)
|
56
|
+
expect(Z_SYNC_FLUSH).to eq(2)
|
57
|
+
expect(Z_FULL_FLUSH).to eq(3)
|
58
|
+
expect(Z_FINISH).to eq(4)
|
59
|
+
expect(Z_BLOCK).to eq(5)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'stream constants' do
|
64
|
+
it 'has the correct values' do
|
65
|
+
expect(Z_OK).to eq(0)
|
66
|
+
expect(Z_STREAM_END).to eq(1)
|
67
|
+
expect(Z_NEED_DICT).to eq(2)
|
68
|
+
expect(Z_ERRNO).to eq(-1)
|
69
|
+
expect(Z_EOF).to eq(-1)
|
70
|
+
expect(Z_STREAM_ERROR).to eq(-2)
|
71
|
+
expect(Z_DATA_ERROR).to eq(-3)
|
72
|
+
expect(Z_MEM_ERROR).to eq(-4)
|
73
|
+
expect(Z_BUF_ERROR).to eq(-5)
|
74
|
+
expect(Z_VERSION_ERROR).to eq(-6)
|
75
|
+
expect(Z_BUFSIZE).to eq(16384)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe 'compression constants' do
|
80
|
+
it 'has the correct values' do
|
81
|
+
expect(Z_NO_COMPRESSION).to eq(0)
|
82
|
+
expect(Z_BEST_SPEED).to eq(1)
|
83
|
+
expect(Z_BEST_COMPRESSION).to eq(9)
|
84
|
+
expect(Z_DEFAULT_COMPRESSION).to eq(-1)
|
85
|
+
expect(Z_DEFLATED).to eq(8)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'encoding constants' do
|
90
|
+
it 'has the correct values' do
|
91
|
+
expect(Z_FILTERED).to eq(1)
|
92
|
+
expect(Z_HUFFMAN_ONLY).to eq(2)
|
93
|
+
expect(Z_RLE).to eq(3)
|
94
|
+
expect(Z_FIXED).to eq(4)
|
95
|
+
expect(Z_DEFAULT_STRATEGY).to eq(0)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'CRC constants' do
|
100
|
+
it 'has the correct values' do
|
101
|
+
expect(ASCII_FLAG).to eq(0x01)
|
102
|
+
expect(HEAD_CRC).to eq(0x02)
|
103
|
+
expect(EXTRA_FIELD).to eq(0x04)
|
104
|
+
expect(ORIG_NAME).to eq(0x08)
|
105
|
+
expect(COMMENT_).to eq(0x10)
|
106
|
+
expect(RESERVED).to eq(0xE0)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#zError' do
|
111
|
+
it 'responds to zError' do
|
112
|
+
expect(self).to respond_to(:zError)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'returns correct error messages' do
|
116
|
+
expect(zError(Z_STREAM_END)).to eq('stream end')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '#zlibVersion' do
|
121
|
+
it 'responds to zlibVersion' do
|
122
|
+
expect(self).to respond_to(:zlibVersion)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'returns the zlib version' do
|
126
|
+
expect(zlibVersion).to eq(ZLIB_VERSION)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe '#z_error' do
|
131
|
+
it 'responds to z_error' do
|
132
|
+
expect(self).to respond_to(:z_error)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'raises RuntimeError' do
|
136
|
+
expect { z_error('hello') }.to raise_error(RuntimeError)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe '.adler32' do
|
141
|
+
it 'responds to adler32' do
|
142
|
+
expect(described_class).to respond_to(:adler32)
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'returns correct values' do
|
146
|
+
expect(described_class.adler32(32, nil)).to eq(1)
|
147
|
+
expect(described_class.adler32(0, buffer)).to eq(0)
|
148
|
+
expect(described_class.adler32(1, buffer)).to eq(1048577)
|
149
|
+
expect(described_class.adler32(10, buffer)).to eq(10485770)
|
150
|
+
expect(described_class.adler32(32, buffer)).to eq(33554464)
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'raises ArgumentError with wrong arguments' do
|
154
|
+
expect { described_class.adler32 }.to raise_error(ArgumentError)
|
155
|
+
expect { described_class.adler32('test') }.to raise_error(ArgumentError)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe '.get_crc_table' do
|
160
|
+
it 'responds to get_crc_table' do
|
161
|
+
expect(described_class).to respond_to(:get_crc_table)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe '.gz_open' do
|
166
|
+
it 'responds to gz_open' do
|
167
|
+
expect(described_class).to respond_to(:gz_open)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pr/zlib'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.expect_with :rspec do |expectations|
|
7
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
8
|
+
end
|
9
|
+
|
10
|
+
config.mock_with :rspec do |mocks|
|
11
|
+
mocks.verify_partial_doubles = true
|
12
|
+
end
|
13
|
+
|
14
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
15
|
+
config.filter_run_when_matching :focus
|
16
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
17
|
+
config.disable_monkey_patching!
|
18
|
+
config.warnings = true
|
19
|
+
|
20
|
+
if config.files_to_run.one?
|
21
|
+
config.default_formatter = "doc"
|
22
|
+
end
|
23
|
+
|
24
|
+
config.profile_examples = 10
|
25
|
+
config.order = :random
|
26
|
+
Kernel.srand config.seed
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
########################################################################
|
4
|
+
# deflate_spec.rb
|
5
|
+
#
|
6
|
+
# Spec for the Zlib::Deflate class.
|
7
|
+
########################################################################
|
8
|
+
require 'spec_helper'
|
9
|
+
|
10
|
+
RSpec.describe Zlib::Deflate do
|
11
|
+
let(:deflate) { described_class.new }
|
12
|
+
|
13
|
+
describe 'class methods' do
|
14
|
+
it 'responds to deflate_run' do
|
15
|
+
expect(described_class).to respond_to(:deflate_run)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'responds to deflate' do
|
19
|
+
expect(described_class).to respond_to(:deflate)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'instance methods' do
|
24
|
+
it 'responds to deflate' do
|
25
|
+
expect(deflate).to respond_to(:deflate)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'responds to <<' do
|
29
|
+
expect(deflate).to respond_to(:<<)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'responds to flush' do
|
33
|
+
expect(deflate).to respond_to(:flush)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'responds to params' do
|
37
|
+
expect(deflate).to respond_to(:params)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'responds to set_dictionary' do
|
41
|
+
expect(deflate).to respond_to(:set_dictionary)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
########################################################################
|
4
|
+
# gzip_file_spec.rb
|
5
|
+
#
|
6
|
+
# Spec for the Zlib::GzipFile base class.
|
7
|
+
########################################################################
|
8
|
+
require 'spec_helper'
|
9
|
+
|
10
|
+
RSpec.describe Zlib::GzipFile do
|
11
|
+
let(:gz_file) { described_class.new }
|
12
|
+
|
13
|
+
describe 'constants' do
|
14
|
+
it 'has the correct constant values' do
|
15
|
+
expect(described_class::GZ_MAGIC1).to eq(0x1f)
|
16
|
+
expect(described_class::GZ_MAGIC2).to eq(0x8b)
|
17
|
+
expect(described_class::GZ_METHOD_DEFLATE).to eq(8)
|
18
|
+
expect(described_class::GZ_FLAG_MULTIPART).to eq(0x2)
|
19
|
+
expect(described_class::GZ_FLAG_EXTRA).to eq(0x4)
|
20
|
+
expect(described_class::GZ_FLAG_ORIG_NAME).to eq(0x8)
|
21
|
+
expect(described_class::GZ_FLAG_COMMENT).to eq(0x10)
|
22
|
+
expect(described_class::GZ_FLAG_ENCRYPT).to eq(0x20)
|
23
|
+
expect(described_class::GZ_FLAG_UNKNOWN_MASK).to eq(0xc0)
|
24
|
+
expect(described_class::GZ_EXTRAFLAG_FAST).to eq(0x4)
|
25
|
+
expect(described_class::GZ_EXTRAFLAG_SLOW).to eq(0x2)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'instance methods' do
|
30
|
+
it 'responds to GZFILE_IS_FINISHED' do
|
31
|
+
expect(gz_file).to respond_to(:GZFILE_IS_FINISHED)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'responds to gzfile_close' do
|
35
|
+
expect(gz_file).to respond_to(:gzfile_close)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'responds to to_io' do
|
39
|
+
expect(gz_file).to respond_to(:to_io)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'responds to crc' do
|
43
|
+
expect(gz_file).to respond_to(:crc)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'responds to mtime' do
|
47
|
+
expect(gz_file).to respond_to(:mtime)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'responds to level' do
|
51
|
+
expect(gz_file).to respond_to(:level)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'responds to os_code' do
|
55
|
+
expect(gz_file).to respond_to(:os_code)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'responds to orig_name' do
|
59
|
+
expect(gz_file).to respond_to(:orig_name)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'responds to comment' do
|
63
|
+
expect(gz_file).to respond_to(:comment)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'responds to close' do
|
67
|
+
expect(gz_file).to respond_to(:close)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'responds to finish' do
|
71
|
+
expect(gz_file).to respond_to(:finish)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'responds to closed?' do
|
75
|
+
expect(gz_file).to respond_to(:closed?)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'responds to sync' do
|
79
|
+
expect(gz_file).to respond_to(:sync)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'responds to sync=' do
|
83
|
+
expect(gz_file).to respond_to(:sync=)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,276 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
########################################################################
|
4
|
+
# gzip_reader_spec.rb
|
5
|
+
#
|
6
|
+
# Spec for the Zlib::GzipReader class.
|
7
|
+
########################################################################
|
8
|
+
require 'spec_helper'
|
9
|
+
require 'fileutils'
|
10
|
+
|
11
|
+
RSpec.describe Zlib::GzipReader do
|
12
|
+
before(:all) do
|
13
|
+
# Set up test file paths
|
14
|
+
@original_dir = Dir.pwd
|
15
|
+
@spec_dir = File.join(@original_dir, 'spec')
|
16
|
+
@test_txt = File.join(@spec_dir, 'test.txt')
|
17
|
+
@gz_file_path = File.join(@spec_dir, 'test.txt.gz')
|
18
|
+
|
19
|
+
# Ensure spec directory exists
|
20
|
+
Dir.mkdir(@spec_dir) unless Dir.exist?(@spec_dir)
|
21
|
+
|
22
|
+
# Clean up any existing files first
|
23
|
+
File.delete(@test_txt) if File.exist?(@test_txt)
|
24
|
+
File.delete(@gz_file_path) if File.exist?(@gz_file_path)
|
25
|
+
|
26
|
+
# Create test file and gzip it
|
27
|
+
File.open(@test_txt, 'wb') { |fh| fh.puts 'Test file' }
|
28
|
+
Dir.chdir(@spec_dir) do
|
29
|
+
system('gzip test.txt')
|
30
|
+
end
|
31
|
+
|
32
|
+
@gz_file = @gz_file_path
|
33
|
+
end
|
34
|
+
|
35
|
+
after(:all) do
|
36
|
+
# Clean up test files
|
37
|
+
[@test_txt, @gz_file_path].each do |file|
|
38
|
+
File.delete(file) if File.exist?(file)
|
39
|
+
end
|
40
|
+
# Also clean up any leftover files in spec directory
|
41
|
+
Dir.glob(File.join(@spec_dir, 'test.txt*')).each { |f| File.delete(f) rescue nil }
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:handle) { File.open(@gz_file) }
|
45
|
+
let(:gz_reader) { described_class.new(handle) }
|
46
|
+
|
47
|
+
after do
|
48
|
+
handle.close if handle && !handle.closed?
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'constructor' do
|
52
|
+
it 'raises ArgumentError with no arguments' do
|
53
|
+
expect { described_class.new }.to raise_error(ArgumentError)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'raises NoMethodError with invalid argument' do
|
57
|
+
expect { described_class.new(1) }.to raise_error(NoMethodError)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#lineno' do
|
62
|
+
it 'responds to lineno getter' do
|
63
|
+
expect(gz_reader).to respond_to(:lineno)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'can get lineno without errors' do
|
67
|
+
expect { gz_reader.lineno }.not_to raise_error
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns an integer' do
|
71
|
+
expect(gz_reader.lineno).to be_a(Integer)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'starts at 0' do
|
75
|
+
expect(gz_reader.lineno).to eq(0)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'responds to lineno setter' do
|
79
|
+
expect(gz_reader).to respond_to(:lineno=)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'can set lineno without errors' do
|
83
|
+
expect { gz_reader.lineno = 0 }.not_to raise_error
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'returns the set value' do
|
87
|
+
expect(gz_reader.lineno = 0).to eq(0)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#eof' do
|
92
|
+
it 'responds to eof' do
|
93
|
+
expect(gz_reader).to respond_to(:eof)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'can call eof without errors' do
|
97
|
+
expect { gz_reader.eof }.not_to raise_error
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#pos' do
|
102
|
+
it 'responds to pos' do
|
103
|
+
expect(gz_reader).to respond_to(:pos)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'can call pos without errors' do
|
107
|
+
expect { gz_reader.pos }.not_to raise_error
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'returns an integer' do
|
111
|
+
expect(gz_reader.pos).to be_a(Integer)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#rewind' do
|
116
|
+
it 'responds to rewind' do
|
117
|
+
expect(gz_reader).to respond_to(:rewind)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'can call rewind without errors' do
|
121
|
+
expect { gz_reader.rewind }.not_to raise_error
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'returns 0' do
|
125
|
+
expect(gz_reader.rewind).to eq(0)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#unused' do
|
130
|
+
it 'responds to unused' do
|
131
|
+
expect(gz_reader).to respond_to(:unused)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'can call unused without errors' do
|
135
|
+
expect { gz_reader.unused }.not_to raise_error
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'returns nil initially' do
|
139
|
+
expect(gz_reader.unused).to be_nil
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '#read' do
|
144
|
+
it 'responds to read' do
|
145
|
+
expect(gz_reader).to respond_to(:read)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'can call read without errors' do
|
149
|
+
expect { gz_reader.read }.not_to raise_error
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'reads the entire file content' do
|
153
|
+
expect(gz_reader.read).to eq("Test file\n")
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'can read with length parameter' do
|
157
|
+
expect(gz_reader.read(4)).to eq("Test")
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'raises ArgumentError for negative length' do
|
161
|
+
expect { gz_reader.read(-1) }.to raise_error(ArgumentError)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe '#getc' do
|
166
|
+
it 'responds to getc' do
|
167
|
+
expect(gz_reader).to respond_to(:getc)
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'can call getc without errors' do
|
171
|
+
expect { gz_reader.getc }.not_to raise_error
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'returns the first character' do
|
175
|
+
expect(gz_reader.getc).to eq('T')
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '#readchar' do
|
180
|
+
it 'responds to readchar' do
|
181
|
+
expect(gz_reader).to respond_to(:readchar)
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'can call readchar without errors' do
|
185
|
+
expect { gz_reader.readchar }.not_to raise_error
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'returns the first character' do
|
189
|
+
expect(gz_reader.readchar).to eq('T')
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe '#each_byte' do
|
194
|
+
it 'responds to each_byte' do
|
195
|
+
expect(gz_reader).to respond_to(:each_byte)
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'can call each_byte without errors' do
|
199
|
+
expect { gz_reader.each_byte {} }.not_to raise_error
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'returns nil when called with block' do
|
203
|
+
expect(gz_reader.each_byte {}).to be_nil
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe '#ungetc' do
|
208
|
+
it 'responds to ungetc' do
|
209
|
+
expect(gz_reader).to respond_to(:ungetc)
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'can call ungetc without errors' do
|
213
|
+
expect { gz_reader.ungetc(99) }.not_to raise_error
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'returns nil' do
|
217
|
+
expect(gz_reader.ungetc(99)).to be_nil
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe '#gets' do
|
222
|
+
it 'responds to gets' do
|
223
|
+
expect(gz_reader).to respond_to(:gets)
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'can call gets without errors' do
|
227
|
+
expect { gz_reader.gets }.not_to raise_error
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'reads a line' do
|
231
|
+
expect(gz_reader.gets).to eq("Test file\n")
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
describe '#readline' do
|
236
|
+
it 'responds to readline' do
|
237
|
+
expect(gz_reader).to respond_to(:readline)
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'can call readline without errors' do
|
241
|
+
expect { gz_reader.readline }.not_to raise_error
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'reads a line' do
|
245
|
+
expect(gz_reader.readline).to eq("Test file\n")
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
describe '#each' do
|
250
|
+
it 'responds to each' do
|
251
|
+
expect(gz_reader).to respond_to(:each)
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'can call each without errors' do
|
255
|
+
expect { gz_reader.each {} }.not_to raise_error
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'returns non-nil when called with block' do
|
259
|
+
expect(gz_reader.each {}).not_to be_nil
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe '#readlines' do
|
264
|
+
it 'responds to readlines' do
|
265
|
+
expect(gz_reader).to respond_to(:readlines)
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'can call readlines without errors' do
|
269
|
+
expect { gz_reader.readlines }.not_to raise_error
|
270
|
+
end
|
271
|
+
|
272
|
+
it 'returns array of lines' do
|
273
|
+
expect(gz_reader.readlines).to eq(["Test file\n"])
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|