Sha256: a32f07efdc27fc4c2d09676793c718c484787697a05181c6d0a1154635d04b5c

Contents?: true

Size: 1.48 KB

Versions: 52

Compression:

Stored size: 1.48 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

describe "Array#values_at" do
  it "returns an array of elements at the indexes when passed indexes" do
    [1, 2, 3, 4, 5].values_at().should == []
    [1, 2, 3, 4, 5].values_at(1, 0, 5, -1, -8, 10).should == [2, 1, nil, 5, nil, nil]
  end

  it "calls to_int on its indices" do
    obj = mock('1')
    def obj.to_int() 1 end
    [1, 2].values_at(obj, obj, obj).should == [2, 2, 2]
  end

  it "returns an array of elements in the ranges when passes ranges" do
    [1, 2, 3, 4, 5].values_at(0..2, 1...3, 4..6).should == [1, 2, 3, 2, 3, 5, nil]
    [1, 2, 3, 4, 5].values_at(6..4).should == []
  end

  it "properly handles recursive arrays" do
    empty = ArraySpecs.empty_recursive_array
    empty.values_at(0, 1, 2).should == [empty, nil, nil]

    array = ArraySpecs.recursive_array
    array.values_at(0, 1, 2, 3).should == [1, 'two', 3.0, array]
  end

  it "calls to_int on arguments of ranges when passes ranges" do
    from = mock('from')
    to = mock('to')

    # So we can construct a range out of them...
    def from.<=>(o) 0 end
    def to.<=>(o) 0 end

    def from.to_int() 1 end
    def to.to_int() -2 end

    ary = [1, 2, 3, 4, 5]
    ary.values_at(from .. to, from ... to, to .. from).should == [2, 3, 4, 2, 3]
  end

  it "does not return subclass instance on Array subclasses" do
    ArraySpecs::MyArray[1, 2, 3].values_at(0, 1..2, 1).should be_kind_of(Array)
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-3.3.4 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.3 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.3.beta.4 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.3.beta.3 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.3.beta.2 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.3.beta.1 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.2 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.2.beta.7 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.2.beta.6 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.2.beta.5 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.2.beta.4 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.2.beta.3 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.2.beta.2 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.2.beta.1 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.1 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.0 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.0.beta.3 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.0.beta.2 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.3.0.beta.1 spec/framework_spec/app/spec/core/array/values_at_spec.rb
rhodes-3.2.3 spec/framework_spec/app/spec/core/array/values_at_spec.rb