github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/util/intersperse.spec.ts (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  import { assert } from "chai";
    12  
    13  import { intersperse } from "src/util/intersperse";
    14  
    15  describe("intersperse", () => {
    16  
    17    it("puts separator in between array items", () => {
    18      const result = intersperse(["foo", "bar", "baz"], "-");
    19      assert.deepEqual(result, ["foo", "-", "bar", "-", "baz"]);
    20    });
    21  
    22    it("puts separator in between array items when given a one-item array", () => {
    23      const result = intersperse(["baz"], "-");
    24      assert.deepEqual(result, ["baz"]);
    25    });
    26  
    27    it("puts separator in between array items when given an empty array", () => {
    28      const result = intersperse([], "-");
    29      assert.deepEqual(result, []);
    30    });
    31  
    32  });