bindata 2.4.12 → 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 +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/record_test.rb
CHANGED
@@ -4,7 +4,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
|
|
4
4
|
|
5
5
|
describe BinData::Record do
|
6
6
|
it "is not registered" do
|
7
|
-
|
7
|
+
_ {
|
8
8
|
BinData::RegisteredClasses.lookup("Record")
|
9
9
|
}.must_raise BinData::UnRegisteredTypeError
|
10
10
|
end
|
@@ -12,7 +12,7 @@ end
|
|
12
12
|
|
13
13
|
describe BinData::Record, "when defining with errors" do
|
14
14
|
it "fails on non registered types" do
|
15
|
-
|
15
|
+
_ {
|
16
16
|
class BadTypeRecord < BinData::Record
|
17
17
|
non_registered_type :a
|
18
18
|
end
|
@@ -20,7 +20,7 @@ describe BinData::Record, "when defining with errors" do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "gives correct error message for non registered nested types" do
|
23
|
-
|
23
|
+
_ {
|
24
24
|
class BadNestedTypeRecord < BinData::Record
|
25
25
|
array :a, type: :non_registered_type
|
26
26
|
end
|
@@ -28,7 +28,7 @@ describe BinData::Record, "when defining with errors" do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "gives correct error message for non registered nested types in blocks" do
|
31
|
-
|
31
|
+
_ {
|
32
32
|
class BadNestedTypeInBlockRecord < BinData::Record
|
33
33
|
array :a do
|
34
34
|
non_registered_type
|
@@ -38,7 +38,7 @@ describe BinData::Record, "when defining with errors" do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "fails on nested choice when missing names" do
|
41
|
-
|
41
|
+
_ {
|
42
42
|
class MissingChoiceNamesRecord < BinData::Record
|
43
43
|
choice do
|
44
44
|
int8 :a
|
@@ -49,16 +49,16 @@ describe BinData::Record, "when defining with errors" do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it "fails on malformed names" do
|
52
|
-
|
52
|
+
_ {
|
53
53
|
class MalformedNameRecord < BinData::Record
|
54
54
|
int8 :a
|
55
55
|
int8 "45"
|
56
56
|
end
|
57
|
-
}.must_raise_on_line
|
57
|
+
}.must_raise_on_line SyntaxError, 3, "field '45' is an illegal fieldname in MalformedNameRecord"
|
58
58
|
end
|
59
59
|
|
60
60
|
it "fails on duplicate names" do
|
61
|
-
|
61
|
+
_ {
|
62
62
|
class DuplicateNameRecord < BinData::Record
|
63
63
|
int8 :a
|
64
64
|
int8 :b
|
@@ -68,24 +68,24 @@ describe BinData::Record, "when defining with errors" do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "fails on reserved names" do
|
71
|
-
|
71
|
+
_ {
|
72
72
|
class ReservedNameRecord < BinData::Record
|
73
73
|
int8 :a
|
74
74
|
int8 :invert # from Hash.instance_methods
|
75
75
|
end
|
76
|
-
}.must_raise_on_line
|
76
|
+
}.must_raise_on_line SyntaxError, 3, "field 'invert' is a reserved name in ReservedNameRecord"
|
77
77
|
end
|
78
78
|
|
79
79
|
it "fails when field name shadows an existing method" do
|
80
|
-
|
80
|
+
_ {
|
81
81
|
class ExistingNameRecord < BinData::Record
|
82
82
|
int8 :object_id
|
83
83
|
end
|
84
|
-
}.must_raise_on_line
|
84
|
+
}.must_raise_on_line SyntaxError, 2, "field 'object_id' shadows an existing method in ExistingNameRecord"
|
85
85
|
end
|
86
86
|
|
87
87
|
it "fails on unknown endian" do
|
88
|
-
|
88
|
+
_ {
|
89
89
|
class BadEndianRecord < BinData::Record
|
90
90
|
endian 'a bad value'
|
91
91
|
end
|
@@ -93,7 +93,7 @@ describe BinData::Record, "when defining with errors" do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it "fails when endian is after a field" do
|
96
|
-
|
96
|
+
_ {
|
97
97
|
class BadEndianPosRecord < BinData::Record
|
98
98
|
string :a
|
99
99
|
endian :little
|
@@ -102,7 +102,7 @@ describe BinData::Record, "when defining with errors" do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
it "fails when search_prefix is after a field" do
|
105
|
-
|
105
|
+
_ {
|
106
106
|
class BadSearchPrefixPosRecord < BinData::Record
|
107
107
|
string :a
|
108
108
|
search_prefix :pre
|
@@ -123,19 +123,19 @@ describe BinData::Record, "with anonymous fields" do
|
|
123
123
|
let(:obj) { AnonymousRecord.new }
|
124
124
|
|
125
125
|
it "only shows non anonymous fields" do
|
126
|
-
obj.field_names.must_equal [:a]
|
126
|
+
_(obj.field_names).must_equal [:a]
|
127
127
|
end
|
128
128
|
|
129
129
|
it "does not include anonymous fields in snapshot" do
|
130
130
|
obj.a = 5
|
131
|
-
obj.snapshot.must_equal({a: 5})
|
131
|
+
_(obj.snapshot).must_equal({a: 5})
|
132
132
|
end
|
133
133
|
|
134
134
|
it "writes anonymous fields" do
|
135
135
|
str = "\001\002\003\004\005"
|
136
136
|
obj.read(str)
|
137
137
|
obj.a.clear
|
138
|
-
obj.to_binary_s.must_equal_binary "\012\002\003\004\012"
|
138
|
+
_(obj.to_binary_s).must_equal_binary "\012\002\003\004\012"
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
@@ -151,20 +151,20 @@ describe BinData::Record, "with hidden fields" do
|
|
151
151
|
let(:obj) { HiddenRecord.new }
|
152
152
|
|
153
153
|
it "only shows fields that aren't hidden" do
|
154
|
-
obj.field_names.must_equal [:a, :d]
|
154
|
+
_(obj.field_names).must_equal [:a, :d]
|
155
155
|
end
|
156
156
|
|
157
157
|
it "accesses hidden fields directly" do
|
158
|
-
obj.b.must_equal 10
|
158
|
+
_(obj.b).must_equal 10
|
159
159
|
obj.c = 15
|
160
|
-
obj.c.must_equal 15
|
160
|
+
_(obj.c).must_equal 15
|
161
161
|
|
162
|
-
obj.must_respond_to :b=
|
162
|
+
_(obj).must_respond_to :b=
|
163
163
|
end
|
164
164
|
|
165
165
|
it "does not include hidden fields in snapshot" do
|
166
166
|
obj.b = 5
|
167
|
-
obj.snapshot.must_equal({a: 0, d: 5})
|
167
|
+
_(obj.snapshot).must_equal({a: 0, d: 5})
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
@@ -177,14 +177,14 @@ describe BinData::Record, "with multiple fields" do
|
|
177
177
|
let(:obj) { MultiFieldRecord.new(a: 1, b: 2) }
|
178
178
|
|
179
179
|
it "returns num_bytes" do
|
180
|
-
obj.a.num_bytes.must_equal 1
|
181
|
-
obj.b.num_bytes.must_equal 1
|
182
|
-
obj.num_bytes.must_equal 2
|
180
|
+
_(obj.a.num_bytes).must_equal 1
|
181
|
+
_(obj.b.num_bytes).must_equal 1
|
182
|
+
_(obj.num_bytes).must_equal 2
|
183
183
|
end
|
184
184
|
|
185
185
|
it "identifies accepted parameters" do
|
186
|
-
BinData::Record.accepted_parameters.all.must_include :hide
|
187
|
-
BinData::Record.accepted_parameters.all.must_include :endian
|
186
|
+
_(BinData::Record.accepted_parameters.all).must_include :hide
|
187
|
+
_(BinData::Record.accepted_parameters.all).must_include :endian
|
188
188
|
end
|
189
189
|
|
190
190
|
it "clears" do
|
@@ -202,29 +202,29 @@ describe BinData::Record, "with multiple fields" do
|
|
202
202
|
end
|
203
203
|
|
204
204
|
it "writes ordered" do
|
205
|
-
obj.to_binary_s.must_equal_binary "\x01\x02"
|
205
|
+
_(obj.to_binary_s).must_equal_binary "\x01\x02"
|
206
206
|
end
|
207
207
|
|
208
208
|
it "reads ordered" do
|
209
209
|
obj.read("\x03\x04")
|
210
210
|
|
211
|
-
obj.a.must_equal 3
|
212
|
-
obj.b.must_equal 4
|
211
|
+
_(obj.a).must_equal 3
|
212
|
+
_(obj.b).must_equal 4
|
213
213
|
end
|
214
214
|
|
215
215
|
it "returns a snapshot" do
|
216
216
|
snap = obj.snapshot
|
217
|
-
snap.a.must_equal 1
|
218
|
-
snap.b.must_equal 2
|
219
|
-
snap.must_equal({ a: 1, b: 2 })
|
217
|
+
_(snap.a).must_equal 1
|
218
|
+
_(snap.b).must_equal 2
|
219
|
+
_(snap).must_equal({ a: 1, b: 2 })
|
220
220
|
end
|
221
221
|
|
222
222
|
it "returns field_names" do
|
223
|
-
obj.field_names.must_equal [:a, :b]
|
223
|
+
_(obj.field_names).must_equal [:a, :b]
|
224
224
|
end
|
225
225
|
|
226
226
|
it "fails on unknown method call" do
|
227
|
-
|
227
|
+
_ { obj.does_not_exist }.must_raise NoMethodError
|
228
228
|
end
|
229
229
|
end
|
230
230
|
|
@@ -245,42 +245,42 @@ describe BinData::Record, "with nested structs" do
|
|
245
245
|
let(:obj) { NestedStructRecord.new }
|
246
246
|
|
247
247
|
it "includes nested field names" do
|
248
|
-
obj.field_names.must_equal [:a, :b, :c]
|
248
|
+
_(obj.field_names).must_equal [:a, :b, :c]
|
249
249
|
end
|
250
250
|
|
251
251
|
it "hides nested field names" do
|
252
|
-
obj.b.field_names.must_equal [:x]
|
252
|
+
_(obj.b.field_names).must_equal [:x]
|
253
253
|
end
|
254
254
|
|
255
255
|
it "accesses nested fields" do
|
256
|
-
obj.a.must_equal 6
|
257
|
-
obj.b.w.must_equal 3
|
258
|
-
obj.b.x.must_equal 6
|
259
|
-
obj.c.y.must_equal 3
|
256
|
+
_(obj.a).must_equal 6
|
257
|
+
_(obj.b.w).must_equal 3
|
258
|
+
_(obj.b.x).must_equal 6
|
259
|
+
_(obj.c.y).must_equal 3
|
260
260
|
end
|
261
261
|
|
262
262
|
it "returns correct abs_offset" do
|
263
|
-
obj.abs_offset.must_equal 0
|
264
|
-
obj.b.abs_offset.must_equal 1
|
265
|
-
obj.b.w.abs_offset.must_equal 1
|
266
|
-
obj.c.abs_offset.must_equal 3
|
267
|
-
obj.c.z.abs_offset.must_equal 4
|
263
|
+
_(obj.abs_offset).must_equal 0
|
264
|
+
_(obj.b.abs_offset).must_equal 1
|
265
|
+
_(obj.b.w.abs_offset).must_equal 1
|
266
|
+
_(obj.c.abs_offset).must_equal 3
|
267
|
+
_(obj.c.z.abs_offset).must_equal 4
|
268
268
|
end
|
269
269
|
|
270
270
|
it "returns correct rel_offset" do
|
271
|
-
obj.rel_offset.must_equal 0
|
272
|
-
obj.b.rel_offset.must_equal 1
|
273
|
-
obj.b.w.rel_offset.must_equal 0
|
274
|
-
obj.c.rel_offset.must_equal 3
|
275
|
-
obj.c.z.rel_offset.must_equal 1
|
271
|
+
_(obj.rel_offset).must_equal 0
|
272
|
+
_(obj.b.rel_offset).must_equal 1
|
273
|
+
_(obj.b.w.rel_offset).must_equal 0
|
274
|
+
_(obj.c.rel_offset).must_equal 3
|
275
|
+
_(obj.c.z.rel_offset).must_equal 1
|
276
276
|
end
|
277
277
|
|
278
278
|
it "assigns nested fields" do
|
279
279
|
obj.assign(a: 2, b: {w: 4})
|
280
|
-
obj.a.must_equal 2
|
281
|
-
obj.b.w.must_equal 4
|
282
|
-
obj.b.x.must_equal 2
|
283
|
-
obj.c.y.must_equal 4
|
280
|
+
_(obj.a).must_equal 2
|
281
|
+
_(obj.b.w).must_equal 4
|
282
|
+
_(obj.b.x).must_equal 2
|
283
|
+
_(obj.c.y).must_equal 4
|
284
284
|
end
|
285
285
|
end
|
286
286
|
|
@@ -294,7 +294,7 @@ describe BinData::Record, "with nested array of primitives" do
|
|
294
294
|
let(:obj) { NestedPrimitiveArrayRecord.new }
|
295
295
|
|
296
296
|
it "uses block as :type" do
|
297
|
-
obj.snapshot.must_equal({a: [0, 1, 2]})
|
297
|
+
_(obj.snapshot).must_equal({a: [0, 1, 2]})
|
298
298
|
end
|
299
299
|
end
|
300
300
|
|
@@ -310,7 +310,7 @@ describe BinData::Record, "with nested array of structs" do
|
|
310
310
|
|
311
311
|
it "uses block as struct for :type" do
|
312
312
|
obj.a[0].b = 2
|
313
|
-
obj.snapshot.must_equal({a: [{b: 2, c: 0}]})
|
313
|
+
_(obj.snapshot).must_equal({a: [{b: 2, c: 0}]})
|
314
314
|
end
|
315
315
|
end
|
316
316
|
|
@@ -324,7 +324,7 @@ describe BinData::Record, "with nested choice with implied keys" do
|
|
324
324
|
|
325
325
|
let(:obj) { NestedChoiceWithImpliedKeysRecord.new }
|
326
326
|
|
327
|
-
specify { obj.a.must_equal 2 }
|
327
|
+
specify { _(obj.a).must_equal 2 }
|
328
328
|
end
|
329
329
|
|
330
330
|
describe BinData::Record, "with nested choice with explicit keys" do
|
@@ -337,7 +337,7 @@ describe BinData::Record, "with nested choice with explicit keys" do
|
|
337
337
|
|
338
338
|
let(:obj) { NestedChoiceWithKeysRecord.new }
|
339
339
|
|
340
|
-
specify { obj.a.must_equal 2 }
|
340
|
+
specify { _(obj.a).must_equal 2 }
|
341
341
|
end
|
342
342
|
|
343
343
|
describe BinData::Record, "with nested choice with names" do
|
@@ -350,7 +350,7 @@ describe BinData::Record, "with nested choice with names" do
|
|
350
350
|
|
351
351
|
let(:obj) { NestedChoiceWithNamesRecord.new }
|
352
352
|
|
353
|
-
specify { obj.a.must_equal 1 }
|
353
|
+
specify { _(obj.a).must_equal 1 }
|
354
354
|
end
|
355
355
|
|
356
356
|
describe BinData::Record, "with an endian defined" do
|
@@ -392,7 +392,7 @@ describe BinData::Record, "with an endian defined" do
|
|
392
392
|
|
393
393
|
lambdaed = [1, 2.0, 3, 4, 5, 6, 7, 8].pack('veCCVvNn')
|
394
394
|
|
395
|
-
obj.to_binary_s.must_equal_binary lambdaed
|
395
|
+
_(obj.to_binary_s).must_equal_binary lambdaed
|
396
396
|
end
|
397
397
|
end
|
398
398
|
|
@@ -430,22 +430,22 @@ describe BinData::Record, "with search_prefix" do
|
|
430
430
|
|
431
431
|
it "uses search_prefix" do
|
432
432
|
obj = RecordWithSearchPrefix.new
|
433
|
-
obj.f.class.name.must_equal "ASprefix"
|
433
|
+
_(obj.f.class.name).must_equal "ASprefix"
|
434
434
|
end
|
435
435
|
|
436
436
|
it "uses parent search_prefix" do
|
437
437
|
obj = RecordWithParentSearchPrefix.new
|
438
|
-
obj.s.f.class.name.must_equal "ASprefix"
|
438
|
+
_(obj.s.f.class.name).must_equal "ASprefix"
|
439
439
|
end
|
440
440
|
|
441
441
|
it "uses nested search_prefix" do
|
442
442
|
obj = RecordWithNestedSearchPrefix.new
|
443
|
-
obj.s.f.class.name.must_equal "ASprefix"
|
443
|
+
_(obj.s.f.class.name).must_equal "ASprefix"
|
444
444
|
end
|
445
445
|
|
446
446
|
it "uses prioritised nested search_prefix" do
|
447
447
|
obj = RecordWithPrioritisedNestedSearchPrefix.new
|
448
|
-
obj.s.f.class.name.must_equal "ASprefix"
|
448
|
+
_(obj.s.f.class.name).must_equal "ASprefix"
|
449
449
|
end
|
450
450
|
end
|
451
451
|
|
@@ -456,30 +456,30 @@ describe BinData::Record, "with endian :big_and_little" do
|
|
456
456
|
end
|
457
457
|
|
458
458
|
it "is not registered" do
|
459
|
-
|
459
|
+
_ {
|
460
460
|
BinData::RegisteredClasses.lookup("RecordWithBnLEndian")
|
461
461
|
}.must_raise BinData::UnRegisteredTypeError
|
462
462
|
end
|
463
463
|
|
464
464
|
it "creates big endian version" do
|
465
465
|
obj = RecordWithBnLEndianBe.new
|
466
|
-
obj.to_binary_s.must_equal_binary "\x00\x01"
|
466
|
+
_(obj.to_binary_s).must_equal_binary "\x00\x01"
|
467
467
|
end
|
468
468
|
|
469
469
|
it "creates little endian version" do
|
470
470
|
obj = RecordWithBnLEndianLe.new
|
471
|
-
obj.to_binary_s.must_equal_binary "\x01\x00"
|
471
|
+
_(obj.to_binary_s).must_equal_binary "\x01\x00"
|
472
472
|
end
|
473
473
|
|
474
474
|
it "requires :endian as argument" do
|
475
|
-
|
475
|
+
_ {
|
476
476
|
RecordWithBnLEndian.new
|
477
477
|
}.must_raise ArgumentError
|
478
478
|
end
|
479
479
|
|
480
480
|
it "accepts :endian as argument" do
|
481
481
|
obj = RecordWithBnLEndian.new(endian: :little)
|
482
|
-
obj.to_binary_s.must_equal_binary "\x01\x00"
|
482
|
+
_(obj.to_binary_s).must_equal_binary "\x01\x00"
|
483
483
|
end
|
484
484
|
end
|
485
485
|
|
@@ -495,12 +495,12 @@ describe BinData::Record, "with endian :big_and_little and search_prefix" do
|
|
495
495
|
|
496
496
|
it "creates big endian version" do
|
497
497
|
obj = RecordWithBnLEndianAndSearchPrefixBe.new
|
498
|
-
obj.to_binary_s.must_equal_binary "\x00\x01"
|
498
|
+
_(obj.to_binary_s).must_equal_binary "\x00\x01"
|
499
499
|
end
|
500
500
|
|
501
501
|
it "creates little endian version" do
|
502
502
|
obj = RecordWithBnLEndianAndSearchPrefixLe.new
|
503
|
-
obj.to_binary_s.must_equal_binary "\x01\x00"
|
503
|
+
_(obj.to_binary_s).must_equal_binary "\x01\x00"
|
504
504
|
end
|
505
505
|
end
|
506
506
|
|
@@ -514,30 +514,30 @@ describe BinData::Record, "with endian :big_and_little when subclassed" do
|
|
514
514
|
end
|
515
515
|
|
516
516
|
it "is not registered" do
|
517
|
-
|
517
|
+
_ {
|
518
518
|
BinData::RegisteredClasses.lookup("BRecordWithBnLEndian")
|
519
519
|
}.must_raise BinData::UnRegisteredTypeError
|
520
520
|
end
|
521
521
|
|
522
522
|
it "creates big endian version" do
|
523
523
|
obj = BRecordWithBnLEndianBe.new
|
524
|
-
obj.to_binary_s.must_equal_binary "\x00\x01\x00\x02"
|
524
|
+
_(obj.to_binary_s).must_equal_binary "\x00\x01\x00\x02"
|
525
525
|
end
|
526
526
|
|
527
527
|
it "creates little endian version" do
|
528
528
|
obj = BRecordWithBnLEndianLe.new
|
529
|
-
obj.to_binary_s.must_equal_binary "\x01\x00\x02\x00"
|
529
|
+
_(obj.to_binary_s).must_equal_binary "\x01\x00\x02\x00"
|
530
530
|
end
|
531
531
|
|
532
532
|
it "requires :endian as argument" do
|
533
|
-
|
533
|
+
_ {
|
534
534
|
BRecordWithBnLEndian.new
|
535
535
|
}.must_raise ArgumentError
|
536
536
|
end
|
537
537
|
|
538
538
|
it "accepts :endian as argument" do
|
539
539
|
obj = BRecordWithBnLEndian.new(endian: :little)
|
540
|
-
obj.to_binary_s.must_equal_binary "\x01\x00\x02\x00"
|
540
|
+
_(obj.to_binary_s).must_equal_binary "\x01\x00\x02\x00"
|
541
541
|
end
|
542
542
|
end
|
543
543
|
|
@@ -556,9 +556,9 @@ describe BinData::Record, "defined recursively" do
|
|
556
556
|
it "reads" do
|
557
557
|
str = "\x00\x01\x01\x00\x02\x01\x00\x03\x00"
|
558
558
|
obj = RecursiveRecord.read(str)
|
559
|
-
obj.val.must_equal 1
|
560
|
-
obj.nxt.val.must_equal 2
|
561
|
-
obj.nxt.nxt.val.must_equal 3
|
559
|
+
_(obj.val).must_equal 1
|
560
|
+
_(obj.nxt.val).must_equal 2
|
561
|
+
_(obj.nxt.nxt.val).must_equal 3
|
562
562
|
end
|
563
563
|
|
564
564
|
it "is assignable on demand" do
|
@@ -573,7 +573,7 @@ describe BinData::Record, "defined recursively" do
|
|
573
573
|
obj.val = 5
|
574
574
|
obj.nxt.val = 6
|
575
575
|
obj.nxt.nxt.val = 7
|
576
|
-
obj.to_binary_s.must_equal_binary "\x00\x05\x01\x00\x06\x01\x00\x07\x00"
|
576
|
+
_(obj.to_binary_s).must_equal_binary "\x00\x05\x01\x00\x06\x01\x00\x07\x00"
|
577
577
|
end
|
578
578
|
end
|
579
579
|
|
@@ -585,12 +585,12 @@ describe BinData::Record, "with custom mandatory parameters" do
|
|
585
585
|
end
|
586
586
|
|
587
587
|
it "raises error if mandatory parameter is not supplied" do
|
588
|
-
|
588
|
+
_ { MandatoryRecord.new }.must_raise ArgumentError
|
589
589
|
end
|
590
590
|
|
591
591
|
it "uses mandatory parameter" do
|
592
592
|
obj = MandatoryRecord.new(arg1: 5)
|
593
|
-
obj.a.must_equal 5
|
593
|
+
_(obj.a).must_equal 5
|
594
594
|
end
|
595
595
|
end
|
596
596
|
|
@@ -604,23 +604,23 @@ describe BinData::Record, "with custom default parameters" do
|
|
604
604
|
|
605
605
|
it "uses default parameter" do
|
606
606
|
obj = DefaultRecord.new
|
607
|
-
obj.a.must_equal 5
|
607
|
+
_(obj.a).must_equal 5
|
608
608
|
end
|
609
609
|
|
610
610
|
it "overrides default parameter" do
|
611
611
|
obj = DefaultRecord.new(arg1: 7)
|
612
|
-
obj.a.must_equal 7
|
612
|
+
_(obj.a).must_equal 7
|
613
613
|
end
|
614
614
|
|
615
615
|
it "accepts values" do
|
616
616
|
obj = DefaultRecord.new(b: 2)
|
617
|
-
obj.b.must_equal 2
|
617
|
+
_(obj.b).must_equal 2
|
618
618
|
end
|
619
619
|
|
620
620
|
it "accepts values and parameters" do
|
621
621
|
obj = DefaultRecord.new({b: 2}, arg1: 3)
|
622
|
-
obj.a.must_equal 3
|
623
|
-
obj.b.must_equal 2
|
622
|
+
_(obj.a).must_equal 3
|
623
|
+
_(obj.b).must_equal 2
|
624
624
|
end
|
625
625
|
end
|
626
626
|
|
@@ -634,20 +634,20 @@ describe BinData::Record, "with :onlyif" do
|
|
634
634
|
let(:obj) { OnlyIfRecord.new }
|
635
635
|
|
636
636
|
it "initial state" do
|
637
|
-
obj.num_bytes.must_equal 2
|
638
|
-
obj.snapshot.must_equal({a: 3, b: 5})
|
639
|
-
obj.to_binary_s.must_equal_binary "\x03\x05"
|
637
|
+
_(obj.num_bytes).must_equal 2
|
638
|
+
_(obj.snapshot).must_equal({a: 3, b: 5})
|
639
|
+
_(obj.to_binary_s).must_equal_binary "\x03\x05"
|
640
640
|
end
|
641
641
|
|
642
642
|
it "identifies if fields are included" do
|
643
|
-
obj.a
|
644
|
-
obj.b
|
645
|
-
obj.c
|
643
|
+
_(obj.a?).must_equal true
|
644
|
+
_(obj.b?).must_equal true
|
645
|
+
_(obj.c?).must_equal false
|
646
646
|
end
|
647
647
|
|
648
648
|
it "reads as lambdaed" do
|
649
649
|
obj.read("\x01\x02")
|
650
|
-
obj.snapshot.must_equal({a: 1, c: 2})
|
650
|
+
_(obj.snapshot).must_equal({a: 1, c: 2})
|
651
651
|
end
|
652
652
|
end
|
653
653
|
|
@@ -665,14 +665,14 @@ describe BinData::Record, "derived classes" do
|
|
665
665
|
end
|
666
666
|
|
667
667
|
it "does not affect parent" do
|
668
|
-
ParentRecord.new.field_names.must_equal [:a]
|
668
|
+
_(ParentRecord.new.field_names).must_equal [:a]
|
669
669
|
end
|
670
670
|
|
671
671
|
it "inherits fields for first child" do
|
672
|
-
Child1Record.new.field_names.must_equal [:a, :b]
|
672
|
+
_(Child1Record.new.field_names).must_equal [:a, :b]
|
673
673
|
end
|
674
674
|
|
675
675
|
it "inherits fields for second child" do
|
676
|
-
Child2Record.new.field_names.must_equal [:a, :b, :c]
|
676
|
+
_(Child2Record.new.field_names).must_equal [:a, :b, :c]
|
677
677
|
end
|
678
678
|
end
|