extend("test")
extend("array")

describe("array:assoc", () => {

  it("sets a key-value pair on a keyed array", () => {
    orig = [ name:"Alice" ]
    updated = array:assoc("city", "London", orig)
    expect_equal(updated, [ name:"Alice", city:"London" ])
  })

  it("updates an existing key if present", () => {
    orig = [ name:"Alice", city:"Paris" ]
    updated = array:assoc("city", "London", orig)
    expect_equal(updated, [ name:"Alice", city:"London" ])
  })

  it("allows partial usage for key, value, object", () => {
    setColorBlue = array:assoc("color", "blue")
    expect_equal( setColorBlue([ model:"Toy", price:42 ]) ,
                  [ model:"Toy", price:42, color:"blue" ] )
  })

  it("supports underscore placeholders", () => {
    partial = array:assoc(_, "banana", [ name:"Alice" ])
    result = partial("fruit")
    expect_equal(result, [ name:"Alice", fruit:"banana" ])
  })

})
