test/array_test.rb in bindata-2.1.0 vs test/array_test.rb in bindata-2.2.0

- old
+ new

@@ -1,8 +1,8 @@ #!/usr/bin/env ruby -require File.expand_path(File.join(File.dirname(__FILE__), "common")) +require File.expand_path(File.join(File.dirname(__FILE__), "test_helper")) describe BinData::Array, "when instantiating" do describe "with no mandatory parameters supplied" do it "raises an error" do args = {} @@ -33,11 +33,11 @@ array.must_equal [5] end end describe BinData::Array, "with no elements" do - let(:obj) { BinData::Array.new(:type => :example_single) } + let(:obj) { BinData::Array.new(:type => :uint32le) } it "initial state" do assert obj.clear? obj.must_be_empty obj.length.must_equal 0 @@ -54,11 +54,11 @@ end end describe BinData::Array, "with several elements" do let(:obj) { - type = [:example_single, {:initial_value => lambda { index + 1 }}] + type = [:uint32le, {:initial_value => lambda { index + 1 }}] BinData::Array.new(:type => type, :initial_length => 5) } it "initial state" do assert obj.clear? @@ -81,16 +81,16 @@ obj.assign([4, 5, 6]) obj.must_equal [4, 5, 6] end it "assigns bindata objects" do - obj.assign([ExampleSingle.new(4), ExampleSingle.new(5), ExampleSingle.new(6)]) + obj.assign([BinData::Uint32le.new(4), BinData::Uint32le.new(5), BinData::Uint32le.new(6)]) obj.must_equal [4, 5, 6] end it "assigns a bindata array" do - array = BinData::Array.new([4, 5, 6], :type => :example_single) + array = BinData::Array.new([4, 5, 6], :type => :uint32le) obj.assign(array) obj.must_equal [4, 5, 6] end it "returns the first element" do @@ -166,25 +166,25 @@ it "has correct debug name" do obj[2].debug_name.must_equal "obj[2]" end it "has correct offset" do - obj[2].rel_offset.must_equal ExampleSingle.new.num_bytes * 2 + obj[2].rel_offset.must_equal 2 * 4 end it "has correct num_bytes" do - obj.num_bytes.must_equal 5 * ExampleSingle.new.num_bytes + obj.num_bytes.must_equal 5 * 4 end it "has correct num_bytes for individual elements" do - obj[0].num_bytes.must_equal ExampleSingle.new.num_bytes + obj[0].num_bytes.must_equal 4 end end describe BinData::Array, "when accessing elements" do let(:obj) { - type = [:example_single, {:initial_value => lambda { index + 1 }}] + type = [:uint32le, {:initial_value => lambda { index + 1 }}] data = BinData::Array.new(:type => type, :initial_length => 5) data.assign([1, 2, 3, 4, 5]) data } @@ -325,11 +325,11 @@ obj.length.must_equal 7 end it "overrides default parameters" do obj = IntArray.new(:initial_length => 3, :initial_element_value => 5) - obj.to_binary_s.must_equal "\x00\x05\x00\x05\x00\x05" + obj.to_binary_s.must_equal_binary "\x00\x05\x00\x05\x00\x05" end end describe BinData::Array, "of bits" do let(:obj) { BinData::Array.new(:type => :bit1, :initial_length => 15) } @@ -354,10 +354,10 @@ obj[14].must_equal 0 end it "writes" do obj[3] = 1 - obj.to_binary_s.must_equal [0b0001_0000, 0b0000_0000].pack("CC") + obj.to_binary_s.must_equal_binary [0b0001_0000, 0b0000_0000].pack("CC") end it "returns num_bytes" do obj.num_bytes.must_equal 2 end