bindata 0.9.0 → 0.9.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.

data/spec/single_spec.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require File.expand_path(File.dirname(__FILE__)) + '/spec_common'
4
+ require 'bindata/io'
4
5
  require 'bindata/single'
5
6
 
6
7
  # An implementation of a unsigned 4 byte integer.
7
8
  class ConcreteSingle < BinData::Single
8
9
  def val_to_str(val) [val].pack("V") end
9
- def read_val(io) readbytes(io, 4).unpack("V")[0] end
10
+ def read_val(io) io.readbytes(4).unpack("V")[0] end
10
11
  def sensible_default() 0 end
11
12
 
12
13
  def in_read?() @in_read end
@@ -22,7 +23,7 @@ describe BinData::Single do
22
23
  it "should conform to rule 2 for returning a value" do
23
24
  io = StringIO.new([42].pack("V"))
24
25
  data = ConcreteSingle.new(:value => 5)
25
- data.do_read(io)
26
+ data.do_read(BinData::IO.new(io))
26
27
  data.should be_in_read
27
28
  data.value.should == 42
28
29
  end
@@ -159,7 +160,7 @@ describe BinData::Single, "with :value" do
159
160
 
160
161
  it "should change during reading" do
161
162
  io = StringIO.new([56].pack("V"))
162
- @data.do_read(io)
163
+ @data.do_read(BinData::IO.new(io))
163
164
  @data.value.should == 56
164
165
  @data.done_read
165
166
  end
data/spec/string_spec.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require File.expand_path(File.dirname(__FILE__)) + '/spec_common'
4
+ require 'bindata/io'
4
5
  require 'bindata/string'
5
6
 
6
7
  describe BinData::String, "with mutually exclusive parameters" do
@@ -146,7 +147,7 @@ describe BinData::String, "with :read_length and :value" do
146
147
  it "should return read value before calling done_read" do
147
148
  io = StringIO.new("ABCDEFGHIJKLMNOPQRST")
148
149
 
149
- @str.do_read(io)
150
+ @str.do_read(BinData::IO.new(io))
150
151
  @str.value.should == "ABCDE"
151
152
 
152
153
  @str.done_read
data/spec/struct_spec.rb CHANGED
@@ -254,3 +254,28 @@ describe BinData::Struct, "with an endian defined" do
254
254
  io.read.should == expected
255
255
  end
256
256
  end
257
+
258
+ describe BinData::Struct, "with bit fields" do
259
+ before(:each) do
260
+ @params = { :fields => [ [:bit1le, :a], [:bit2le, :b] ] }
261
+ @obj = BinData::Struct.new(@params)
262
+ @obj.a = 1
263
+ @obj.b = 2
264
+ end
265
+
266
+ it "should return num_bytes" do
267
+ @obj.num_bytes.should == 1
268
+ end
269
+
270
+ it "should write" do
271
+ @obj.to_s.should == [0b0000_0101].pack("C")
272
+ end
273
+
274
+ it "should read" do
275
+ str = [0b0000_0110].pack("C")
276
+ @obj.read(str)
277
+ @obj.a.should == 0
278
+ @obj.b.should == 3
279
+ end
280
+ end
281
+
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.0
7
- date: 2008-06-02 00:00:00 +08:00
6
+ version: 0.9.1
7
+ date: 2008-06-15 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
@@ -37,6 +37,7 @@ files:
37
37
  - README
38
38
  - examples/gzip.rb
39
39
  - spec/registry_spec.rb
40
+ - spec/bits_spec.rb
40
41
  - spec/sanitize_spec.rb
41
42
  - spec/array_spec.rb
42
43
  - spec/float_spec.rb
@@ -51,11 +52,13 @@ files:
51
52
  - spec/base_spec.rb
52
53
  - spec/single_value_spec.rb
53
54
  - spec/int_spec.rb
55
+ - spec/io_spec.rb
54
56
  - spec/stringz_spec.rb
55
57
  - lib/bindata.rb
56
58
  - lib/bindata
57
59
  - lib/bindata/lazy.rb
58
60
  - lib/bindata/sanitize.rb
61
+ - lib/bindata/io.rb
59
62
  - lib/bindata/string.rb
60
63
  - lib/bindata/int.rb
61
64
  - lib/bindata/multi_value.rb
@@ -68,6 +71,7 @@ files:
68
71
  - lib/bindata/single.rb
69
72
  - lib/bindata/base.rb
70
73
  - lib/bindata/array.rb
74
+ - lib/bindata/bits.rb
71
75
  - lib/bindata/float.rb
72
76
  test_files: []
73
77