bindata 0.11.0 → 0.11.1

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.

@@ -6,12 +6,10 @@ require 'bindata/int'
6
6
  require 'bindata/registry'
7
7
 
8
8
  describe BinData::Registry do
9
- before(:all) do
10
- A = Class.new
11
- B = Class.new
12
- C = Class.new
13
- D = Class.new
14
- end
9
+ A = Class.new
10
+ B = Class.new
11
+ C = Class.new
12
+ D = Class.new
15
13
 
16
14
  before(:each) do
17
15
  @r = BinData::Registry.new
@@ -58,6 +56,7 @@ describe BinData::Registry do
58
56
  @r.underscore_name('A::B::C').should == 'c'
59
57
  end
60
58
 
59
+ =begin
61
60
  it "should lookup integers with endian" do
62
61
  @r.register("Int24be", A)
63
62
  @r.register("Int24le", B)
@@ -105,4 +104,5 @@ describe BinData::Registry do
105
104
  @r.lookup("bit802le")
106
105
  BinData.const_defined?(:Bit802le).should be_true
107
106
  end
107
+ =end
108
108
  end
data/spec/system_spec.rb CHANGED
@@ -5,12 +5,8 @@ require File.expand_path(File.join(File.dirname(__FILE__), "example"))
5
5
  require 'bindata'
6
6
 
7
7
  describe "lambdas with index" do
8
- before(:all) do
9
- eval <<-END
10
- class NestedLambdaWithIndex < BinData::Record
11
- uint8 :a, :value => lambda { index * 10 }
12
- end
13
- END
8
+ class NestedLambdaWithIndex < BinData::Record
9
+ uint8 :a, :value => lambda { index * 10 }
14
10
  end
15
11
 
16
12
  it "should use index of containing array" do
@@ -65,27 +61,23 @@ describe "lambdas with parent" do
65
61
  end
66
62
 
67
63
  describe BinData::Record, "with choice field" do
68
- before(:all) do
69
- eval <<-END
70
- class TupleRecord < BinData::Record
71
- uint8 :a, :value => 3
72
- uint8 :b, :value => 5
73
- end
74
-
75
- class RecordWithChoiceField < BinData::Record
76
- choice :x, :choices => [[:tuple_record]], :selection => 0
77
- end
78
-
79
- class RecordWithNestedChoiceField < BinData::Record
80
- choice :x, :choices => [
81
- [:choice, {
82
- :choices => [[:tuple_record]],
83
- :selection => 0}
84
- ]
85
- ],
86
- :selection => 0
87
- end
88
- END
64
+ class TupleRecord < BinData::Record
65
+ uint8 :a, :value => 3
66
+ uint8 :b, :value => 5
67
+ end
68
+
69
+ class RecordWithChoiceField < BinData::Record
70
+ choice :x, :choices => [[:tuple_record]], :selection => 0
71
+ end
72
+
73
+ class RecordWithNestedChoiceField < BinData::Record
74
+ choice :x, :choices => [
75
+ [:choice, {
76
+ :choices => [[:tuple_record]],
77
+ :selection => 0}
78
+ ]
79
+ ],
80
+ :selection => 0
89
81
  end
90
82
 
91
83
  it "should treat choice object transparently " do
@@ -216,13 +208,9 @@ describe "Tracing" do
216
208
  end
217
209
 
218
210
  describe "Forward referencing with Single" do
219
- before(:all) do
220
- eval <<-END
221
- class FRSingle < BinData::Record
222
- uint8 :len, :value => lambda { data.length }
223
- string :data, :read_length => :len
224
- end
225
- END
211
+ class FRSingle < BinData::Record
212
+ uint8 :len, :value => lambda { data.length }
213
+ string :data, :read_length => :len
226
214
  end
227
215
 
228
216
  it "should initialise" do
@@ -244,13 +232,9 @@ describe "Forward referencing with Single" do
244
232
  end
245
233
 
246
234
  describe "Forward referencing with Array" do
247
- before(:all) do
248
- eval <<-END
249
- class FRArray < BinData::Record
250
- uint8 :len, :value => lambda { data.length }
251
- array :data, :type => :uint8, :initial_length => :len
252
- end
253
- END
235
+ class FRArray < BinData::Record
236
+ uint8 :len, :value => lambda { data.length }
237
+ array :data, :type => :uint8, :initial_length => :len
254
238
  end
255
239
 
256
240
  it "should initialise" do
@@ -272,16 +256,12 @@ describe "Forward referencing with Array" do
272
256
  end
273
257
 
274
258
  describe "Evaluating custom parameters" do
275
- before(:all) do
276
- eval <<-END
277
- class CustomParameterRecord < BinData::Record
278
- mandatory_parameter :zz
259
+ class CustomParameterRecord < BinData::Record
260
+ mandatory_parameter :zz
279
261
 
280
- uint8 :a, :value => :zz
281
- uint8 :b, :value => :a
282
- uint8 :c, :custom => :b
283
- end
284
- END
262
+ uint8 :a, :value => :zz
263
+ uint8 :b, :value => :a
264
+ uint8 :c, :custom => :b
285
265
  end
286
266
 
287
267
  it "should recursively evaluate parameter" do
@@ -291,12 +271,8 @@ describe "Evaluating custom parameters" do
291
271
  end
292
272
 
293
273
  describe BinData::Record, "with custom sized integers" do
294
- before(:all) do
295
- eval <<-END
296
- class CustomIntRecord < BinData::Record
297
- int40be :a
298
- end
299
- END
274
+ class CustomIntRecord < BinData::Record
275
+ int40be :a
300
276
  end
301
277
 
302
278
  it "should read as expected" do
data/spec/wrapper_spec.rb CHANGED
@@ -2,30 +2,23 @@
2
2
 
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_common"))
4
4
  require 'bindata'
5
- require 'bindata/wrapper'
6
5
 
7
6
  describe BinData::Wrapper, "with errors" do
8
7
  it "should not wrap more than one type" do
9
8
  lambda {
10
- eval <<-END
11
- class WrappedMultipleTypes < BinData::Wrapper
12
- uint8
13
- uint8
14
- end
15
- END
9
+ class WrappedMultipleTypes < BinData::Wrapper
10
+ uint8
11
+ uint8
12
+ end
16
13
  }.should raise_error(SyntaxError)
17
14
  end
18
15
  end
19
16
 
20
17
  describe BinData::Wrapper, "around a Primitive" do
21
- before(:all) do
22
- eval <<-END
23
- class WrappedPrimitive < BinData::Wrapper
24
- default_parameter :a => 3
18
+ class WrappedPrimitive < BinData::Wrapper
19
+ default_parameter :a => 3
25
20
 
26
- uint8 :initial_value => :a
27
- end
28
- END
21
+ uint8 :initial_value => :a
29
22
  end
30
23
 
31
24
  it "should access custom parameter" do
@@ -46,14 +39,10 @@ describe BinData::Wrapper, "around a Primitive" do
46
39
  end
47
40
 
48
41
  describe BinData::Wrapper, "around an Array" do
49
- before(:all) do
50
- eval <<-END
51
- class WrappedIntArray < BinData::Wrapper
52
- endian :big
53
- default_parameter :initial_element_value => 0
54
- array :type => [:uint16, {:initial_value => :initial_element_value}]
55
- end
56
- END
42
+ class WrappedIntArray < BinData::Wrapper
43
+ endian :big
44
+ default_parameter :initial_element_value => 0
45
+ array :type => [:uint16, {:initial_value => :initial_element_value}]
57
46
  end
58
47
 
59
48
  it "should forward parameters" do
@@ -68,13 +57,9 @@ describe BinData::Wrapper, "around an Array" do
68
57
  end
69
58
 
70
59
  describe BinData::Wrapper, "around a Choice" do
71
- before(:all) do
72
- eval <<-END
73
- class WrappedChoice < BinData::Wrapper
74
- endian :big
75
- choice :choices => { 'a' => :uint8, 'b' => :uint16 }
76
- end
77
- END
60
+ class WrappedChoice < BinData::Wrapper
61
+ endian :big
62
+ choice :choices => { 'a' => :uint8, 'b' => :uint16 }
78
63
  end
79
64
 
80
65
  it "should forward parameters" do
@@ -82,3 +67,17 @@ describe BinData::Wrapper, "around a Choice" do
82
67
  obj.num_bytes.should == 2
83
68
  end
84
69
  end
70
+
71
+ describe BinData::Wrapper, "inside a struct" do
72
+ class WrappedUint32le < BinData::Wrapper
73
+ uint32le
74
+ end
75
+
76
+ it "should handle onlyif" do
77
+ field1 = [:wrapped_uint32le, :a, {:onlyif => false, :value => 1 }]
78
+ field2 = [:wrapped_uint32le, :b, {:onlyif => true, :value => 2 }]
79
+
80
+ obj = BinData::Struct.new(:fields => [field1, field2])
81
+ obj.should == {'b' => 2}
82
+ end
83
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bindata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dion Mendel
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-28 00:00:00 +08:00
12
+ date: 2009-08-29 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,6 +23,7 @@ extra_rdoc_files:
23
23
  - README
24
24
  files:
25
25
  - INSTALL
26
+ - TUTORIAL
26
27
  - TODO
27
28
  - GPL
28
29
  - Rakefile