Sha256: d6d22e7346d4435ed0bedd6464611ef7c8ce08c36b07d13ee7b4a27e95f0f8ec

Contents?: true

Size: 735 Bytes

Versions: 15

Compression:

Stored size: 735 Bytes

Contents

describe "Array#assoc" do
  it "returns the first array whose 1st item is == obj or nil" do
    s1 = ["colors", "red", "blue", "green"]
    s2 = [:letters, "a", "b", "c"]
    s3 = [4]
    s4 = ["colors", "cyan", "yellow", "magenda"]
    s5 = [:letters, "a", "i", "u"]
    s_nil = [nil, nil]
    a = [s1, s2, s3, s4, s5, s_nil]
    a.assoc(s1.first).should == s1
    a.assoc(s2.first).should == s2
    a.assoc(s3.first).should == s3
    a.assoc(s4.first).should == s1
    a.assoc(s5.first).should == s2
  end

  it "ignores any non-Array elements" do
    [1, 2, 3].assoc(2).should be_nil
    s1 = [4]
    s2 = [5, 4, 3]
    a = ["foo", [], s1, s2, nil, []]
    a.assoc(s1.first).should == s1
    a.assoc(s2.first).should == s2
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
opal-0.3.41 spec/core/array/assoc_spec.rb
opal-0.3.40 spec/core/array/assoc_spec.rb
opal-0.3.39 spec/core/array/assoc_spec.rb
opal-0.3.38 spec/core/array/assoc_spec.rb
opal-0.3.37 spec/core/array/assoc_spec.rb
opal-0.3.36 spec/core/array/assoc_spec.rb
opal-0.3.35 spec/core/array/assoc_spec.rb
opal-0.3.34 spec/core/array/assoc_spec.rb
opal-0.3.33 spec/core/array/assoc_spec.rb
opal-0.3.32 spec/core/array/assoc_spec.rb
opal-0.3.31 spec/core/array/assoc_spec.rb
opal-0.3.30 spec/core/array/assoc_spec.rb
opal-0.3.29 spec/core/array/assoc_spec.rb
opal-0.3.28 spec/core/array/assoc_spec.rb
opal-0.3.27 spec/core/array/assoc_spec.rb