bindata 2.4.12 → 2.4.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.rdoc +11 -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/params.rb +1 -1
- 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 +19 -19
- 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/system_test.rb
CHANGED
@@ -11,18 +11,18 @@ describe "lambdas with index" do
|
|
11
11
|
arr = BinData::Array.new(type:
|
12
12
|
[:uint8, { value: -> { index * 10 } }],
|
13
13
|
initial_length: 3)
|
14
|
-
arr.snapshot.must_equal [0, 10, 20]
|
14
|
+
_(arr.snapshot).must_equal [0, 10, 20]
|
15
15
|
end
|
16
16
|
|
17
17
|
it "uses index of nearest containing array" do
|
18
18
|
arr = BinData::Array.new(type: :nested_lambda_with_index,
|
19
19
|
initial_length: 3)
|
20
|
-
arr.snapshot.must_equal [{a: 0}, {a: 10}, {a: 20}]
|
20
|
+
_(arr.snapshot).must_equal [{a: 0}, {a: 10}, {a: 20}]
|
21
21
|
end
|
22
22
|
|
23
23
|
it "fails if there is no containing array" do
|
24
24
|
obj = NestedLambdaWithIndex.new
|
25
|
-
|
25
|
+
_ { obj.a.to_s }.must_raise NoMethodError
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -39,7 +39,7 @@ describe "lambdas with parent" do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
obj = TestLambdaWithoutParent.new
|
42
|
-
obj.x.b.must_equal 5
|
42
|
+
_(obj.x.b).must_equal 5
|
43
43
|
end
|
44
44
|
|
45
45
|
it "accesses parent's parent when parent is specified" do
|
@@ -54,7 +54,7 @@ describe "lambdas with parent" do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
obj = TestLambdaWithParent.new
|
57
|
-
obj.x.b.must_equal 3
|
57
|
+
_(obj.x.b).must_equal 3
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -82,18 +82,18 @@ describe BinData::Record, "with choice field" do
|
|
82
82
|
it "treats choice object transparently " do
|
83
83
|
obj = RecordWithChoiceField.new
|
84
84
|
|
85
|
-
obj.x.a.must_equal 3
|
85
|
+
_(obj.x.a).must_equal 3
|
86
86
|
end
|
87
87
|
|
88
88
|
it "treats nested choice object transparently " do
|
89
89
|
obj = RecordWithNestedChoiceField.new
|
90
90
|
|
91
|
-
obj.x.a.must_equal 3
|
91
|
+
_(obj.x.a).must_equal 3
|
92
92
|
end
|
93
93
|
|
94
94
|
it "has correct offset" do
|
95
95
|
obj = RecordWithNestedChoiceField.new
|
96
|
-
obj.x.b.abs_offset.must_equal 2
|
96
|
+
_(obj.x.b.abs_offset).must_equal 2
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
@@ -132,17 +132,17 @@ describe BinData::Record, "containing bitfields" do
|
|
132
132
|
let(:obj) { BitfieldRecord.new }
|
133
133
|
|
134
134
|
it "has correct num_bytes" do
|
135
|
-
obj.num_bytes.must_equal 5
|
135
|
+
_(obj.num_bytes).must_equal 5
|
136
136
|
end
|
137
137
|
|
138
138
|
it "reads across bitfield boundaries" do
|
139
139
|
obj.read [0b0111_0010, 0b0110_0101, 0b0010_1010, 0b1000_0101, 0b1000_0000].pack("CCCCC")
|
140
140
|
|
141
|
-
obj.a.w.must_equal 7
|
142
|
-
obj.b.must_equal [0, 0, 1, 0, 0, 1, 1, 0, 0]
|
143
|
-
obj.c.x.must_equal 2
|
144
|
-
obj.d.must_equal 954
|
145
|
-
obj.e.must_equal 11
|
141
|
+
_(obj.a.w).must_equal 7
|
142
|
+
_(obj.b).must_equal [0, 0, 1, 0, 0, 1, 1, 0, 0]
|
143
|
+
_(obj.c.x).must_equal 2
|
144
|
+
_(obj.d).must_equal 954
|
145
|
+
_(obj.e).must_equal 11
|
146
146
|
end
|
147
147
|
|
148
148
|
it "writes across bitfield boundaries" do
|
@@ -152,37 +152,37 @@ describe BinData::Record, "containing bitfields" do
|
|
152
152
|
obj.c.x = 1
|
153
153
|
obj.d = 850
|
154
154
|
obj.e = 35
|
155
|
-
obj.to_binary_s.must_equal_binary [0b0011_0010, 0b0100_0011, 0b0000_1010, 0b0001_0001, 0b1000_0000].pack("CCCCC")
|
155
|
+
_(obj.to_binary_s).must_equal_binary [0b0011_0010, 0b0100_0011, 0b0000_1010, 0b0001_0001, 0b1000_0000].pack("CCCCC")
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
159
|
describe "Objects with debug_name" do
|
160
160
|
it "haves default name of obj" do
|
161
161
|
el = BinData::Uint8.new
|
162
|
-
el.debug_name.must_equal "obj"
|
162
|
+
_(el.debug_name).must_equal "obj"
|
163
163
|
end
|
164
164
|
|
165
165
|
it "includes array index" do
|
166
166
|
arr = BinData::Array.new(type: :uint8, initial_length: 2)
|
167
|
-
arr[2].debug_name.must_equal "obj[2]"
|
167
|
+
_(arr[2].debug_name).must_equal "obj[2]"
|
168
168
|
end
|
169
169
|
|
170
170
|
it "includes field name" do
|
171
171
|
s = BinData::Struct.new(fields: [[:uint8, :a]])
|
172
|
-
s.a.debug_name.must_equal "obj.a"
|
172
|
+
_(s.a.debug_name).must_equal "obj.a"
|
173
173
|
end
|
174
174
|
|
175
175
|
it "delegates to choice" do
|
176
176
|
choice_params = {choices: [:uint8], selection: 0}
|
177
177
|
s = BinData::Struct.new(fields: [[:choice, :a, choice_params]])
|
178
|
-
s.a.debug_name.must_equal "obj.a"
|
178
|
+
_(s.a.debug_name).must_equal "obj.a"
|
179
179
|
end
|
180
180
|
|
181
181
|
it "nests" do
|
182
182
|
nested_struct_params = {fields: [[:uint8, :c]]}
|
183
183
|
struct_params = {fields: [[:struct, :b, nested_struct_params]]}
|
184
184
|
s = BinData::Struct.new(fields: [[:struct, :a, struct_params]])
|
185
|
-
s.a.b.c.debug_name.must_equal "obj.a.b.c"
|
185
|
+
_(s.a.b.c.debug_name).must_equal "obj.a.b.c"
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
@@ -194,7 +194,7 @@ describe "Tracing" do
|
|
194
194
|
BinData::trace_reading(io) { arr.read("\x01\x02\x03\x04\x05") }
|
195
195
|
|
196
196
|
expected = (0..4).collect { |i| "obj[#{i}] => #{i + 1}\n" }.join("")
|
197
|
-
io.value.must_equal expected
|
197
|
+
_(io.value).must_equal expected
|
198
198
|
end
|
199
199
|
|
200
200
|
it "traces custom single values" do
|
@@ -209,7 +209,7 @@ describe "Tracing" do
|
|
209
209
|
io = StringIO.new
|
210
210
|
BinData::trace_reading(io) { obj.read("\x01") }
|
211
211
|
|
212
|
-
io.value.must_equal ["obj-internal-.ex => 1\n", "obj => 1\n"].join("")
|
212
|
+
_(io.value).must_equal ["obj-internal-.ex => 1\n", "obj => 1\n"].join("")
|
213
213
|
end
|
214
214
|
|
215
215
|
it "traces choice selection" do
|
@@ -218,7 +218,7 @@ describe "Tracing" do
|
|
218
218
|
io = StringIO.new
|
219
219
|
BinData::trace_reading(io) { obj.read("\x01") }
|
220
220
|
|
221
|
-
io.value.must_equal ["obj-selection- => 0\n", "obj => 1\n"].join("")
|
221
|
+
_(io.value).must_equal ["obj-selection- => 0\n", "obj => 1\n"].join("")
|
222
222
|
end
|
223
223
|
|
224
224
|
it "trims long trace values" do
|
@@ -227,7 +227,7 @@ describe "Tracing" do
|
|
227
227
|
io = StringIO.new
|
228
228
|
BinData::trace_reading(io) { obj.read("0000000000111111111122222222223333333333") }
|
229
229
|
|
230
|
-
io.value.must_equal "obj => \"000000000011111111112222222222...\n"
|
230
|
+
_(io.value).must_equal "obj => \"000000000011111111112222222222...\n"
|
231
231
|
end
|
232
232
|
end
|
233
233
|
|
@@ -240,17 +240,17 @@ describe "Forward referencing with Primitive" do
|
|
240
240
|
let(:obj) { FRPrimitive.new }
|
241
241
|
|
242
242
|
it "initialises" do
|
243
|
-
obj.snapshot.must_equal({len: 0, data: ""})
|
243
|
+
_(obj.snapshot).must_equal({len: 0, data: ""})
|
244
244
|
end
|
245
245
|
|
246
246
|
it "reads" do
|
247
247
|
obj.read("\x04test")
|
248
|
-
obj.snapshot.must_equal({len: 4, data: "test"})
|
248
|
+
_(obj.snapshot).must_equal({len: 4, data: "test"})
|
249
249
|
end
|
250
250
|
|
251
251
|
it "sets value" do
|
252
252
|
obj.data = "hello"
|
253
|
-
obj.snapshot.must_equal({len: 5, data: "hello"})
|
253
|
+
_(obj.snapshot).must_equal({len: 5, data: "hello"})
|
254
254
|
end
|
255
255
|
end
|
256
256
|
|
@@ -263,17 +263,17 @@ describe "Forward referencing with Array" do
|
|
263
263
|
let(:obj) { FRArray.new }
|
264
264
|
|
265
265
|
it "initialises" do
|
266
|
-
obj.snapshot.must_equal({len: 0, data: []})
|
266
|
+
_(obj.snapshot).must_equal({len: 0, data: []})
|
267
267
|
end
|
268
268
|
|
269
269
|
it "reads" do
|
270
270
|
obj.read("\x04\x01\x02\x03\x04")
|
271
|
-
obj.snapshot.must_equal({len: 4, data: [1, 2, 3, 4]})
|
271
|
+
_(obj.snapshot).must_equal({len: 4, data: [1, 2, 3, 4]})
|
272
272
|
end
|
273
273
|
|
274
274
|
it "sets value" do
|
275
275
|
obj.data = [1, 2, 3]
|
276
|
-
obj.snapshot.must_equal({len: 3, data: [1, 2, 3]})
|
276
|
+
_(obj.snapshot).must_equal({len: 3, data: [1, 2, 3]})
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
@@ -288,7 +288,7 @@ describe "Evaluating custom parameters" do
|
|
288
288
|
|
289
289
|
it "recursively evaluates parameter" do
|
290
290
|
obj = CustomParameterRecord.new(zz: 5)
|
291
|
-
obj.c.eval_parameter(:custom).must_equal 5
|
291
|
+
_(obj.c.eval_parameter(:custom)).must_equal 5
|
292
292
|
end
|
293
293
|
end
|
294
294
|
|
@@ -299,7 +299,7 @@ describe BinData::Record, "with custom sized integers" do
|
|
299
299
|
|
300
300
|
it "reads as expected" do
|
301
301
|
str = "\x00\x00\x00\x00\x05"
|
302
|
-
CustomIntRecord.read(str).snapshot.must_equal({a: 5})
|
302
|
+
_(CustomIntRecord.read(str).snapshot).must_equal({a: 5})
|
303
303
|
end
|
304
304
|
end
|
305
305
|
|
@@ -330,11 +330,11 @@ describe BinData::Primitive, "representing a string" do
|
|
330
330
|
let(:obj) { PascalStringPrimitive.new("testing") }
|
331
331
|
|
332
332
|
it "compares to regexp" do
|
333
|
-
(obj =~ /es/).must_equal 1
|
333
|
+
_((obj =~ /es/)).must_equal 1
|
334
334
|
end
|
335
335
|
|
336
336
|
it "compares to regexp" do
|
337
|
-
(/es/ =~ obj).must_equal 1
|
337
|
+
_((/es/ =~ obj)).must_equal 1
|
338
338
|
end
|
339
339
|
end
|
340
340
|
|
@@ -347,17 +347,17 @@ describe BinData::Record, "with boolean parameters" do
|
|
347
347
|
|
348
348
|
it "uses default parameter" do
|
349
349
|
obj = BooleanParameterRecord.new
|
350
|
-
obj.a.must_equal 2
|
350
|
+
_(obj.a).must_equal 2
|
351
351
|
end
|
352
352
|
|
353
353
|
it "overrides parameter" do
|
354
354
|
obj = BooleanParameterRecord.new(flag: false)
|
355
|
-
obj.a.must_equal 3
|
355
|
+
_(obj.a).must_equal 3
|
356
356
|
end
|
357
357
|
|
358
358
|
it "overrides parameter with same value" do
|
359
359
|
obj = BooleanParameterRecord.new(flag: true)
|
360
|
-
obj.a.must_equal 2
|
360
|
+
_(obj.a).must_equal 2
|
361
361
|
end
|
362
362
|
end
|
363
363
|
|
@@ -372,12 +372,12 @@ describe BinData::Record, "encoding" do
|
|
372
372
|
|
373
373
|
it "returns binary encoded data" do
|
374
374
|
obj = EncodingTestBufferRecord.new(num: 3)
|
375
|
-
obj.to_binary_s.encoding.must_equal Encoding::ASCII_8BIT
|
375
|
+
_(obj.to_binary_s.encoding).must_equal Encoding::ASCII_8BIT
|
376
376
|
end
|
377
377
|
|
378
378
|
it "returns binary encoded data with utf-8 string" do
|
379
379
|
obj = EncodingTestBufferRecord.new(num: 3, str: "日本語")
|
380
|
-
obj.to_binary_s.encoding.must_equal Encoding::ASCII_8BIT
|
380
|
+
_(obj.to_binary_s.encoding).must_equal Encoding::ASCII_8BIT
|
381
381
|
end
|
382
382
|
|
383
383
|
it "returns binary encoded data despite Encoding.default_internal" do
|
@@ -387,7 +387,7 @@ describe BinData::Record, "encoding" do
|
|
387
387
|
begin
|
388
388
|
Encoding.default_internal = Encoding::UTF_8
|
389
389
|
obj = EncodingTestBufferRecord.new(num: 3, str: "日本語")
|
390
|
-
obj.to_binary_s.encoding.must_equal Encoding::ASCII_8BIT
|
390
|
+
_(obj.to_binary_s.encoding).must_equal Encoding::ASCII_8BIT
|
391
391
|
ensure
|
392
392
|
Encoding.default_internal = before_enc
|
393
393
|
$-w = w
|
data/test/test_helper.rb
CHANGED
@@ -37,7 +37,7 @@ module Kernel
|
|
37
37
|
|
38
38
|
def must_raise_on_line(exp, line, msg = nil)
|
39
39
|
ex = self.must_raise exp
|
40
|
-
ex.message.must_equal msg if msg
|
40
|
+
(ex.message).must_equal msg if msg
|
41
41
|
|
42
42
|
idx = ex.backtrace.find_index { |bt| /:in `must_raise_on_line'$/ =~ bt }
|
43
43
|
|
@@ -56,6 +56,6 @@ module Kernel
|
|
56
56
|
self.stub(:warn, callable) do
|
57
57
|
block.call
|
58
58
|
end
|
59
|
-
result.must_equal msg
|
59
|
+
(result).must_equal msg
|
60
60
|
end
|
61
61
|
end
|
data/test/uint8_array_test.rb
CHANGED
@@ -5,17 +5,17 @@ require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
|
|
5
5
|
describe BinData::Uint8Array, "when initialising" do
|
6
6
|
it "with mutually exclusive parameters :initial_length and :read_until" do
|
7
7
|
params = {initial_length: 5, read_until: :eof}
|
8
|
-
|
8
|
+
_ { BinData::Uint8Array.new(params) }.must_raise ArgumentError
|
9
9
|
end
|
10
10
|
|
11
11
|
it "with :read_until" do
|
12
12
|
params = {read_until: :not_eof}
|
13
|
-
|
13
|
+
_ { BinData::Uint8Array.new(params) }.must_raise ArgumentError
|
14
14
|
end
|
15
15
|
|
16
16
|
it "with no parameters" do
|
17
17
|
arr = BinData::Uint8Array.new
|
18
|
-
arr.num_bytes.must_equal 0
|
18
|
+
_(arr.num_bytes).must_equal 0
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -23,7 +23,7 @@ describe BinData::Uint8Array, "with :read_until" do
|
|
23
23
|
it "reads until :eof" do
|
24
24
|
arr = BinData::Uint8Array.new(read_until: :eof)
|
25
25
|
arr.read("\xff\xfe\xfd\xfc")
|
26
|
-
arr.must_equal([255, 254, 253, 252])
|
26
|
+
_(arr).must_equal([255, 254, 253, 252])
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -31,7 +31,7 @@ describe BinData::Uint8Array, "with :initial_length" do
|
|
31
31
|
it "reads" do
|
32
32
|
arr = BinData::Uint8Array.new(initial_length: 3)
|
33
33
|
arr.read("\xff\xfe\xfd\xfc")
|
34
|
-
arr.must_equal([255, 254, 253])
|
34
|
+
_(arr).must_equal([255, 254, 253])
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -39,6 +39,6 @@ describe BinData::Uint8Array, "when assigning" do
|
|
39
39
|
it "copies data" do
|
40
40
|
arr = BinData::Uint8Array.new
|
41
41
|
arr.assign([1, 2, 3])
|
42
|
-
arr.must_equal([1, 2, 3])
|
42
|
+
_(arr).must_equal([1, 2, 3])
|
43
43
|
end
|
44
44
|
end
|
data/test/virtual_test.rb
CHANGED
@@ -7,17 +7,17 @@ describe BinData::Virtual do
|
|
7
7
|
|
8
8
|
it "must not read from any stream" do
|
9
9
|
BinData::Virtual.read(stream)
|
10
|
-
stream.pos.must_equal 0
|
10
|
+
_(stream.pos).must_equal 0
|
11
11
|
end
|
12
12
|
|
13
13
|
it "must not write to a stream" do
|
14
14
|
obj = BinData::Virtual.new
|
15
|
-
obj.to_binary_s.must_equal_binary ""
|
15
|
+
_(obj.to_binary_s).must_equal_binary ""
|
16
16
|
end
|
17
17
|
|
18
18
|
it "occupies no space" do
|
19
19
|
obj = BinData::Virtual.new
|
20
|
-
obj.num_bytes.must_equal 0
|
20
|
+
_(obj.num_bytes).must_equal 0
|
21
21
|
end
|
22
22
|
|
23
23
|
it "asserts on #read" do
|
@@ -25,7 +25,7 @@ describe BinData::Virtual do
|
|
25
25
|
obj = BinData::Virtual.new(assert: -> { data << 1; true })
|
26
26
|
|
27
27
|
obj.read ""
|
28
|
-
data.must_equal [1]
|
28
|
+
_(data).must_equal [1]
|
29
29
|
end
|
30
30
|
|
31
31
|
it "asserts on #assign" do
|
@@ -33,16 +33,16 @@ describe BinData::Virtual do
|
|
33
33
|
obj = BinData::Virtual.new(assert: -> { data << 1; true })
|
34
34
|
|
35
35
|
obj.assign("foo")
|
36
|
-
data.must_equal [1]
|
36
|
+
_(data).must_equal [1]
|
37
37
|
end
|
38
38
|
|
39
39
|
it "assigns a value" do
|
40
40
|
obj = BinData::Virtual.new(3)
|
41
|
-
obj.must_equal 3
|
41
|
+
_(obj).must_equal 3
|
42
42
|
end
|
43
43
|
|
44
44
|
it "accepts the :value parameter" do
|
45
45
|
obj = BinData::Virtual.new(value: 3)
|
46
|
-
obj.must_equal 3
|
46
|
+
_(obj).must_equal 3
|
47
47
|
end
|
48
48
|
end
|
data/test/warnings_test.rb
CHANGED
@@ -10,7 +10,7 @@ describe BinData::Base, "when defining" do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
_ {
|
14
14
|
BaseWithInitialize.new
|
15
15
|
}.must_raise RuntimeError
|
16
16
|
end
|
@@ -22,7 +22,7 @@ describe BinData::Base, "when defining" do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
_ {
|
26
26
|
BaseWithInitializeInstance.new
|
27
27
|
}.must_raise RuntimeError
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dion Mendel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
170
|
- !ruby/object:Gem::Version
|
171
171
|
version: '0'
|
172
172
|
requirements: []
|
173
|
-
rubygems_version: 3.
|
173
|
+
rubygems_version: 3.3.7
|
174
174
|
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: A declarative way to read and write binary file formats
|