Sha256: b43f981064b2496f58665441c47a96907c668b0531a1d64edc9df0b7a5ecb91a

Contents?: true

Size: 1.04 KB

Versions: 23

Compression:

Stored size: 1.04 KB

Contents

describe "Array#compact" do
  it "returns a copy of array with all nil elements removed" do
    a = [1, 2, 4]
    a.compact.should == [1, 2, 4]
    a = [1, nil, 2, 4]
    a.compact.should == [1, 2, 4]
    a = [1, 2, 4, nil]
    a.compact.should == [1, 2, 4]
    a = [nil, 1, 2, 4]
    a.compact.should == [1, 2, 4]
  end

  it "does not return self" do
    a = [1, 2, 3]
    a.compact.should_not equal(a)
  end
end

describe "Array#compact!" do
  it "removes all nil elements" do
    a = ['a', nil, 'b', false, 'c']
    a.compact!.should equal(a)
    a.should == ["a", "b", false, "c"]
    a = [nil, 'a', 'b', false, 'c']
    a.compact!.should equal(a)
    a.should == ["a", "b", false, "c"]
    a = ['a', 'b', false, 'c', nil]
    a.compact!.should equal(a)
    a.should == ["a", "b", false, "c"]
  end

  it "returns self if some nil elements are removed" do
    a = ['a', nil, 'b', false, 'c']
    a.compact!.object_id.should == a.object_id
  end

  it "returns nil if there are no nil elements to remove" do
    [1, 2, false, 3].compact!.should == nil
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
opal-0.3.41 spec/core/array/compact_spec.rb
opal-0.3.40 spec/core/array/compact_spec.rb
opal-0.3.39 spec/core/array/compact_spec.rb
opal-0.3.38 spec/core/array/compact_spec.rb
opal-0.3.37 spec/core/array/compact_spec.rb
opal-0.3.36 spec/core/array/compact_spec.rb
opal-0.3.35 spec/core/array/compact_spec.rb
opal-0.3.34 spec/core/array/compact_spec.rb
opal-0.3.33 spec/core/array/compact_spec.rb
opal-0.3.32 spec/core/array/compact_spec.rb
opal-0.3.31 spec/core/array/compact_spec.rb
opal-0.3.30 spec/core/array/compact_spec.rb
opal-0.3.29 spec/core/array/compact_spec.rb
opal-0.3.28 spec/core/array/compact_spec.rb
opal-0.3.27 spec/core/array/compact_spec.rb
opal-0.3.26 spec/core/array/compact_spec.rb
opal-0.3.25 spec/core/array/compact_spec.rb
opal-0.3.22 spec/core/array/compact_spec.rb
opal-0.3.21 test/core/array/compact_spec.rb
opal-0.3.20 test/core/array/compact_spec.rb