array-mumu 0.2.0-rc.5

Array tools plugin for the Mumu ecosystem
Documentation
extend("test")
extend("array")

describe("array:keys returns the list of keys from a keyed array and raises errors for invalid inputs", () => {

  it("returns all keys of a keyed array in order", () => {
    obj = [alpha: 10, beta: 20, gamma: 42]
    keys = array:keys(obj)
    expect_equal(keys, ["alpha", "beta", "gamma"])
  })

  it("raises an error if called with an empty array", () => {
    obj = []
    test:expect_error(() => array:keys(obj))
  })

  it("raises an error if called with a non-keyed array", () => {
    arr = [1, 2, 3]
    test:expect_error(() => array:keys(arr))
  })

  it("raises an error if called with a scalar", () => {
    test:expect_error(() => array:keys(123))
    test:expect_error(() => array:keys("hello"))
  })

  it("raises an error if called with no arguments", () => {
    test:expect_error(() => array:keys())
  })

  it("raises an error if called with too many arguments", () => {
    obj = [a: 1]
    test:expect_error(() => array:keys(obj, obj))
  })

  it("preserves insertion order if the keyed array is ordered", () => {
    obj = [first: 1, second: 2, third: 3]
    keys = array:keys(obj)
    expect_equal(keys, ["first", "second", "third"])
  })

})