Sha256: 74404f50f81eb671d46a0466a9f01401e7bcb7e622e58b36fb557f300ac39e99

Contents?: true

Size: 1.36 KB

Versions: 83

Compression:

Stored size: 1.36 KB

Contents

require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/../../spec_helper'
require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/fixtures/classes'

describe "Array#zip" do
  it "returns an array of arrays containing corresponding elements of each array" do
    [1, 2, 3, 4].zip(["a", "b", "c", "d", "e"]).should ==
      [[1, "a"], [2, "b"], [3, "c"], [4, "d"]]
  end

  it "fills in missing values with nil" do
    [1, 2, 3, 4, 5].zip(["a", "b", "c", "d"]).should ==
      [[1, "a"], [2, "b"], [3, "c"], [4, "d"], [5, nil]]
  end

  it "properly handles recursive arrays" do
    a = []; a << a
    b = [1]; b << b

    a.zip(a).should == [ [a[0], a[0]] ]
    a.zip(b).should == [ [a[0], b[0]] ]
    b.zip(a).should == [ [b[0], a[0]], [b[1], a[1]] ]
    b.zip(b).should == [ [b[0], b[0]], [b[1], b[1]] ]
  end

  it "calls #to_ary to convert the argument to an Array" do
    obj = mock('[3,4]')
    obj.should_receive(:to_ary).and_return([3, 4])
    [1, 2].zip(obj).should == [[1, 3], [2, 4]]
  end

  it "calls block if supplied" do
    values = []
    [1, 2, 3, 4].zip(["a", "b", "c", "d", "e"]) { |value|
      values << value
    }.should == nil

    values.should == [[1, "a"], [2, "b"], [3, "c"], [4, "d"]]
  end

  it "does not return subclass instance on Array subclasses" do
    ArraySpecs::MyArray[1, 2, 3].zip(["a", "b"]).class.should == Array
  end
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
rhodes-3.1.1 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.1.1.beta spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.1.0 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.1.0.beta.5 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.1.0.beta.4 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.1.0.beta.3 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.1.0.beta.2 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.1.0.beta.1 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.0.2 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.0.2.beta.1 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.0.1 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.0.1.beta.8 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.0.1.beta.7 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.0.1.beta.6 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.0.1.beta.5 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.0.1.beta.4 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.0.1.beta.3 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.0.1.beta.2 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.0.0 spec/framework_spec/app/spec/core/array/zip_spec.rb
rhodes-3.0.0.beta.7 spec/framework_spec/app/spec/core/array/zip_spec.rb