bindata 2.4.10 → 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 +19 -0
- data/lib/bindata/bits.rb +10 -10
- data/lib/bindata/delayed_io.rb +7 -0
- data/lib/bindata/dsl.rb +3 -3
- data/lib/bindata/int.rb +5 -7
- data/lib/bindata/params.rb +1 -1
- data/lib/bindata/struct.rb +9 -2
- 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 +75 -30
- 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/stringz_test.rb
CHANGED
@@ -6,9 +6,9 @@ describe BinData::Stringz, "when empty" do
|
|
6
6
|
let(:obj) { BinData::Stringz.new }
|
7
7
|
|
8
8
|
it "initial state" do
|
9
|
-
obj.value.must_equal ""
|
10
|
-
obj.num_bytes.must_equal 1
|
11
|
-
obj.to_binary_s.must_equal_binary "\0"
|
9
|
+
_(obj.value).must_equal ""
|
10
|
+
_(obj.num_bytes).must_equal 1
|
11
|
+
_(obj.to_binary_s).must_equal_binary "\0"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -16,9 +16,9 @@ describe BinData::Stringz, "with value set" do
|
|
16
16
|
let(:obj) { BinData::Stringz.new("abcd") }
|
17
17
|
|
18
18
|
it "initial state" do
|
19
|
-
obj.value.must_equal "abcd"
|
20
|
-
obj.num_bytes.must_equal 5
|
21
|
-
obj.to_binary_s.must_equal_binary "abcd\0"
|
19
|
+
_(obj.value).must_equal "abcd"
|
20
|
+
_(obj.num_bytes).must_equal 5
|
21
|
+
_(obj.to_binary_s).must_equal_binary "abcd\0"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -28,19 +28,19 @@ describe BinData::Stringz, "when reading" do
|
|
28
28
|
it "stops at the first zero byte" do
|
29
29
|
io = StringIO.new("abcd\0xyz\0")
|
30
30
|
obj.read(io)
|
31
|
-
io.pos.must_equal 5
|
32
|
-
obj.must_equal "abcd"
|
31
|
+
_(io.pos).must_equal 5
|
32
|
+
_(obj).must_equal "abcd"
|
33
33
|
end
|
34
34
|
|
35
35
|
it "handles a zero length string" do
|
36
36
|
io = StringIO.new("\0abcd")
|
37
37
|
obj.read(io)
|
38
|
-
io.pos.must_equal 1
|
39
|
-
obj.must_equal ""
|
38
|
+
_(io.pos).must_equal 1
|
39
|
+
_(obj).must_equal ""
|
40
40
|
end
|
41
41
|
|
42
42
|
it "fails if no zero byte is found" do
|
43
|
-
|
43
|
+
_ {obj.read("abcd") }.must_raise EOFError
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -49,27 +49,27 @@ describe BinData::Stringz, "when setting the value" do
|
|
49
49
|
|
50
50
|
it "includes the zero byte in num_bytes total" do
|
51
51
|
obj.assign("abcd")
|
52
|
-
obj.num_bytes.must_equal 5
|
52
|
+
_(obj.num_bytes).must_equal 5
|
53
53
|
end
|
54
54
|
|
55
55
|
it "accepts empty strings" do
|
56
56
|
obj.assign("")
|
57
|
-
obj.must_equal ""
|
57
|
+
_(obj).must_equal ""
|
58
58
|
end
|
59
59
|
|
60
60
|
it "accepts strings that aren't zero terminated" do
|
61
61
|
obj.assign("abcd")
|
62
|
-
obj.must_equal "abcd"
|
62
|
+
_(obj).must_equal "abcd"
|
63
63
|
end
|
64
64
|
|
65
65
|
it "accepts strings that are zero terminated" do
|
66
66
|
obj.assign("abcd\0")
|
67
|
-
obj.must_equal "abcd"
|
67
|
+
_(obj).must_equal "abcd"
|
68
68
|
end
|
69
69
|
|
70
70
|
it "accepts up to the first zero byte" do
|
71
71
|
obj.assign("abcd\0xyz\0")
|
72
|
-
obj.must_equal "abcd"
|
72
|
+
_(obj).must_equal "abcd"
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -79,49 +79,49 @@ describe BinData::Stringz, "with max_length" do
|
|
79
79
|
it "reads less than max_length" do
|
80
80
|
io = StringIO.new("abc\0xyz")
|
81
81
|
obj.read(io)
|
82
|
-
obj.must_equal "abc"
|
82
|
+
_(obj).must_equal "abc"
|
83
83
|
end
|
84
84
|
|
85
85
|
it "reads exactly max_length" do
|
86
86
|
io = StringIO.new("abcd\0xyz")
|
87
87
|
obj.read(io)
|
88
|
-
obj.must_equal "abcd"
|
88
|
+
_(obj).must_equal "abcd"
|
89
89
|
end
|
90
90
|
|
91
91
|
it "reads no more than max_length" do
|
92
92
|
io = StringIO.new("abcdefg\0xyz")
|
93
93
|
obj.read(io)
|
94
|
-
io.pos.must_equal 5
|
95
|
-
obj.must_equal "abcd"
|
94
|
+
_(io.pos).must_equal 5
|
95
|
+
_(obj).must_equal "abcd"
|
96
96
|
end
|
97
97
|
|
98
98
|
it "accepts values less than max_length" do
|
99
99
|
obj.assign("abc")
|
100
|
-
obj.must_equal "abc"
|
100
|
+
_(obj).must_equal "abc"
|
101
101
|
end
|
102
102
|
|
103
103
|
it "accepts values exactly max_length" do
|
104
104
|
obj.assign("abcd")
|
105
|
-
obj.must_equal "abcd"
|
105
|
+
_(obj).must_equal "abcd"
|
106
106
|
end
|
107
107
|
|
108
108
|
it "trims values greater than max_length" do
|
109
109
|
obj.assign("abcdefg")
|
110
|
-
obj.must_equal "abcd"
|
110
|
+
_(obj).must_equal "abcd"
|
111
111
|
end
|
112
112
|
|
113
113
|
it "writes values greater than max_length" do
|
114
114
|
obj.assign("abcdefg")
|
115
|
-
obj.to_binary_s.must_equal_binary "abcd\0"
|
115
|
+
_(obj.to_binary_s).must_equal_binary "abcd\0"
|
116
116
|
end
|
117
117
|
|
118
118
|
it "writes values less than max_length" do
|
119
119
|
obj.assign("abc")
|
120
|
-
obj.to_binary_s.must_equal_binary "abc\0"
|
120
|
+
_(obj.to_binary_s).must_equal_binary "abc\0"
|
121
121
|
end
|
122
122
|
|
123
123
|
it "writes values exactly max_length" do
|
124
124
|
obj.assign("abcd")
|
125
|
-
obj.to_binary_s.must_equal_binary "abcd\0"
|
125
|
+
_(obj.to_binary_s).must_equal_binary "abcd\0"
|
126
126
|
end
|
127
127
|
end
|
data/test/struct_test.rb
CHANGED
@@ -5,14 +5,14 @@ require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
|
|
5
5
|
describe BinData::Struct, "when initializing" do
|
6
6
|
it "fails on non registered types" do
|
7
7
|
params = {fields: [[:non_registered_type, :a]]}
|
8
|
-
|
8
|
+
_ {
|
9
9
|
BinData::Struct.new(params)
|
10
10
|
}.must_raise BinData::UnRegisteredTypeError
|
11
11
|
end
|
12
12
|
|
13
13
|
it "fails on duplicate names" do
|
14
14
|
params = {fields: [[:int8, :a], [:int8, :b], [:int8, :a]]}
|
15
|
-
|
15
|
+
_ {
|
16
16
|
BinData::Struct.new(params)
|
17
17
|
}.must_raise NameError
|
18
18
|
end
|
@@ -20,21 +20,21 @@ describe BinData::Struct, "when initializing" do
|
|
20
20
|
it "fails on reserved names" do
|
21
21
|
# note that #invert is from Hash.instance_methods
|
22
22
|
params = {fields: [[:int8, :a], [:int8, :invert]]}
|
23
|
-
|
23
|
+
_ {
|
24
24
|
BinData::Struct.new(params)
|
25
25
|
}.must_raise NameError
|
26
26
|
end
|
27
27
|
|
28
28
|
it "fails when field name shadows an existing method" do
|
29
29
|
params = {fields: [[:int8, :object_id]]}
|
30
|
-
|
30
|
+
_ {
|
31
31
|
BinData::Struct.new(params)
|
32
32
|
}.must_raise NameError
|
33
33
|
end
|
34
34
|
|
35
35
|
it "fails on unknown endian" do
|
36
36
|
params = {endian: 'bad value', fields: []}
|
37
|
-
|
37
|
+
_ {
|
38
38
|
BinData::Struct.new(params)
|
39
39
|
}.must_raise ArgumentError
|
40
40
|
end
|
@@ -51,18 +51,18 @@ describe BinData::Struct, "with anonymous fields" do
|
|
51
51
|
}
|
52
52
|
|
53
53
|
it "only shows non anonymous fields" do
|
54
|
-
obj.field_names.must_equal [:a]
|
54
|
+
_(obj.field_names).must_equal [:a]
|
55
55
|
end
|
56
56
|
|
57
57
|
it "does not include anonymous fields in snapshot" do
|
58
58
|
obj.a = 5
|
59
|
-
obj.snapshot.must_equal({a: 5})
|
59
|
+
_(obj.snapshot).must_equal({a: 5})
|
60
60
|
end
|
61
61
|
|
62
62
|
it "writes anonymous fields" do
|
63
63
|
obj.read("\001\002\003")
|
64
64
|
obj.a.clear
|
65
|
-
obj.to_binary_s.must_equal_binary "\005\002\005"
|
65
|
+
_(obj.to_binary_s).must_equal_binary "\005\002\005"
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -78,24 +78,24 @@ describe BinData::Struct, "with hidden fields" do
|
|
78
78
|
}
|
79
79
|
|
80
80
|
it "only shows fields that aren't hidden" do
|
81
|
-
obj.field_names.must_equal [:a, :d]
|
81
|
+
_(obj.field_names).must_equal [:a, :d]
|
82
82
|
end
|
83
83
|
|
84
84
|
it "shows all fields when requested" do
|
85
|
-
obj.field_names(true).must_equal [:a, :b, :c, :d]
|
85
|
+
_(obj.field_names(true)).must_equal [:a, :b, :c, :d]
|
86
86
|
end
|
87
87
|
|
88
88
|
it "accesses hidden fields directly" do
|
89
|
-
obj.b.must_equal 5
|
89
|
+
_(obj.b).must_equal 5
|
90
90
|
obj.c = 15
|
91
|
-
obj.c.must_equal 15
|
91
|
+
_(obj.c).must_equal 15
|
92
92
|
|
93
|
-
obj.must_respond_to :b=
|
93
|
+
_(obj).must_respond_to :b=
|
94
94
|
end
|
95
95
|
|
96
96
|
it "does not include hidden fields in snapshot" do
|
97
97
|
obj.b = 7
|
98
|
-
obj.snapshot.must_equal({a: 0, d: 7})
|
98
|
+
_(obj.snapshot).must_equal({a: 0, d: 7})
|
99
99
|
end
|
100
100
|
|
101
101
|
it "detects hidden fields with has_key?" do
|
@@ -107,19 +107,19 @@ describe BinData::Struct, "with multiple fields" do
|
|
107
107
|
let(:params) { { fields: [ [:int8, :a], [:int8, :b] ] } }
|
108
108
|
let(:obj) { BinData::Struct.new({a: 1, b: 2}, params) }
|
109
109
|
|
110
|
-
specify { obj.field_names.must_equal [:a, :b] }
|
111
|
-
specify { obj.to_binary_s.must_equal_binary "\x01\x02" }
|
110
|
+
specify { _(obj.field_names).must_equal [:a, :b] }
|
111
|
+
specify { _(obj.to_binary_s).must_equal_binary "\x01\x02" }
|
112
112
|
|
113
113
|
it "returns num_bytes" do
|
114
|
-
obj.a.num_bytes.must_equal 1
|
115
|
-
obj.b.num_bytes.must_equal 1
|
116
|
-
obj.num_bytes.must_equal 2
|
114
|
+
_(obj.a.num_bytes).must_equal 1
|
115
|
+
_(obj.b.num_bytes).must_equal 1
|
116
|
+
_(obj.num_bytes).must_equal 2
|
117
117
|
end
|
118
118
|
|
119
119
|
it "identifies accepted parameters" do
|
120
|
-
BinData::Struct.accepted_parameters.all.must_include :fields
|
121
|
-
BinData::Struct.accepted_parameters.all.must_include :hide
|
122
|
-
BinData::Struct.accepted_parameters.all.must_include :endian
|
120
|
+
_(BinData::Struct.accepted_parameters.all).must_include :fields
|
121
|
+
_(BinData::Struct.accepted_parameters.all).must_include :hide
|
122
|
+
_(BinData::Struct.accepted_parameters.all).must_include :endian
|
123
123
|
end
|
124
124
|
|
125
125
|
it "clears" do
|
@@ -137,16 +137,16 @@ describe BinData::Struct, "with multiple fields" do
|
|
137
137
|
end
|
138
138
|
|
139
139
|
it "reads elements dynamically" do
|
140
|
-
obj[:a].must_equal 1
|
140
|
+
_(obj[:a]).must_equal 1
|
141
141
|
end
|
142
142
|
|
143
143
|
it "handles not existing elements" do
|
144
|
-
obj[:does_not_exist].must_be_nil
|
144
|
+
_(obj[:does_not_exist]).must_be_nil
|
145
145
|
end
|
146
146
|
|
147
147
|
it "writes elements dynamically" do
|
148
148
|
obj[:a] = 2
|
149
|
-
obj.a.must_equal 2
|
149
|
+
_(obj.a).must_equal 2
|
150
150
|
end
|
151
151
|
|
152
152
|
it "implements has_key?" do
|
@@ -156,28 +156,28 @@ describe BinData::Struct, "with multiple fields" do
|
|
156
156
|
it "reads ordered" do
|
157
157
|
obj.read("\x03\x04")
|
158
158
|
|
159
|
-
obj.a.must_equal 3
|
160
|
-
obj.b.must_equal 4
|
159
|
+
_(obj.a).must_equal 3
|
160
|
+
_(obj.b).must_equal 4
|
161
161
|
end
|
162
162
|
|
163
163
|
it "returns a snapshot" do
|
164
164
|
snap = obj.snapshot
|
165
165
|
assert snap.respond_to?(:a)
|
166
|
-
snap.a.must_equal 1
|
167
|
-
snap.b.must_equal 2
|
168
|
-
snap.must_equal({ a: 1, b: 2 })
|
166
|
+
_(snap.a).must_equal 1
|
167
|
+
_(snap.b).must_equal 2
|
168
|
+
_(snap).must_equal({ a: 1, b: 2 })
|
169
169
|
end
|
170
170
|
|
171
171
|
it "assigns from partial hash" do
|
172
172
|
obj.assign(a: 3)
|
173
|
-
obj.a.must_equal 3
|
174
|
-
obj.b.must_equal 0
|
173
|
+
_(obj.a).must_equal 3
|
174
|
+
_(obj.b).must_equal 0
|
175
175
|
end
|
176
176
|
|
177
177
|
it "assigns from hash" do
|
178
178
|
obj.assign(a: 3, b: 4)
|
179
|
-
obj.a.must_equal 3
|
180
|
-
obj.b.must_equal 4
|
179
|
+
_(obj.a).must_equal 3
|
180
|
+
_(obj.b).must_equal 4
|
181
181
|
end
|
182
182
|
|
183
183
|
it "assigns from nil" do
|
@@ -191,8 +191,8 @@ describe BinData::Struct, "with multiple fields" do
|
|
191
191
|
src.b = 4
|
192
192
|
|
193
193
|
obj.assign(src)
|
194
|
-
obj.a.must_equal 3
|
195
|
-
obj.b.must_equal 4
|
194
|
+
_(obj.a).must_equal 3
|
195
|
+
_(obj.b).must_equal 4
|
196
196
|
end
|
197
197
|
|
198
198
|
it "assigns from snapshot" do
|
@@ -201,29 +201,29 @@ describe BinData::Struct, "with multiple fields" do
|
|
201
201
|
src.b = 4
|
202
202
|
|
203
203
|
obj.assign(src.snapshot)
|
204
|
-
obj.a.must_equal 3
|
205
|
-
obj.b.must_equal 4
|
204
|
+
_(obj.a).must_equal 3
|
205
|
+
_(obj.b).must_equal 4
|
206
206
|
end
|
207
207
|
|
208
208
|
it "fails on unknown method call" do
|
209
|
-
|
209
|
+
_ { obj.does_not_exist }.must_raise NoMethodError
|
210
210
|
end
|
211
211
|
|
212
212
|
describe "#snapshot" do
|
213
213
|
it "has ordered #keys" do
|
214
|
-
obj.snapshot.keys.must_equal [:a, :b]
|
214
|
+
_(obj.snapshot.keys).must_equal [:a, :b]
|
215
215
|
end
|
216
216
|
|
217
217
|
it "has ordered #each" do
|
218
218
|
keys = []
|
219
219
|
obj.snapshot.each { |el| keys << el[0] }
|
220
|
-
keys.must_equal [:a, :b]
|
220
|
+
_(keys).must_equal [:a, :b]
|
221
221
|
end
|
222
222
|
|
223
223
|
it "has ordered #each_pair" do
|
224
224
|
keys = []
|
225
225
|
obj.snapshot.each_pair { |k, v| keys << k }
|
226
|
-
keys.must_equal [:a, :b]
|
226
|
+
_(keys).must_equal [:a, :b]
|
227
227
|
end
|
228
228
|
end
|
229
229
|
end
|
@@ -243,27 +243,27 @@ describe BinData::Struct, "with nested structs" do
|
|
243
243
|
BinData::Struct.new(params)
|
244
244
|
}
|
245
245
|
|
246
|
-
specify { obj.field_names.must_equal [:a, :b, :c] }
|
246
|
+
specify { _(obj.field_names).must_equal [:a, :b, :c] }
|
247
247
|
|
248
248
|
it "returns num_bytes" do
|
249
|
-
obj.b.num_bytes.must_equal 2
|
250
|
-
obj.c.num_bytes.must_equal 2
|
251
|
-
obj.num_bytes.must_equal 5
|
249
|
+
_(obj.b.num_bytes).must_equal 2
|
250
|
+
_(obj.c.num_bytes).must_equal 2
|
251
|
+
_(obj.num_bytes).must_equal 5
|
252
252
|
end
|
253
253
|
|
254
254
|
it "accesses nested fields" do
|
255
|
-
obj.a.must_equal 6
|
256
|
-
obj.b.w.must_equal 3
|
257
|
-
obj.b.x.must_equal 6
|
258
|
-
obj.c.y.must_equal 3
|
259
|
-
obj.c.z.must_equal 0
|
255
|
+
_(obj.a).must_equal 6
|
256
|
+
_(obj.b.w).must_equal 3
|
257
|
+
_(obj.b.x).must_equal 6
|
258
|
+
_(obj.c.y).must_equal 3
|
259
|
+
_(obj.c.z).must_equal 0
|
260
260
|
end
|
261
261
|
|
262
262
|
it "returns correct abs_offset" do
|
263
|
-
obj.b.abs_offset.must_equal 1
|
264
|
-
obj.b.w.abs_offset.must_equal 1
|
265
|
-
obj.c.abs_offset.must_equal 3
|
266
|
-
obj.c.z.abs_offset.must_equal 4
|
263
|
+
_(obj.b.abs_offset).must_equal 1
|
264
|
+
_(obj.b.w.abs_offset).must_equal 1
|
265
|
+
_(obj.c.abs_offset).must_equal 3
|
266
|
+
_(obj.c.z.abs_offset).must_equal 4
|
267
267
|
end
|
268
268
|
end
|
269
269
|
|
@@ -300,7 +300,7 @@ describe BinData::Struct, "with an endian defined" do
|
|
300
300
|
|
301
301
|
expected = [1, 2.0, 3, 4, 5, 6, 7, 8].pack('veCCVvNv')
|
302
302
|
|
303
|
-
obj.to_binary_s.must_equal_binary expected
|
303
|
+
_(obj.to_binary_s).must_equal_binary expected
|
304
304
|
end
|
305
305
|
end
|
306
306
|
|
@@ -310,23 +310,23 @@ describe BinData::Struct, "with bit fields" do
|
|
310
310
|
BinData::Struct.new({a: 1, b: 2, c: 3, d: 1}, params)
|
311
311
|
}
|
312
312
|
|
313
|
-
specify { obj.num_bytes.must_equal 3 }
|
314
|
-
specify { obj.to_binary_s.must_equal_binary [0b0000_0101, 3, 1].pack("C*") }
|
313
|
+
specify { _(obj.num_bytes).must_equal 3 }
|
314
|
+
specify { _(obj.to_binary_s).must_equal_binary [0b0000_0101, 3, 1].pack("C*") }
|
315
315
|
|
316
316
|
it "reads" do
|
317
317
|
str = [0b0000_0110, 5, 0].pack("C*")
|
318
318
|
obj.read(str)
|
319
|
-
obj.a.must_equal 0
|
320
|
-
obj.b.must_equal 3
|
321
|
-
obj.c.must_equal 5
|
322
|
-
obj.d.must_equal 0
|
319
|
+
_(obj.a).must_equal 0
|
320
|
+
_(obj.b).must_equal 3
|
321
|
+
_(obj.c).must_equal 5
|
322
|
+
_(obj.d).must_equal 0
|
323
323
|
end
|
324
324
|
|
325
325
|
it "has correct offsets" do
|
326
|
-
obj.a.rel_offset.must_equal 0
|
327
|
-
obj.b.rel_offset.must_equal 0
|
328
|
-
obj.c.rel_offset.must_equal 1
|
329
|
-
obj.d.rel_offset.must_equal 2
|
326
|
+
_(obj.a.rel_offset).must_equal 0
|
327
|
+
_(obj.b.rel_offset).must_equal 0
|
328
|
+
_(obj.c.rel_offset).must_equal 1
|
329
|
+
_(obj.d.rel_offset).must_equal 2
|
330
330
|
end
|
331
331
|
end
|
332
332
|
|
@@ -341,10 +341,10 @@ describe BinData::Struct, "with nested endian" do
|
|
341
341
|
obj = BinData::Struct.new(params)
|
342
342
|
obj.read("\x00\x01\x02\x00\x03\x00\x00\x04")
|
343
343
|
|
344
|
-
obj.a.must_equal 1
|
345
|
-
obj.s.b.must_equal 2
|
346
|
-
obj.s.c.must_equal 3
|
347
|
-
obj.d.must_equal 4
|
344
|
+
_(obj.a).must_equal 1
|
345
|
+
_(obj.s.b).must_equal 2
|
346
|
+
_(obj.s.c).must_equal 3
|
347
|
+
_(obj.d).must_equal 4
|
348
348
|
end
|
349
349
|
end
|
350
350
|
|
@@ -355,46 +355,46 @@ describe BinData::Struct, "with a search_prefix" do
|
|
355
355
|
it "searches symbol prefixes" do
|
356
356
|
obj = BinData::Struct.new(search_prefix: :a,
|
357
357
|
fields: [ [:short, :f] ])
|
358
|
-
obj.f.class.name.must_equal "AShort"
|
358
|
+
_(obj.f.class.name).must_equal "AShort"
|
359
359
|
end
|
360
360
|
|
361
361
|
it "searches string prefixes" do
|
362
362
|
obj = BinData::Struct.new(search_prefix: "a",
|
363
363
|
fields: [ [:short, :f] ])
|
364
|
-
obj.f.class.name.must_equal "AShort"
|
364
|
+
_(obj.f.class.name).must_equal "AShort"
|
365
365
|
end
|
366
366
|
|
367
367
|
it "searches string prefixes with optional underscore" do
|
368
368
|
obj = BinData::Struct.new(search_prefix: "a_",
|
369
369
|
fields: [ [:short, :f] ])
|
370
|
-
obj.f.class.name.must_equal "AShort"
|
370
|
+
_(obj.f.class.name).must_equal "AShort"
|
371
371
|
end
|
372
372
|
|
373
373
|
it "searches multiple prefixes" do
|
374
374
|
obj = BinData::Struct.new(search_prefix: [:x, :a],
|
375
375
|
fields: [ [:short, :f] ])
|
376
|
-
obj.f.class.name.must_equal "AShort"
|
376
|
+
_(obj.f.class.name).must_equal "AShort"
|
377
377
|
end
|
378
378
|
|
379
379
|
it "uses parent search_prefix" do
|
380
380
|
nested_params = { fields: [[:short, :f]] }
|
381
381
|
obj = BinData::Struct.new(search_prefix: :a,
|
382
382
|
fields: [[:struct, :s, nested_params]])
|
383
|
-
obj.s.f.class.name.must_equal "AShort"
|
383
|
+
_(obj.s.f.class.name).must_equal "AShort"
|
384
384
|
end
|
385
385
|
|
386
386
|
it "searches parent search_prefix" do
|
387
387
|
nested_params = { search_prefix: :x, fields: [[:short, :f]] }
|
388
388
|
obj = BinData::Struct.new(search_prefix: :a,
|
389
389
|
fields: [[:struct, :s, nested_params]])
|
390
|
-
obj.s.f.class.name.must_equal "AShort"
|
390
|
+
_(obj.s.f.class.name).must_equal "AShort"
|
391
391
|
end
|
392
392
|
|
393
393
|
it "prioritises nested search_prefix" do
|
394
394
|
nested_params = { search_prefix: :a, fields: [[:short, :f]] }
|
395
395
|
obj = BinData::Struct.new(search_prefix: :b,
|
396
396
|
fields: [[:struct, :s, nested_params]])
|
397
|
-
obj.s.f.class.name.must_equal "AShort"
|
397
|
+
_(obj.s.f.class.name).must_equal "AShort"
|
398
398
|
end
|
399
399
|
end
|
400
400
|
|
@@ -408,24 +408,24 @@ describe BinData::Struct, "with byte_align" do
|
|
408
408
|
}
|
409
409
|
|
410
410
|
it "has #num_bytes" do
|
411
|
-
obj.num_bytes.must_equal 10
|
411
|
+
_(obj.num_bytes).must_equal 10
|
412
412
|
end
|
413
413
|
|
414
414
|
it "reads" do
|
415
415
|
obj.read("\x01\x00\x00\x00\x00\x02\xc0\x00\x00\x04")
|
416
|
-
obj.snapshot.must_equal({ a: 1, b: 2, c: 3, d: 4 })
|
416
|
+
_(obj.snapshot).must_equal({ a: 1, b: 2, c: 3, d: 4 })
|
417
417
|
end
|
418
418
|
|
419
419
|
it "writes" do
|
420
420
|
obj.assign(a: 1, b: 2, c: 3, d: 4)
|
421
|
-
obj.to_binary_s.must_equal_binary "\x01\x00\x00\x00\x00\x02\xc0\x00\x00\x04"
|
421
|
+
_(obj.to_binary_s).must_equal_binary "\x01\x00\x00\x00\x00\x02\xc0\x00\x00\x04"
|
422
422
|
end
|
423
423
|
|
424
424
|
it "has correct offsets" do
|
425
|
-
obj.a.rel_offset.must_equal 0
|
426
|
-
obj.b.rel_offset.must_equal 5
|
427
|
-
obj.c.rel_offset.must_equal 6
|
428
|
-
obj.d.rel_offset.must_equal 9
|
425
|
+
_(obj.a.rel_offset).must_equal 0
|
426
|
+
_(obj.b.rel_offset).must_equal 5
|
427
|
+
_(obj.c.rel_offset).must_equal 6
|
428
|
+
_(obj.d.rel_offset).must_equal 9
|
429
429
|
end
|
430
430
|
end
|
431
431
|
|
@@ -435,6 +435,6 @@ describe BinData::Struct, "with dynamically named types" do
|
|
435
435
|
|
436
436
|
obj = BinData::Struct.new(fields: [[:my_struct, :v]])
|
437
437
|
|
438
|
-
obj.v.a.must_equal 3
|
438
|
+
_(obj.v.a).must_equal 3
|
439
439
|
end
|
440
440
|
end
|