bzip2-ffi 1.0.0 → 1.1.1

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.
@@ -1,9 +1,12 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'pathname'
2
5
 
3
6
  module Bzip2
4
7
  module FFI
5
- # `Writer` compresses and writes a bzip2 compressed stream or file. The
6
- # public instance methods of `Writer` are intended to be equivalent to those
8
+ # {Writer} compresses and writes a bzip2 compressed stream or file. The
9
+ # public instance methods of {Writer} are intended to be equivalent to those
7
10
  # of a standard `IO` object.
8
11
  #
9
12
  # Data can be written as a stream using {open} and {#write}. For example,
@@ -15,7 +18,7 @@ module Bzip2
15
18
  # end
16
19
  # end
17
20
  #
18
- # Alternatively, without passing a block to `open`:
21
+ # Alternatively, without passing a block to {open}:
19
22
  #
20
23
  # writer = Bzip2::FFI::Writer.open(io_or_path)
21
24
  # begin
@@ -30,41 +33,45 @@ module Bzip2
30
33
  #
31
34
  # Bzip2::FFI::Writer.write(io_or_path, 'Hello, World!')
32
35
  #
33
- # The {open} and {write} methods accept either an `IO`-like object or a file
34
- # path. `IO`-like objects must have a `write` method. Paths can be given as
36
+ # The {open} and {write} methods accept either an IO-like object or a file
37
+ # path. IO-like objects must have a `#write` method. Paths can be given as
35
38
  # either a `String` or `Pathname`.
36
39
  #
37
40
  # No character conversion is performed when writing and compressing. The
38
41
  # {write} and {#write} methods compress the raw bytes from the given
39
42
  # `String` (using the encoding of the `String`).
43
+ #
44
+ # {Writer} does not support seeking (it's not supported by the underlying
45
+ # libbz2 library). There are no `#seek` or `#pos=` methods.
40
46
  class Writer < IO
41
47
  # Size of the buffer passed to libbz2 for it to write compressed data to.
42
48
  #
43
49
  # @private
44
50
  OUT_BUFFER_SIZE = 4096 #:nodoc:
51
+ private_constant :OUT_BUFFER_SIZE
45
52
 
46
53
  class << self
47
54
  # Use send to keep this hidden from YARD (visibility tag does not work).
48
55
  send(:public, :new)
49
56
 
50
- # Opens a {Writer} to compress and write bzip2 compressed data to
51
- # either an `IO`-like object or a file. `IO`-like objects must have a
52
- # `write` method. Files can be specified using either a `String`
53
- # containing the file path or a `Pathname`.
57
+ # Opens a {Writer} to compress and write bzip2 compressed data to either
58
+ # an IO-like object or a file. IO-like objects must have a `#write`
59
+ # method. Files can be specified using either a `String` containing the
60
+ # file path or a `Pathname`.
54
61
  #
55
- # If no block is given, the opened `Writer` instance is returned. After
62
+ # If no block is given, the opened {Writer} instance is returned. After
56
63
  # writing data, the instance must be closed using the {#close} method in
57
64
  # order to complete the compression process.
58
65
  #
59
- # If a block is given, it will be passed the opened `Writer` instance
60
- # as an argument. After the block terminates, the `Writer` instance will
66
+ # If a block is given, it will be passed the opened {Writer} instance
67
+ # as an argument. After the block terminates, the {Writer} instance will
61
68
  # automatically be closed. `open` will then return the result of the
62
69
  # block.
63
70
  #
64
71
  # The following options can be specified using the `options` `Hash`:
65
72
  #
66
- # * `:autoclose` - When passing an `IO`-like object, set to `true` to
67
- # close the `IO` when the `Writer` instance is closed.
73
+ # * `:autoclose` - When passing an IO-like object, set to `true` to
74
+ # close it when the {Writer} instance is closed.
68
75
  # * `:block_size` - Specifies the block size used for compression. It
69
76
  # should be set to an integer between 1 and 9
70
77
  # inclusive. The actual block size used is 100 kB
@@ -86,25 +93,25 @@ module Bzip2
86
93
  # the fallback. Allowable values range from 0 to 250
87
94
  # inclusive. 0 is a special case, equivalent to using
88
95
  # the default libbz2 work factor value (30 as of
89
- # bzip2 v1.0.6). If not specified, `:work_factor`
96
+ # bzip2 v1.0.8). If not specified, `:work_factor`
90
97
  # defaults to 0.
91
98
  #
92
- # If an `IO`-like object that has a `binmode` method is passed to
93
- # `open`, `binmode` will be called on `io_or_path` before yielding to
94
- # the block or returning.
99
+ # If an IO-like object that has a `#binmode` method is passed to {open},
100
+ # `#binmode` will be called on `io_or_path` before yielding to the block
101
+ # or returning.
95
102
  #
96
103
  # If a path to a file that already exists is passed to `open`, the file
97
104
  # will be truncated before writing.
98
105
  #
99
- # @param io_or_path [Object] Either an `IO`-like object with a `write`
106
+ # @param io_or_path [Object] Either an IO-like object with a `#write`
100
107
  # method or a file path as a `String` or
101
108
  # `Pathname`.
102
109
  # @param options [Hash] Optional parameters (`:autoclose`, `:block_size`
103
110
  # and `:small`).
104
- # @return [Object] The opened `Writer` instance if no block is given, or
111
+ # @return [Object] The opened {Writer} instance if no block is given, or
105
112
  # the result of the block if a block is given.
106
113
  # @raise [ArgumentError] If `io_or_path` is _not_ a `String`, `Pathname`
107
- # or an `IO`-like object with a `write` method.
114
+ # or an IO-like object with a `#write` method.
108
115
  # @raise [Errno::ENOENT] If the parent directory of the specified file
109
116
  # does not exist.
110
117
  # @raise [Error::Bzip2Error] If an error occurs when initializing
@@ -122,14 +129,14 @@ module Bzip2
122
129
  end
123
130
 
124
131
  # Compresses data from a `String` and writes an entire bzip2 compressed
125
- # structure to either an `IO`-like object or a file. `IO`-like objects
126
- # must have a `write` method. Files can be specified using either a
132
+ # structure to either an IO-like object or a file. IO-like objects
133
+ # must have a `#write` method. Files can be specified using either a
127
134
  # `String` containing the file path or a `Pathname`.
128
135
  #
129
136
  # The following options can be specified using the `options` `Hash`:
130
137
  #
131
- # * `:autoclose` - When passing an `IO`-like object, set to `true` to
132
- # close the `IO` when the `Writer` instance is closed.
138
+ # * `:autoclose` - When passing an IO-like object, set to `true` to
139
+ # close it when the {Writer} instance is closed.
133
140
  # * `:block_size` - Specifies the block size used for compression. It
134
141
  # should be set to an integer between 1 and 9
135
142
  # inclusive. The actual block size used is 100 kB
@@ -151,28 +158,28 @@ module Bzip2
151
158
  # the fallback. Allowable values range from 0 to 250
152
159
  # inclusive. 0 is a special case, equivalent to using
153
160
  # the default libbz2 work factor value (30 as of
154
- # bzip2 v1.0.6). If not specified, `:work_factor`
161
+ # bzip2 v1.0.8). If not specified, `:work_factor`
155
162
  # defaults to 0.
156
163
  #
157
164
  # No character conversion is performed. The raw bytes from `string` are
158
165
  # compressed (using the encoding of `string`).
159
166
  #
160
- # If an `IO`-like object that has a `binmode` method is passed to
161
- # `write`, `binmode` will be called on `io_or_path` before any
167
+ # If an IO-like object that has a `#binmode` method is passed to
168
+ # {write}, `#binmode` will be called on `io_or_path` before any
162
169
  # compressed data is written.
163
170
  #
164
171
  # The number of uncompressed bytes written is returned.
165
172
  #
166
- # @param io_or_path [Object] Either an `IO`-like object with a `write`
173
+ # @param io_or_path [Object] Either an IO-like object with a `#write`
167
174
  # method or a file path as a `String` or
168
175
  # `Pathname`.
169
- # @param string [Object] The string to write (`to_s` will be called
170
- # before writing).
176
+ # @param string [Object] The string to write (the result of calling
177
+ # `#to_s` on `string` will be written).
171
178
  # @param options [Hash] Optional parameters (`:autoclose`, `:block_size`
172
179
  # and `:small`).
173
180
  # @return [Integer] The number of uncompressed bytes written.
174
181
  # @raise [ArgumentError] If `io_or_path` is _not_ a `String`, `Pathname`
175
- # or an `IO`-like object with a `write` method.
182
+ # or an IO-like object with a `#write` method.
176
183
  # @raise [Errno::ENOENT] If the parent directory of the specified file
177
184
  # does not exist.
178
185
  # @raise [Error::Bzip2Error] If an error occurs when initializing
@@ -186,10 +193,10 @@ module Bzip2
186
193
  private
187
194
 
188
195
  # Returns a Proc that can be used as a finalizer to call
189
- # `BZ2_bzCompressEnd` with the given `stream`.
196
+ # {Libbz2::BZ2_bzCompressEnd} with the given `stream`.
190
197
  #
191
198
  # @param stream [Libbz2::BzStream] The stream that should be passed to
192
- # `BZ2_bzCompressEnd`.
199
+ # {Libbz2::BZ2_bzCompressEnd}.
193
200
  def finalize(stream)
194
201
  ->(id) do
195
202
  Libbz2::BZ2_bzCompressEnd(stream)
@@ -197,13 +204,13 @@ module Bzip2
197
204
  end
198
205
  end
199
206
 
200
- # Initializes a {Writer} to write compressed data to an `IO`-like object
201
- # (`io`). `io` must have a `write` method.
207
+ # Initializes a {Writer} to write compressed data to an IO-like object
208
+ # (`io`). `io` must have a `#write` method.
202
209
  #
203
210
  # The following options can be specified using the `options` `Hash`:
204
211
  #
205
- # * `:autoclose` - When passing an `IO`-like object, set to `true` to
206
- # close the `IO` when the `Writer` instance is closed.
212
+ # * `:autoclose` - When passing an IO-like object, set to `true` to
213
+ # close it when the {Writer} instance is closed.
207
214
  # * `:block_size` - Specifies the block size used for compression. It
208
215
  # should be set to an integer between 1 and 9
209
216
  # inclusive. The actual block size used is 100 kB
@@ -225,32 +232,32 @@ module Bzip2
225
232
  # the fallback. Allowable values range from 0 to 250
226
233
  # inclusive. 0 is a special case, equivalent to using
227
234
  # the default libbz2 work factor value (30 as of
228
- # bzip2 v1.0.6). If not specified, `:work_factor`
235
+ # bzip2 v1.0.8). If not specified, `:work_factor`
229
236
  # defaults to 0.
230
237
  #
231
- # `binmode` is called on `io` if `io` responds to `binmode`.
238
+ # `#binmode` is called on `io` if `io` responds to `#binmode`.
232
239
  #
233
- # After use, the `Writer` instance must be closed using the {#close}
240
+ # After use, the {Writer} instance must be closed using the {#close}
234
241
  # method in order to complete the compression process.
235
242
  #
236
- # @param io [Object] An `IO`-like object that has a `write` method.
243
+ # @param io [Object] An IO-like object that has a `#write` method.
237
244
  # @param options [Hash] Optional parameters (`:autoclose`, `:block_size`
238
245
  # and `:small`).
239
- # @raise [ArgumentError] If `io` is `nil` or does not respond to `write`.
246
+ # @raise [ArgumentError] If `io` is `nil` or does not respond to `#write`.
240
247
  # @raise [RangeError] If `options[:block_size]` is less than 1 or greater
241
248
  # than 9, or `options[:work_factor]` is less than 0 or
242
249
  # greater than 250.
243
250
  # @raise [Error::Bzip2Error] If an error occurs when initializing libbz2.
244
- def initialize(io, options = {})
251
+ def initialize(io, options = {})
245
252
  super
246
253
  raise ArgumentError, 'io must respond to write' unless io.respond_to?(:write)
247
-
254
+
248
255
  block_size = options[:block_size] || 9
249
256
  work_factor = options[:work_factor] || 0
250
-
257
+
251
258
  raise RangeError, 'block_size must be >= 1 and <= 9' if block_size < 1 || block_size > 9
252
259
  raise RangeError, 'work_factor must be >= 0 and <= 250' if work_factor < 0 || work_factor > 250
253
-
260
+
254
261
  check_error(Libbz2::BZ2_bzCompressInit(stream, block_size, 0, work_factor))
255
262
 
256
263
  ObjectSpace.define_finalizer(self, self.class.send(:finalize, stream))
@@ -261,11 +268,11 @@ module Bzip2
261
268
  # {Writer}.
262
269
  #
263
270
  # If the {open} method is used with a block, it is not necessary to call
264
- # `close`. Otherwise, `close` must be called once the all the data to be
271
+ # {close}. Otherwise, {close} must be called once the all the data to be
265
272
  # compressed has been passed to `#write`.
266
273
  #
267
274
  # @return [NilType] `nil`.
268
- # @raise [IOError] If the `Writer` has already been closed.
275
+ # @raise [IOError] If the {Writer} has already been closed.
269
276
  def close
270
277
  s = stream
271
278
  flush_buffers(s, Libbz2::BZ_FINISH, Libbz2::BZ_STREAM_END)
@@ -283,11 +290,11 @@ module Bzip2
283
290
  #
284
291
  # The number of uncompressed bytes written is returned.
285
292
  #
286
- # @param string [Object] The string to write (`to_s` will be called
287
- # before writing).
293
+ # @param string [Object] The string to write (the result of calling
294
+ # `#to_s` on `string` will be written).
288
295
  # @return [Integer] The number of uncompressed bytes written.
289
296
  # @raise [Error::Bzip2Error] If an error occurs during compression.
290
- # @raise [IOError] If the `Writer` has been closed.
297
+ # @raise [IOError] If the {Writer} has been closed.
291
298
  def write(string)
292
299
  string = string.to_s
293
300
 
@@ -296,7 +303,7 @@ module Bzip2
296
303
  buffer = ::FFI::MemoryPointer.new(1, OUT_BUFFER_SIZE)
297
304
  begin
298
305
  next_in.write_bytes(string)
299
- s[:next_in] = next_in
306
+ s[:next_in] = next_in
300
307
  s[:avail_in] = next_in.size
301
308
 
302
309
  while s[:avail_in] > 0
@@ -322,29 +329,41 @@ module Bzip2
322
329
  # writes out the current bzip2 compressed block to the underlying
323
330
  # compressed stream or file.
324
331
  #
325
- # It is not usually necessary to call `flush`.
332
+ # It is not usually necessary to call {flush}.
326
333
  #
327
- # Calling `flush` may result in a larger compressed output.
334
+ # Calling {flush} may result in a larger compressed output.
328
335
  #
329
336
  # @return [Writer] `self`.
330
337
  # @raise [Error::Bzip2Error] If an error occurs during the flush
331
338
  # operation.
332
- # @raise [IOError] If the `Writer` has been closed.
339
+ # @raise [IOError] If the {Writer} has been closed.
333
340
  def flush
334
341
  flush_buffers(stream, Libbz2::BZ_FLUSH, Libbz2::BZ_RUN_OK)
335
342
  self
336
343
  end
337
344
 
345
+ # Returns the number of uncompressed bytes that have been written.
346
+ #
347
+ # @return [Integer] The number of uncompressed bytes that have been
348
+ # written.
349
+ # @raise [IOError] If the {Writer} has been closed.
350
+ def tell
351
+ s = stream
352
+ (s[:total_in_hi32] << 32) | s[:total_in_lo32]
353
+ end
354
+ alias pos tell
355
+
338
356
  private
339
357
 
340
- # Calls `BZ2_bzCompress` repeatedly without input to complete compression
341
- # of data that has been provided in prior calls.
358
+ # Calls {Libbz2::BZ2_bzCompress} repeatedly without input to complete
359
+ # compression of data that has been provided in prior calls.
342
360
  #
343
- # @param s [Libbz2::BzStream] The stream to pass to `BZ2_bzCompress`.
344
- # @param action [Integer] The action to pass to `BZ2_bzCompress`.
361
+ # @param s [Libbz2::BzStream] The stream to pass to
362
+ # {Libbz2::BZ2_bzCompress}.
363
+ # @param action [Integer] The action to pass to {Libbz2::BZ2_bzCompress}.
345
364
  # @param terminate_result [Integer] The result code that indicates when
346
365
  # the action has been completed.
347
- # @raise [Error::Bzip2Error] If `BZ2_bzCompress` reports an error.
366
+ # @raise [Error::Bzip2Error] If {Libbz2::BZ2_bzCompress} reports an error.
348
367
  def flush_buffers(s, action, terminate_result)
349
368
  s[:next_in] = nil
350
369
  s[:avail_in] = 0
@@ -367,7 +386,7 @@ module Bzip2
367
386
  buffer.free
368
387
  s[:next_out] = nil
369
388
  end
370
- end
389
+ end
371
390
  end
372
391
  end
373
392
  end
data/lib/bzip2/ffi.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  module Bzip2
2
5
  # Bzip2::FFI is a wrapper for libbz2 using FFI bindings. Bzip2 compressed data
3
6
  # can be read and written as a stream using the Reader and Writer classes.
@@ -5,10 +8,10 @@ module Bzip2
5
8
  end
6
9
  end
7
10
 
8
- require 'bzip2/ffi/libbz2'
9
- require 'bzip2/ffi/error'
10
- require 'bzip2/ffi/io'
11
- require 'bzip2/ffi/reader'
12
- require 'bzip2/ffi/writer'
13
- require 'bzip2/ffi/version'
11
+ require_relative 'ffi/libbz2'
12
+ require_relative 'ffi/error'
13
+ require_relative 'ffi/io'
14
+ require_relative 'ffi/reader'
15
+ require_relative 'ffi/writer'
16
+ require_relative 'ffi/version'
14
17
 
data/test/error_test.rb CHANGED
@@ -1,4 +1,7 @@
1
- require 'test_helper'
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'test_helper'
2
5
 
3
6
  class ErrorTest < Minitest::Test
4
7
  def test_initialize_base_class
@@ -7,30 +10,26 @@ class ErrorTest < Minitest::Test
7
10
  assert_same(message, error.message)
8
11
  end
9
12
 
10
- def test_initialize_sub_classes
11
- classes = [
12
- Bzip2::FFI::Error::SequenceError,
13
- Bzip2::FFI::Error::ParamError,
14
- Bzip2::FFI::Error::MemoryError,
15
- Bzip2::FFI::Error::ParamError,
16
- Bzip2::FFI::Error::DataError,
17
- Bzip2::FFI::Error::MagicDataError,
18
- Bzip2::FFI::Error::ConfigError,
19
- Bzip2::FFI::Error::UnexpectedEofError
20
- ]
21
-
22
- classes.each do |c|
13
+ [
14
+ Bzip2::FFI::Error::SequenceError,
15
+ Bzip2::FFI::Error::ParamError,
16
+ Bzip2::FFI::Error::MemoryError,
17
+ Bzip2::FFI::Error::DataError,
18
+ Bzip2::FFI::Error::MagicDataError,
19
+ Bzip2::FFI::Error::ConfigError,
20
+ Bzip2::FFI::Error::UnexpectedEofError
21
+ ].each do |c|
22
+ define_method("test_initialize_sub_classes_#{c.name.split('::').last.gsub(/([a-z])([A-Z])/, '\1_\2').downcase}") do
23
23
  error = c.new
24
24
  refute_nil(error.message)
25
25
  end
26
26
  end
27
27
 
28
- def test_initialize_unexpected
29
- # -6, -7 and -8 are errors that are only raised by the libbz2 high-level
30
- # interface. Only the low-level interface is used by Bzip2::FFI.
31
- # -10 is not defined by libbz2.
32
-
33
- [-6, -7, -8, -10].each do |code|
28
+ # -6, -7 and -8 are errors that are only raised by the libbz2 high-level
29
+ # interface. Only the low-level interface is used by Bzip2::FFI. -10 is not
30
+ # defined by libbz2.
31
+ [-6, -7, -8, -10].each do |code|
32
+ define_method("test_initialize_unexpected_#{code}") do
34
33
  error = Bzip2::FFI::Error::UnexpectedError.new(code)
35
34
  assert_includes(error.message, code.to_s)
36
35
  end
Binary file
data/test/io_test.rb CHANGED
@@ -1,11 +1,14 @@
1
- require 'test_helper'
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'test_helper'
2
5
 
3
6
  class IOTest < Minitest::Test
4
7
  class DummyIO
5
8
  def initialize
6
9
  @closed = false
7
10
  end
8
-
11
+
9
12
  def close
10
13
  @closed = true
11
14
  end
@@ -36,6 +39,9 @@ class IOTest < Minitest::Test
36
39
  end
37
40
  end
38
41
 
42
+ # Private constant.
43
+ LIBBZ2 = Bzip2::FFI.const_get(:Libbz2)
44
+
39
45
  def test_autoclose_set_true
40
46
  io = TestIO.new(DummyIO.new, autoclose: false)
41
47
  assert_equal(false, io.autoclose?)
@@ -138,7 +144,7 @@ class IOTest < Minitest::Test
138
144
  io.close
139
145
  assert_equal(true, io.closed?)
140
146
  end
141
-
147
+
142
148
  def test_external_encoding
143
149
  io = TestIO.new(DummyIO.new)
144
150
  assert_equal(Encoding::ASCII_8BIT, io.external_encoding)
@@ -192,7 +198,7 @@ class IOTest < Minitest::Test
192
198
  io = TestIO.new(DummyIO.new)
193
199
  s = io.stream
194
200
  refute_nil(s)
195
- assert_kind_of(Bzip2::FFI::Libbz2::BzStream, s)
201
+ assert_kind_of(LIBBZ2.const_get(:BzStream), s)
196
202
  end
197
203
 
198
204
  def test_stream_when_closed
@@ -213,38 +219,34 @@ class IOTest < Minitest::Test
213
219
  assert_equal('closed stream', e.message)
214
220
  end
215
221
 
216
- def test_check_error_not_error
217
- io = TestIO.new(DummyIO.new)
218
-
219
- (0..4).each do |i|
222
+ (0..4).each do |i|
223
+ define_method("test_check_error_not_error_#{i}") do
224
+ io = TestIO.new(DummyIO.new)
220
225
  assert_equal(i, io.check_error(i))
221
226
  end
222
227
  end
223
228
 
224
- def test_check_error_error
225
- codes = {
226
- Bzip2::FFI::Libbz2::BZ_SEQUENCE_ERROR => Bzip2::FFI::Error::SequenceError,
227
- Bzip2::FFI::Libbz2::BZ_PARAM_ERROR => Bzip2::FFI::Error::ParamError,
228
- Bzip2::FFI::Libbz2::BZ_MEM_ERROR => Bzip2::FFI::Error::MemoryError,
229
- Bzip2::FFI::Libbz2::BZ_DATA_ERROR => Bzip2::FFI::Error::DataError,
230
- Bzip2::FFI::Libbz2::BZ_DATA_ERROR_MAGIC => Bzip2::FFI::Error::MagicDataError,
231
- Bzip2::FFI::Libbz2::BZ_CONFIG_ERROR => Bzip2::FFI::Error::ConfigError
232
- }
233
-
234
- io = TestIO.new(DummyIO.new)
235
-
236
- codes.each do |code, error_class|
229
+ {
230
+ :BZ_SEQUENCE_ERROR => Bzip2::FFI::Error::SequenceError,
231
+ :BZ_PARAM_ERROR => Bzip2::FFI::Error::ParamError,
232
+ :BZ_MEM_ERROR => Bzip2::FFI::Error::MemoryError,
233
+ :BZ_DATA_ERROR => Bzip2::FFI::Error::DataError,
234
+ :BZ_DATA_ERROR_MAGIC => Bzip2::FFI::Error::MagicDataError,
235
+ :BZ_CONFIG_ERROR => Bzip2::FFI::Error::ConfigError
236
+ }.each do |type, error_class|
237
+ define_method("test_check_error_error_#{type}") do
238
+ io = TestIO.new(DummyIO.new)
239
+ code = LIBBZ2.const_get(type)
237
240
  assert_raises(error_class) { io.check_error(code) }
238
241
  end
239
242
  end
240
243
 
241
- def test_check_error_unexpected
242
- io = TestIO.new(DummyIO.new)
243
-
244
- # -6, -7 and -8 are codes that are only raised by the libbz2 high-level
245
- # interface. Only the low-level interface is used by Bzip2::FFI.
246
- # -10 is not defined by libbz2.
247
- [-6, -7, -8, -10].each do |code|
244
+ # -6, -7 and -8 are codes that are only raised by the libbz2 high-level
245
+ # interface. Only the low-level interface is used by Bzip2::FFI. -10 is not
246
+ # defined by libbz2.
247
+ [-6, -7, -8, -10].each do |code|
248
+ define_method("test_check_error_unexpected_#{code}") do
249
+ io = TestIO.new(DummyIO.new)
248
250
  error = assert_raises(Bzip2::FFI::Error::UnexpectedError) { io.check_error(code) }
249
251
  assert_includes(error.message, code.to_s)
250
252
  end
@@ -304,14 +306,14 @@ class IOTest < Minitest::Test
304
306
  res = TestIO.open(dummy_io) do |io|
305
307
  assert_kind_of(TestIO, io)
306
308
  refute(io.closed?)
307
- assert_equal(false, io.autoclose?)
309
+ assert_equal(false, io.autoclose?)
308
310
  assert_same(dummy_io, io.io)
309
311
  copy_io = io
310
312
  42
311
313
  end
312
314
 
313
315
  assert(copy_io.closed?)
314
- assert_equal(42, res)
316
+ assert_equal(42, res)
315
317
  end
316
318
 
317
319
  def test_open_block_options
@@ -321,14 +323,14 @@ class IOTest < Minitest::Test
321
323
  res = TestIO.open(dummy_io, autoclose: true) do |io|
322
324
  assert_kind_of(TestIO, io)
323
325
  refute(io.closed?)
324
- assert_equal(true, io.autoclose?)
326
+ assert_equal(true, io.autoclose?)
325
327
  assert_same(dummy_io, io.io)
326
328
  copy_io = io
327
329
  42
328
330
  end
329
331
 
330
332
  assert(copy_io.closed?)
331
- assert_equal(42, res)
333
+ assert_equal(42, res)
332
334
  end
333
335
 
334
336
  def test_open_block_closes