Sha256: 4d91c9ddb33fc1bc9f97475f9d361cbfdab1cd7b5d5c4c8010cc74b04e0f8ae8

Contents?: true

Size: 1.8 KB

Versions: 8

Compression:

Stored size: 1.8 KB

Contents

describe "d3-collections - maps" do
  it "d3.map" do
    expect(D3.map).to be_instance_of(D3::Map)
  end

  it "d3.has?" do
    expect(D3.map().has?("1")).to eq(false)
    expect(D3.map(["a","b"]).has?("0")).to eq(true)
    expect(D3.map(["a","b"]).has?(0)).to eq(true)
    expect(D3.map(["a","b"]).has?(2)).to eq(false)
    expect(D3.map(["a","b"]).has?("a")).to eq(false)
  end

  it "d3.get" do
    a = D3.map(["a", "b"])
    expect(nil).to eq(nil)
    expect(a[0]).to eq("a")
    expect(a[2]).to eq(nil)
    expect(a.get(0)).to eq("a")
    expect(a.get(2)).to eq(nil)
  end

  it "d3.set" do
    a = D3.map.set("foo", 1).set("bar", 2)
    a["baz"] = 3
    expect(a["foo"]).to eq(1)
    expect(a["bar"]).to eq(2)
    expect(a["baz"]).to eq(3)
  end

  it "map.remove" do
    a = D3.map.set("a", 1).set("b", 2).remove("a").set("c", 3)
    expect(a.keys).to eq(["b", "c"])
  end

  it "map.clear" do
    a = D3.map.set("a", 1).set("b", 2).clear.set("c", 3)
    expect(a.keys).to eq(["c"])
  end

  it "map.keys" do
    a = D3.map.set("foo", 1).set("bar", 2)
    expect(a.keys).to eq(["foo", "bar"])
  end

  it "map.values" do
    a = D3.map.set("foo", 1).set("bar", 2)
    expect(a.values).to eq([1, 2])
  end

  it "map.entries" do
    a = D3.map.set("foo", 1).set("bar", 2)
    expect(a.entries).to eq([["foo", 1], ["bar", 2]])
  end

  it "map.to_h" do
    a = D3.map.set("foo", 1).set("bar", 2)
    expect(a.to_h).to eq({"foo" => 1, "bar" => 2})
  end

  it "map.each" do
    called = []
    a = D3.map.set("foo", 1).set("bar", 2)
    a.each do |v,k|
      called << [k,v]
    end
    expect(called).to eq([["foo",1], ["bar",2]])

  end

  it "map.empty" do
    expect(D3.map).to be_empty
    expect(D3.map(["a"])).to_not be_empty
  end

  it "map.size" do
    expect(D3.map.size).to eq(0)
    expect(D3.map(["a"]).size).to eq(1)
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
hyper-d3-1.0.0.lap28 spec/map_spec.rb
hyper-d3-1.0.0.lap27 spec/map_spec.rb
hyper-d3-1.0.0.lap26 spec/map_spec.rb
hyper-d3-1.0.0.lap25 spec/map_spec.rb
hyper-d3-1.0.0.lap24 spec/map_spec.rb
hyper-d3-1.0.0.lap23 spec/map_spec.rb
opal-d3-0.0.20170822 spec/map_spec.rb
opal-d3-0.0.20170205 spec/map_spec.rb