bindata 0.9.1 → 0.9.2

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/spec/single_spec.rb CHANGED
@@ -65,10 +65,6 @@ describe BinData::Single, "after initialisation" do
65
65
  lambda { ConcreteSingle.new(params) }.should raise_error(ArgumentError)
66
66
  end
67
67
 
68
- it "should not have any field_names" do
69
- BinData::Single.all_possible_field_names(nil).should be_empty
70
- end
71
-
72
68
  it "should have a sensible value" do
73
69
  @data.value.should == 0
74
70
  end
@@ -112,10 +108,6 @@ describe BinData::Single, "after initialisation" do
112
108
  @data.num_bytes.should == 4
113
109
  end
114
110
 
115
- it "should not contain any field names" do
116
- @data.field_names.should be_empty
117
- end
118
-
119
111
  it "should return a snapshot" do
120
112
  @data.value = 5
121
113
  @data.snapshot.should == 5
data/spec/struct_spec.rb CHANGED
@@ -14,11 +14,6 @@ describe BinData::Struct, "with hidden fields" do
14
14
  @obj = BinData::Struct.new(@params)
15
15
  end
16
16
 
17
- it "should not include hidden names in all_possible_field_names" do
18
- params = BinData::SanitizedParameters.new(BinData::Struct, @params)
19
- BinData::Struct.all_possible_field_names(params).should == ["a", "d"]
20
- end
21
-
22
17
  it "should only show fields that aren't hidden" do
23
18
  @obj.field_names.should == ["a", "d"]
24
19
  end
@@ -45,13 +40,6 @@ describe BinData::Struct do
45
40
  }.should raise_error(TypeError)
46
41
  end
47
42
 
48
- it "should fail on all_possible_field_names with unsanitized parameters" do
49
- params = {:fields => [[:int8, :a], [:int8, :b]]}
50
- lambda {
51
- BinData::Struct.all_possible_field_names(params)
52
- }.should raise_error(ArgumentError)
53
- end
54
-
55
43
  it "should fail on duplicate names" do
56
44
  params = {:fields => [[:int8, :a], [:int8, :b], [:int8, :a]]}
57
45
  lambda {
@@ -59,23 +47,6 @@ describe BinData::Struct do
59
47
  }.should raise_error(NameError)
60
48
  end
61
49
 
62
- it "should fail on duplicate names in nested structs" do
63
- params = {:fields => [[:int8, :a],
64
- [:struct, nil, {:fields => [[:int8, :a]]}]]}
65
- lambda {
66
- BinData::Struct.new(params)
67
- }.should raise_error(NameError)
68
- end
69
-
70
- it "should fail on duplicate names in triple nested structs" do
71
- params = {:fields => [[:int8, :a],
72
- [:struct, nil, {:fields => [
73
- [:struct, nil, {:fields => [[:int8, :a]]}]]}]]}
74
- lambda {
75
- BinData::Struct.new(params)
76
- }.should raise_error(NameError)
77
- end
78
-
79
50
  it "should fail on reserved names" do
80
51
  # note that #invert is from Hash.instance_methods
81
52
  params = {:fields => [[:int8, :a], [:int8, :invert]]}
@@ -120,11 +91,6 @@ describe BinData::Struct, "with multiple fields" do
120
91
  BinData::Struct.accepted_parameters.should include(:endian)
121
92
  end
122
93
 
123
- it "should return all possible field names" do
124
- params = BinData::SanitizedParameters.new(BinData::Struct, @params)
125
- BinData::Struct.all_possible_field_names(params).should == ["a", "b"]
126
- end
127
-
128
94
  it "should return field names" do
129
95
  @obj.field_names.should == ["a", "b"]
130
96
  end
@@ -186,31 +152,33 @@ describe BinData::Struct, "with nested structs" do
186
152
  @params = { :fields => [
187
153
  [:int8, :a, {:initial_value => 6}],
188
154
  [:struct, :b, {:fields => inner1, :the_val => :a}],
189
- [:struct, nil, {:fields => inner2}]] }
155
+ [:struct, :c, {:fields => inner2}]] }
190
156
  @obj = BinData::Struct.new(@params)
191
157
  end
192
158
 
193
159
  it "should included nested field names" do
194
- @obj.field_names.should == ["a", "b", "y", "z"]
160
+ @obj.field_names.should == ["a", "b", "c"]
195
161
  end
196
162
 
197
- it "should return all possible field names" do
198
- params = BinData::SanitizedParameters.new(BinData::Struct, @params)
199
- all_params = BinData::Struct.all_possible_field_names(params)
200
- all_params.should == ["a", "b", "y", "z"]
163
+ it "should return num_bytes" do
164
+ @obj.num_bytes(:b).should == 2
165
+ @obj.num_bytes(:c).should == 2
166
+ @obj.num_bytes.should == 5
201
167
  end
202
168
 
203
169
  it "should access nested fields" do
204
170
  @obj.a.should == 6
205
171
  @obj.b.w.should == 3
206
172
  @obj.b.x.should == 6
207
- @obj.y.should == 3
173
+ @obj.c.y.should == 3
174
+ @obj.c.z.should == 0
208
175
  end
209
176
 
210
177
  it "should return correct offset of" do
211
178
  @obj.offset_of("b").should == 1
212
- @obj.offset_of("y").should == 3
213
- @obj.offset_of("z").should == 4
179
+ @obj.offset_of("b").should == 1
180
+ @obj.offset_of("c").should == 3
181
+ @obj.offset_of("y").should be_nil
214
182
  end
215
183
  end
216
184
 
@@ -279,3 +247,21 @@ describe BinData::Struct, "with bit fields" do
279
247
  end
280
248
  end
281
249
 
250
+ describe BinData::Struct, "with nested endian" do
251
+ it "should use correct endian" do
252
+ nested_params = { :endian => :little,
253
+ :fields => [[:int16, :b], [:int16, :c]] }
254
+ params = { :endian => :big,
255
+ :fields => [[:int16, :a],
256
+ [:struct, :s, nested_params],
257
+ [:int16, :d]] }
258
+ obj = BinData::Struct.new(params)
259
+ str = "\x00\x01\x02\x00\x03\x00\x00\x04"
260
+ obj.read(str)
261
+
262
+ obj.a.should == 1
263
+ obj.s.b.should == 2
264
+ obj.s.c.should == 3
265
+ obj.d.should == 4
266
+ end
267
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: bindata
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.1
7
- date: 2008-06-15 00:00:00 +08:00
6
+ version: 0.9.2
7
+ date: 2008-07-18 00:00:00 +08:00
8
8
  summary: A declarative way to read and write binary file formats
9
9
  require_paths:
10
10
  - lib