Spaces:
Running
Running
File size: 872 Bytes
e4dc8c3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import { describe, expect, it } from "vitest";
import { parseCommaSeparatedList } from "./parseCommaSeparatedList";
describe("parseCommaSeparatedList", () => {
it("splits on commas", () => {
expect(parseCommaSeparatedList("a,b,c")).toEqual(["a", "b", "c"]);
});
it("trims whitespace around each entry", () => {
expect(parseCommaSeparatedList("localhost, example.com ")).toEqual([
"localhost",
"example.com",
]);
});
it("drops empty entries", () => {
expect(parseCommaSeparatedList("key1, key2,")).toEqual(["key1", "key2"]);
expect(parseCommaSeparatedList(",")).toEqual([]);
expect(parseCommaSeparatedList(" , ,")).toEqual([]);
});
it("returns an empty list for an unset or empty value", () => {
expect(parseCommaSeparatedList(undefined)).toEqual([]);
expect(parseCommaSeparatedList("")).toEqual([]);
});
});
|