Sha256: f04fa350c07eed8b45b84bcd0e6dc577c12c7a827354e76e4c4e02d4981ed6ed

Contents?: true

Size: 1.21 KB

Versions: 23

Compression:

Stored size: 1.21 KB

Contents

describe "Array#map" do
  it "returns a copy of array with each element replaced by the value returned by block" do
    a = ['a', 'b', 'c', 'd']
    b = a.map { |i| i + '!' }
    b.should == ['a!', 'b!', 'c!', 'd!']
    b.object_id.should_not == a.object_id
  end

  it "does not change self" do
    a = ['a', 'b', 'c', 'd']
    b = a.map { |i| i + '!' }
    a.should == ['a', 'b', 'c', 'd']
  end

  it "returns the evaluated value of block if it broke in the block" do
    a = ['a', 'b', 'c', 'd']
    b = a.map {|i|
      if i == 'c'
        break 0
      else
        i + '!'
      end
    }
    b.should == 0
  end
end

describe "Array#map!" do
  it "replaces each element with the value returned by block" do
    a = [7, 9, 3, 5]
    a.map! { |i| i - 1 }.should equal(a)
    a.should == [6, 8, 2, 4]
  end

  it "returns self" do
    a = [1, 2, 3, 4, 5]
    b = a.map! {|i| i+1 }
    a.object_id.should == b.object_id
  end

  it "returns the evaluated value of block but its contents is partially modified, if it broke in the block" do
    a = ['a', 'b', 'c', 'd']
    b = a.map! {|i|
      if i == 'c'
        break 0
      else
        i + '!'
      end
    }
    b.should == 0
    a.should == ['a!', 'b!', 'c', 'd']
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

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