bindata 0.11.1 → 1.0.0

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.

@@ -15,7 +15,7 @@ describe BinData::Array, "when instantiating" do
15
15
 
16
16
  it "should fail if a given type is unknown" do
17
17
  args = {:type => :does_not_exist, :initial_length => 3}
18
- lambda { BinData::Array.new(args) }.should raise_error(TypeError)
18
+ lambda { BinData::Array.new(args) }.should raise_error(BinData::UnknownTypeError)
19
19
  end
20
20
 
21
21
  it "should not allow both :initial_length and :read_until" do
@@ -36,10 +36,10 @@ describe BinData::BasePrimitive do
36
36
  end
37
37
 
38
38
  it "should conform to rule 2 for returning a value" do
39
- io = StringIO.new([42].pack("V"))
39
+ io = BinData::IO.new([42].pack("V"))
40
40
  data = ExampleSingle.new(:value => 5)
41
41
  data.expose_methods_for_testing
42
- data.do_read(BinData::IO.new(io))
42
+ data.do_read(io)
43
43
  data.should be_in_read
44
44
  data.value.should == 42
45
45
  end
@@ -218,14 +218,14 @@ describe BinData::BasePrimitive, "with :value" do
218
218
  end
219
219
 
220
220
  it "should change during reading" do
221
- io = StringIO.new([56].pack("V"))
222
- @data.do_read(BinData::IO.new(io))
221
+ io = BinData::IO.new([56].pack("V"))
222
+ @data.do_read(io)
223
223
  @data.value.should == 56
224
224
  @data.done_read
225
225
  end
226
226
 
227
227
  it "should not change after reading" do
228
- io = StringIO.new([56].pack("V"))
228
+ io = BinData::IO.new([56].pack("V"))
229
229
  @data.read(io)
230
230
  @data.value.should == 5
231
231
  end
@@ -238,7 +238,7 @@ end
238
238
 
239
239
  describe BinData::BasePrimitive, "with :check_value" do
240
240
  before(:each) do
241
- @io = StringIO.new([34].pack("V"))
241
+ @io = BinData::IO.new([34].pack("V"))
242
242
  end
243
243
 
244
244
  it "should succeed when check_value is non boolean and correct" do
@@ -10,7 +10,7 @@ class BaseStub < BinData::Base
10
10
  def _do_read(io) end
11
11
  def _done_read; end
12
12
  def _do_write(io) end
13
- def _do_num_bytes(x) end
13
+ def _do_num_bytes; end
14
14
  def _assign(x); end
15
15
  def _snapshot; end
16
16
 
@@ -24,7 +24,7 @@ class MockBaseStub < BaseStub
24
24
  def _do_read(io) mock._do_read(io); end
25
25
  def _done_read; mock._done_read; end
26
26
  def _do_write(io) mock._do_write(io); end
27
- def _do_num_bytes(x) mock._do_num_bytes(x) end
27
+ def _do_num_bytes; mock._do_num_bytes; end
28
28
  def _assign(x); mock._assign(x); end
29
29
  def _snapshot; mock._snapshot; end
30
30
  end
@@ -42,12 +42,10 @@ describe BinData::Base, "when subclassing" do
42
42
  lambda { @obj.clear }.should raise_error(NotImplementedError)
43
43
  lambda { @obj.clear? }.should raise_error(NotImplementedError)
44
44
  lambda { @obj.assign(nil) }.should raise_error(NotImplementedError)
45
- lambda { @obj.debug_name_of(nil) }.should raise_error(NotImplementedError)
46
- lambda { @obj.offset_of(nil) }.should raise_error(NotImplementedError)
47
45
  lambda { @obj._do_read(nil) }.should raise_error(NotImplementedError)
48
46
  lambda { @obj._done_read }.should raise_error(NotImplementedError)
49
47
  lambda { @obj._do_write(nil) }.should raise_error(NotImplementedError)
50
- lambda { @obj._do_num_bytes(nil) }.should raise_error(NotImplementedError)
48
+ lambda { @obj._do_num_bytes }.should raise_error(NotImplementedError)
51
49
  lambda { @obj._snapshot }.should raise_error(NotImplementedError)
52
50
  end
53
51
  end
@@ -168,27 +166,6 @@ describe BinData::Base, "with multiple parameters" do
168
166
  lambda { WithParamBase.new(:p1 => 1, :p2 => nil) }.should raise_error(ArgumentError)
169
167
  end
170
168
 
171
- =begin
172
- # TODO: how should we evaluate internal parameters? think about this
173
- it "should only recall mandatory, default and optional parameters" do
174
- obj = WithParamBase.new(:p1 => 1, :p3 => 3, :p4 => 4, :p5 => 5)
175
- obj.should have_param(:p1)
176
- obj.should_not have_param(:p2)
177
- obj.should have_param(:p3)
178
- obj.should_not have_param(:p4)
179
- obj.should_not have_param(:p5)
180
- end
181
-
182
- it "should evaluate mandatory, default and optional parameters" do
183
- obj = WithParamBase.new(:p1 => 1, :p3 => lambda {1 + 2}, :p4 => 4, :p5 => 5)
184
- obj.eval_parameter(:p1).should == 1
185
- obj.eval_parameter(:p2).should be_nil
186
- obj.eval_parameter(:p3).should == 3
187
- obj.eval_parameter(:p4).should be_nil
188
- obj.eval_parameter(:p5).should be_nil
189
- end
190
- =end
191
-
192
169
  it "should be able to access without evaluating" do
193
170
  obj = WithParamBase.new(:p1 => :asym, :p3 => lambda {1 + 2})
194
171
  obj.get_parameter(:p1).should == :asym
@@ -207,7 +184,7 @@ describe BinData::Base, "with :check_offset" do
207
184
  end
208
185
 
209
186
  before(:each) do
210
- @io = StringIO.new("12345678901234567890")
187
+ @io = BinData::IO.create_string_io("12345678901234567890")
211
188
  end
212
189
 
213
190
  it "should fail if offset is incorrect" do
@@ -245,7 +222,7 @@ describe BinData::Base, "with :adjust_offset" do
245
222
  end
246
223
 
247
224
  before(:each) do
248
- @io = StringIO.new("12345678901234567890")
225
+ @io = BinData::IO.create_string_io("12345678901234567890")
249
226
  end
250
227
 
251
228
  it "should be mutually exclusive with :check_offset" do
@@ -317,7 +294,7 @@ describe BinData::Base, "as black box" do
317
294
  end
318
295
 
319
296
  obj = WriteToSBase.new
320
- io = StringIO.new
297
+ io = BinData::IO.create_string_io
321
298
  obj.write(io)
322
299
  io.rewind
323
300
  written = io.read
@@ -20,12 +20,12 @@ describe BinData::Choice, "when instantiating" do
20
20
 
21
21
  it "should fail if a given type is unknown" do
22
22
  args = {:choices => [:does_not_exist], :selection => 0}
23
- lambda { BinData::Choice.new(args) }.should raise_error(TypeError)
23
+ lambda { BinData::Choice.new(args) }.should raise_error(BinData::UnknownTypeError)
24
24
  end
25
25
 
26
26
  it "should fail if a given type is unknown" do
27
27
  args = {:choices => {0 => :does_not_exist}, :selection => 0}
28
- lambda { BinData::Choice.new(args) }.should raise_error(TypeError)
28
+ lambda { BinData::Choice.new(args) }.should raise_error(BinData::UnknownTypeError)
29
29
  end
30
30
 
31
31
  it "should fail if :choices Hash has a symbol as key" do
@@ -5,88 +5,19 @@ require File.expand_path(File.join(File.dirname(__FILE__), "example"))
5
5
  require 'bindata'
6
6
 
7
7
  describe BinData::SingleValue, "when defining" do
8
- it "should allow inheriting from deprecated SingleValue" do
8
+ it "should fail when inheriting from deprecated SingleValue" do
9
9
  lambda {
10
10
  class SubclassSingleValue < BinData::SingleValue
11
11
  end
12
- }.should_not raise_error
12
+ }.should raise_error
13
13
  end
14
14
  end
15
15
 
16
16
  describe BinData::MultiValue, "when defining" do
17
- it "should allow inheriting from deprecated MultiValue" do
17
+ it "should fail inheriting from deprecated MultiValue" do
18
18
  lambda {
19
19
  class SubclassMultiValue < BinData::MultiValue
20
20
  end
21
- }.should_not raise_error
22
- end
23
- end
24
-
25
- describe BinData::Array, "with several elements" do
26
- before(:each) do
27
- type = [:example_single, {:initial_value => lambda { index + 1 }}]
28
- @data = BinData::Array.new(:type => type, :initial_length => 5)
29
- end
30
-
31
- it "should clear a single element" do
32
- @data[1] = 8
33
- @data.clear(1)
34
- @data[1].should == 2
35
- end
36
-
37
- it "should test clear status of individual elements" do
38
- @data[1] = 8
39
- @data.clear?(0).should be_true
40
- @data.clear?(1).should be_false
41
- end
42
-
43
- it "should have correct num_bytes for individual elements" do
44
- @data.num_bytes(0).should == ExampleSingle.new.num_bytes
45
- end
46
-
47
- it "should not extend on clear" do
48
- @data.clear(9)
49
- @data.length.should == 5
50
- end
51
-
52
- it "should not extend on clear?" do
53
- @data.clear?(9).should be_true
54
- @data.length.should == 5
55
- end
56
-
57
- it "should not extend on num_bytes" do
58
- @data.num_bytes(9).should == 0
59
- @data.length.should == 5
60
- end
61
- end
62
-
63
- describe BinData::String, "with deprecated parameters" do
64
- it "should substitude :trim_padding for :trim_value" do
65
- obj = BinData::String.new(:trim_value => true)
66
- obj.value = "abc\0"
67
- obj.value.should == "abc"
68
- end
69
- end
70
-
71
- describe BinData::Struct, "with multiple fields" do
72
- before(:each) do
73
- @params = { :fields => [ [:int8, :a], [:int8, :b] ] }
74
- @obj = BinData::Struct.new(@params)
75
- @obj.a = 1
76
- @obj.b = 2
77
- end
78
-
79
- it "should return num_bytes" do
80
- @obj.num_bytes(:a).should == 1
81
- @obj.num_bytes(:b).should == 1
82
- @obj.num_bytes.should == 2
83
- end
84
-
85
- it "should clear individual elements" do
86
- @obj.a = 6
87
- @obj.b = 7
88
- @obj.clear(:a)
89
- @obj.should be_clear(:a)
90
- @obj.should_not be_clear(:b)
21
+ }.should raise_error
91
22
  end
92
23
  end
@@ -172,7 +172,7 @@ end
172
172
 
173
173
  class BitWriterHelper
174
174
  def initialize
175
- @stringio = StringIO.new
175
+ @stringio = BinData::IO.create_string_io
176
176
  @io = BinData::IO.new(@stringio)
177
177
  end
178
178
 
@@ -3,48 +3,71 @@
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), "spec_common"))
4
4
  require 'bindata'
5
5
 
6
+ def capture_exception(exception_type, &block)
7
+ block.call
8
+ rescue Exception => err
9
+ err.class.should == exception_type
10
+ return err
11
+ else
12
+ lambda {}.should raise_error(exception_type)
13
+ end
14
+
6
15
  describe BinData::Record, "when defining" do
7
16
  it "should fail on non registered types" do
8
- lambda {
17
+ err = capture_exception(TypeError) {
9
18
  class BadTypeRecord < BinData::Record
10
- non_registerd_type :a
19
+ non_registered_type :a
11
20
  end
12
- }.should raise_error(TypeError)
21
+ }
22
+ err.message.should == "unknown type 'non_registered_type' for #{BadTypeRecord}"
23
+ end
24
+
25
+ it "should give correct error message for non registered nested types" do
26
+ err = capture_exception(TypeError) {
27
+ class BadNestedTypeRecord < BinData::Record
28
+ array :a, :type => :non_registered_type
29
+ end
30
+ }
31
+ err.message.should == "unknown type 'non_registered_type' for #{BadNestedTypeRecord}"
13
32
  end
14
33
 
15
34
  it "should fail on duplicate names" do
16
- lambda {
35
+ err = capture_exception(SyntaxError) {
17
36
  class DuplicateNameRecord < BinData::Record
18
37
  int8 :a
19
38
  int8 :b
20
39
  int8 :a
21
40
  end
22
- }.should raise_error(SyntaxError)
41
+ }
42
+ err.message.should == "duplicate field 'a' in #{DuplicateNameRecord}"
23
43
  end
24
44
 
25
45
  it "should fail on reserved names" do
26
- lambda {
46
+ err = capture_exception(NameError) {
27
47
  class ReservedNameRecord < BinData::Record
28
48
  int8 :a
29
49
  int8 :invert # from Hash.instance_methods
30
50
  end
31
- }.should raise_error(NameError)
51
+ }
52
+ err.message.should == "field 'invert' is a reserved name in #{ReservedNameRecord}"
32
53
  end
33
54
 
34
55
  it "should fail when field name shadows an existing method" do
35
- lambda {
56
+ err = capture_exception(NameError) {
36
57
  class ExistingNameRecord < BinData::Record
37
58
  int8 :object_id
38
59
  end
39
- }.should raise_error(NameError)
60
+ }
61
+ err.message.should == "field 'object_id' shadows an existing method in #{ExistingNameRecord}"
40
62
  end
41
63
 
42
64
  it "should fail on unknown endian" do
43
- lambda {
65
+ err = capture_exception(ArgumentError) {
44
66
  class BadEndianRecord < BinData::Record
45
67
  endian 'a bad value'
46
68
  end
47
- }.should raise_error(ArgumentError)
69
+ }
70
+ err.message.should == "unknown value for endian 'a bad value' in #{BadEndianRecord}"
48
71
  end
49
72
  end
50
73
 
@@ -176,11 +199,20 @@ describe BinData::Record, "with nested structs" do
176
199
  end
177
200
 
178
201
  it "should return correct offset" do
202
+ @obj.offset.should == 0
179
203
  @obj.b.offset.should == 1
180
204
  @obj.b.w.offset.should == 1
181
205
  @obj.c.offset.should == 3
182
206
  @obj.c.z.offset.should == 4
183
207
  end
208
+
209
+ it "should return correct rel_offset" do
210
+ @obj.rel_offset.should == 0
211
+ @obj.b.rel_offset.should == 1
212
+ @obj.b.w.rel_offset.should == 0
213
+ @obj.c.rel_offset.should == 3
214
+ @obj.c.z.rel_offset.should == 1
215
+ end
184
216
  end
185
217
 
186
218
  describe BinData::Record, "with an endian defined" do
@@ -8,7 +8,7 @@ describe BinData::Struct, "when initializing" do
8
8
  params = {:fields => [[:non_registered_type, :a]]}
9
9
  lambda {
10
10
  BinData::Struct.new(params)
11
- }.should raise_error(TypeError)
11
+ }.should raise_error(BinData::UnknownTypeError)
12
12
  end
13
13
 
14
14
  it "should fail on duplicate names" do
@@ -0,0 +1,36 @@
1
+ load_failed = false
2
+
3
+ begin
4
+ require 'haml'
5
+ rescue LoadError
6
+ puts "Haml must be installed to build documentation"
7
+ load_failed = true
8
+ end
9
+
10
+ begin
11
+ require 'maruku'
12
+ rescue LoadError
13
+ puts "Maruku must be installed to build documentation"
14
+ load_failed = true
15
+ end
16
+
17
+ begin
18
+ require 'syntax'
19
+ rescue LoadError
20
+ puts "Syntax must be installed to build documentation"
21
+ load_failed = true
22
+ end
23
+
24
+ unless load_failed
25
+ file "manual.html" => ["README", "manual.haml"] do |t|
26
+ require 'haml/exec'
27
+
28
+ opts = Haml::Exec::Haml.new(["manual.haml", "manual.html"])
29
+ opts.parse!
30
+ end
31
+
32
+ CLOBBER.include("manual.html")
33
+
34
+ desc "Build the reference manual"
35
+ task :manual => "manual.html"
36
+ end
@@ -13,8 +13,8 @@ begin
13
13
  s.rubyforge_project = 'bindata'
14
14
  s.require_path = 'lib'
15
15
  s.has_rdoc = true
16
- s.extra_rdoc_files = ['README']
17
- s.rdoc_options << '--main' << 'README'
16
+ s.extra_rdoc_files = ['NEWS']
17
+ s.rdoc_options << '--main' << 'NEWS'
18
18
  s.files = PKG_FILES
19
19
  end
20
20
 
@@ -1,8 +1,8 @@
1
1
  require 'rake/rdoctask'
2
2
 
3
3
  Rake::RDocTask.new() do |rdoc|
4
- rdoc.main = "README"
5
- rdoc.rdoc_files.include("README", "NEWS")
4
+ rdoc.main = "NEWS"
5
+ rdoc.rdoc_files.include("NEWS")
6
6
  rdoc.rdoc_files.include("lib/**/*.rb")
7
7
  end
8
8
 
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.1
4
+ version: 1.0.0
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-08-29 00:00:00 +08:00
12
+ date: 2009-09-13 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -20,10 +20,9 @@ executables: []
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README
23
+ - NEWS
24
24
  files:
25
25
  - INSTALL
26
- - TUTORIAL
27
26
  - TODO
28
27
  - GPL
29
28
  - Rakefile
@@ -32,6 +31,7 @@ files:
32
31
  - README
33
32
  - ChangeLog
34
33
  - examples/gzip.rb
34
+ - examples/ip_address.rb
35
35
  - spec/primitive_spec.rb
36
36
  - spec/record_spec.rb
37
37
  - spec/float_spec.rb
@@ -76,15 +76,17 @@ files:
76
76
  - lib/bindata/wrapper.rb
77
77
  - lib/bindata.rb
78
78
  - tasks/rdoc.rake
79
+ - tasks/manual.rake
79
80
  - tasks/pkg.rake
80
81
  - tasks/rspec.rake
81
82
  - setup.rb
83
+ - manual.haml
82
84
  has_rdoc: true
83
85
  homepage: http://bindata.rubyforge.org
84
86
  post_install_message:
85
87
  rdoc_options:
86
88
  - --main
87
- - README
89
+ - NEWS
88
90
  require_paths:
89
91
  - lib
90
92
  required_ruby_version: !ruby/object:Gem::Requirement