spec/array_spec.rb in bindata-0.9.1 vs spec/array_spec.rb in bindata-0.9.2

- old
+ new

@@ -28,22 +28,14 @@ describe BinData::Array, "with no elements" do before(:each) do @data = BinData::Array.new(:type => :int8) end - it "should not have any field_names" do - BinData::Array.all_possible_field_names(nil).should be_empty - end - it "should not be a single_value" do @data.should_not be_single_value end - it "should have no field names" do - @data.field_names.should be_empty - end - it "should return correct length" do @data.length.should be_zero end it "should be empty" do @@ -77,22 +69,14 @@ before(:each) do type = [:int16le, {:initial_value => lambda { index + 1 }}] @data = BinData::Array.new(:type => type, :initial_length => 5) end - it "should not have any field_names" do - BinData::Array.all_possible_field_names(nil).should be_empty - end - it "should not be a single_value" do @data.should_not be_single_value end - it "should have no field names" do - @data.field_names.should be_empty - end - it "should return a correct snapshot" do @data.snapshot.should == [1, 2, 3, 4, 5] end it "should coerce to ::Array if required" do @@ -132,14 +116,10 @@ it "should have correct num_bytes for individual elements" do @data.num_bytes(0).should == 2 end - it "should have no field_names" do - @data.field_names.should be_empty - end - it "should be able to directly access elements" do @data[1] = 8 @data[1].should == 8 end @@ -153,10 +133,16 @@ it "should be able to use methods from Enumerable" do @data.select { |x| (x % 2) == 0 }.should == [2, 4] end + it "should automatically extend" do + @data[9] = 3 + @data[8].should == 9 + @data.length.should == 10 + end + it "should clear" do @data[1] = 8 @data.clear @data.collect.should == [1, 2, 3, 4, 5] end @@ -165,10 +151,15 @@ @data[1] = 8 @data.clear(1) @data[1].should == 2 end + it "should clear a single element out of range without extending" do + @data.clear(9) + @data.length.should == 5 + end + it "should be clear upon creation" do @data.clear?.should be_true end it "should be clear if all elements are clear" do @@ -179,9 +170,14 @@ it "should test clear status of individual elements" do @data[1] = 8 @data.clear?(0).should be_true @data.clear?(1).should be_false + end + + it "should test clear status of out of range elements without extending" do + @data.clear?(9).should be_true + @data.length.should == 5 end it "should read and write correctly" do io = StringIO.new @data[1] = 8