bindata 1.4.3 → 1.4.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.

data/spec/int_spec.rb CHANGED
@@ -3,21 +3,21 @@
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_common"))
4
4
  require 'bindata'
5
5
 
6
- share_examples_for "All Integers" do
6
+ shared_examples "All Integers" do
7
7
 
8
- it "should have correct num_bytes" do
8
+ it "have correct num_bytes" do
9
9
  all_classes do |int_class|
10
10
  int_class.new.num_bytes.should == @nbytes
11
11
  end
12
12
  end
13
13
 
14
- it "should have a sensible value of zero" do
14
+ it "have a sensible value of zero" do
15
15
  all_classes do |int_class|
16
16
  int_class.new.should be_zero
17
17
  end
18
18
  end
19
19
 
20
- it "should avoid underflow" do
20
+ it "avoid underflow" do
21
21
  all_classes do |int_class|
22
22
  subject = int_class.new
23
23
  subject.assign(min_value - 1)
@@ -26,7 +26,7 @@ share_examples_for "All Integers" do
26
26
  end
27
27
  end
28
28
 
29
- it "should avoid overflow" do
29
+ it "avoid overflow" do
30
30
  all_classes do |int_class|
31
31
  subject = int_class.new
32
32
  subject.assign(max_value + 1)
@@ -35,7 +35,7 @@ share_examples_for "All Integers" do
35
35
  end
36
36
  end
37
37
 
38
- it "should assign values" do
38
+ it "assign values" do
39
39
  all_classes do |int_class|
40
40
  subject = int_class.new
41
41
  test_int = gen_test_int
@@ -45,7 +45,7 @@ share_examples_for "All Integers" do
45
45
  end
46
46
  end
47
47
 
48
- it "should assign values from other int objects" do
48
+ it "assign values from other int objects" do
49
49
  all_classes do |int_class|
50
50
  src = int_class.new
51
51
  src.assign(gen_test_int)
@@ -56,7 +56,7 @@ share_examples_for "All Integers" do
56
56
  end
57
57
  end
58
58
 
59
- it "should symmetrically read and write a +ve number" do
59
+ it "symmetrically read and write a +ve number" do
60
60
  all_classes do |int_class|
61
61
  subject = int_class.new
62
62
  subject.assign(gen_test_int)
@@ -65,7 +65,7 @@ share_examples_for "All Integers" do
65
65
  end
66
66
  end
67
67
 
68
- it "should symmetrically read and write a -ve number" do
68
+ it "symmetrically read and write a -ve number" do
69
69
  all_classes do |int_class|
70
70
  if @signed
71
71
  subject = int_class.new
@@ -76,7 +76,7 @@ share_examples_for "All Integers" do
76
76
  end
77
77
  end
78
78
 
79
- it "should convert a +ve number to string" do
79
+ it "convert a +ve number to string" do
80
80
  all_classes do |int_class|
81
81
  val = gen_test_int
82
82
 
@@ -87,7 +87,7 @@ share_examples_for "All Integers" do
87
87
  end
88
88
  end
89
89
 
90
- it "should convert a -ve number to string" do
90
+ it "convert a -ve number to string" do
91
91
  all_classes do |int_class|
92
92
  if @signed
93
93
  val = -gen_test_int
@@ -156,7 +156,7 @@ share_examples_for "All Integers" do
156
156
  end
157
157
 
158
158
  describe "All signed big endian integers" do
159
- it_should_behave_like "All Integers"
159
+ include_examples "All Integers"
160
160
 
161
161
  before(:all) do
162
162
  @endian = :big
@@ -166,7 +166,7 @@ describe "All signed big endian integers" do
166
166
  end
167
167
 
168
168
  describe "All unsigned big endian integers" do
169
- it_should_behave_like "All Integers"
169
+ include_examples "All Integers"
170
170
 
171
171
  before(:all) do
172
172
  @endian = :big
@@ -176,7 +176,7 @@ describe "All unsigned big endian integers" do
176
176
  end
177
177
 
178
178
  describe "All signed little endian integers" do
179
- it_should_behave_like "All Integers"
179
+ include_examples "All Integers"
180
180
 
181
181
  before(:all) do
182
182
  @endian = :little
@@ -186,7 +186,7 @@ describe "All signed little endian integers" do
186
186
  end
187
187
 
188
188
  describe "All unsigned little endian integers" do
189
- it_should_behave_like "All Integers"
189
+ include_examples "All Integers"
190
190
 
191
191
  before(:all) do
192
192
  @endian = :little
@@ -196,21 +196,21 @@ describe "All unsigned little endian integers" do
196
196
  end
197
197
 
198
198
  describe "Custom defined integers" do
199
- it "should fail unless bits are a multiple of 8" do
200
- lambda {
199
+ it "fail unless bits are a multiple of 8" do
200
+ expect {
201
201
  BinData::Uint7le
202
- }.should raise_error
202
+ }.to raise_error
203
203
 
204
- lambda {
204
+ expect {
205
205
  BinData::Uint7be
206
- }.should raise_error
206
+ }.to raise_error
207
207
 
208
- lambda {
208
+ expect {
209
209
  BinData::Int7le
210
- }.should raise_error
210
+ }.to raise_error
211
211
 
212
- lambda {
212
+ expect {
213
213
  BinData::Int7be
214
- }.should raise_error
214
+ }.to raise_error
215
215
  end
216
216
  end
data/spec/io_spec.rb CHANGED
@@ -30,17 +30,17 @@ describe BinData::IO, "reading from non seekable stream" do
30
30
  Process.wait
31
31
  end
32
32
 
33
- it "should always have an offset of 0" do
33
+ it "always has an offset of 0" do
34
34
  @io.readbytes(10)
35
35
  @io.offset.should == 0
36
36
  end
37
37
 
38
- it "should seek" do
38
+ it "seeks correctly" do
39
39
  @io.seekbytes(4999)
40
40
  @io.readbytes(5).should == "abbbb"
41
41
  end
42
42
 
43
- it "should return zero for num bytes remaining" do
43
+ it "returns zero for num bytes remaining" do
44
44
  @io.num_bytes_remaining.should == 0
45
45
  end
46
46
  end
@@ -49,21 +49,21 @@ describe BinData::IO, "when reading" do
49
49
  let(:stream) { StringIO.new "abcdefghij" }
50
50
  let(:io) { BinData::IO.new(stream) }
51
51
 
52
- it "should wrap strings in StringIO" do
52
+ it "wraps strings in StringIO" do
53
53
  io.raw_io.class.should == StringIO
54
54
  end
55
55
 
56
- it "should not wrap IO objects" do
56
+ it "does not wrap IO objects" do
57
57
  io.raw_io.should == stream
58
58
  end
59
59
 
60
- it "should raise error when io is BinData::IO" do
61
- lambda {
60
+ it "raises error when io is BinData::IO" do
61
+ expect {
62
62
  BinData::IO.new(BinData::IO.new(""))
63
- }.should raise_error(ArgumentError)
63
+ }.to raise_error(ArgumentError)
64
64
  end
65
65
 
66
- it "should return correct offset" do
66
+ it "returns correct offset" do
67
67
  stream.seek(3, IO::SEEK_CUR)
68
68
 
69
69
  io.offset.should == 0
@@ -71,33 +71,33 @@ describe BinData::IO, "when reading" do
71
71
  io.offset.should == 4
72
72
  end
73
73
 
74
- it "should seek" do
74
+ it "seeks correctly" do
75
75
  io.seekbytes(2)
76
76
  io.readbytes(4).should == "cdef"
77
77
  end
78
78
 
79
- it "should read all bytes" do
79
+ it "reads all bytes" do
80
80
  io.read_all_bytes.should == "abcdefghij"
81
81
  end
82
82
 
83
- it "should return number of bytes remaining" do
83
+ it "returns number of bytes remaining" do
84
84
  stream_length = io.num_bytes_remaining
85
85
 
86
86
  io.readbytes(4)
87
87
  io.num_bytes_remaining.should == stream_length - 4
88
88
  end
89
89
 
90
- it "should raise error when reading at eof" do
90
+ it "raises error when reading at eof" do
91
91
  io.seekbytes(10)
92
- lambda {
92
+ expect {
93
93
  io.readbytes(3)
94
- }.should raise_error(EOFError)
94
+ }.to raise_error(EOFError)
95
95
  end
96
96
 
97
- it "should raise error on short reads" do
98
- lambda {
97
+ it "raises error on short reads" do
98
+ expect {
99
99
  io.readbytes(20)
100
- }.should raise_error(IOError)
100
+ }.to raise_error(IOError)
101
101
  end
102
102
  end
103
103
 
@@ -105,23 +105,23 @@ describe BinData::IO, "when writing" do
105
105
  let(:stream) { StringIO.new }
106
106
  let(:io) { BinData::IO.new(stream) }
107
107
 
108
- it "should not wrap IO objects" do
108
+ it "does not wrap IO objects" do
109
109
  io.raw_io.should == stream
110
110
  end
111
111
 
112
- it "should raise error when io is BinData::IO" do
113
- lambda {
112
+ it "raises error when io is BinData::IO" do
113
+ expect {
114
114
  BinData::IO.new(BinData::IO.new(""))
115
- }.should raise_error(ArgumentError)
115
+ }.to raise_error(ArgumentError)
116
116
  end
117
117
 
118
- it "should write" do
118
+ it "writes correctly" do
119
119
  io.writebytes("abcd")
120
120
 
121
121
  stream.value.should == "abcd"
122
122
  end
123
123
 
124
- it "should flush" do
124
+ it "flushes" do
125
125
  io.writebytes("abcd")
126
126
  io.flush
127
127
 
@@ -135,40 +135,40 @@ describe BinData::IO, "reading bits in big endian" do
135
135
  let(:b3) { 0b0110_1010 }
136
136
  let(:io) { BinData::IO.new([b1, b2, b3].pack("CCC")) }
137
137
 
138
- it "should read a bitfield less than 1 byte" do
138
+ it "reads a bitfield less than 1 byte" do
139
139
  io.readbits(3, :big).should == 0b111
140
140
  end
141
141
 
142
- it "should read a bitfield more than 1 byte" do
142
+ it "reads a bitfield more than 1 byte" do
143
143
  io.readbits(10, :big).should == 0b1111_1010_11
144
144
  end
145
145
 
146
- it "should read a bitfield more than 2 bytes" do
146
+ it "reads a bitfield more than 2 bytes" do
147
147
  io.readbits(17, :big).should == 0b1111_1010_1100_1110_0
148
148
  end
149
149
 
150
- it "should read two bitfields totalling less than 1 byte" do
150
+ it "reads two bitfields totalling less than 1 byte" do
151
151
  io.readbits(5, :big).should == 0b1111_1
152
152
  io.readbits(2, :big).should == 0b01
153
153
  end
154
154
 
155
- it "should read two bitfields totalling more than 1 byte" do
155
+ it "reads two bitfields totalling more than 1 byte" do
156
156
  io.readbits(6, :big).should == 0b1111_10
157
157
  io.readbits(8, :big).should == 0b10_1100_11
158
158
  end
159
159
 
160
- it "should read two bitfields totalling more than 2 bytes" do
160
+ it "reads two bitfields totalling more than 2 bytes" do
161
161
  io.readbits(7, :big).should == 0b1111_101
162
162
  io.readbits(12, :big).should == 0b0_1100_1110_011
163
163
  end
164
164
 
165
- it "should ignore unused bits when reading bytes" do
165
+ it "ignores unused bits when reading bytes" do
166
166
  io.readbits(3, :big).should == 0b111
167
167
  io.readbytes(1).should == [b2].pack("C")
168
168
  io.readbits(2, :big).should == 0b01
169
169
  end
170
170
 
171
- it "should reset read bits to realign stream to next byte" do
171
+ it "resets read bits to realign stream to next byte" do
172
172
  io.readbits(3, :big).should == 0b111
173
173
  io.reset_read_bits
174
174
  io.readbits(3, :big).should == 0b110
@@ -181,40 +181,40 @@ describe BinData::IO, "reading bits in little endian" do
181
181
  let(:b3) { 0b0110_1010 }
182
182
  let(:io) { BinData::IO.new([b1, b2, b3].pack("CCC")) }
183
183
 
184
- it "should read a bitfield less than 1 byte" do
184
+ it "reads a bitfield less than 1 byte" do
185
185
  io.readbits(3, :little).should == 0b010
186
186
  end
187
187
 
188
- it "should read a bitfield more than 1 byte" do
188
+ it "reads a bitfield more than 1 byte" do
189
189
  io.readbits(10, :little).should == 0b10_1111_1010
190
190
  end
191
191
 
192
- it "should read a bitfield more than 2 bytes" do
192
+ it "reads a bitfield more than 2 bytes" do
193
193
  io.readbits(17, :little).should == 0b0_1100_1110_1111_1010
194
194
  end
195
195
 
196
- it "should read two bitfields totalling less than 1 byte" do
196
+ it "reads two bitfields totalling less than 1 byte" do
197
197
  io.readbits(5, :little).should == 0b1_1010
198
198
  io.readbits(2, :little).should == 0b11
199
199
  end
200
200
 
201
- it "should read two bitfields totalling more than 1 byte" do
201
+ it "reads two bitfields totalling more than 1 byte" do
202
202
  io.readbits(6, :little).should == 0b11_1010
203
203
  io.readbits(8, :little).should == 0b00_1110_11
204
204
  end
205
205
 
206
- it "should read two bitfields totalling more than 2 bytes" do
206
+ it "reads two bitfields totalling more than 2 bytes" do
207
207
  io.readbits(7, :little).should == 0b111_1010
208
208
  io.readbits(12, :little).should == 0b010_1100_1110_1
209
209
  end
210
210
 
211
- it "should ignore unused bits when reading bytes" do
211
+ it "ignores unused bits when reading bytes" do
212
212
  io.readbits(3, :little).should == 0b010
213
213
  io.readbytes(1).should == [b2].pack("C")
214
214
  io.readbits(2, :little).should == 0b10
215
215
  end
216
216
 
217
- it "should reset read bits to realign stream to next byte" do
217
+ it "resets read bits to realign stream to next byte" do
218
218
  io.readbits(3, :little).should == 0b010
219
219
  io.reset_read_bits
220
220
  io.readbits(3, :little).should == 0b110
@@ -245,40 +245,40 @@ end
245
245
  describe BinData::IO, "writing bits in big endian" do
246
246
  let(:io) { BitWriterHelper.new }
247
247
 
248
- it "should write a bitfield less than 1 byte" do
248
+ it "writes a bitfield less than 1 byte" do
249
249
  io.writebits(0b010, 3, :big)
250
250
  io.value.should == [0b0100_0000].pack("C")
251
251
  end
252
252
 
253
- it "should write a bitfield more than 1 byte" do
253
+ it "writes a bitfield more than 1 byte" do
254
254
  io.writebits(0b10_1001_1101, 10, :big)
255
255
  io.value.should == [0b1010_0111, 0b0100_0000].pack("CC")
256
256
  end
257
257
 
258
- it "should write a bitfield more than 2 bytes" do
258
+ it "writes a bitfield more than 2 bytes" do
259
259
  io.writebits(0b101_1000_0010_1001_1101, 19, :big)
260
260
  io.value.should == [0b1011_0000, 0b0101_0011, 0b1010_0000].pack("CCC")
261
261
  end
262
262
 
263
- it "should write two bitfields totalling less than 1 byte" do
263
+ it "writes two bitfields totalling less than 1 byte" do
264
264
  io.writebits(0b1_1001, 5, :big)
265
265
  io.writebits(0b00, 2, :big)
266
266
  io.value.should == [0b1100_1000].pack("C")
267
267
  end
268
268
 
269
- it "should write two bitfields totalling more than 1 byte" do
269
+ it "writes two bitfields totalling more than 1 byte" do
270
270
  io.writebits(0b01_0101, 6, :big)
271
271
  io.writebits(0b001_1001, 7, :big)
272
272
  io.value.should == [0b0101_0100, 0b1100_1000].pack("CC")
273
273
  end
274
274
 
275
- it "should write two bitfields totalling more than 2 bytes" do
275
+ it "writes two bitfields totalling more than 2 bytes" do
276
276
  io.writebits(0b01_0111, 6, :big)
277
277
  io.writebits(0b1_0010_1001_1001, 13, :big)
278
278
  io.value.should == [0b0101_1110, 0b0101_0011, 0b0010_0000].pack("CCC")
279
279
  end
280
280
 
281
- it "should pad unused bits when writing bytes" do
281
+ it "pads unused bits when writing bytes" do
282
282
  io.writebits(0b101, 3, :big)
283
283
  io.writebytes([0b1011_1111].pack("C"))
284
284
  io.writebits(0b01, 2, :big)
@@ -290,40 +290,40 @@ end
290
290
  describe BinData::IO, "writing bits in little endian" do
291
291
  let(:io) { BitWriterHelper.new }
292
292
 
293
- it "should write a bitfield less than 1 byte" do
293
+ it "writes a bitfield less than 1 byte" do
294
294
  io.writebits(0b010, 3, :little)
295
295
  io.value.should == [0b0000_0010].pack("C")
296
296
  end
297
297
 
298
- it "should write a bitfield more than 1 byte" do
298
+ it "writes a bitfield more than 1 byte" do
299
299
  io.writebits(0b10_1001_1101, 10, :little)
300
300
  io.value.should == [0b1001_1101, 0b0000_0010].pack("CC")
301
301
  end
302
302
 
303
- it "should write a bitfield more than 2 bytes" do
303
+ it "writes a bitfield more than 2 bytes" do
304
304
  io.writebits(0b101_1000_0010_1001_1101, 19, :little)
305
305
  io.value.should == [0b1001_1101, 0b1000_0010, 0b0000_0101].pack("CCC")
306
306
  end
307
307
 
308
- it "should write two bitfields totalling less than 1 byte" do
308
+ it "writes two bitfields totalling less than 1 byte" do
309
309
  io.writebits(0b1_1001, 5, :little)
310
310
  io.writebits(0b00, 2, :little)
311
311
  io.value.should == [0b0001_1001].pack("C")
312
312
  end
313
313
 
314
- it "should write two bitfields totalling more than 1 byte" do
314
+ it "writes two bitfields totalling more than 1 byte" do
315
315
  io.writebits(0b01_0101, 6, :little)
316
316
  io.writebits(0b001_1001, 7, :little)
317
317
  io.value.should == [0b0101_0101, 0b0000_0110].pack("CC")
318
318
  end
319
319
 
320
- it "should write two bitfields totalling more than 2 bytes" do
320
+ it "writes two bitfields totalling more than 2 bytes" do
321
321
  io.writebits(0b01_0111, 6, :little)
322
322
  io.writebits(0b1_0010_1001_1001, 13, :little)
323
323
  io.value.should == [0b0101_0111, 0b1010_0110, 0b0000_0100].pack("CCC")
324
324
  end
325
325
 
326
- it "should pad unused bits when writing bytes" do
326
+ it "pads unused bits when writing bytes" do
327
327
  io.writebits(0b101, 3, :little)
328
328
  io.writebytes([0b1011_1111].pack("C"))
329
329
  io.writebits(0b01, 2, :little)
@@ -333,7 +333,7 @@ describe BinData::IO, "writing bits in little endian" do
333
333
  end
334
334
 
335
335
  describe BinData::IO, "with changing endian" do
336
- it "should not mix different endianess when reading" do
336
+ it "does not mix different endianess when reading" do
337
337
  b1 = 0b0110_1010
338
338
  b2 = 0b1110_0010
339
339
  str = [b1, b2].pack("CC")
@@ -343,7 +343,7 @@ describe BinData::IO, "with changing endian" do
343
343
  io.readbits(4, :little).should == 0b0010
344
344
  end
345
345
 
346
- it "should not mix different endianess when writing" do
346
+ it "does not mix different endianess when writing" do
347
347
  io = BitWriterHelper.new
348
348
  io.writebits(0b110, 3, :big)
349
349
  io.writebits(0b010, 3, :little)