bzip2-ffi 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,9 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  module Bzip2
2
5
  module FFI
3
6
  # The Bzip2::FFI version number.
4
- VERSION = '1.0.0'
7
+ VERSION = '1.1.0'
5
8
  end
6
9
  end
@@ -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,8 +33,8 @@ 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
@@ -42,29 +45,30 @@ module Bzip2
42
45
  #
43
46
  # @private
44
47
  OUT_BUFFER_SIZE = 4096 #:nodoc:
48
+ private_constant :OUT_BUFFER_SIZE
45
49
 
46
50
  class << self
47
51
  # Use send to keep this hidden from YARD (visibility tag does not work).
48
52
  send(:public, :new)
49
53
 
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`.
54
+ # Opens a {Writer} to compress and write bzip2 compressed data to either
55
+ # an IO-like object or a file. IO-like objects must have a `#write`
56
+ # method. Files can be specified using either a `String` containing the
57
+ # file path or a `Pathname`.
54
58
  #
55
- # If no block is given, the opened `Writer` instance is returned. After
59
+ # If no block is given, the opened {Writer} instance is returned. After
56
60
  # writing data, the instance must be closed using the {#close} method in
57
61
  # order to complete the compression process.
58
62
  #
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
63
+ # If a block is given, it will be passed the opened {Writer} instance
64
+ # as an argument. After the block terminates, the {Writer} instance will
61
65
  # automatically be closed. `open` will then return the result of the
62
66
  # block.
63
67
  #
64
68
  # The following options can be specified using the `options` `Hash`:
65
69
  #
66
- # * `:autoclose` - When passing an `IO`-like object, set to `true` to
67
- # close the `IO` when the `Writer` instance is closed.
70
+ # * `:autoclose` - When passing an IO-like object, set to `true` to
71
+ # close it when the {Writer} instance is closed.
68
72
  # * `:block_size` - Specifies the block size used for compression. It
69
73
  # should be set to an integer between 1 and 9
70
74
  # inclusive. The actual block size used is 100 kB
@@ -86,25 +90,25 @@ module Bzip2
86
90
  # the fallback. Allowable values range from 0 to 250
87
91
  # inclusive. 0 is a special case, equivalent to using
88
92
  # the default libbz2 work factor value (30 as of
89
- # bzip2 v1.0.6). If not specified, `:work_factor`
93
+ # bzip2 v1.0.8). If not specified, `:work_factor`
90
94
  # defaults to 0.
91
95
  #
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.
96
+ # If an IO-like object that has a `#binmode` method is passed to {open},
97
+ # `#binmode` will be called on `io_or_path` before yielding to the block
98
+ # or returning.
95
99
  #
96
100
  # If a path to a file that already exists is passed to `open`, the file
97
101
  # will be truncated before writing.
98
102
  #
99
- # @param io_or_path [Object] Either an `IO`-like object with a `write`
103
+ # @param io_or_path [Object] Either an IO-like object with a `#write`
100
104
  # method or a file path as a `String` or
101
105
  # `Pathname`.
102
106
  # @param options [Hash] Optional parameters (`:autoclose`, `:block_size`
103
107
  # and `:small`).
104
- # @return [Object] The opened `Writer` instance if no block is given, or
108
+ # @return [Object] The opened {Writer} instance if no block is given, or
105
109
  # the result of the block if a block is given.
106
110
  # @raise [ArgumentError] If `io_or_path` is _not_ a `String`, `Pathname`
107
- # or an `IO`-like object with a `write` method.
111
+ # or an IO-like object with a `#write` method.
108
112
  # @raise [Errno::ENOENT] If the parent directory of the specified file
109
113
  # does not exist.
110
114
  # @raise [Error::Bzip2Error] If an error occurs when initializing
@@ -122,14 +126,14 @@ module Bzip2
122
126
  end
123
127
 
124
128
  # 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
129
+ # structure to either an IO-like object or a file. IO-like objects
130
+ # must have a `#write` method. Files can be specified using either a
127
131
  # `String` containing the file path or a `Pathname`.
128
132
  #
129
133
  # The following options can be specified using the `options` `Hash`:
130
134
  #
131
- # * `:autoclose` - When passing an `IO`-like object, set to `true` to
132
- # close the `IO` when the `Writer` instance is closed.
135
+ # * `:autoclose` - When passing an IO-like object, set to `true` to
136
+ # close it when the {Writer} instance is closed.
133
137
  # * `:block_size` - Specifies the block size used for compression. It
134
138
  # should be set to an integer between 1 and 9
135
139
  # inclusive. The actual block size used is 100 kB
@@ -151,28 +155,28 @@ module Bzip2
151
155
  # the fallback. Allowable values range from 0 to 250
152
156
  # inclusive. 0 is a special case, equivalent to using
153
157
  # the default libbz2 work factor value (30 as of
154
- # bzip2 v1.0.6). If not specified, `:work_factor`
158
+ # bzip2 v1.0.8). If not specified, `:work_factor`
155
159
  # defaults to 0.
156
160
  #
157
161
  # No character conversion is performed. The raw bytes from `string` are
158
162
  # compressed (using the encoding of `string`).
159
163
  #
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
164
+ # If an IO-like object that has a `#binmode` method is passed to
165
+ # {write}, `#binmode` will be called on `io_or_path` before any
162
166
  # compressed data is written.
163
167
  #
164
168
  # The number of uncompressed bytes written is returned.
165
169
  #
166
- # @param io_or_path [Object] Either an `IO`-like object with a `write`
170
+ # @param io_or_path [Object] Either an IO-like object with a `#write`
167
171
  # method or a file path as a `String` or
168
172
  # `Pathname`.
169
- # @param string [Object] The string to write (`to_s` will be called
170
- # before writing).
173
+ # @param string [Object] The string to write (the result of calling
174
+ # `#to_s` on `string` will be written).
171
175
  # @param options [Hash] Optional parameters (`:autoclose`, `:block_size`
172
176
  # and `:small`).
173
177
  # @return [Integer] The number of uncompressed bytes written.
174
178
  # @raise [ArgumentError] If `io_or_path` is _not_ a `String`, `Pathname`
175
- # or an `IO`-like object with a `write` method.
179
+ # or an IO-like object with a `#write` method.
176
180
  # @raise [Errno::ENOENT] If the parent directory of the specified file
177
181
  # does not exist.
178
182
  # @raise [Error::Bzip2Error] If an error occurs when initializing
@@ -186,10 +190,10 @@ module Bzip2
186
190
  private
187
191
 
188
192
  # Returns a Proc that can be used as a finalizer to call
189
- # `BZ2_bzCompressEnd` with the given `stream`.
193
+ # {Libbz2::BZ2_bzCompressEnd} with the given `stream`.
190
194
  #
191
195
  # @param stream [Libbz2::BzStream] The stream that should be passed to
192
- # `BZ2_bzCompressEnd`.
196
+ # {Libbz2::BZ2_bzCompressEnd}.
193
197
  def finalize(stream)
194
198
  ->(id) do
195
199
  Libbz2::BZ2_bzCompressEnd(stream)
@@ -197,13 +201,13 @@ module Bzip2
197
201
  end
198
202
  end
199
203
 
200
- # Initializes a {Writer} to write compressed data to an `IO`-like object
201
- # (`io`). `io` must have a `write` method.
204
+ # Initializes a {Writer} to write compressed data to an IO-like object
205
+ # (`io`). `io` must have a `#write` method.
202
206
  #
203
207
  # The following options can be specified using the `options` `Hash`:
204
208
  #
205
- # * `:autoclose` - When passing an `IO`-like object, set to `true` to
206
- # close the `IO` when the `Writer` instance is closed.
209
+ # * `:autoclose` - When passing an IO-like object, set to `true` to
210
+ # close it when the {Writer} instance is closed.
207
211
  # * `:block_size` - Specifies the block size used for compression. It
208
212
  # should be set to an integer between 1 and 9
209
213
  # inclusive. The actual block size used is 100 kB
@@ -225,32 +229,32 @@ module Bzip2
225
229
  # the fallback. Allowable values range from 0 to 250
226
230
  # inclusive. 0 is a special case, equivalent to using
227
231
  # the default libbz2 work factor value (30 as of
228
- # bzip2 v1.0.6). If not specified, `:work_factor`
232
+ # bzip2 v1.0.8). If not specified, `:work_factor`
229
233
  # defaults to 0.
230
234
  #
231
- # `binmode` is called on `io` if `io` responds to `binmode`.
235
+ # `#binmode` is called on `io` if `io` responds to `#binmode`.
232
236
  #
233
- # After use, the `Writer` instance must be closed using the {#close}
237
+ # After use, the {Writer} instance must be closed using the {#close}
234
238
  # method in order to complete the compression process.
235
239
  #
236
- # @param io [Object] An `IO`-like object that has a `write` method.
240
+ # @param io [Object] An IO-like object that has a `#write` method.
237
241
  # @param options [Hash] Optional parameters (`:autoclose`, `:block_size`
238
242
  # and `:small`).
239
- # @raise [ArgumentError] If `io` is `nil` or does not respond to `write`.
243
+ # @raise [ArgumentError] If `io` is `nil` or does not respond to `#write`.
240
244
  # @raise [RangeError] If `options[:block_size]` is less than 1 or greater
241
245
  # than 9, or `options[:work_factor]` is less than 0 or
242
246
  # greater than 250.
243
247
  # @raise [Error::Bzip2Error] If an error occurs when initializing libbz2.
244
- def initialize(io, options = {})
248
+ def initialize(io, options = {})
245
249
  super
246
250
  raise ArgumentError, 'io must respond to write' unless io.respond_to?(:write)
247
-
251
+
248
252
  block_size = options[:block_size] || 9
249
253
  work_factor = options[:work_factor] || 0
250
-
254
+
251
255
  raise RangeError, 'block_size must be >= 1 and <= 9' if block_size < 1 || block_size > 9
252
256
  raise RangeError, 'work_factor must be >= 0 and <= 250' if work_factor < 0 || work_factor > 250
253
-
257
+
254
258
  check_error(Libbz2::BZ2_bzCompressInit(stream, block_size, 0, work_factor))
255
259
 
256
260
  ObjectSpace.define_finalizer(self, self.class.send(:finalize, stream))
@@ -261,11 +265,11 @@ module Bzip2
261
265
  # {Writer}.
262
266
  #
263
267
  # 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
268
+ # {close}. Otherwise, {close} must be called once the all the data to be
265
269
  # compressed has been passed to `#write`.
266
270
  #
267
271
  # @return [NilType] `nil`.
268
- # @raise [IOError] If the `Writer` has already been closed.
272
+ # @raise [IOError] If the {Writer} has already been closed.
269
273
  def close
270
274
  s = stream
271
275
  flush_buffers(s, Libbz2::BZ_FINISH, Libbz2::BZ_STREAM_END)
@@ -283,11 +287,11 @@ module Bzip2
283
287
  #
284
288
  # The number of uncompressed bytes written is returned.
285
289
  #
286
- # @param string [Object] The string to write (`to_s` will be called
287
- # before writing).
290
+ # @param string [Object] The string to write (the result of calling
291
+ # `#to_s` on `string` will be written).
288
292
  # @return [Integer] The number of uncompressed bytes written.
289
293
  # @raise [Error::Bzip2Error] If an error occurs during compression.
290
- # @raise [IOError] If the `Writer` has been closed.
294
+ # @raise [IOError] If the {Writer} has been closed.
291
295
  def write(string)
292
296
  string = string.to_s
293
297
 
@@ -296,7 +300,7 @@ module Bzip2
296
300
  buffer = ::FFI::MemoryPointer.new(1, OUT_BUFFER_SIZE)
297
301
  begin
298
302
  next_in.write_bytes(string)
299
- s[:next_in] = next_in
303
+ s[:next_in] = next_in
300
304
  s[:avail_in] = next_in.size
301
305
 
302
306
  while s[:avail_in] > 0
@@ -322,29 +326,40 @@ module Bzip2
322
326
  # writes out the current bzip2 compressed block to the underlying
323
327
  # compressed stream or file.
324
328
  #
325
- # It is not usually necessary to call `flush`.
329
+ # It is not usually necessary to call {flush}.
326
330
  #
327
- # Calling `flush` may result in a larger compressed output.
331
+ # Calling {flush} may result in a larger compressed output.
328
332
  #
329
333
  # @return [Writer] `self`.
330
334
  # @raise [Error::Bzip2Error] If an error occurs during the flush
331
335
  # operation.
332
- # @raise [IOError] If the `Writer` has been closed.
336
+ # @raise [IOError] If the {Writer} has been closed.
333
337
  def flush
334
338
  flush_buffers(stream, Libbz2::BZ_FLUSH, Libbz2::BZ_RUN_OK)
335
339
  self
336
340
  end
337
341
 
342
+ # Returns the number of uncompressed bytes that have been written.
343
+ #
344
+ # @return [Integer] The number of uncompressed bytes that have been
345
+ # written.
346
+ # @raise [IOError] If the {Writer} has been closed.
347
+ def pos
348
+ s = stream
349
+ (s[:total_in_hi32] << 32) | s[:total_in_lo32]
350
+ end
351
+
338
352
  private
339
353
 
340
- # Calls `BZ2_bzCompress` repeatedly without input to complete compression
341
- # of data that has been provided in prior calls.
354
+ # Calls {Libbz2::BZ2_bzCompress} repeatedly without input to complete
355
+ # compression of data that has been provided in prior calls.
342
356
  #
343
- # @param s [Libbz2::BzStream] The stream to pass to `BZ2_bzCompress`.
344
- # @param action [Integer] The action to pass to `BZ2_bzCompress`.
357
+ # @param s [Libbz2::BzStream] The stream to pass to
358
+ # {Libbz2::BZ2_bzCompress}.
359
+ # @param action [Integer] The action to pass to {Libbz2::BZ2_bzCompress}.
345
360
  # @param terminate_result [Integer] The result code that indicates when
346
361
  # the action has been completed.
347
- # @raise [Error::Bzip2Error] If `BZ2_bzCompress` reports an error.
362
+ # @raise [Error::Bzip2Error] If {Libbz2::BZ2_bzCompress} reports an error.
348
363
  def flush_buffers(s, action, terminate_result)
349
364
  s[:next_in] = nil
350
365
  s[:avail_in] = 0
@@ -367,7 +382,7 @@ module Bzip2
367
382
  buffer.free
368
383
  s[:next_out] = nil
369
384
  end
370
- end
385
+ end
371
386
  end
372
387
  end
373
388
  end
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
File without changes
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