bindata 1.4.3 → 1.4.4
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.
- data/BSDL +1 -1
 - data/ChangeLog +8 -0
 - data/NEWS +7 -0
 - data/lib/bindata.rb +3 -3
 - data/lib/bindata/base.rb +7 -0
 - data/lib/bindata/base_primitive.rb +2 -2
 - data/lib/bindata/choice.rb +4 -0
 - data/lib/bindata/io.rb +1 -1
 - data/lib/bindata/lazy.rb +2 -2
 - data/lib/bindata/sanitize.rb +9 -0
 - data/lib/bindata/string.rb +33 -16
 - data/manual.haml +55 -53
 - data/manual.md +346 -253
 - data/spec/alignment_spec.rb +7 -7
 - data/spec/array_spec.rb +67 -66
 - data/spec/base_primitive_spec.rb +47 -49
 - data/spec/base_spec.rb +70 -73
 - data/spec/bits_spec.rb +14 -14
 - data/spec/choice_spec.rb +44 -41
 - data/spec/count_bytes_remaining_spec.rb +8 -11
 - data/spec/deprecated_spec.rb +29 -29
 - data/spec/float_spec.rb +12 -12
 - data/spec/int_spec.rb +24 -24
 - data/spec/io_spec.rb +56 -56
 - data/spec/lazy_spec.rb +41 -39
 - data/spec/primitive_spec.rb +31 -33
 - data/spec/record_spec.rb +55 -57
 - data/spec/registry_spec.rb +25 -25
 - data/spec/rest_spec.rb +5 -5
 - data/spec/skip_spec.rb +3 -3
 - data/spec/spec_common.rb +2 -2
 - data/spec/string_spec.rb +38 -38
 - data/spec/stringz_spec.rb +18 -18
 - data/spec/struct_spec.rb +48 -48
 - data/spec/system_spec.rb +38 -37
 - data/spec/wrapper_spec.rb +21 -23
 - data/tasks/pkg.rake +3 -3
 - data/tasks/rdoc.rake +1 -1
 - data/tasks/rspec.rake +7 -7
 - metadata +51 -53
 
    
        data/spec/choice_spec.rb
    CHANGED
    
    | 
         @@ -3,6 +3,7 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require File.expand_path(File.join(File.dirname(__FILE__), "spec_common"))
         
     | 
| 
       4 
4 
     | 
    
         
             
            require File.expand_path(File.join(File.dirname(__FILE__), "example"))
         
     | 
| 
       5 
5 
     | 
    
         
             
            require 'bindata/choice'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'bindata/int'
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
8 
     | 
    
         
             
            class Chooser
         
     | 
| 
       8 
9 
     | 
    
         
             
              attr_accessor :choice
         
     | 
| 
         @@ -26,89 +27,91 @@ def create_choice(choices, options = {}) 
     | 
|
| 
       26 
27 
     | 
    
         
             
            end
         
     | 
| 
       27 
28 
     | 
    
         | 
| 
       28 
29 
     | 
    
         
             
            describe BinData::Choice, "when instantiating" do
         
     | 
| 
       29 
     | 
    
         
            -
              it " 
     | 
| 
      
 30 
     | 
    
         
            +
              it "ensures mandatory parameters are supplied" do
         
     | 
| 
       30 
31 
     | 
    
         
             
                args = {}
         
     | 
| 
       31 
     | 
    
         
            -
                 
     | 
| 
      
 32 
     | 
    
         
            +
                expect { BinData::Choice.new(args) }.to raise_error(ArgumentError)
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
       32 
34 
     | 
    
         
             
                args = {:selection => 1}
         
     | 
| 
       33 
     | 
    
         
            -
                 
     | 
| 
      
 35 
     | 
    
         
            +
                expect { BinData::Choice.new(args) }.to raise_error(ArgumentError)
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
       34 
37 
     | 
    
         
             
                args = {:choices => []}
         
     | 
| 
       35 
     | 
    
         
            -
                 
     | 
| 
      
 38 
     | 
    
         
            +
                expect { BinData::Choice.new(args) }.to raise_error(ArgumentError)
         
     | 
| 
       36 
39 
     | 
    
         
             
              end
         
     | 
| 
       37 
40 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
              it " 
     | 
| 
      
 41 
     | 
    
         
            +
              it "fails when a given type is unknown" do
         
     | 
| 
       39 
42 
     | 
    
         
             
                args = {:choices => [:does_not_exist], :selection => 0}
         
     | 
| 
       40 
     | 
    
         
            -
                 
     | 
| 
      
 43 
     | 
    
         
            +
                expect { BinData::Choice.new(args) }.to raise_error(BinData::UnRegisteredTypeError)
         
     | 
| 
       41 
44 
     | 
    
         
             
              end
         
     | 
| 
       42 
45 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
              it " 
     | 
| 
      
 46 
     | 
    
         
            +
              it "fails when a given type is unknown" do
         
     | 
| 
       44 
47 
     | 
    
         
             
                args = {:choices => {0 => :does_not_exist}, :selection => 0}
         
     | 
| 
       45 
     | 
    
         
            -
                 
     | 
| 
      
 48 
     | 
    
         
            +
                expect { BinData::Choice.new(args) }.to raise_error(BinData::UnRegisteredTypeError)
         
     | 
| 
       46 
49 
     | 
    
         
             
              end
         
     | 
| 
       47 
50 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
              it " 
     | 
| 
      
 51 
     | 
    
         
            +
              it "fails when :choices Hash has a symbol as key" do
         
     | 
| 
       49 
52 
     | 
    
         
             
                args = {:choices => {:a => :example_single}, :selection => 0}
         
     | 
| 
       50 
     | 
    
         
            -
                 
     | 
| 
      
 53 
     | 
    
         
            +
                expect { BinData::Choice.new(args) }.to raise_error(ArgumentError)
         
     | 
| 
       51 
54 
     | 
    
         
             
              end
         
     | 
| 
       52 
55 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
              it " 
     | 
| 
      
 56 
     | 
    
         
            +
              it "fails when :choices Hash has a nil key" do
         
     | 
| 
       54 
57 
     | 
    
         
             
                args = {:choices => {nil => :example_single}, :selection => 0}
         
     | 
| 
       55 
     | 
    
         
            -
                 
     | 
| 
      
 58 
     | 
    
         
            +
                expect { BinData::Choice.new(args) }.to raise_error(ArgumentError)
         
     | 
| 
       56 
59 
     | 
    
         
             
              end
         
     | 
| 
       57 
60 
     | 
    
         
             
            end
         
     | 
| 
       58 
61 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
              it " 
     | 
| 
      
 62 
     | 
    
         
            +
            shared_examples "Choice initialized with array or hash" do
         
     | 
| 
      
 63 
     | 
    
         
            +
              it "can select the choice" do
         
     | 
| 
       61 
64 
     | 
    
         
             
                subject.choice = 3
         
     | 
| 
       62 
65 
     | 
    
         
             
                subject.should == 30
         
     | 
| 
       63 
66 
     | 
    
         
             
              end
         
     | 
| 
       64 
67 
     | 
    
         | 
| 
       65 
     | 
    
         
            -
              it " 
     | 
| 
      
 68 
     | 
    
         
            +
              it "shows the current selection" do
         
     | 
| 
       66 
69 
     | 
    
         
             
                subject.choice = 3
         
     | 
| 
       67 
70 
     | 
    
         
             
                subject.selection.should == 3
         
     | 
| 
       68 
71 
     | 
    
         
             
              end
         
     | 
| 
       69 
72 
     | 
    
         | 
| 
       70 
     | 
    
         
            -
              it " 
     | 
| 
      
 73 
     | 
    
         
            +
              it "forwards #snapshot" do
         
     | 
| 
       71 
74 
     | 
    
         
             
                subject.choice = 3
         
     | 
| 
       72 
75 
     | 
    
         
             
                subject.snapshot.should == 30
         
     | 
| 
       73 
76 
     | 
    
         
             
              end
         
     | 
| 
       74 
77 
     | 
    
         | 
| 
       75 
     | 
    
         
            -
              it " 
     | 
| 
      
 78 
     | 
    
         
            +
              it "can change the choice" do
         
     | 
| 
       76 
79 
     | 
    
         
             
                subject.choice = 3
         
     | 
| 
       77 
80 
     | 
    
         | 
| 
       78 
81 
     | 
    
         
             
                subject.choice = 7
         
     | 
| 
       79 
82 
     | 
    
         
             
                subject.should == 70
         
     | 
| 
       80 
83 
     | 
    
         
             
              end
         
     | 
| 
       81 
84 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
              it " 
     | 
| 
       83 
     | 
    
         
            -
                 
     | 
| 
      
 85 
     | 
    
         
            +
              it "fails if no choice has been set" do
         
     | 
| 
      
 86 
     | 
    
         
            +
                expect { subject.to_s }.to raise_error(IndexError)
         
     | 
| 
       84 
87 
     | 
    
         
             
              end
         
     | 
| 
       85 
88 
     | 
    
         | 
| 
       86 
     | 
    
         
            -
              it " 
     | 
| 
      
 89 
     | 
    
         
            +
              it "will not select an invalid choice" do
         
     | 
| 
       87 
90 
     | 
    
         
             
                subject.choice = 99
         
     | 
| 
       88 
     | 
    
         
            -
                 
     | 
| 
      
 91 
     | 
    
         
            +
                expect { subject.to_s }.to raise_error(IndexError)
         
     | 
| 
       89 
92 
     | 
    
         
             
              end
         
     | 
| 
       90 
93 
     | 
    
         | 
| 
       91 
     | 
    
         
            -
              it " 
     | 
| 
      
 94 
     | 
    
         
            +
              it "will not select a nil choice" do
         
     | 
| 
       92 
95 
     | 
    
         
             
                subject.choice = 1
         
     | 
| 
       93 
     | 
    
         
            -
                 
     | 
| 
      
 96 
     | 
    
         
            +
                expect { subject.to_s }.to raise_error(IndexError)
         
     | 
| 
       94 
97 
     | 
    
         
             
              end
         
     | 
| 
       95 
98 
     | 
    
         | 
| 
       96 
     | 
    
         
            -
              it " 
     | 
| 
      
 99 
     | 
    
         
            +
              it "handles missing methods correctly" do
         
     | 
| 
       97 
100 
     | 
    
         
             
                subject.choice = 3
         
     | 
| 
       98 
101 
     | 
    
         | 
| 
       99 
102 
     | 
    
         
             
                subject.should respond_to(:value)
         
     | 
| 
       100 
103 
     | 
    
         
             
                subject.should_not respond_to(:does_not_exist)
         
     | 
| 
       101 
     | 
    
         
            -
                 
     | 
| 
      
 104 
     | 
    
         
            +
                expect { subject.does_not_exist }.to raise_error(NoMethodError)
         
     | 
| 
       102 
105 
     | 
    
         
             
              end
         
     | 
| 
       103 
106 
     | 
    
         | 
| 
       104 
     | 
    
         
            -
              it " 
     | 
| 
      
 107 
     | 
    
         
            +
              it "delegates methods to the selected single choice" do
         
     | 
| 
       105 
108 
     | 
    
         
             
                subject.choice = 5
         
     | 
| 
       106 
109 
     | 
    
         
             
                subject.num_bytes.should == ExampleSingle.new.num_bytes
         
     | 
| 
       107 
110 
     | 
    
         
             
              end
         
     | 
| 
       108 
111 
     | 
    
         
             
            end
         
     | 
| 
       109 
112 
     | 
    
         | 
| 
       110 
113 
     | 
    
         
             
            describe BinData::Choice, "with sparse choices array" do
         
     | 
| 
       111 
     | 
    
         
            -
               
     | 
| 
      
 114 
     | 
    
         
            +
              include_examples "Choice initialized with array or hash"
         
     | 
| 
       112 
115 
     | 
    
         | 
| 
       113 
116 
     | 
    
         
             
              subject {
         
     | 
| 
       114 
117 
     | 
    
         
             
                choices = [nil, nil, nil,
         
     | 
| 
         @@ -120,7 +123,7 @@ describe BinData::Choice, "with sparse choices array" do 
     | 
|
| 
       120 
123 
     | 
    
         
             
            end
         
     | 
| 
       121 
124 
     | 
    
         | 
| 
       122 
125 
     | 
    
         
             
            describe BinData::Choice, "with choices hash" do
         
     | 
| 
       123 
     | 
    
         
            -
               
     | 
| 
      
 126 
     | 
    
         
            +
              include_examples "Choice initialized with array or hash"
         
     | 
| 
       124 
127 
     | 
    
         | 
| 
       125 
128 
     | 
    
         
             
              subject {
         
     | 
| 
       126 
129 
     | 
    
         
             
                choices = {3 => [:example_single, {:value => 30}],
         
     | 
| 
         @@ -138,13 +141,13 @@ describe BinData::Choice, "with single values" do 
     | 
|
| 
       138 
141 
     | 
    
         
             
                create_choice(choices)
         
     | 
| 
       139 
142 
     | 
    
         
             
              }
         
     | 
| 
       140 
143 
     | 
    
         | 
| 
       141 
     | 
    
         
            -
              it " 
     | 
| 
      
 144 
     | 
    
         
            +
              it "assigns raw values" do
         
     | 
| 
       142 
145 
     | 
    
         
             
                subject.choice = 3
         
     | 
| 
       143 
146 
     | 
    
         
             
                subject.assign(254)
         
     | 
| 
       144 
147 
     | 
    
         
             
                subject.should == 254
         
     | 
| 
       145 
148 
     | 
    
         
             
              end
         
     | 
| 
       146 
149 
     | 
    
         | 
| 
       147 
     | 
    
         
            -
              it " 
     | 
| 
      
 150 
     | 
    
         
            +
              it "assigns Single values" do
         
     | 
| 
       148 
151 
     | 
    
         
             
                obj = ExampleSingle.new(11)
         
     | 
| 
       149 
152 
     | 
    
         | 
| 
       150 
153 
     | 
    
         
             
                subject.choice = 3
         
     | 
| 
         @@ -152,7 +155,7 @@ describe BinData::Choice, "with single values" do 
     | 
|
| 
       152 
155 
     | 
    
         
             
                subject.should == 11
         
     | 
| 
       153 
156 
     | 
    
         
             
              end
         
     | 
| 
       154 
157 
     | 
    
         | 
| 
       155 
     | 
    
         
            -
              it " 
     | 
| 
      
 158 
     | 
    
         
            +
              it "clears" do
         
     | 
| 
       156 
159 
     | 
    
         
             
                subject.choice = 3
         
     | 
| 
       157 
160 
     | 
    
         
             
                subject.assign(254)
         
     | 
| 
       158 
161 
     | 
    
         | 
| 
         @@ -160,20 +163,20 @@ describe BinData::Choice, "with single values" do 
     | 
|
| 
       160 
163 
     | 
    
         
             
                subject.should be_zero
         
     | 
| 
       161 
164 
     | 
    
         
             
              end
         
     | 
| 
       162 
165 
     | 
    
         | 
| 
       163 
     | 
    
         
            -
              it " 
     | 
| 
      
 166 
     | 
    
         
            +
              it "is clear on initialisation" do
         
     | 
| 
       164 
167 
     | 
    
         
             
                subject.choice = 3
         
     | 
| 
       165 
168 
     | 
    
         | 
| 
       166 
169 
     | 
    
         
             
                subject.should be_clear
         
     | 
| 
       167 
170 
     | 
    
         
             
              end
         
     | 
| 
       168 
171 
     | 
    
         | 
| 
       169 
     | 
    
         
            -
              it " 
     | 
| 
      
 172 
     | 
    
         
            +
              it "is not clear after assignment" do
         
     | 
| 
       170 
173 
     | 
    
         
             
                subject.choice = 3
         
     | 
| 
       171 
174 
     | 
    
         
             
                subject.assign(254)
         
     | 
| 
       172 
175 
     | 
    
         | 
| 
       173 
176 
     | 
    
         
             
                subject.should_not be_clear
         
     | 
| 
       174 
177 
     | 
    
         
             
              end
         
     | 
| 
       175 
178 
     | 
    
         | 
| 
       176 
     | 
    
         
            -
              it " 
     | 
| 
      
 179 
     | 
    
         
            +
              it "does not copy value when changing selection" do
         
     | 
| 
       177 
180 
     | 
    
         
             
                subject.choice = 3
         
     | 
| 
       178 
181 
     | 
    
         
             
                subject.assign(254)
         
     | 
| 
       179 
182 
     | 
    
         | 
| 
         @@ -181,7 +184,7 @@ describe BinData::Choice, "with single values" do 
     | 
|
| 
       181 
184 
     | 
    
         
             
                subject.should_not == 254
         
     | 
| 
       182 
185 
     | 
    
         
             
              end
         
     | 
| 
       183 
186 
     | 
    
         | 
| 
       184 
     | 
    
         
            -
              it " 
     | 
| 
      
 187 
     | 
    
         
            +
              it "behaves as value" do
         
     | 
| 
       185 
188 
     | 
    
         
             
                subject.choice = 3
         
     | 
| 
       186 
189 
     | 
    
         
             
                subject.assign(5)
         
     | 
| 
       187 
190 
     | 
    
         | 
| 
         @@ -198,7 +201,7 @@ describe BinData::Choice, "with copy_on_change => true" do 
     | 
|
| 
       198 
201 
     | 
    
         
             
                create_choice(choices, :copy_on_change => true)
         
     | 
| 
       199 
202 
     | 
    
         
             
              }
         
     | 
| 
       200 
203 
     | 
    
         | 
| 
       201 
     | 
    
         
            -
              it " 
     | 
| 
      
 204 
     | 
    
         
            +
              it "copies value when changing selection" do
         
     | 
| 
       202 
205 
     | 
    
         
             
                subject.choice = 3
         
     | 
| 
       203 
206 
     | 
    
         
             
                subject.assign(254)
         
     | 
| 
       204 
207 
     | 
    
         | 
| 
         @@ -210,12 +213,12 @@ end 
     | 
|
| 
       210 
213 
     | 
    
         
             
            describe BinData::Choice, "with :default" do
         
     | 
| 
       211 
214 
     | 
    
         
             
              let(:choices) { { "a" => :int8, :default => :int16be } }
         
     | 
| 
       212 
215 
     | 
    
         | 
| 
       213 
     | 
    
         
            -
              it " 
     | 
| 
      
 216 
     | 
    
         
            +
              it "selects for existing case" do
         
     | 
| 
       214 
217 
     | 
    
         
             
                subject = BinData::Choice.new(:selection => "a", :choices => choices)
         
     | 
| 
       215 
218 
     | 
    
         
             
                subject.num_bytes.should == 1
         
     | 
| 
       216 
219 
     | 
    
         
             
              end
         
     | 
| 
       217 
220 
     | 
    
         | 
| 
       218 
     | 
    
         
            -
              it " 
     | 
| 
      
 221 
     | 
    
         
            +
              it "selects for default case" do
         
     | 
| 
       219 
222 
     | 
    
         
             
                subject = BinData::Choice.new(:selection => "other", :choices => choices)
         
     | 
| 
       220 
223 
     | 
    
         
             
                subject.num_bytes.should == 2
         
     | 
| 
       221 
224 
     | 
    
         
             
              end
         
     | 
| 
         @@ -231,17 +234,17 @@ describe BinData::Choice, "subclassed with default parameters" do 
     | 
|
| 
       231 
234 
     | 
    
         
             
                uint64 :default
         
     | 
| 
       232 
235 
     | 
    
         
             
              end
         
     | 
| 
       233 
236 
     | 
    
         | 
| 
       234 
     | 
    
         
            -
              it " 
     | 
| 
      
 237 
     | 
    
         
            +
              it "sets initial selection" do
         
     | 
| 
       235 
238 
     | 
    
         
             
                subject = DerivedChoice.new
         
     | 
| 
       236 
239 
     | 
    
         
             
                subject.num_bytes.should == 2
         
     | 
| 
       237 
240 
     | 
    
         
             
              end
         
     | 
| 
       238 
241 
     | 
    
         | 
| 
       239 
     | 
    
         
            -
              it " 
     | 
| 
      
 242 
     | 
    
         
            +
              it "overides default parameter" do
         
     | 
| 
       240 
243 
     | 
    
         
             
                subject = DerivedChoice.new(:selection => 'b')
         
     | 
| 
       241 
244 
     | 
    
         
             
                subject.num_bytes.should == 4
         
     | 
| 
       242 
245 
     | 
    
         
             
              end
         
     | 
| 
       243 
246 
     | 
    
         | 
| 
       244 
     | 
    
         
            -
              it " 
     | 
| 
      
 247 
     | 
    
         
            +
              it "selects default selection" do
         
     | 
| 
       245 
248 
     | 
    
         
             
                subject = DerivedChoice.new(:selection => 'z')
         
     | 
| 
       246 
249 
     | 
    
         
             
                subject.num_bytes.should == 8
         
     | 
| 
       247 
250 
     | 
    
         
             
              end
         
     | 
| 
         @@ -5,37 +5,34 @@ require 'bindata/count_bytes_remaining' 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            describe BinData::CountBytesRemaining do
         
     | 
| 
       7 
7 
     | 
    
         
             
              it { should == 0 }
         
     | 
| 
      
 8 
     | 
    
         
            +
              its(:num_bytes) { should be_zero }
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
              it " 
     | 
| 
      
 10 
     | 
    
         
            +
              it "counts till end of stream" do
         
     | 
| 
       10 
11 
     | 
    
         
             
                data = "abcdefghij"
         
     | 
| 
       11 
12 
     | 
    
         
             
                subject.read(data).should == 10
         
     | 
| 
       12 
13 
     | 
    
         
             
              end
         
     | 
| 
       13 
14 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
              it " 
     | 
| 
       15 
     | 
    
         
            -
                subject.num_bytes.should == 0
         
     | 
| 
       16 
     | 
    
         
            -
              end
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
              it "should not read any data" do
         
     | 
| 
      
 15 
     | 
    
         
            +
              it "does not read any data" do
         
     | 
| 
       19 
16 
     | 
    
         
             
                io = StringIO.new "abcdefghij"
         
     | 
| 
       20 
17 
     | 
    
         
             
                subject.read(io)
         
     | 
| 
       21 
18 
     | 
    
         | 
| 
       22 
19 
     | 
    
         
             
                io.pos.should == 0
         
     | 
| 
       23 
20 
     | 
    
         
             
              end
         
     | 
| 
       24 
21 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
              it " 
     | 
| 
      
 22 
     | 
    
         
            +
              it "does not write any data" do
         
     | 
| 
       26 
23 
     | 
    
         
             
                subject.to_binary_s.should == ""
         
     | 
| 
       27 
24 
     | 
    
         
             
              end
         
     | 
| 
       28 
25 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
              it " 
     | 
| 
      
 26 
     | 
    
         
            +
              it "allows setting value for completeness" do
         
     | 
| 
       30 
27 
     | 
    
         
             
                subject.assign("123")
         
     | 
| 
       31 
28 
     | 
    
         
             
                subject.should == "123"
         
     | 
| 
       32 
29 
     | 
    
         
             
                subject.to_binary_s.should == ""
         
     | 
| 
       33 
30 
     | 
    
         
             
              end
         
     | 
| 
       34 
31 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
              it " 
     | 
| 
      
 32 
     | 
    
         
            +
              it "accepts BinData::BasePrimitive parameters" do
         
     | 
| 
       36 
33 
     | 
    
         
             
                count = BinData::CountBytesRemaining.new(:check_value => 2)
         
     | 
| 
       37 
     | 
    
         
            -
                 
     | 
| 
      
 34 
     | 
    
         
            +
                expect {
         
     | 
| 
       38 
35 
     | 
    
         
             
                  count.read("xyz")
         
     | 
| 
       39 
     | 
    
         
            -
                }. 
     | 
| 
      
 36 
     | 
    
         
            +
                }.to raise_error(BinData::ValidityError)
         
     | 
| 
       40 
37 
     | 
    
         
             
              end
         
     | 
| 
       41 
38 
     | 
    
         
             
            end
         
     | 
    
        data/spec/deprecated_spec.rb
    CHANGED
    
    | 
         @@ -5,66 +5,66 @@ 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 " 
     | 
| 
       9 
     | 
    
         
            -
                 
     | 
| 
      
 8 
     | 
    
         
            +
              it "fails when inheriting from deprecated SingleValue" do
         
     | 
| 
      
 9 
     | 
    
         
            +
                expect {
         
     | 
| 
       10 
10 
     | 
    
         
             
                  class SubclassSingleValue < BinData::SingleValue
         
     | 
| 
       11 
11 
     | 
    
         
             
                  end
         
     | 
| 
       12 
     | 
    
         
            -
                }. 
     | 
| 
      
 12 
     | 
    
         
            +
                }.to raise_error
         
     | 
| 
       13 
13 
     | 
    
         
             
              end
         
     | 
| 
       14 
14 
     | 
    
         
             
            end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
            describe BinData::MultiValue, "when defining" do
         
     | 
| 
       17 
     | 
    
         
            -
              it " 
     | 
| 
       18 
     | 
    
         
            -
                 
     | 
| 
      
 17 
     | 
    
         
            +
              it "fails inheriting from deprecated MultiValue" do
         
     | 
| 
      
 18 
     | 
    
         
            +
                expect {
         
     | 
| 
       19 
19 
     | 
    
         
             
                  class SubclassMultiValue < BinData::MultiValue
         
     | 
| 
       20 
20 
     | 
    
         
             
                  end
         
     | 
| 
       21 
     | 
    
         
            -
                }. 
     | 
| 
      
 21 
     | 
    
         
            +
                }.to raise_error
         
     | 
| 
       22 
22 
     | 
    
         
             
              end
         
     | 
| 
       23 
23 
     | 
    
         
             
            end
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
            describe BinData::Base, "when defining" do
         
     | 
| 
       26 
     | 
    
         
            -
              it " 
     | 
| 
      
 26 
     | 
    
         
            +
              it "fails if #initialize is overridden" do
         
     | 
| 
       27 
27 
     | 
    
         
             
                class BaseWithInitialize < BinData::Base
         
     | 
| 
       28 
28 
     | 
    
         
             
                  def initialize(params = {}, parent = nil)
         
     | 
| 
       29 
29 
     | 
    
         
             
                    super
         
     | 
| 
       30 
30 
     | 
    
         
             
                  end
         
     | 
| 
       31 
31 
     | 
    
         
             
                end
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
                 
     | 
| 
      
 33 
     | 
    
         
            +
                expect {
         
     | 
| 
       34 
34 
     | 
    
         
             
                  BaseWithInitialize.new
         
     | 
| 
       35 
     | 
    
         
            -
                }. 
     | 
| 
      
 35 
     | 
    
         
            +
                }.to raise_error
         
     | 
| 
       36 
36 
     | 
    
         
             
              end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
              it " 
     | 
| 
      
 38 
     | 
    
         
            +
              it "handles if #initialize is naively renamed to #initialize_instance" do
         
     | 
| 
       39 
39 
     | 
    
         
             
                class BaseWithInitializeInstance < BinData::Base
         
     | 
| 
       40 
40 
     | 
    
         
             
                  def initialize_instance(params = {}, parent = nil)
         
     | 
| 
       41 
41 
     | 
    
         
             
                    super
         
     | 
| 
       42 
42 
     | 
    
         
             
                  end
         
     | 
| 
       43 
43 
     | 
    
         
             
                end
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
                 
     | 
| 
      
 45 
     | 
    
         
            +
                expect {
         
     | 
| 
       46 
46 
     | 
    
         
             
                  BaseWithInitializeInstance.new
         
     | 
| 
       47 
     | 
    
         
            -
                }. 
     | 
| 
      
 47 
     | 
    
         
            +
                }.not_to raise_error
         
     | 
| 
       48 
48 
     | 
    
         
             
              end
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
              it " 
     | 
| 
       51 
     | 
    
         
            -
                 
     | 
| 
      
 50 
     | 
    
         
            +
              it "handles deprecated #register_self method" do
         
     | 
| 
      
 51 
     | 
    
         
            +
                expect {
         
     | 
| 
       52 
52 
     | 
    
         
             
                  class DeprecatedRegisterSelfBase < BinData::Base
         
     | 
| 
       53 
53 
     | 
    
         
             
                    register_self
         
     | 
| 
       54 
54 
     | 
    
         
             
                  end
         
     | 
| 
       55 
     | 
    
         
            -
                }. 
     | 
| 
      
 55 
     | 
    
         
            +
                }.not_to raise_error
         
     | 
| 
       56 
56 
     | 
    
         
             
              end
         
     | 
| 
       57 
57 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
              it " 
     | 
| 
       59 
     | 
    
         
            -
                 
     | 
| 
      
 58 
     | 
    
         
            +
              it "handles deprecated #register method" do
         
     | 
| 
      
 59 
     | 
    
         
            +
                expect {
         
     | 
| 
       60 
60 
     | 
    
         
             
                  class DeprecatedRegisterBase < BinData::Base
         
     | 
| 
       61 
61 
     | 
    
         
             
                    register(self.name, self)
         
     | 
| 
       62 
62 
     | 
    
         
             
                  end
         
     | 
| 
       63 
     | 
    
         
            -
                }. 
     | 
| 
      
 63 
     | 
    
         
            +
                }.not_to raise_error
         
     | 
| 
       64 
64 
     | 
    
         
             
              end
         
     | 
| 
       65 
65 
     | 
    
         | 
| 
       66 
     | 
    
         
            -
              it " 
     | 
| 
       67 
     | 
    
         
            -
                 
     | 
| 
      
 66 
     | 
    
         
            +
              it "handles deprecated #register method for subclasses" do
         
     | 
| 
      
 67 
     | 
    
         
            +
                expect {
         
     | 
| 
       68 
68 
     | 
    
         
             
                  class DeprecatedSuperBase < BinData::Base
         
     | 
| 
       69 
69 
     | 
    
         
             
                    def self.inherited(subclass)
         
     | 
| 
       70 
70 
     | 
    
         
             
                      register(subclass.name, subclass)                                                                                                                                      
         
     | 
| 
         @@ -73,15 +73,15 @@ describe BinData::Base, "when defining" do 
     | 
|
| 
       73 
73 
     | 
    
         | 
| 
       74 
74 
     | 
    
         
             
                  class DeprecatedSubBase < DeprecatedSuperBase
         
     | 
| 
       75 
75 
     | 
    
         
             
                  end
         
     | 
| 
       76 
     | 
    
         
            -
                }. 
     | 
| 
      
 76 
     | 
    
         
            +
                }.not_to raise_error
         
     | 
| 
       77 
77 
     | 
    
         
             
              end
         
     | 
| 
       78 
78 
     | 
    
         | 
| 
       79 
     | 
    
         
            -
              it " 
     | 
| 
       80 
     | 
    
         
            -
                 
     | 
| 
      
 79 
     | 
    
         
            +
              it "handles deprecated #register method with custom calling" do
         
     | 
| 
      
 80 
     | 
    
         
            +
                expect {
         
     | 
| 
       81 
81 
     | 
    
         
             
                  class DeprecatedCustomBase < BinData::Base
         
     | 
| 
       82 
82 
     | 
    
         
             
                    register(name, Object)
         
     | 
| 
       83 
83 
     | 
    
         
             
                  end
         
     | 
| 
       84 
     | 
    
         
            -
                }. 
     | 
| 
      
 84 
     | 
    
         
            +
                }.not_to raise_error
         
     | 
| 
       85 
85 
     | 
    
         
             
              end
         
     | 
| 
       86 
86 
     | 
    
         
             
            end
         
     | 
| 
       87 
87 
     | 
    
         | 
| 
         @@ -92,28 +92,28 @@ describe BinData::Base do 
     | 
|
| 
       92 
92 
     | 
    
         
             
              subject { DeprecatedBase.new }
         
     | 
| 
       93 
93 
     | 
    
         
             
              let(:io)  { "abcde" }
         
     | 
| 
       94 
94 
     | 
    
         | 
| 
       95 
     | 
    
         
            -
              it " 
     | 
| 
      
 95 
     | 
    
         
            +
              it "forwards _do_read to do_read" do
         
     | 
| 
       96 
96 
     | 
    
         
             
                subject.should_receive(:do_read).with(io)
         
     | 
| 
       97 
97 
     | 
    
         
             
                subject._do_read(io)
         
     | 
| 
       98 
98 
     | 
    
         
             
              end
         
     | 
| 
       99 
99 
     | 
    
         | 
| 
       100 
     | 
    
         
            -
              it " 
     | 
| 
      
 100 
     | 
    
         
            +
              it "forwards _do_write to do_write" do
         
     | 
| 
       101 
101 
     | 
    
         
             
                subject.should_receive(:do_write).with(io)
         
     | 
| 
       102 
102 
     | 
    
         
             
                subject._do_write(io)
         
     | 
| 
       103 
103 
     | 
    
         
             
              end
         
     | 
| 
       104 
104 
     | 
    
         | 
| 
       105 
     | 
    
         
            -
              it " 
     | 
| 
      
 105 
     | 
    
         
            +
              it "forwards _do_num_bytes to do_num_bytes" do
         
     | 
| 
       106 
106 
     | 
    
         
             
                subject.should_receive(:do_num_bytes)
         
     | 
| 
       107 
107 
     | 
    
         
             
                subject._do_num_bytes
         
     | 
| 
       108 
108 
     | 
    
         
             
              end
         
     | 
| 
       109 
109 
     | 
    
         | 
| 
       110 
     | 
    
         
            -
              it " 
     | 
| 
      
 110 
     | 
    
         
            +
              it "forwards _assign to assign" do
         
     | 
| 
       111 
111 
     | 
    
         
             
                val = 3
         
     | 
| 
       112 
112 
     | 
    
         
             
                subject.should_receive(:assign).with(val)
         
     | 
| 
       113 
113 
     | 
    
         
             
                subject._assign(val)
         
     | 
| 
       114 
114 
     | 
    
         
             
              end
         
     | 
| 
       115 
115 
     | 
    
         | 
| 
       116 
     | 
    
         
            -
              it " 
     | 
| 
      
 116 
     | 
    
         
            +
              it "forwards _snapshot to snapshot" do
         
     | 
| 
       117 
117 
     | 
    
         
             
                subject.should_receive(:snapshot)
         
     | 
| 
       118 
118 
     | 
    
         
             
                subject._snapshot
         
     | 
| 
       119 
119 
     | 
    
         
             
              end
         
     | 
    
        data/spec/float_spec.rb
    CHANGED
    
    | 
         @@ -6,32 +6,32 @@ require 'bindata/float' 
     | 
|
| 
       6 
6 
     | 
    
         
             
            describe "A FloatLe" do
         
     | 
| 
       7 
7 
     | 
    
         
             
              subject { BinData::FloatLe.new(Math::PI) }
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
              its(:num_bytes) 
     | 
| 
       10 
     | 
    
         
            -
              its(:to_binary_s) 
     | 
| 
       11 
     | 
    
         
            -
              its(:value_read_from_written) { should  
     | 
| 
      
 9 
     | 
    
         
            +
              its(:num_bytes)               { should == 4 }
         
     | 
| 
      
 10 
     | 
    
         
            +
              its(:to_binary_s)             { should == [Math::PI].pack('e') }
         
     | 
| 
      
 11 
     | 
    
         
            +
              its(:value_read_from_written) { should be_within(0.000001).of(Math::PI) }
         
     | 
| 
       12 
12 
     | 
    
         
             
            end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
            describe "A FloatBe" do
         
     | 
| 
       15 
15 
     | 
    
         
             
              subject { BinData::FloatBe.new(Math::PI) }
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
              its(:num_bytes) 
     | 
| 
       18 
     | 
    
         
            -
              its(:to_binary_s) 
     | 
| 
       19 
     | 
    
         
            -
              its(:value_read_from_written) { should  
     | 
| 
      
 17 
     | 
    
         
            +
              its(:num_bytes)               { should == 4 }
         
     | 
| 
      
 18 
     | 
    
         
            +
              its(:to_binary_s)             { should == [Math::PI].pack('g') }
         
     | 
| 
      
 19 
     | 
    
         
            +
              its(:value_read_from_written) { should be_within(0.000001).of(Math::PI) }
         
     | 
| 
       20 
20 
     | 
    
         
             
            end
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
            describe "A DoubleLe" do
         
     | 
| 
       23 
23 
     | 
    
         
             
              subject { BinData::DoubleLe.new(Math::PI) }
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
              its(:num_bytes) 
     | 
| 
       26 
     | 
    
         
            -
              its(:to_binary_s) 
     | 
| 
       27 
     | 
    
         
            -
              its(:value_read_from_written) { should  
     | 
| 
      
 25 
     | 
    
         
            +
              its(:num_bytes)               { should == 8 }
         
     | 
| 
      
 26 
     | 
    
         
            +
              its(:to_binary_s)             { should == [Math::PI].pack('E') }
         
     | 
| 
      
 27 
     | 
    
         
            +
              its(:value_read_from_written) { should be_within(0.0000000000000001).of(Math::PI) }
         
     | 
| 
       28 
28 
     | 
    
         
             
            end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
            describe "A DoubleBe" do
         
     | 
| 
       32 
32 
     | 
    
         
             
              subject { BinData::DoubleBe.new(Math::PI) }
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
              its(:num_bytes) 
     | 
| 
       35 
     | 
    
         
            -
              its(:to_binary_s) 
     | 
| 
       36 
     | 
    
         
            -
              its(:value_read_from_written) { should  
     | 
| 
      
 34 
     | 
    
         
            +
              its(:num_bytes)               { should == 8 }
         
     | 
| 
      
 35 
     | 
    
         
            +
              its(:to_binary_s)             { should == [Math::PI].pack('G') }
         
     | 
| 
      
 36 
     | 
    
         
            +
              its(:value_read_from_written) { should be_within(0.0000000000000001).of(Math::PI) }
         
     | 
| 
       37 
37 
     | 
    
         
             
            end
         
     |