bindata 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bindata might be problematic. Click here for more details.
- data/ChangeLog.rdoc +7 -0
- data/NEWS.rdoc +11 -0
- data/Rakefile +6 -1
- data/bindata.gemspec +2 -1
- data/doc/manual.md +17 -9
- data/examples/gzip.rb +2 -2
- data/examples/list.rb +2 -2
- data/lib/bindata/alignment.rb +4 -9
- data/lib/bindata/array.rb +57 -51
- data/lib/bindata/base.rb +13 -110
- data/lib/bindata/base_primitive.rb +130 -75
- data/lib/bindata/bits.rb +5 -7
- data/lib/bindata/choice.rb +24 -32
- data/lib/bindata/dsl.rb +1 -6
- data/lib/bindata/framework.rb +81 -0
- data/lib/bindata/int.rb +5 -7
- data/lib/bindata/name.rb +28 -0
- data/lib/bindata/offset.rb +42 -53
- data/lib/bindata/params.rb +33 -38
- data/lib/bindata/struct.rb +2 -6
- data/lib/bindata/trace.rb +16 -16
- data/lib/bindata/version.rb +1 -1
- data/lib/bindata/virtual.rb +3 -3
- data/{spec/alignment_spec.rb → test/alignment_test.rb} +17 -16
- data/test/array_test.rb +371 -0
- data/test/base_primitive_test.rb +312 -0
- data/test/base_test.rb +183 -0
- data/{spec/bits_spec.rb → test/bits_test.rb} +59 -59
- data/test/choice_test.rb +260 -0
- data/{spec/spec_common.rb → test/common.rb} +33 -18
- data/test/count_bytes_remaining_test.rb +41 -0
- data/{spec/deprecated_spec.rb → test/deprecated_test.rb} +5 -7
- data/test/float_test.rb +72 -0
- data/{spec/int_spec.rb → test/int_test.rb} +34 -43
- data/{spec/io_spec.rb → test/io_test.rb} +70 -71
- data/{spec/lazy_spec.rb → test/lazy_test.rb} +38 -39
- data/test/offset_test.rb +93 -0
- data/test/params_test.rb +144 -0
- data/{spec/primitive_spec.rb → test/primitive_test.rb} +42 -54
- data/{spec/record_spec.rb → test/record_test.rb} +133 -154
- data/test/registry_test.rb +104 -0
- data/test/rest_test.rb +29 -0
- data/test/skip_test.rb +28 -0
- data/{spec/string_spec.rb → test/string_test.rb} +96 -97
- data/test/stringz_test.rb +127 -0
- data/{spec/struct_spec.rb → test/struct_test.rb} +119 -120
- data/{spec/system_spec.rb → test/system_test.rb} +66 -106
- metadata +39 -38
- data/lib/a.rb +0 -24
- data/spec/array_spec.rb +0 -331
- data/spec/base_primitive_spec.rb +0 -238
- data/spec/base_spec.rb +0 -376
- data/spec/choice_spec.rb +0 -263
- data/spec/count_bytes_remaining_spec.rb +0 -38
- data/spec/example.rb +0 -21
- data/spec/float_spec.rb +0 -37
- data/spec/registry_spec.rb +0 -108
- data/spec/rest_spec.rb +0 -26
- data/spec/skip_spec.rb +0 -27
- data/spec/stringz_spec.rb +0 -118
- data/tasks/rspec.rake +0 -17
@@ -1,13 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "
|
4
|
-
require 'bindata'
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "common"))
|
5
4
|
|
6
5
|
describe BinData::Record do
|
7
6
|
it "is not registered" do
|
8
|
-
|
7
|
+
lambda {
|
9
8
|
BinData::RegisteredClasses.lookup("Record")
|
10
|
-
}.
|
9
|
+
}.must_raise BinData::UnRegisteredTypeError
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
@@ -17,9 +16,7 @@ describe BinData::Record, "when defining with errors" do
|
|
17
16
|
class BadTypeRecord < BinData::Record
|
18
17
|
non_registered_type :a
|
19
18
|
end
|
20
|
-
}.
|
21
|
-
err.message.should == "unknown type 'non_registered_type' in #{BadTypeRecord}"
|
22
|
-
}
|
19
|
+
}.must_raise_on_line TypeError, 2, "unknown type 'non_registered_type' in BadTypeRecord"
|
23
20
|
end
|
24
21
|
|
25
22
|
it "gives correct error message for non registered nested types" do
|
@@ -27,9 +24,7 @@ describe BinData::Record, "when defining with errors" do
|
|
27
24
|
class BadNestedTypeRecord < BinData::Record
|
28
25
|
array :a, :type => :non_registered_type
|
29
26
|
end
|
30
|
-
}.
|
31
|
-
err.message.should == "unknown type 'non_registered_type' in #{BadNestedTypeRecord}"
|
32
|
-
}
|
27
|
+
}.must_raise_on_line TypeError, 2, "unknown type 'non_registered_type' in BadNestedTypeRecord"
|
33
28
|
end
|
34
29
|
|
35
30
|
it "gives correct error message for non registered nested types in blocks" do
|
@@ -39,9 +34,7 @@ describe BinData::Record, "when defining with errors" do
|
|
39
34
|
non_registered_type
|
40
35
|
end
|
41
36
|
end
|
42
|
-
}.
|
43
|
-
err.message.should == "unknown type 'non_registered_type' in #{BinData::Array}"
|
44
|
-
}
|
37
|
+
}.must_raise_on_line TypeError, 3, "unknown type 'non_registered_type' in BinData::Array"
|
45
38
|
end
|
46
39
|
|
47
40
|
it "fails on nested choice when missing names" do
|
@@ -52,9 +45,7 @@ describe BinData::Record, "when defining with errors" do
|
|
52
45
|
int8
|
53
46
|
end
|
54
47
|
end
|
55
|
-
}.
|
56
|
-
err.message.should == "fields must either all have names, or none must have names in BinData::Choice"
|
57
|
-
}
|
48
|
+
}.must_raise_on_line SyntaxError, 4, "fields must either all have names, or none must have names in BinData::Choice"
|
58
49
|
end
|
59
50
|
|
60
51
|
it "fails on malformed names" do
|
@@ -63,9 +54,7 @@ describe BinData::Record, "when defining with errors" do
|
|
63
54
|
int8 :a
|
64
55
|
int8 "45"
|
65
56
|
end
|
66
|
-
}.
|
67
|
-
err.message.should == "field '45' is an illegal fieldname in #{MalformedNameRecord}"
|
68
|
-
}
|
57
|
+
}.must_raise_on_line NameError, 3, "field '45' is an illegal fieldname in MalformedNameRecord"
|
69
58
|
end
|
70
59
|
|
71
60
|
it "fails on duplicate names" do
|
@@ -75,9 +64,7 @@ describe BinData::Record, "when defining with errors" do
|
|
75
64
|
int8 :b
|
76
65
|
int8 :a
|
77
66
|
end
|
78
|
-
}.
|
79
|
-
err.message.should == "duplicate field 'a' in #{DuplicateNameRecord}"
|
80
|
-
}
|
67
|
+
}.must_raise_on_line SyntaxError, 4, "duplicate field 'a' in DuplicateNameRecord"
|
81
68
|
end
|
82
69
|
|
83
70
|
it "fails on reserved names" do
|
@@ -86,9 +73,7 @@ describe BinData::Record, "when defining with errors" do
|
|
86
73
|
int8 :a
|
87
74
|
int8 :invert # from Hash.instance_methods
|
88
75
|
end
|
89
|
-
}.
|
90
|
-
err.message.should == "field 'invert' is a reserved name in #{ReservedNameRecord}"
|
91
|
-
}
|
76
|
+
}.must_raise_on_line NameError, 3, "field 'invert' is a reserved name in ReservedNameRecord"
|
92
77
|
end
|
93
78
|
|
94
79
|
it "fails when field name shadows an existing method" do
|
@@ -96,9 +81,7 @@ describe BinData::Record, "when defining with errors" do
|
|
96
81
|
class ExistingNameRecord < BinData::Record
|
97
82
|
int8 :object_id
|
98
83
|
end
|
99
|
-
}.
|
100
|
-
err.message.should == "field 'object_id' shadows an existing method in #{ExistingNameRecord}"
|
101
|
-
}
|
84
|
+
}.must_raise_on_line NameError, 2, "field 'object_id' shadows an existing method in ExistingNameRecord"
|
102
85
|
end
|
103
86
|
|
104
87
|
it "fails on unknown endian" do
|
@@ -106,9 +89,7 @@ describe BinData::Record, "when defining with errors" do
|
|
106
89
|
class BadEndianRecord < BinData::Record
|
107
90
|
endian 'a bad value'
|
108
91
|
end
|
109
|
-
}.
|
110
|
-
err.message.should == "unknown value for endian 'a bad value' in #{BadEndianRecord}"
|
111
|
-
}
|
92
|
+
}.must_raise_on_line ArgumentError, 2, "unknown value for endian 'a bad value' in BadEndianRecord"
|
112
93
|
end
|
113
94
|
end
|
114
95
|
|
@@ -121,22 +102,22 @@ describe BinData::Record, "with anonymous fields" do
|
|
121
102
|
int8 :value => :a
|
122
103
|
end
|
123
104
|
|
124
|
-
|
105
|
+
let(:obj) { AnonymousRecord.new }
|
125
106
|
|
126
107
|
it "only shows non anonymous fields" do
|
127
|
-
|
108
|
+
obj.field_names.must_equal ["a"]
|
128
109
|
end
|
129
110
|
|
130
111
|
it "does not include anonymous fields in snapshot" do
|
131
|
-
|
132
|
-
|
112
|
+
obj.a = 5
|
113
|
+
obj.snapshot.must_equal({"a" => 5})
|
133
114
|
end
|
134
115
|
|
135
116
|
it "writes anonymous fields" do
|
136
117
|
str = "\001\002\003\004\005"
|
137
|
-
|
138
|
-
|
139
|
-
|
118
|
+
obj.read(str)
|
119
|
+
obj.a.clear
|
120
|
+
obj.to_binary_s.must_equal "\012\002\003\004\012"
|
140
121
|
end
|
141
122
|
end
|
142
123
|
|
@@ -149,23 +130,23 @@ describe BinData::Record, "with hidden fields" do
|
|
149
130
|
int8 :d, :value => :b
|
150
131
|
end
|
151
132
|
|
152
|
-
|
133
|
+
let(:obj) { HiddenRecord.new }
|
153
134
|
|
154
135
|
it "only shows fields that aren't hidden" do
|
155
|
-
|
136
|
+
obj.field_names.must_equal ["a", "d"]
|
156
137
|
end
|
157
138
|
|
158
139
|
it "accesses hidden fields directly" do
|
159
|
-
|
160
|
-
|
161
|
-
|
140
|
+
obj.b.must_equal 10
|
141
|
+
obj.c = 15
|
142
|
+
obj.c.must_equal 15
|
162
143
|
|
163
|
-
|
144
|
+
obj.must_respond_to :b=
|
164
145
|
end
|
165
146
|
|
166
147
|
it "does not include hidden fields in snapshot" do
|
167
|
-
|
168
|
-
|
148
|
+
obj.b = 5
|
149
|
+
obj.snapshot.must_equal({"a" => 0, "d" => 5})
|
169
150
|
end
|
170
151
|
end
|
171
152
|
|
@@ -175,57 +156,57 @@ describe BinData::Record, "with multiple fields" do
|
|
175
156
|
int8 :b
|
176
157
|
end
|
177
158
|
|
178
|
-
|
159
|
+
let(:obj) { MultiFieldRecord.new(:a => 1, :b => 2) }
|
179
160
|
|
180
161
|
it "returns num_bytes" do
|
181
|
-
|
182
|
-
|
183
|
-
|
162
|
+
obj.a.num_bytes.must_equal 1
|
163
|
+
obj.b.num_bytes.must_equal 1
|
164
|
+
obj.num_bytes.must_equal 2
|
184
165
|
end
|
185
166
|
|
186
167
|
it "identifies accepted parameters" do
|
187
|
-
BinData::Record.accepted_parameters.all.
|
188
|
-
BinData::Record.accepted_parameters.all.
|
168
|
+
BinData::Record.accepted_parameters.all.must_include :hide
|
169
|
+
BinData::Record.accepted_parameters.all.must_include :endian
|
189
170
|
end
|
190
171
|
|
191
172
|
it "clears" do
|
192
|
-
|
193
|
-
|
194
|
-
|
173
|
+
obj.a = 6
|
174
|
+
obj.clear
|
175
|
+
assert obj.clear?
|
195
176
|
end
|
196
177
|
|
197
178
|
it "clears individual elements" do
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
179
|
+
obj.a = 6
|
180
|
+
obj.b = 7
|
181
|
+
obj.a.clear
|
182
|
+
assert obj.a.clear?
|
183
|
+
refute obj.b.clear?
|
203
184
|
end
|
204
185
|
|
205
186
|
it "writes ordered" do
|
206
|
-
|
187
|
+
obj.to_binary_s.must_equal "\x01\x02"
|
207
188
|
end
|
208
189
|
|
209
190
|
it "reads ordered" do
|
210
|
-
|
191
|
+
obj.read("\x03\x04")
|
211
192
|
|
212
|
-
|
213
|
-
|
193
|
+
obj.a.must_equal 3
|
194
|
+
obj.b.must_equal 4
|
214
195
|
end
|
215
196
|
|
216
197
|
it "returns a snapshot" do
|
217
|
-
snap =
|
218
|
-
snap.a.
|
219
|
-
snap.b.
|
220
|
-
snap.
|
198
|
+
snap = obj.snapshot
|
199
|
+
snap.a.must_equal 1
|
200
|
+
snap.b.must_equal 2
|
201
|
+
snap.must_equal({ "a" => 1, "b" => 2 })
|
221
202
|
end
|
222
203
|
|
223
204
|
it "returns field_names" do
|
224
|
-
|
205
|
+
obj.field_names.must_equal ["a", "b"]
|
225
206
|
end
|
226
207
|
|
227
208
|
it "fails on unknown method call" do
|
228
|
-
|
209
|
+
lambda { obj.does_not_exist }.must_raise NoMethodError
|
229
210
|
end
|
230
211
|
end
|
231
212
|
|
@@ -243,45 +224,45 @@ describe BinData::Record, "with nested structs" do
|
|
243
224
|
end
|
244
225
|
end
|
245
226
|
|
246
|
-
|
227
|
+
let(:obj) { NestedStructRecord.new }
|
247
228
|
|
248
229
|
it "includes nested field names" do
|
249
|
-
|
230
|
+
obj.field_names.must_equal ["a", "b", "c"]
|
250
231
|
end
|
251
232
|
|
252
233
|
it "hides nested field names" do
|
253
|
-
|
234
|
+
obj.b.field_names.must_equal ["x"]
|
254
235
|
end
|
255
236
|
|
256
237
|
it "accesses nested fields" do
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
238
|
+
obj.a.must_equal 6
|
239
|
+
obj.b.w.must_equal 3
|
240
|
+
obj.b.x.must_equal 6
|
241
|
+
obj.c.y.must_equal 3
|
261
242
|
end
|
262
243
|
|
263
244
|
it "returns correct offset" do
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
245
|
+
obj.offset.must_equal 0
|
246
|
+
obj.b.offset.must_equal 1
|
247
|
+
obj.b.w.offset.must_equal 1
|
248
|
+
obj.c.offset.must_equal 3
|
249
|
+
obj.c.z.offset.must_equal 4
|
269
250
|
end
|
270
251
|
|
271
252
|
it "returns correct rel_offset" do
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
253
|
+
obj.rel_offset.must_equal 0
|
254
|
+
obj.b.rel_offset.must_equal 1
|
255
|
+
obj.b.w.rel_offset.must_equal 0
|
256
|
+
obj.c.rel_offset.must_equal 3
|
257
|
+
obj.c.z.rel_offset.must_equal 1
|
277
258
|
end
|
278
259
|
|
279
260
|
it "assigns nested fields" do
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
261
|
+
obj.assign(:a => 2, :b => {:w => 4})
|
262
|
+
obj.a.must_equal 2
|
263
|
+
obj.b.w.must_equal 4
|
264
|
+
obj.b.x.must_equal 2
|
265
|
+
obj.c.y.must_equal 4
|
285
266
|
end
|
286
267
|
end
|
287
268
|
|
@@ -292,10 +273,10 @@ describe BinData::Record, "with nested array of primitives" do
|
|
292
273
|
end
|
293
274
|
end
|
294
275
|
|
295
|
-
|
276
|
+
let(:obj) { NestedPrimitiveArrayRecord.new }
|
296
277
|
|
297
278
|
it "uses block as :type" do
|
298
|
-
|
279
|
+
obj.snapshot.must_equal({"a" => [0, 1, 2]})
|
299
280
|
end
|
300
281
|
end
|
301
282
|
|
@@ -307,11 +288,11 @@ describe BinData::Record, "with nested array of structs" do
|
|
307
288
|
end
|
308
289
|
end
|
309
290
|
|
310
|
-
|
291
|
+
let(:obj) { NestedStructArrayRecord.new }
|
311
292
|
|
312
293
|
it "uses block as struct for :type" do
|
313
|
-
|
314
|
-
|
294
|
+
obj.a[0].b = 2
|
295
|
+
obj.snapshot.must_equal({"a" => [{"b" => 2, "c" => 0}]})
|
315
296
|
end
|
316
297
|
end
|
317
298
|
|
@@ -323,9 +304,9 @@ describe BinData::Record, "with nested choice with implied keys" do
|
|
323
304
|
end
|
324
305
|
end
|
325
306
|
|
326
|
-
|
307
|
+
let(:obj) { NestedChoiceWithImpliedKeysRecord.new }
|
327
308
|
|
328
|
-
|
309
|
+
specify { obj.a.must_equal 2 }
|
329
310
|
end
|
330
311
|
|
331
312
|
describe BinData::Record, "with nested choice with explicit keys" do
|
@@ -336,9 +317,9 @@ describe BinData::Record, "with nested choice with explicit keys" do
|
|
336
317
|
end
|
337
318
|
end
|
338
319
|
|
339
|
-
|
320
|
+
let(:obj) { NestedChoiceWithKeysRecord.new }
|
340
321
|
|
341
|
-
|
322
|
+
specify { obj.a.must_equal 2 }
|
342
323
|
end
|
343
324
|
|
344
325
|
describe BinData::Record, "with nested choice with names" do
|
@@ -349,9 +330,9 @@ describe BinData::Record, "with nested choice with names" do
|
|
349
330
|
end
|
350
331
|
end
|
351
332
|
|
352
|
-
|
333
|
+
let(:obj) { NestedChoiceWithNamesRecord.new }
|
353
334
|
|
354
|
-
|
335
|
+
specify { obj.a.must_equal 1 }
|
355
336
|
end
|
356
337
|
|
357
338
|
describe BinData::Record, "with an endian defined" do
|
@@ -379,21 +360,21 @@ describe BinData::Record, "with an endian defined" do
|
|
379
360
|
end
|
380
361
|
end
|
381
362
|
|
382
|
-
|
363
|
+
let(:obj) { RecordWithEndian.new }
|
383
364
|
|
384
365
|
it "uses correct endian" do
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
366
|
+
obj.a = 1
|
367
|
+
obj.b = 2.0
|
368
|
+
obj.c[0] = 3
|
369
|
+
obj.c[1] = 4
|
370
|
+
obj.d = 5
|
371
|
+
obj.e.f = 6
|
372
|
+
obj.e.g = 7
|
373
|
+
obj.h.i.j = 8
|
393
374
|
|
394
|
-
|
375
|
+
lambdaed = [1, 2.0, 3, 4, 5, 6, 7, 8].pack('veCCVvNn')
|
395
376
|
|
396
|
-
|
377
|
+
obj.to_binary_s.must_equal lambdaed
|
397
378
|
end
|
398
379
|
end
|
399
380
|
|
@@ -406,30 +387,30 @@ describe BinData::Record, "defined recursively" do
|
|
406
387
|
end
|
407
388
|
|
408
389
|
it "can be created" do
|
409
|
-
|
390
|
+
obj = RecursiveRecord.new
|
410
391
|
end
|
411
392
|
|
412
393
|
it "reads" do
|
413
394
|
str = "\x00\x01\x01\x00\x02\x01\x00\x03\x00"
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
395
|
+
obj = RecursiveRecord.read(str)
|
396
|
+
obj.val.must_equal 1
|
397
|
+
obj.nxt.val.must_equal 2
|
398
|
+
obj.nxt.nxt.val.must_equal 3
|
418
399
|
end
|
419
400
|
|
420
401
|
it "is assignable on demand" do
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
402
|
+
obj = RecursiveRecord.new
|
403
|
+
obj.val = 13
|
404
|
+
obj.nxt.val = 14
|
405
|
+
obj.nxt.nxt.val = 15
|
425
406
|
end
|
426
407
|
|
427
408
|
it "writes" do
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
409
|
+
obj = RecursiveRecord.new
|
410
|
+
obj.val = 5
|
411
|
+
obj.nxt.val = 6
|
412
|
+
obj.nxt.nxt.val = 7
|
413
|
+
obj.to_binary_s.must_equal "\x00\x05\x01\x00\x06\x01\x00\x07\x00"
|
433
414
|
end
|
434
415
|
end
|
435
416
|
|
@@ -441,12 +422,12 @@ describe BinData::Record, "with custom mandatory parameters" do
|
|
441
422
|
end
|
442
423
|
|
443
424
|
it "raises error if mandatory parameter is not supplied" do
|
444
|
-
|
425
|
+
lambda { MandatoryRecord.new }.must_raise ArgumentError
|
445
426
|
end
|
446
427
|
|
447
428
|
it "uses mandatory parameter" do
|
448
|
-
|
449
|
-
|
429
|
+
obj = MandatoryRecord.new(:arg1 => 5)
|
430
|
+
obj.a.must_equal 5
|
450
431
|
end
|
451
432
|
end
|
452
433
|
|
@@ -458,29 +439,25 @@ describe BinData::Record, "with custom default parameters" do
|
|
458
439
|
uint8 :b
|
459
440
|
end
|
460
441
|
|
461
|
-
it "does not raise error if default parameter is not supplied" do
|
462
|
-
expect { DefaultRecord.new }.not_to raise_error(ArgumentError)
|
463
|
-
end
|
464
|
-
|
465
442
|
it "uses default parameter" do
|
466
|
-
|
467
|
-
|
443
|
+
obj = DefaultRecord.new
|
444
|
+
obj.a.must_equal 5
|
468
445
|
end
|
469
446
|
|
470
447
|
it "overrides default parameter" do
|
471
|
-
|
472
|
-
|
448
|
+
obj = DefaultRecord.new(:arg1 => 7)
|
449
|
+
obj.a.must_equal 7
|
473
450
|
end
|
474
451
|
|
475
452
|
it "accepts values" do
|
476
|
-
|
477
|
-
|
453
|
+
obj = DefaultRecord.new(:b => 2)
|
454
|
+
obj.b.must_equal 2
|
478
455
|
end
|
479
456
|
|
480
457
|
it "accepts values and parameters" do
|
481
|
-
|
482
|
-
|
483
|
-
|
458
|
+
obj = DefaultRecord.new({:b => 2}, :arg1 => 3)
|
459
|
+
obj.a.must_equal 3
|
460
|
+
obj.b.must_equal 2
|
484
461
|
end
|
485
462
|
end
|
486
463
|
|
@@ -491,15 +468,17 @@ describe BinData::Record, "with :onlyif" do
|
|
491
468
|
uint8 :c, :initial_value => 7, :onlyif => lambda { a != 3 }
|
492
469
|
end
|
493
470
|
|
494
|
-
|
471
|
+
let(:obj) { OnlyIfRecord.new }
|
495
472
|
|
496
|
-
|
497
|
-
|
498
|
-
|
473
|
+
it "initial state" do
|
474
|
+
obj.num_bytes.must_equal 2
|
475
|
+
obj.snapshot.must_equal({"a" => 3, "b" => 5})
|
476
|
+
obj.to_binary_s.must_equal "\x03\x05"
|
477
|
+
end
|
499
478
|
|
500
|
-
it "reads as
|
501
|
-
|
502
|
-
|
479
|
+
it "reads as lambdaed" do
|
480
|
+
obj.read("\x01\x02")
|
481
|
+
obj.snapshot.must_equal({"a" => 1, "c" => 2})
|
503
482
|
end
|
504
483
|
end
|
505
484
|
|
@@ -517,14 +496,14 @@ describe BinData::Record, "derived classes" do
|
|
517
496
|
end
|
518
497
|
|
519
498
|
it "does not affect parent" do
|
520
|
-
ParentRecord.new.field_names.
|
499
|
+
ParentRecord.new.field_names.must_equal ["a"]
|
521
500
|
end
|
522
501
|
|
523
502
|
it "inherits fields for first child" do
|
524
|
-
Child1Record.new.field_names.
|
503
|
+
Child1Record.new.field_names.must_equal ["a", "b"]
|
525
504
|
end
|
526
505
|
|
527
506
|
it "inherits fields for second child" do
|
528
|
-
Child2Record.new.field_names.
|
507
|
+
Child2Record.new.field_names.must_equal ["a", "b", "c"]
|
529
508
|
end
|
530
509
|
end
|