bindata 2.3.3 → 2.3.4

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.

Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.rdoc +4 -0
  3. data/Rakefile +2 -2
  4. data/examples/gzip.rb +24 -24
  5. data/examples/ip_address.rb +3 -4
  6. data/examples/list.rb +20 -20
  7. data/examples/nbt.rb +14 -14
  8. data/examples/tcp_ip.rb +12 -14
  9. data/lib/bindata/alignment.rb +2 -2
  10. data/lib/bindata/array.rb +22 -23
  11. data/lib/bindata/base.rb +13 -12
  12. data/lib/bindata/base_primitive.rb +20 -17
  13. data/lib/bindata/bits.rb +4 -4
  14. data/lib/bindata/buffer.rb +5 -5
  15. data/lib/bindata/choice.rb +11 -13
  16. data/lib/bindata/count_bytes_remaining.rb +1 -2
  17. data/lib/bindata/delayed_io.rb +11 -11
  18. data/lib/bindata/dsl.rb +57 -64
  19. data/lib/bindata/float.rb +16 -13
  20. data/lib/bindata/int.rb +6 -6
  21. data/lib/bindata/io.rb +16 -16
  22. data/lib/bindata/lazy.rb +3 -3
  23. data/lib/bindata/name.rb +2 -2
  24. data/lib/bindata/offset.rb +3 -3
  25. data/lib/bindata/params.rb +13 -15
  26. data/lib/bindata/primitive.rb +3 -3
  27. data/lib/bindata/registry.rb +12 -12
  28. data/lib/bindata/rest.rb +1 -2
  29. data/lib/bindata/sanitize.rb +17 -18
  30. data/lib/bindata/skip.rb +7 -8
  31. data/lib/bindata/string.rb +6 -6
  32. data/lib/bindata/stringz.rb +3 -3
  33. data/lib/bindata/struct.rb +16 -16
  34. data/lib/bindata/trace.rb +9 -8
  35. data/lib/bindata/version.rb +1 -1
  36. data/lib/bindata/virtual.rb +3 -3
  37. data/lib/bindata/warnings.rb +6 -2
  38. data/test/alignment_test.rb +4 -4
  39. data/test/array_test.rb +29 -29
  40. data/test/base_primitive_test.rb +17 -17
  41. data/test/base_test.rb +6 -6
  42. data/test/bits_test.rb +1 -1
  43. data/test/buffer_test.rb +19 -19
  44. data/test/choice_test.rb +20 -20
  45. data/test/count_bytes_remaining_test.rb +1 -1
  46. data/test/delayed_io_test.rb +26 -26
  47. data/test/lazy_test.rb +16 -16
  48. data/test/offset_test.rb +8 -8
  49. data/test/params_test.rb +11 -11
  50. data/test/primitive_test.rb +11 -11
  51. data/test/record_test.rb +50 -50
  52. data/test/registry_test.rb +26 -26
  53. data/test/rest_test.rb +1 -1
  54. data/test/skip_test.rb +27 -27
  55. data/test/string_test.rb +24 -24
  56. data/test/stringz_test.rb +1 -1
  57. data/test/struct_test.rb +76 -75
  58. data/test/system_test.rb +51 -51
  59. data/test/virtual_test.rb +3 -3
  60. metadata +2 -2
data/test/lazy_test.rb CHANGED
@@ -35,8 +35,8 @@ end
35
35
 
36
36
  describe BinData::LazyEvaluator, "with no parents" do
37
37
  subject {
38
- methods = {:m1 => 'm1', :com => 'mC'}
39
- params = {:p1 => 'p1', :com => 'pC'}
38
+ methods = {m1: 'm1', com: 'mC'}
39
+ params = {p1: 'p1', com: 'pC'}
40
40
  MockBinDataObject.new(methods, params)
41
41
  }
42
42
 
@@ -53,7 +53,7 @@ describe BinData::LazyEvaluator, "with no parents" do
53
53
  end
54
54
 
55
55
  it "evaluates overrides" do
56
- lazy_eval(lambda { o1 }, :o1 => 'o1').must_equal 'o1'
56
+ lazy_eval(lambda { o1 }, o1: 'o1').must_equal 'o1'
57
57
  end
58
58
 
59
59
  it "does not resolve any unknown methods" do
@@ -73,8 +73,8 @@ end
73
73
 
74
74
  describe BinData::LazyEvaluator, "with one parent" do
75
75
  subject {
76
- parent_methods = {:m1 => 'Pm1', :m2 => 'Pm2', :com1 => 'PmC', :mm => 3}
77
- parent_params = {:p1 => 'Pp1', :com1 => 'PpC'}
76
+ parent_methods = {m1: 'Pm1', m2: 'Pm2', com1: 'PmC', mm: 3}
77
+ parent_params = {p1: 'Pp1', com1: 'PpC'}
78
78
  parent_obj = MockBinDataObject.new(parent_methods, parent_params)
79
79
 
80
80
  class << parent_obj
@@ -85,8 +85,8 @@ describe BinData::LazyEvaluator, "with one parent" do
85
85
  private :m2
86
86
  end
87
87
 
88
- methods = {:m1 => 'm1', :com1 => 'mC'}
89
- params = {:p1 => 'p1', :com1 => 'pC'}
88
+ methods = {m1: 'm1', com1: 'mC'}
89
+ params = {p1: 'p1', com1: 'pC'}
90
90
  MockBinDataObject.new(methods, params, parent_obj)
91
91
  }
92
92
 
@@ -99,11 +99,11 @@ describe BinData::LazyEvaluator, "with one parent" do
99
99
  end
100
100
 
101
101
  it "evaluates overrides before params" do
102
- lazy_eval(lambda { p1 }, :p1 => 'o1').must_equal 'o1'
102
+ lazy_eval(lambda { p1 }, p1: 'o1').must_equal 'o1'
103
103
  end
104
104
 
105
105
  it "evaluates overrides before methods" do
106
- lazy_eval(lambda { m1 }, :m1 => 'o1').must_equal 'o1'
106
+ lazy_eval(lambda { m1 }, m1: 'o1').must_equal 'o1'
107
107
  end
108
108
 
109
109
  it "does not resolve any unknown methods" do
@@ -141,8 +141,8 @@ end
141
141
 
142
142
  describe BinData::LazyEvaluator, "with nested parents" do
143
143
  subject {
144
- pparent_methods = {:m1 => 'PPm1', :m2 => 'PPm2', :com1 => 'PPmC'}
145
- pparent_params = {:p1 => 'PPp1', :p2 => 'PPp2', :com1 => 'PPpC'}
144
+ pparent_methods = {m1: 'PPm1', m2: 'PPm2', com1: 'PPmC'}
145
+ pparent_params = {p1: 'PPp1', p2: 'PPp2', com1: 'PPpC'}
146
146
  pparent_obj = MockBinDataObject.new(pparent_methods, pparent_params)
147
147
 
148
148
  def pparent_obj.echo(arg)
@@ -153,16 +153,16 @@ describe BinData::LazyEvaluator, "with nested parents" do
153
153
  ["PP2", arg]
154
154
  end
155
155
 
156
- parent_methods = {:m1 => 'Pm1', :com1 => 'PmC', :sym1 => :m2, :sym2 => lambda { m2 }}
157
- parent_params = {:p1 => 'Pp1', :com1 => 'PpC'}
156
+ parent_methods = {m1: 'Pm1', com1: 'PmC', sym1: :m2, sym2: -> { m2 }}
157
+ parent_params = {p1: 'Pp1', com1: 'PpC'}
158
158
  parent_obj = MockBinDataObject.new(parent_methods, parent_params, pparent_obj)
159
159
 
160
160
  def parent_obj.echo(arg)
161
161
  ["P", arg]
162
162
  end
163
163
 
164
- methods = {:m1 => 'm1', :com1 => 'mC'}
165
- params = {:p1 => 'p1', :com1 => 'pC'}
164
+ methods = {m1: 'm1', com1: 'mC'}
165
+ params = {p1: 'p1', com1: 'pC'}
166
166
  MockBinDataObject.new(methods, params, parent_obj)
167
167
  }
168
168
 
@@ -198,7 +198,7 @@ describe BinData::LazyEvaluator, "with nested parents" do
198
198
  end
199
199
 
200
200
  it "invokes methods in the parent's parent" do
201
- lazy_eval(lambda { parent.echo(m1) }, { :m1 => 'o1'}).must_equal ['PP', 'o1']
201
+ lazy_eval(lambda { parent.echo(m1) }, { m1: 'o1'}).must_equal ['PP', 'o1']
202
202
  end
203
203
 
204
204
  it "invokes methods in the parent's parent" do
data/test/offset_test.rb CHANGED
@@ -44,50 +44,50 @@ describe BinData::Base, "offsets" do
44
44
  describe "with :check_offset" do
45
45
  it "fails when offset is incorrect" do
46
46
  io.seek(2)
47
- obj = TenByteOffsetBase.create(:check_offset => 10 - 4)
47
+ obj = TenByteOffsetBase.create(check_offset: 10 - 4)
48
48
  lambda { obj.read(io) }.must_raise BinData::ValidityError
49
49
  end
50
50
 
51
51
  it "succeeds when offset is correct" do
52
52
  io.seek(3)
53
- obj = TenByteOffsetBase.create(:check_offset => 10)
53
+ obj = TenByteOffsetBase.create(check_offset: 10)
54
54
  obj.read(io).snapshot.must_equal data[3 + 10, 3]
55
55
  end
56
56
 
57
57
  it "fails when :check_offset fails" do
58
58
  io.seek(4)
59
- obj = TenByteOffsetBase.create(:check_offset => lambda { offset == 10 + 1 } )
59
+ obj = TenByteOffsetBase.create(check_offset: -> { offset == 10 + 1 } )
60
60
  lambda { obj.read(io) }.must_raise BinData::ValidityError
61
61
  end
62
62
 
63
63
  it "succeeds when :check_offset succeeds" do
64
64
  io.seek(5)
65
- obj = TenByteOffsetBase.create(:check_offset => lambda { offset == 10 } )
65
+ obj = TenByteOffsetBase.create(check_offset: -> { offset == 10 } )
66
66
  obj.read(io).snapshot.must_equal data[5 + 10, 3]
67
67
  end
68
68
  end
69
69
 
70
70
  describe "with :adjust_offset" do
71
71
  it "is mutually exclusive with :check_offset" do
72
- params = { :check_offset => 8, :adjust_offset => 8 }
72
+ params = { check_offset: 8, adjust_offset: 8 }
73
73
  lambda { TenByteOffsetBase.create(params) }.must_raise ArgumentError
74
74
  end
75
75
 
76
76
  it "adjust offset when incorrect" do
77
77
  io.seek(2)
78
- obj = TenByteOffsetBase.create(:adjust_offset => 13)
78
+ obj = TenByteOffsetBase.create(adjust_offset: 13)
79
79
  obj.read(io).snapshot.must_equal data[2 + 13, 3]
80
80
  end
81
81
 
82
82
  it "succeeds when offset is correct" do
83
83
  io.seek(3)
84
- obj = TenByteOffsetBase.create(:adjust_offset => 10)
84
+ obj = TenByteOffsetBase.create(adjust_offset: 10)
85
85
  obj.read(io).snapshot.must_equal data[3 + 10, 3]
86
86
  end
87
87
 
88
88
  it "fails if cannot adjust offset" do
89
89
  io.seek(4)
90
- obj = TenByteOffsetBase.create(:adjust_offset => -5)
90
+ obj = TenByteOffsetBase.create(adjust_offset: -5)
91
91
  lambda { obj.read(io) }.must_raise BinData::ValidityError
92
92
  end
93
93
  end
data/test/params_test.rb CHANGED
@@ -13,13 +13,13 @@ describe BinData::Base, "parameters" do
13
13
  end
14
14
 
15
15
  it "fails when parameter has nil value" do
16
- lambda { BinData::Base.new(:a => nil) }.must_raise ArgumentError
16
+ lambda { BinData::Base.new(a: nil) }.must_raise ArgumentError
17
17
  end
18
18
  end
19
19
 
20
20
  describe BinData::Base, "#has_parameter?" do
21
21
  it "true for existing parameters" do
22
- obj = BinData::Base.new(:a => 3)
22
+ obj = BinData::Base.new(a: 3)
23
23
  assert obj.has_parameter?(:a)
24
24
  end
25
25
 
@@ -31,7 +31,7 @@ end
31
31
 
32
32
  describe BinData::Base, "#get_parameter" do
33
33
  it "retrieves parameter values" do
34
- obj = BinData::Base.new(:a => 3)
34
+ obj = BinData::Base.new(a: 3)
35
35
  obj.get_parameter(:a).must_equal 3
36
36
  end
37
37
 
@@ -46,14 +46,14 @@ describe BinData::Base, "#get_parameter" do
46
46
  end
47
47
 
48
48
  it "wont eval parameters" do
49
- obj = BinData::Base.new(:a => lambda { 3 })
49
+ obj = BinData::Base.new(a: -> { 3 })
50
50
  assert_kind_of Proc, obj.get_parameter(:a)
51
51
  end
52
52
  end
53
53
 
54
54
  describe BinData::Base, "#eval_parameter" do
55
55
  it "evals the parameter" do
56
- obj = BinData::Base.new(:a => lambda { 3 })
56
+ obj = BinData::Base.new(a: -> { 3 })
57
57
  obj.eval_parameter(:a).must_equal 3
58
58
  end
59
59
 
@@ -70,7 +70,7 @@ describe BinData::Base, ".mandatory_parameters" do
70
70
  end
71
71
 
72
72
  it "fails when not all mandatory parameters are present" do
73
- params = {:p1 => "a", :xx => "b" }
73
+ params = {p1: "a", xx: "b" }
74
74
  lambda { MandatoryBase.new(params) }.must_raise ArgumentError
75
75
  end
76
76
 
@@ -81,7 +81,7 @@ end
81
81
 
82
82
  describe BinData::Base, ".default_parameters" do
83
83
  class DefaultBase < BinData::Base
84
- default_parameter :p1 => "a"
84
+ default_parameter p1: "a"
85
85
  end
86
86
 
87
87
  it "uses default parameters when not specified" do
@@ -90,7 +90,7 @@ describe BinData::Base, ".default_parameters" do
90
90
  end
91
91
 
92
92
  it "can override default parameters" do
93
- obj = DefaultBase.new(:p1 => "b")
93
+ obj = DefaultBase.new(p1: "b")
94
94
  obj.eval_parameter(:p1).must_equal "b"
95
95
  end
96
96
  end
@@ -102,9 +102,9 @@ describe BinData::Base, ".mutually_exclusive_parameters" do
102
102
  end
103
103
 
104
104
  it "fails when any two of those parameters are present" do
105
- lambda { MutexParamBase.new(:p1 => "a", :p2 => "b") }.must_raise ArgumentError
106
- lambda { MutexParamBase.new(:p1 => "a", :p3 => "c") }.must_raise ArgumentError
107
- lambda { MutexParamBase.new(:p2 => "b", :p3 => "c") }.must_raise ArgumentError
105
+ lambda { MutexParamBase.new(p1: "a", p2: "b") }.must_raise ArgumentError
106
+ lambda { MutexParamBase.new(p1: "a", p3: "c") }.must_raise ArgumentError
107
+ lambda { MutexParamBase.new(p2: "b", p3: "c") }.must_raise ArgumentError
108
108
  end
109
109
  end
110
110
 
@@ -85,7 +85,7 @@ describe BinData::Primitive do
85
85
  end
86
86
 
87
87
  it "accepts standard parameters" do
88
- obj = PrimitiveWithEndian.new(:initial_value => 2)
88
+ obj = PrimitiveWithEndian.new(initial_value: 2)
89
89
  obj.to_binary_s.must_equal_binary "\x02\x00"
90
90
  end
91
91
 
@@ -100,7 +100,7 @@ describe BinData::Primitive do
100
100
  end
101
101
 
102
102
  it "uses read value whilst reading" do
103
- obj = PrimitiveWithEndian.new(:value => 2)
103
+ obj = PrimitiveWithEndian.new(value: 2)
104
104
  obj.read "\x05\x00"
105
105
  obj.must_equal 2
106
106
 
@@ -117,13 +117,13 @@ end
117
117
 
118
118
  describe BinData::Primitive, "requiring custom parameters" do
119
119
  class PrimitiveWithCustom < BinData::Primitive
120
- int8 :a, :initial_value => :iv
120
+ int8 :a, initial_value: :iv
121
121
  def get; self.a; end
122
122
  def set(v); self.a = v; end
123
123
  end
124
124
 
125
125
  it "passes parameters correctly" do
126
- obj = PrimitiveWithCustom.new(:iv => 5)
126
+ obj = PrimitiveWithCustom.new(iv: 5)
127
127
  obj.must_equal 5
128
128
  end
129
129
  end
@@ -132,7 +132,7 @@ describe BinData::Primitive, "with custom mandatory parameters" do
132
132
  class MandatoryPrimitive < BinData::Primitive
133
133
  mandatory_parameter :arg1
134
134
 
135
- uint8 :a, :value => :arg1
135
+ uint8 :a, value: :arg1
136
136
  def get; self.a; end
137
137
  def set(v); self.a = v; end
138
138
  end
@@ -142,16 +142,16 @@ describe BinData::Primitive, "with custom mandatory parameters" do
142
142
  end
143
143
 
144
144
  it "uses mandatory parameter" do
145
- obj = MandatoryPrimitive.new(:arg1 => 5)
145
+ obj = MandatoryPrimitive.new(arg1: 5)
146
146
  obj.must_equal 5
147
147
  end
148
148
  end
149
149
 
150
150
  describe BinData::Primitive, "with custom default parameters" do
151
151
  class DefaultPrimitive < BinData::Primitive
152
- default_parameter :arg1 => 5
152
+ default_parameter arg1: 5
153
153
 
154
- uint8 :a, :value => :arg1
154
+ uint8 :a, value: :arg1
155
155
  def get; self.a; end
156
156
  def set(v); self.a = v; end
157
157
  end
@@ -162,7 +162,7 @@ describe BinData::Primitive, "with custom default parameters" do
162
162
  end
163
163
 
164
164
  it "overrides default parameter" do
165
- obj = DefaultPrimitive.new(:arg1 => 7)
165
+ obj = DefaultPrimitive.new(arg1: 7)
166
166
  obj.must_equal 7
167
167
  end
168
168
  end
@@ -175,11 +175,11 @@ describe BinData::Primitive, "subclassed with default parameter" do
175
175
  end
176
176
 
177
177
  class ChildDerivedPrimitive < ParentDerivedPrimitive
178
- default_parameter :initial_value => 5
178
+ default_parameter initial_value: 5
179
179
  end
180
180
 
181
181
  it "overrides initial_value" do
182
- a = ChildDerivedPrimitive.new(:initial_value => 7)
182
+ a = ChildDerivedPrimitive.new(initial_value: 7)
183
183
  a.to_binary_s.must_equal_binary "\000\007"
184
184
  end
185
185
 
data/test/record_test.rb CHANGED
@@ -22,7 +22,7 @@ describe BinData::Record, "when defining with errors" do
22
22
  it "gives correct error message for non registered nested types" do
23
23
  lambda {
24
24
  class BadNestedTypeRecord < BinData::Record
25
- array :a, :type => :non_registered_type
25
+ array :a, type: :non_registered_type
26
26
  end
27
27
  }.must_raise_on_line TypeError, 2, "unknown type 'non_registered_type' in BadNestedTypeRecord"
28
28
  end
@@ -113,11 +113,11 @@ end
113
113
 
114
114
  describe BinData::Record, "with anonymous fields" do
115
115
  class AnonymousRecord < BinData::Record
116
- int8 'a', :initial_value => 10
116
+ int8 'a', initial_value: 10
117
117
  int8 ''
118
118
  int8 nil
119
119
  int8
120
- int8 :value => :a
120
+ int8 value: :a
121
121
  end
122
122
 
123
123
  let(:obj) { AnonymousRecord.new }
@@ -128,7 +128,7 @@ describe BinData::Record, "with anonymous fields" do
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
@@ -143,9 +143,9 @@ describe BinData::Record, "with hidden fields" do
143
143
  class HiddenRecord < BinData::Record
144
144
  hide :b, :c
145
145
  int8 :a
146
- int8 'b', :initial_value => 10
146
+ int8 'b', initial_value: 10
147
147
  int8 :c
148
- int8 :d, :value => :b
148
+ int8 :d, value: :b
149
149
  end
150
150
 
151
151
  let(:obj) { HiddenRecord.new }
@@ -164,7 +164,7 @@ describe BinData::Record, "with hidden fields" do
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
 
@@ -174,7 +174,7 @@ describe BinData::Record, "with multiple fields" do
174
174
  int8 :b
175
175
  end
176
176
 
177
- let(:obj) { MultiFieldRecord.new(:a => 1, :b => 2) }
177
+ let(:obj) { MultiFieldRecord.new(a: 1, b: 2) }
178
178
 
179
179
  it "returns num_bytes" do
180
180
  obj.a.num_bytes.must_equal 1
@@ -216,7 +216,7 @@ describe BinData::Record, "with multiple fields" do
216
216
  snap = obj.snapshot
217
217
  snap.a.must_equal 1
218
218
  snap.b.must_equal 2
219
- snap.must_equal({ :a => 1, :b => 2 })
219
+ snap.must_equal({ a: 1, b: 2 })
220
220
  end
221
221
 
222
222
  it "returns field_names" do
@@ -230,14 +230,14 @@ end
230
230
 
231
231
  describe BinData::Record, "with nested structs" do
232
232
  class NestedStructRecord < BinData::Record
233
- int8 :a, :initial_value => 6
234
- struct :b, :the_val => :a do
233
+ int8 :a, initial_value: 6
234
+ struct :b, the_val: :a do
235
235
  hide :w
236
- int8 :w, :initial_value => 3
237
- int8 :x, :value => :the_val
236
+ int8 :w, initial_value: 3
237
+ int8 :x, value: :the_val
238
238
  end
239
239
  struct :c do
240
- int8 :y, :value => lambda { b.w }
240
+ int8 :y, value: -> { b.w }
241
241
  int8 :z
242
242
  end
243
243
  end
@@ -276,7 +276,7 @@ describe BinData::Record, "with nested structs" do
276
276
  end
277
277
 
278
278
  it "assigns nested fields" do
279
- obj.assign(:a => 2, :b => {:w => 4})
279
+ obj.assign(a: 2, b: {w: 4})
280
280
  obj.a.must_equal 2
281
281
  obj.b.w.must_equal 4
282
282
  obj.b.x.must_equal 2
@@ -286,15 +286,15 @@ end
286
286
 
287
287
  describe BinData::Record, "with nested array of primitives" do
288
288
  class NestedPrimitiveArrayRecord < BinData::Record
289
- array :a, :initial_length => 3 do
290
- uint8 :value => lambda { index }
289
+ array :a, initial_length: 3 do
290
+ uint8 value: -> { index }
291
291
  end
292
292
  end
293
293
 
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,15 +310,15 @@ 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
 
317
317
  describe BinData::Record, "with nested choice with implied keys" do
318
318
  class NestedChoiceWithImpliedKeysRecord < BinData::Record
319
- choice :a, :selection => 1 do
320
- uint8 :value => 1
321
- uint8 :value => 2
319
+ choice :a, selection: 1 do
320
+ uint8 value: 1
321
+ uint8 value: 2
322
322
  end
323
323
  end
324
324
 
@@ -329,9 +329,9 @@ end
329
329
 
330
330
  describe BinData::Record, "with nested choice with explicit keys" do
331
331
  class NestedChoiceWithKeysRecord < BinData::Record
332
- choice :a, :selection => 5 do
333
- uint8 3, :value => 1
334
- uint8 5, :value => 2
332
+ choice :a, selection: 5 do
333
+ uint8 3, value: 1
334
+ uint8 5, value: 2
335
335
  end
336
336
  end
337
337
 
@@ -342,9 +342,9 @@ end
342
342
 
343
343
  describe BinData::Record, "with nested choice with names" do
344
344
  class NestedChoiceWithNamesRecord < BinData::Record
345
- choice :a, :selection => "b" do
346
- uint8 "b", :value => 1
347
- uint8 "c", :value => 2
345
+ choice :a, selection: "b" do
346
+ uint8 "b", value: 1
347
+ uint8 "c", value: 2
348
348
  end
349
349
  end
350
350
 
@@ -359,10 +359,10 @@ describe BinData::Record, "with an endian defined" do
359
359
 
360
360
  uint16 :a
361
361
  float :b
362
- array :c, :initial_length => 2 do
362
+ array :c, initial_length: 2 do
363
363
  int8
364
364
  end
365
- choice :d, :selection => 1 do
365
+ choice :d, selection: 1 do
366
366
  uint16
367
367
  uint32
368
368
  end
@@ -452,7 +452,7 @@ end
452
452
  describe BinData::Record, "with endian :big_and_little" do
453
453
  class RecordWithBnLEndian < BinData::Record
454
454
  endian :big_and_little
455
- int16 :a, :value => 1
455
+ int16 :a, value: 1
456
456
  end
457
457
 
458
458
  it "is not registered" do
@@ -478,7 +478,7 @@ describe BinData::Record, "with endian :big_and_little" do
478
478
  end
479
479
 
480
480
  it "accepts :endian as argument" do
481
- obj = RecordWithBnLEndian.new(:endian => :little)
481
+ obj = RecordWithBnLEndian.new(endian: :little)
482
482
  obj.to_binary_s.must_equal_binary "\x01\x00"
483
483
  end
484
484
  end
@@ -490,7 +490,7 @@ describe BinData::Record, "with endian :big_and_little and search_prefix" do
490
490
  class RecordWithBnLEndianAndSearchPrefix < BinData::Record
491
491
  endian :big_and_little
492
492
  search_prefix :ns
493
- bnl_int :a, :value => 1
493
+ bnl_int :a, value: 1
494
494
  end
495
495
 
496
496
  it "creates big endian version" do
@@ -507,10 +507,10 @@ end
507
507
  describe BinData::Record, "with endian :big_and_little when subclassed" do
508
508
  class ARecordWithBnLEndian < BinData::Record
509
509
  endian :big_and_little
510
- int16 :a, :value => 1
510
+ int16 :a, value: 1
511
511
  end
512
512
  class BRecordWithBnLEndian < ARecordWithBnLEndian
513
- int16 :b, :value => 2
513
+ int16 :b, value: 2
514
514
  end
515
515
 
516
516
  it "is not registered" do
@@ -536,7 +536,7 @@ describe BinData::Record, "with endian :big_and_little when subclassed" do
536
536
  end
537
537
 
538
538
  it "accepts :endian as argument" do
539
- obj = BRecordWithBnLEndian.new(:endian => :little)
539
+ obj = BRecordWithBnLEndian.new(endian: :little)
540
540
  obj.to_binary_s.must_equal_binary "\x01\x00\x02\x00"
541
541
  end
542
542
  end
@@ -545,8 +545,8 @@ describe BinData::Record, "defined recursively" do
545
545
  class RecursiveRecord < BinData::Record
546
546
  endian :big
547
547
  uint16 :val
548
- uint8 :has_nxt, :value => lambda { nxt.clear? ? 0 : 1 }
549
- recursive_record :nxt, :onlyif => lambda { has_nxt > 0 }
548
+ uint8 :has_nxt, value: -> { nxt.clear? ? 0 : 1 }
549
+ recursive_record :nxt, onlyif: -> { has_nxt > 0 }
550
550
  end
551
551
 
552
552
  it "can be created" do
@@ -581,7 +581,7 @@ describe BinData::Record, "with custom mandatory parameters" do
581
581
  class MandatoryRecord < BinData::Record
582
582
  mandatory_parameter :arg1
583
583
 
584
- uint8 :a, :value => :arg1
584
+ uint8 :a, value: :arg1
585
585
  end
586
586
 
587
587
  it "raises error if mandatory parameter is not supplied" do
@@ -589,16 +589,16 @@ describe BinData::Record, "with custom mandatory parameters" do
589
589
  end
590
590
 
591
591
  it "uses mandatory parameter" do
592
- obj = MandatoryRecord.new(:arg1 => 5)
592
+ obj = MandatoryRecord.new(arg1: 5)
593
593
  obj.a.must_equal 5
594
594
  end
595
595
  end
596
596
 
597
597
  describe BinData::Record, "with custom default parameters" do
598
598
  class DefaultRecord < BinData::Record
599
- default_parameter :arg1 => 5
599
+ default_parameter arg1: 5
600
600
 
601
- uint8 :a, :value => :arg1
601
+ uint8 :a, value: :arg1
602
602
  uint8 :b
603
603
  end
604
604
 
@@ -608,17 +608,17 @@ describe BinData::Record, "with custom default parameters" do
608
608
  end
609
609
 
610
610
  it "overrides default parameter" do
611
- obj = DefaultRecord.new(:arg1 => 7)
611
+ obj = DefaultRecord.new(arg1: 7)
612
612
  obj.a.must_equal 7
613
613
  end
614
614
 
615
615
  it "accepts values" do
616
- obj = DefaultRecord.new(:b => 2)
616
+ obj = DefaultRecord.new(b: 2)
617
617
  obj.b.must_equal 2
618
618
  end
619
619
 
620
620
  it "accepts values and parameters" do
621
- obj = DefaultRecord.new({:b => 2}, :arg1 => 3)
621
+ obj = DefaultRecord.new({b: 2}, arg1: 3)
622
622
  obj.a.must_equal 3
623
623
  obj.b.must_equal 2
624
624
  end
@@ -626,16 +626,16 @@ end
626
626
 
627
627
  describe BinData::Record, "with :onlyif" do
628
628
  class OnlyIfRecord < BinData::Record
629
- uint8 :a, :initial_value => 3
630
- uint8 :b, :initial_value => 5, :onlyif => lambda { a == 3 }
631
- uint8 :c, :initial_value => 7, :onlyif => lambda { a != 3 }
629
+ uint8 :a, initial_value: 3
630
+ uint8 :b, initial_value: 5, onlyif: -> { a == 3 }
631
+ uint8 :c, initial_value: 7, onlyif: -> { a != 3 }
632
632
  end
633
633
 
634
634
  let(:obj) { OnlyIfRecord.new }
635
635
 
636
636
  it "initial state" do
637
637
  obj.num_bytes.must_equal 2
638
- obj.snapshot.must_equal({:a => 3, :b => 5})
638
+ obj.snapshot.must_equal({a: 3, b: 5})
639
639
  obj.to_binary_s.must_equal_binary "\x03\x05"
640
640
  end
641
641
 
@@ -647,7 +647,7 @@ describe BinData::Record, "with :onlyif" do
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