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