bindata 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bindata might be problematic. Click here for more details.

@@ -3,20 +3,20 @@
3
3
  require File.expand_path(File.dirname(__FILE__)) + '/spec_common'
4
4
  require 'bindata/stringz'
5
5
 
6
- context "An empty Stringz data object" do
7
- setup do
6
+ describe "An empty Stringz data object" do
7
+ before(:each) do
8
8
  @str = BinData::Stringz.new
9
9
  end
10
10
 
11
- specify "should include the zero byte in num_bytes total" do
11
+ it "should include the zero byte in num_bytes total" do
12
12
  @str.num_bytes.should eql(1)
13
13
  end
14
14
 
15
- specify "should not append the zero byte terminator to the value" do
15
+ it "should not append the zero byte terminator to the value" do
16
16
  @str.value.should eql("")
17
17
  end
18
18
 
19
- specify "should write the zero byte terminator" do
19
+ it "should write the zero byte terminator" do
20
20
  io = StringIO.new
21
21
  @str.write(io)
22
22
  io.rewind
@@ -24,21 +24,21 @@ context "An empty Stringz data object" do
24
24
  end
25
25
  end
26
26
 
27
- context "A Stringz data object with value set" do
28
- setup do
27
+ describe "A Stringz data object with value set" do
28
+ before(:each) do
29
29
  @str = BinData::Stringz.new
30
30
  @str.value = "abcd"
31
31
  end
32
32
 
33
- specify "should include the zero byte in num_bytes total" do
33
+ it "should include the zero byte in num_bytes total" do
34
34
  @str.num_bytes.should eql(5)
35
35
  end
36
36
 
37
- specify "should not append the zero byte terminator to the value" do
37
+ it "should not append the zero byte terminator to the value" do
38
38
  @str.value.should eql("abcd")
39
39
  end
40
40
 
41
- specify "should write the zero byte terminator" do
41
+ it "should write the zero byte terminator" do
42
42
  io = StringIO.new
43
43
  @str.write(io)
44
44
  io.rewind
@@ -46,102 +46,102 @@ context "A Stringz data object with value set" do
46
46
  end
47
47
  end
48
48
 
49
- context "Reading with a Stringz data object" do
50
- setup do
49
+ describe "Reading with a Stringz data object" do
50
+ before(:each) do
51
51
  @str = BinData::Stringz.new
52
52
  end
53
53
 
54
- specify "should stop at the first zero byte" do
54
+ it "should stop at the first zero byte" do
55
55
  io = StringIO.new("abcd\0xyz\0")
56
56
  @str.read(io)
57
57
  @str.value.should eql("abcd")
58
58
  io.read(1).should eql("x")
59
59
  end
60
60
 
61
- specify "should handle a zero length string" do
61
+ it "should handle a zero length string" do
62
62
  io = StringIO.new("\0abcd")
63
63
  @str.read(io)
64
64
  @str.value.should eql("")
65
65
  io.read(1).should eql("a")
66
66
  end
67
67
 
68
- specify "should fail if no zero byte is found" do
68
+ it "should fail if no zero byte is found" do
69
69
  io = StringIO.new("abcd")
70
70
  lambda {@str.read(io) }.should raise_error(EOFError)
71
71
  end
72
72
  end
73
73
 
74
- context "Setting the value of a Stringz data object" do
75
- setup do
74
+ describe "Setting the value of a Stringz data object" do
75
+ before(:each) do
76
76
  @str = BinData::Stringz.new
77
77
  end
78
78
 
79
- specify "should include the zero byte in num_bytes total" do
79
+ it "should include the zero byte in num_bytes total" do
80
80
  @str.value = "abcd"
81
81
  @str.num_bytes.should eql(5)
82
82
  end
83
83
 
84
- specify "should accept empty strings" do
84
+ it "should accept empty strings" do
85
85
  @str.value = ""
86
86
  @str.value.should eql("")
87
87
  end
88
88
 
89
- specify "should accept strings that aren't zero terminated" do
89
+ it "should accept strings that aren't zero terminated" do
90
90
  @str.value = "abcd"
91
91
  @str.value.should eql("abcd")
92
92
  end
93
93
 
94
- specify "should accept strings that are zero terminated" do
94
+ it "should accept strings that are zero terminated" do
95
95
  @str.value = "abcd\0"
96
96
  @str.value.should eql("abcd")
97
97
  end
98
98
 
99
- specify "should accept up to the first zero byte" do
99
+ it "should accept up to the first zero byte" do
100
100
  @str.value = "abcd\0xyz\0"
101
101
  @str.value.should eql("abcd")
102
102
  end
103
103
  end
104
104
 
105
- context "A Stringz data object with max_length" do
106
- setup do
105
+ describe "A Stringz data object with max_length" do
106
+ before(:each) do
107
107
  @str = BinData::Stringz.new(:max_length => 5)
108
108
  end
109
109
 
110
- specify "should read less than max_length" do
110
+ it "should read less than max_length" do
111
111
  io = StringIO.new("abc\0xyz")
112
112
  @str.read(io)
113
113
  @str.value.should eql("abc")
114
114
  end
115
115
 
116
- specify "should read exactly max_length" do
116
+ it "should read exactly max_length" do
117
117
  io = StringIO.new("abcd\0xyz")
118
118
  @str.read(io)
119
119
  @str.value.should eql("abcd")
120
120
  end
121
121
 
122
- specify "should read no more than max_length" do
122
+ it "should read no more than max_length" do
123
123
  io = StringIO.new("abcdefg\0xyz")
124
124
  @str.read(io)
125
125
  @str.value.should eql("abcd")
126
126
  io.read(1).should eql("f")
127
127
  end
128
128
 
129
- specify "should accept values less than max_length" do
129
+ it "should accept values less than max_length" do
130
130
  @str.value = "abc"
131
131
  @str.value.should eql("abc")
132
132
  end
133
133
 
134
- specify "should accept values exactly max_length" do
134
+ it "should accept values exactly max_length" do
135
135
  @str.value = "abcd"
136
136
  @str.value.should eql("abcd")
137
137
  end
138
138
 
139
- specify "should trim values greater than max_length" do
139
+ it "should trim values greater than max_length" do
140
140
  @str.value = "abcde"
141
141
  @str.value.should eql("abcd")
142
142
  end
143
143
 
144
- specify "should write values less than max_length" do
144
+ it "should write values less than max_length" do
145
145
  io = StringIO.new
146
146
  @str.value = "abc"
147
147
  @str.write(io)
@@ -149,7 +149,7 @@ context "A Stringz data object with max_length" do
149
149
  io.read.should eql("abc\0")
150
150
  end
151
151
 
152
- specify "should write values exactly max_length" do
152
+ it "should write values exactly max_length" do
153
153
  io = StringIO.new
154
154
  @str.value = "abcd"
155
155
  @str.write(io)
@@ -3,8 +3,8 @@
3
3
  require File.expand_path(File.dirname(__FILE__)) + '/spec_common'
4
4
  require 'bindata'
5
5
 
6
- context "A Struct with hidden fields" do
7
- context_setup do
6
+ describe "A Struct with hidden fields" do
7
+ before(:all) do
8
8
  eval <<-END
9
9
  class TestStruct < BinData::Struct
10
10
  hide :b, 'c'
@@ -17,11 +17,11 @@ context "A Struct with hidden fields" do
17
17
  @obj = TestStruct.new
18
18
  end
19
19
 
20
- specify "should only show fields that aren't hidden" do
20
+ it "should only show fields that aren't hidden" do
21
21
  @obj.field_names.should == ["a", "d"]
22
22
  end
23
23
 
24
- specify "should be able to access hidden fields directly" do
24
+ it "should be able to access hidden fields directly" do
25
25
  @obj.b.should eql(10)
26
26
  @obj.c = 15
27
27
  @obj.c.should eql(15)
@@ -29,14 +29,14 @@ context "A Struct with hidden fields" do
29
29
  @obj.should respond_to?(:b=)
30
30
  end
31
31
 
32
- specify "should not include hidden fields in snapshot" do
32
+ it "should not include hidden fields in snapshot" do
33
33
  @obj.b = 5
34
34
  @obj.snapshot.should == {"a" => 0, "d" => 5}
35
35
  end
36
36
  end
37
37
 
38
- context "Defining a Struct" do
39
- specify "should fail on non registered types" do
38
+ describe "Defining a Struct" do
39
+ it "should fail on non registered types" do
40
40
  lambda {
41
41
  eval <<-END
42
42
  class BadType < BinData::Struct
@@ -46,7 +46,7 @@ context "Defining a Struct" do
46
46
  }.should raise_error(TypeError)
47
47
  end
48
48
 
49
- specify "should fail on duplicate names" do
49
+ it "should fail on duplicate names" do
50
50
  lambda {
51
51
  eval <<-END
52
52
  class DuplicateName < BinData::Struct
@@ -58,7 +58,7 @@ context "Defining a Struct" do
58
58
  }.should raise_error(SyntaxError)
59
59
  end
60
60
 
61
- specify "should fail when field name shadows an existing method" do
61
+ it "should fail when field name shadows an existing method" do
62
62
  lambda {
63
63
  eval <<-END
64
64
  class ExistingName < BinData::Struct
@@ -72,7 +72,7 @@ context "Defining a Struct" do
72
72
  }.should raise_error(NameError)
73
73
  end
74
74
 
75
- specify "should fail on unknown endian" do
75
+ it "should fail on unknown endian" do
76
76
  lambda {
77
77
  eval <<-END
78
78
  class BadEndian < BinData::Struct
@@ -83,27 +83,27 @@ context "Defining a Struct" do
83
83
  end
84
84
  end
85
85
 
86
- context "A Struct with multiple fields" do
87
- setup do
86
+ describe "A Struct with multiple fields" do
87
+ before(:each) do
88
88
  fields = [ [:int8, :a], [:int8, :b] ]
89
89
  @obj = BinData::Struct.new(:fields => fields)
90
90
  @obj.a = 1
91
91
  @obj.b = 2
92
92
  end
93
93
 
94
- specify "should return num_bytes" do
94
+ it "should return num_bytes" do
95
95
  @obj.num_bytes(:a).should eql(1)
96
96
  @obj.num_bytes(:b).should eql(1)
97
97
  @obj.num_bytes.should eql(2)
98
98
  end
99
99
 
100
- specify "should clear" do
100
+ it "should clear" do
101
101
  @obj.a = 6
102
102
  @obj.clear
103
103
  @obj.clear?.should be_true
104
104
  end
105
105
 
106
- specify "should clear individual elements" do
106
+ it "should clear individual elements" do
107
107
  @obj.a = 6
108
108
  @obj.b = 7
109
109
  @obj.clear(:a)
@@ -111,7 +111,7 @@ context "A Struct with multiple fields" do
111
111
  @obj.clear?(:b).should be_false
112
112
  end
113
113
 
114
- specify "should write ordered" do
114
+ it "should write ordered" do
115
115
  io = StringIO.new
116
116
  @obj.write(io)
117
117
 
@@ -119,7 +119,7 @@ context "A Struct with multiple fields" do
119
119
  io.read.should eql("\x01\x02")
120
120
  end
121
121
 
122
- specify "should read ordered" do
122
+ it "should read ordered" do
123
123
  io = StringIO.new "\x03\x04"
124
124
  @obj.read(io)
125
125
 
@@ -127,24 +127,24 @@ context "A Struct with multiple fields" do
127
127
  @obj.b.should eql(4)
128
128
  end
129
129
 
130
- specify "should return a snapshot" do
130
+ it "should return a snapshot" do
131
131
  snap = @obj.snapshot
132
132
  snap.a.should eql(1)
133
133
  snap.b.should eql(2)
134
134
  snap.should == { "a" => 1, "b" => 2 }
135
135
  end
136
136
 
137
- specify "should return field_names" do
137
+ it "should return field_names" do
138
138
  @obj.field_names.should == ["a", "b"]
139
139
  end
140
140
 
141
- specify "should fail on unknown method call" do
141
+ it "should fail on unknown method call" do
142
142
  lambda { @obj.does_not_exist }.should raise_error(NoMethodError)
143
143
  end
144
144
  end
145
145
 
146
- context "A Struct with a value method" do
147
- context_setup do
146
+ describe "A Struct with a value method" do
147
+ before(:all) do
148
148
  eval <<-END
149
149
  class StructWithValue < BinData::Struct
150
150
  int8 :a
@@ -158,21 +158,21 @@ context "A Struct with a value method" do
158
158
  @obj = StructWithValue.new
159
159
  end
160
160
 
161
- specify "should be single value object" do
161
+ it "should be single value object" do
162
162
  @obj.should be_a_single_value
163
163
  end
164
164
 
165
- specify "should have no field names" do
165
+ it "should have no field names" do
166
166
  @obj.field_names.should be_empty
167
167
  end
168
168
 
169
- specify "should not respond to field accesses" do
169
+ it "should not respond to field accesses" do
170
170
  @obj.should_not respond_to?(:a)
171
171
  end
172
172
  end
173
173
 
174
- context "A Struct with nested structs" do
175
- context_setup do
174
+ describe "A Struct with nested structs" do
175
+ before(:all) do
176
176
  eval <<-END
177
177
  class StructInner1 < BinData::Struct
178
178
  int8 :w, :initial_value => 3
@@ -193,26 +193,26 @@ context "A Struct with nested structs" do
193
193
  @obj = StructOuter.new
194
194
  end
195
195
 
196
- specify "should included nested field names" do
196
+ it "should included nested field names" do
197
197
  @obj.field_names.should == ["a", "b", "y", "z"]
198
198
  end
199
199
 
200
- specify "should access nested fields" do
200
+ it "should access nested fields" do
201
201
  @obj.a.should eql(6)
202
202
  @obj.b.w.should eql(3)
203
203
  @obj.b.x.should eql(6)
204
204
  @obj.y.should eql(3)
205
205
  end
206
206
 
207
- specify "should return correct offset of" do
207
+ it "should return correct offset of" do
208
208
  @obj.offset_of("b").should eql(1)
209
209
  @obj.offset_of("y").should eql(3)
210
210
  @obj.offset_of("z").should eql(4)
211
211
  end
212
212
  end
213
213
 
214
- context "A Struct with an endian defined" do
215
- context_setup do
214
+ describe "A Struct with an endian defined" do
215
+ before(:all) do
216
216
  eval <<-END
217
217
  class StructWithEndian < BinData::Struct
218
218
  endian :little
@@ -227,7 +227,7 @@ context "A Struct with an endian defined" do
227
227
  @obj = StructWithEndian.new
228
228
  end
229
229
 
230
- specify "should use correct endian" do
230
+ it "should use correct endian" do
231
231
  @obj.a = 1
232
232
  @obj.b = 2.0
233
233
  @obj.c[0] = 3
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: bindata
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.6.0
7
- date: 2007-03-28 00:00:00 +08:00
6
+ version: 0.7.0
7
+ date: 2007-08-27 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