bindata 2.4.10 → 2.5.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.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.rdoc +39 -0
  3. data/LICENSE +25 -0
  4. data/NEWS.rdoc +5 -0
  5. data/README.md +6 -9
  6. data/bindata.gemspec +9 -4
  7. data/examples/NBT.txt +1 -1
  8. data/examples/list.rb +1 -1
  9. data/lib/bindata/alignment.rb +15 -7
  10. data/lib/bindata/array.rb +54 -54
  11. data/lib/bindata/base.rb +14 -25
  12. data/lib/bindata/base_primitive.rb +24 -20
  13. data/lib/bindata/bits.rb +15 -15
  14. data/lib/bindata/buffer.rb +89 -11
  15. data/lib/bindata/choice.rb +9 -6
  16. data/lib/bindata/count_bytes_remaining.rb +1 -1
  17. data/lib/bindata/delayed_io.rb +18 -10
  18. data/lib/bindata/dsl.rb +37 -35
  19. data/lib/bindata/float.rb +3 -3
  20. data/lib/bindata/framework.rb +8 -10
  21. data/lib/bindata/int.rb +14 -16
  22. data/lib/bindata/io.rb +276 -253
  23. data/lib/bindata/name.rb +1 -1
  24. data/lib/bindata/params.rb +9 -7
  25. data/lib/bindata/primitive.rb +3 -3
  26. data/lib/bindata/registry.rb +18 -18
  27. data/lib/bindata/rest.rb +1 -1
  28. data/lib/bindata/sanitize.rb +9 -16
  29. data/lib/bindata/section.rb +97 -0
  30. data/lib/bindata/skip.rb +140 -51
  31. data/lib/bindata/string.rb +9 -9
  32. data/lib/bindata/stringz.rb +12 -10
  33. data/lib/bindata/struct.rb +92 -68
  34. data/lib/bindata/trace.rb +35 -42
  35. data/lib/bindata/transform/brotli.rb +35 -0
  36. data/lib/bindata/transform/lz4.rb +35 -0
  37. data/lib/bindata/transform/lzma.rb +35 -0
  38. data/lib/bindata/transform/xor.rb +19 -0
  39. data/lib/bindata/transform/xz.rb +35 -0
  40. data/lib/bindata/transform/zlib.rb +33 -0
  41. data/lib/bindata/transform/zstd.rb +35 -0
  42. data/lib/bindata/uint8_array.rb +2 -2
  43. data/lib/bindata/version.rb +1 -1
  44. data/lib/bindata/virtual.rb +4 -7
  45. data/lib/bindata/warnings.rb +1 -1
  46. data/lib/bindata.rb +1 -0
  47. data/test/alignment_test.rb +8 -8
  48. data/test/array_test.rb +98 -96
  49. data/test/base_primitive_test.rb +47 -47
  50. data/test/base_test.rb +24 -24
  51. data/test/bits_test.rb +15 -15
  52. data/test/buffer_test.rb +31 -22
  53. data/test/choice_test.rb +32 -32
  54. data/test/count_bytes_remaining_test.rb +8 -8
  55. data/test/delayed_io_test.rb +91 -30
  56. data/test/float_test.rb +8 -8
  57. data/test/int_test.rb +14 -14
  58. data/test/io_test.rb +110 -302
  59. data/test/lazy_test.rb +38 -38
  60. data/test/params_test.rb +19 -19
  61. data/test/primitive_test.rb +26 -26
  62. data/test/record_test.rb +99 -99
  63. data/test/registry_test.rb +43 -43
  64. data/test/rest_test.rb +5 -5
  65. data/test/section_test.rb +111 -0
  66. data/test/skip_test.rb +71 -26
  67. data/test/string_test.rb +60 -60
  68. data/test/stringz_test.rb +34 -26
  69. data/test/struct_test.rb +167 -92
  70. data/test/system_test.rb +159 -41
  71. data/test/test_helper.rb +24 -13
  72. data/test/uint8_array_test.rb +6 -6
  73. data/test/virtual_test.rb +7 -7
  74. data/test/warnings_test.rb +14 -2
  75. metadata +19 -22
  76. data/.gitignore +0 -2
  77. data/.travis.yml +0 -15
  78. data/BSDL +0 -22
  79. data/COPYING +0 -52
  80. data/INSTALL +0 -12
  81. data/lib/bindata/offset.rb +0 -94
  82. data/test/offset_test.rb +0 -100
data/test/io_test.rb CHANGED
@@ -15,214 +15,108 @@ describe BinData::IO::Read, "reading from non seekable stream" do
15
15
  @rd.close
16
16
  end
17
17
 
18
- it "has correct offset" do
19
- @io.readbytes(10)
20
- @io.offset.must_equal 10
18
+ it "seeks correctly" do
19
+ @io.skipbytes(1999)
20
+ _(@io.readbytes(5)).must_equal "abbbb"
21
21
  end
22
22
 
23
- it "seeks correctly" do
24
- @io.seekbytes(1999)
25
- @io.readbytes(5).must_equal "abbbb"
23
+ it "seeks to abs_offset" do
24
+ @io.skipbytes(1000)
25
+ @io.seek_to_abs_offset(1999)
26
+ _(@io.readbytes(5)).must_equal "abbbb"
27
+ end
28
+
29
+ it "wont seek backwards" do
30
+ @io.skipbytes(5)
31
+ _ {
32
+ @io.skipbytes(-1)
33
+ }.must_raise IOError
26
34
  end
27
35
 
28
36
  it "#num_bytes_remaining raises IOError" do
29
- lambda {
37
+ _ {
30
38
  @io.num_bytes_remaining
31
39
  }.must_raise IOError
32
40
  end
33
41
  end
34
42
 
43
+ describe BinData::IO::Write, "writing to non seekable stream" do
44
+ before do
45
+ @rd, @wr = IO::pipe
46
+ @io = BinData::IO::Write.new(@wr)
47
+ end
48
+
49
+ after do
50
+ @rd.close
51
+ @wr.close
52
+ end
53
+
54
+ def written_data
55
+ @io.flush
56
+ @wr.close
57
+ @rd.read
58
+ end
59
+
60
+ it "writes correctly" do
61
+ @io.writebytes("hello")
62
+ _(written_data).must_equal "hello"
63
+ end
64
+
65
+ it "must not attempt to seek" do
66
+ _ {
67
+ @io.seek_to_abs_offset(5)
68
+ }.must_raise IOError
69
+ end
70
+ end
71
+
35
72
  describe BinData::IO::Read, "when reading" do
36
73
  let(:stream) { StringIO.new "abcdefghij" }
37
74
  let(:io) { BinData::IO::Read.new(stream) }
38
75
 
39
76
  it "raises error when io is BinData::IO::Read" do
40
- lambda {
77
+ _ {
41
78
  BinData::IO::Read.new(BinData::IO::Read.new(""))
42
79
  }.must_raise ArgumentError
43
80
  end
44
81
 
45
- it "returns correct offset" do
46
- stream.seek(3, IO::SEEK_CUR)
47
-
48
- io.offset.must_equal 0
49
- io.readbytes(4).must_equal "defg"
50
- io.offset.must_equal 4
82
+ it "seeks correctly" do
83
+ io.skipbytes(2)
84
+ _(io.readbytes(4)).must_equal "cdef"
51
85
  end
52
86
 
53
- it "seeks correctly" do
54
- io.seekbytes(2)
55
- io.readbytes(4).must_equal "cdef"
87
+ it "wont seek backwards" do
88
+ io.skipbytes(5)
89
+ _ {
90
+ io.skipbytes(-1)
91
+ }.must_raise IOError
56
92
  end
57
93
 
94
+
58
95
  it "reads all bytes" do
59
- io.read_all_bytes.must_equal "abcdefghij"
96
+ _(io.read_all_bytes).must_equal "abcdefghij"
60
97
  end
61
98
 
62
99
  it "returns number of bytes remaining" do
63
100
  stream_length = io.num_bytes_remaining
64
101
 
65
102
  io.readbytes(4)
66
- io.num_bytes_remaining.must_equal stream_length - 4
103
+ _(io.num_bytes_remaining).must_equal stream_length - 4
67
104
  end
68
105
 
69
106
  it "raises error when reading at eof" do
70
- io.seekbytes(10)
71
- lambda {
107
+ io.skipbytes(10)
108
+ _ {
72
109
  io.readbytes(3)
73
110
  }.must_raise EOFError
74
111
  end
75
112
 
76
113
  it "raises error on short reads" do
77
- lambda {
114
+ _ {
78
115
  io.readbytes(20)
79
116
  }.must_raise IOError
80
117
  end
81
118
  end
82
119
 
83
- describe BinData::IO::Read, "#with_buffer" do
84
- let(:stream) { StringIO.new "abcdefghijklmnopqrst" }
85
- let(:io) { BinData::IO::Read.new(stream) }
86
-
87
- it "consumes entire buffer on short reads" do
88
- io.with_buffer(10) do
89
- io.readbytes(4).must_equal "abcd"
90
- end
91
- io.offset.must_equal(10)
92
- end
93
-
94
- it "consumes entire buffer on read_all_bytes" do
95
- io.with_buffer(10) do
96
- io.read_all_bytes.must_equal "abcdefghij"
97
- end
98
- io.offset.must_equal(10)
99
- end
100
-
101
- it "restricts large reads" do
102
- io.with_buffer(10) do
103
- lambda {
104
- io.readbytes(15)
105
- }.must_raise IOError
106
- end
107
- end
108
-
109
- it "is nestable" do
110
- io.with_buffer(10) do
111
- io.readbytes(2).must_equal "ab"
112
- io.with_buffer(5) do
113
- io.read_all_bytes.must_equal "cdefg"
114
- end
115
- io.offset.must_equal(2 + 5)
116
- end
117
- io.offset.must_equal(10)
118
- end
119
-
120
- it "restricts large nested buffers" do
121
- io.with_buffer(10) do
122
- io.readbytes(2).must_equal "ab"
123
- io.with_buffer(20) do
124
- io.read_all_bytes.must_equal "cdefghij"
125
- io.offset.must_equal(10)
126
- end
127
- end
128
- io.offset.must_equal(10)
129
- end
130
-
131
- it "restricts large seeks" do
132
- io.with_buffer(10) do
133
- io.seekbytes(15)
134
- end
135
- io.offset.must_equal(10)
136
- end
137
-
138
- it "restricts large -ve seeks" do
139
- io.readbytes(2)
140
- io.with_buffer(10) do
141
- io.seekbytes(-1)
142
- io.offset.must_equal(2)
143
- end
144
- end
145
-
146
- it "greater than stream size consumes all bytes" do
147
- io.with_buffer(30) do
148
- io.readbytes(4).must_equal "abcd"
149
- end
150
- io.offset.must_equal(20)
151
- end
152
-
153
- it "restricts #num_bytes_remaining" do
154
- io.with_buffer(10) do
155
- io.readbytes(2)
156
- io.num_bytes_remaining.must_equal 8
157
- end
158
- end
159
-
160
- it "greater than stream size doesn't restrict #num_bytes_remaining" do
161
- io.with_buffer(30) do
162
- io.readbytes(2)
163
- io.num_bytes_remaining.must_equal 18
164
- end
165
- end
166
- end
167
-
168
- module IOReadWithReadahead
169
- def test_rolls_back_short_reads
170
- io.readbytes(2).must_equal "ab"
171
- io.with_readahead do
172
- io.readbytes(4).must_equal "cdef"
173
- end
174
- io.offset.must_equal 2
175
- end
176
-
177
- def test_rolls_back_read_all_bytes
178
- io.readbytes(3).must_equal "abc"
179
- io.with_readahead do
180
- io.read_all_bytes.must_equal "defghijklmnopqrst"
181
- end
182
- io.offset.must_equal 3
183
- end
184
-
185
- def test_inside_buffer_rolls_back_reads
186
- io.with_buffer(10) do
187
- io.with_readahead do
188
- io.readbytes(4).must_equal "abcd"
189
- end
190
- io.offset.must_equal 0
191
- end
192
- io.offset.must_equal 10
193
- end
194
-
195
- def test_outside_buffer_rolls_back_reads
196
- io.with_readahead do
197
- io.with_buffer(10) do
198
- io.readbytes(4).must_equal "abcd"
199
- end
200
- io.offset.must_equal 10
201
- end
202
- io.offset.must_equal 0
203
- end
204
- end
205
-
206
- describe BinData::IO::Read, "#with_readahead" do
207
- let(:stream) { StringIO.new "abcdefghijklmnopqrst" }
208
- let(:io) { BinData::IO::Read.new(stream) }
209
-
210
- include IOReadWithReadahead
211
- end
212
-
213
- describe BinData::IO::Read, "unseekable stream #with_readahead" do
214
- let(:stream) {
215
- io = StringIO.new "abcdefghijklmnopqrst"
216
- def io.pos
217
- raise Errno::EPIPE
218
- end
219
- io
220
- }
221
- let(:io) { BinData::IO::Read.new(stream) }
222
-
223
- include IOReadWithReadahead
224
- end
225
-
226
120
  describe BinData::IO::Write, "writing to non seekable stream" do
227
121
  before do
228
122
  @rd, @wr = IO::pipe
@@ -236,31 +130,7 @@ describe BinData::IO::Write, "writing to non seekable stream" do
236
130
 
237
131
  it "writes data" do
238
132
  @io.writebytes("1234567890")
239
- @rd.read(10).must_equal "1234567890"
240
- end
241
-
242
- it "has correct offset" do
243
- @io.writebytes("1234567890")
244
- @io.offset.must_equal 10
245
- end
246
-
247
- it "does not seek backwards" do
248
- @io.writebytes("1234567890")
249
- lambda {
250
- @io.seekbytes(-5)
251
- }.must_raise IOError
252
- end
253
-
254
- it "does not seek forwards" do
255
- lambda {
256
- @io.seekbytes(5)
257
- }.must_raise IOError
258
- end
259
-
260
- it "#num_bytes_remaining raises IOError" do
261
- lambda {
262
- @io.num_bytes_remaining
263
- }.must_raise IOError
133
+ _(@rd.read(10)).must_equal "1234567890"
264
134
  end
265
135
  end
266
136
 
@@ -269,7 +139,7 @@ describe BinData::IO::Write, "when writing" do
269
139
  let(:io) { BinData::IO::Write.new(stream) }
270
140
 
271
141
  it "raises error when io is BinData::IO" do
272
- lambda {
142
+ _ {
273
143
  BinData::IO::Write.new(BinData::IO::Write.new(""))
274
144
  }.must_raise ArgumentError
275
145
  end
@@ -277,76 +147,14 @@ describe BinData::IO::Write, "when writing" do
277
147
  it "writes correctly" do
278
148
  io.writebytes("abcd")
279
149
 
280
- stream.value.must_equal "abcd"
281
- end
282
-
283
- it "has #offset" do
284
- io.offset.must_equal 0
285
-
286
- io.writebytes("abcd")
287
- io.offset.must_equal 4
288
-
289
- io.writebytes("ABCD")
290
- io.offset.must_equal 8
291
- end
292
-
293
- it "rounds up #offset when writing bits" do
294
- io.writebits(123, 9, :little)
295
- io.offset.must_equal 2
150
+ _(stream.value).must_equal "abcd"
296
151
  end
297
152
 
298
153
  it "flushes" do
299
154
  io.writebytes("abcd")
300
155
  io.flush
301
156
 
302
- stream.value.must_equal "abcd"
303
- end
304
- end
305
-
306
- describe BinData::IO::Write, "#with_buffer" do
307
- let(:stream) { StringIO.new }
308
- let(:io) { BinData::IO::Write.new(stream) }
309
-
310
- it "pads entire buffer on short reads" do
311
- io.with_buffer(10) do
312
- io.writebytes "abcde"
313
- end
314
-
315
- stream.value.must_equal "abcde\0\0\0\0\0"
316
- end
317
-
318
- it "discards excess on large writes" do
319
- io.with_buffer(5) do
320
- io.writebytes "abcdefghij"
321
- end
322
-
323
- stream.value.must_equal "abcde"
324
- end
325
-
326
- it "is nestable" do
327
- io.with_buffer(10) do
328
- io.with_buffer(5) do
329
- io.writebytes "abc"
330
- end
331
- io.writebytes "de"
332
- end
333
-
334
- stream.value.must_equal "abc\0\0de\0\0\0"
335
- end
336
-
337
- it "restricts large seeks" do
338
- io.with_buffer(10) do
339
- io.seekbytes(15)
340
- end
341
- io.offset.must_equal(10)
342
- end
343
-
344
- it "restricts large -ve seeks" do
345
- io.writebytes("12")
346
- io.with_buffer(10) do
347
- io.seekbytes(-1)
348
- io.offset.must_equal(2)
349
- end
157
+ _(stream.value).must_equal "abcd"
350
158
  end
351
159
  end
352
160
 
@@ -357,42 +165,42 @@ describe BinData::IO::Read, "reading bits in big endian" do
357
165
  let(:io) { BinData::IO::Read.new([b1, b2, b3].pack("CCC")) }
358
166
 
359
167
  it "reads a bitfield less than 1 byte" do
360
- io.readbits(3, :big).must_equal 0b111
168
+ _(io.readbits(3, :big)).must_equal 0b111
361
169
  end
362
170
 
363
171
  it "reads a bitfield more than 1 byte" do
364
- io.readbits(10, :big).must_equal 0b1111_1010_11
172
+ _(io.readbits(10, :big)).must_equal 0b1111_1010_11
365
173
  end
366
174
 
367
175
  it "reads a bitfield more than 2 bytes" do
368
- io.readbits(17, :big).must_equal 0b1111_1010_1100_1110_0
176
+ _(io.readbits(17, :big)).must_equal 0b1111_1010_1100_1110_0
369
177
  end
370
178
 
371
179
  it "reads two bitfields totalling less than 1 byte" do
372
- io.readbits(5, :big).must_equal 0b1111_1
373
- io.readbits(2, :big).must_equal 0b01
180
+ _(io.readbits(5, :big)).must_equal 0b1111_1
181
+ _(io.readbits(2, :big)).must_equal 0b01
374
182
  end
375
183
 
376
184
  it "reads two bitfields totalling more than 1 byte" do
377
- io.readbits(6, :big).must_equal 0b1111_10
378
- io.readbits(8, :big).must_equal 0b10_1100_11
185
+ _(io.readbits(6, :big)).must_equal 0b1111_10
186
+ _(io.readbits(8, :big)).must_equal 0b10_1100_11
379
187
  end
380
188
 
381
189
  it "reads two bitfields totalling more than 2 bytes" do
382
- io.readbits(7, :big).must_equal 0b1111_101
383
- io.readbits(12, :big).must_equal 0b0_1100_1110_011
190
+ _(io.readbits(7, :big)).must_equal 0b1111_101
191
+ _(io.readbits(12, :big)).must_equal 0b0_1100_1110_011
384
192
  end
385
193
 
386
194
  it "ignores unused bits when reading bytes" do
387
- io.readbits(3, :big).must_equal 0b111
388
- io.readbytes(1).must_equal [b2].pack("C")
389
- io.readbits(2, :big).must_equal 0b01
195
+ _(io.readbits(3, :big)).must_equal 0b111
196
+ _(io.readbytes(1)).must_equal [b2].pack("C")
197
+ _(io.readbits(2, :big)).must_equal 0b01
390
198
  end
391
199
 
392
200
  it "resets read bits to realign stream to next byte" do
393
- io.readbits(3, :big).must_equal 0b111
201
+ _(io.readbits(3, :big)).must_equal 0b111
394
202
  io.reset_read_bits
395
- io.readbits(3, :big).must_equal 0b110
203
+ _(io.readbits(3, :big)).must_equal 0b110
396
204
  end
397
205
  end
398
206
 
@@ -403,42 +211,42 @@ describe BinData::IO::Read, "reading bits in little endian" do
403
211
  let(:io) { BinData::IO::Read.new([b1, b2, b3].pack("CCC")) }
404
212
 
405
213
  it "reads a bitfield less than 1 byte" do
406
- io.readbits(3, :little).must_equal 0b010
214
+ _(io.readbits(3, :little)).must_equal 0b010
407
215
  end
408
216
 
409
217
  it "reads a bitfield more than 1 byte" do
410
- io.readbits(10, :little).must_equal 0b10_1111_1010
218
+ _(io.readbits(10, :little)).must_equal 0b10_1111_1010
411
219
  end
412
220
 
413
221
  it "reads a bitfield more than 2 bytes" do
414
- io.readbits(17, :little).must_equal 0b0_1100_1110_1111_1010
222
+ _(io.readbits(17, :little)).must_equal 0b0_1100_1110_1111_1010
415
223
  end
416
224
 
417
225
  it "reads two bitfields totalling less than 1 byte" do
418
- io.readbits(5, :little).must_equal 0b1_1010
419
- io.readbits(2, :little).must_equal 0b11
226
+ _(io.readbits(5, :little)).must_equal 0b1_1010
227
+ _(io.readbits(2, :little)).must_equal 0b11
420
228
  end
421
229
 
422
230
  it "reads two bitfields totalling more than 1 byte" do
423
- io.readbits(6, :little).must_equal 0b11_1010
424
- io.readbits(8, :little).must_equal 0b00_1110_11
231
+ _(io.readbits(6, :little)).must_equal 0b11_1010
232
+ _(io.readbits(8, :little)).must_equal 0b00_1110_11
425
233
  end
426
234
 
427
235
  it "reads two bitfields totalling more than 2 bytes" do
428
- io.readbits(7, :little).must_equal 0b111_1010
429
- io.readbits(12, :little).must_equal 0b010_1100_1110_1
236
+ _(io.readbits(7, :little)).must_equal 0b111_1010
237
+ _(io.readbits(12, :little)).must_equal 0b010_1100_1110_1
430
238
  end
431
239
 
432
240
  it "ignores unused bits when reading bytes" do
433
- io.readbits(3, :little).must_equal 0b010
434
- io.readbytes(1).must_equal [b2].pack("C")
435
- io.readbits(2, :little).must_equal 0b10
241
+ _(io.readbits(3, :little)).must_equal 0b010
242
+ _(io.readbytes(1)).must_equal [b2].pack("C")
243
+ _(io.readbits(2, :little)).must_equal 0b10
436
244
  end
437
245
 
438
246
  it "resets read bits to realign stream to next byte" do
439
- io.readbits(3, :little).must_equal 0b010
247
+ _(io.readbits(3, :little)).must_equal 0b010
440
248
  io.reset_read_bits
441
- io.readbits(3, :little).must_equal 0b110
249
+ _(io.readbits(3, :little)).must_equal 0b110
442
250
  end
443
251
  end
444
252
 
@@ -468,35 +276,35 @@ describe BinData::IO::Write, "writing bits in big endian" do
468
276
 
469
277
  it "writes a bitfield less than 1 byte" do
470
278
  io.writebits(0b010, 3, :big)
471
- io.value.must_equal [0b0100_0000].pack("C")
279
+ _(io.value).must_equal [0b0100_0000].pack("C")
472
280
  end
473
281
 
474
282
  it "writes a bitfield more than 1 byte" do
475
283
  io.writebits(0b10_1001_1101, 10, :big)
476
- io.value.must_equal [0b1010_0111, 0b0100_0000].pack("CC")
284
+ _(io.value).must_equal [0b1010_0111, 0b0100_0000].pack("CC")
477
285
  end
478
286
 
479
287
  it "writes a bitfield more than 2 bytes" do
480
288
  io.writebits(0b101_1000_0010_1001_1101, 19, :big)
481
- io.value.must_equal [0b1011_0000, 0b0101_0011, 0b1010_0000].pack("CCC")
289
+ _(io.value).must_equal [0b1011_0000, 0b0101_0011, 0b1010_0000].pack("CCC")
482
290
  end
483
291
 
484
292
  it "writes two bitfields totalling less than 1 byte" do
485
293
  io.writebits(0b1_1001, 5, :big)
486
294
  io.writebits(0b00, 2, :big)
487
- io.value.must_equal [0b1100_1000].pack("C")
295
+ _(io.value).must_equal [0b1100_1000].pack("C")
488
296
  end
489
297
 
490
298
  it "writes two bitfields totalling more than 1 byte" do
491
299
  io.writebits(0b01_0101, 6, :big)
492
300
  io.writebits(0b001_1001, 7, :big)
493
- io.value.must_equal [0b0101_0100, 0b1100_1000].pack("CC")
301
+ _(io.value).must_equal [0b0101_0100, 0b1100_1000].pack("CC")
494
302
  end
495
303
 
496
304
  it "writes two bitfields totalling more than 2 bytes" do
497
305
  io.writebits(0b01_0111, 6, :big)
498
306
  io.writebits(0b1_0010_1001_1001, 13, :big)
499
- io.value.must_equal [0b0101_1110, 0b0101_0011, 0b0010_0000].pack("CCC")
307
+ _(io.value).must_equal [0b0101_1110, 0b0101_0011, 0b0010_0000].pack("CCC")
500
308
  end
501
309
 
502
310
  it "pads unused bits when writing bytes" do
@@ -504,7 +312,7 @@ describe BinData::IO::Write, "writing bits in big endian" do
504
312
  io.writebytes([0b1011_1111].pack("C"))
505
313
  io.writebits(0b01, 2, :big)
506
314
 
507
- io.value.must_equal [0b1010_0000, 0b1011_1111, 0b0100_0000].pack("CCC")
315
+ _(io.value).must_equal [0b1010_0000, 0b1011_1111, 0b0100_0000].pack("CCC")
508
316
  end
509
317
  end
510
318
 
@@ -513,35 +321,35 @@ describe BinData::IO::Write, "writing bits in little endian" do
513
321
 
514
322
  it "writes a bitfield less than 1 byte" do
515
323
  io.writebits(0b010, 3, :little)
516
- io.value.must_equal [0b0000_0010].pack("C")
324
+ _(io.value).must_equal [0b0000_0010].pack("C")
517
325
  end
518
326
 
519
327
  it "writes a bitfield more than 1 byte" do
520
328
  io.writebits(0b10_1001_1101, 10, :little)
521
- io.value.must_equal [0b1001_1101, 0b0000_0010].pack("CC")
329
+ _(io.value).must_equal [0b1001_1101, 0b0000_0010].pack("CC")
522
330
  end
523
331
 
524
332
  it "writes a bitfield more than 2 bytes" do
525
333
  io.writebits(0b101_1000_0010_1001_1101, 19, :little)
526
- io.value.must_equal [0b1001_1101, 0b1000_0010, 0b0000_0101].pack("CCC")
334
+ _(io.value).must_equal [0b1001_1101, 0b1000_0010, 0b0000_0101].pack("CCC")
527
335
  end
528
336
 
529
337
  it "writes two bitfields totalling less than 1 byte" do
530
338
  io.writebits(0b1_1001, 5, :little)
531
339
  io.writebits(0b00, 2, :little)
532
- io.value.must_equal [0b0001_1001].pack("C")
340
+ _(io.value).must_equal [0b0001_1001].pack("C")
533
341
  end
534
342
 
535
343
  it "writes two bitfields totalling more than 1 byte" do
536
344
  io.writebits(0b01_0101, 6, :little)
537
345
  io.writebits(0b001_1001, 7, :little)
538
- io.value.must_equal [0b0101_0101, 0b0000_0110].pack("CC")
346
+ _(io.value).must_equal [0b0101_0101, 0b0000_0110].pack("CC")
539
347
  end
540
348
 
541
349
  it "writes two bitfields totalling more than 2 bytes" do
542
350
  io.writebits(0b01_0111, 6, :little)
543
351
  io.writebits(0b1_0010_1001_1001, 13, :little)
544
- io.value.must_equal [0b0101_0111, 0b1010_0110, 0b0000_0100].pack("CCC")
352
+ _(io.value).must_equal [0b0101_0111, 0b1010_0110, 0b0000_0100].pack("CCC")
545
353
  end
546
354
 
547
355
  it "pads unused bits when writing bytes" do
@@ -549,27 +357,27 @@ describe BinData::IO::Write, "writing bits in little endian" do
549
357
  io.writebytes([0b1011_1111].pack("C"))
550
358
  io.writebits(0b01, 2, :little)
551
359
 
552
- io.value.must_equal [0b0000_0101, 0b1011_1111, 0b0000_0001].pack("CCC")
360
+ _(io.value).must_equal [0b0000_0101, 0b1011_1111, 0b0000_0001].pack("CCC")
553
361
  end
554
362
  end
555
363
 
556
364
  describe BinData::IO::Read, "with changing endian" do
557
- it "does not mix different endianess when reading" do
365
+ it "does not mix different endianness when reading" do
558
366
  b1 = 0b0110_1010
559
367
  b2 = 0b1110_0010
560
368
  str = [b1, b2].pack("CC")
561
369
  io = BinData::IO::Read.new(str)
562
370
 
563
- io.readbits(3, :big).must_equal 0b011
564
- io.readbits(4, :little).must_equal 0b0010
371
+ _(io.readbits(3, :big)).must_equal 0b011
372
+ _(io.readbits(4, :little)).must_equal 0b0010
565
373
  end
566
374
  end
567
375
 
568
376
  describe BinData::IO::Write, "with changing endian" do
569
- it "does not mix different endianess when writing" do
377
+ it "does not mix different endianness when writing" do
570
378
  io = BitWriterHelper.new
571
379
  io.writebits(0b110, 3, :big)
572
380
  io.writebits(0b010, 3, :little)
573
- io.value.must_equal [0b1100_0000, 0b0000_0010].pack("CC")
381
+ _(io.value).must_equal [0b1100_0000, 0b0000_0010].pack("CC")
574
382
  end
575
383
  end