Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839import { describe, expect, it } from "vitest";
import { count } from "./print";
describe("count", () => { it("agrees with a count of one", () => { // The whole reason the helper exists. Every caller was written against a library of // thousands of songs, so this is the branch nobody's eye has ever been over. expect(count(1, "track")).toBe("1 track"); expect(count(1, "album")).toBe("1 album"); });
it("takes the plural above one", () => { expect(count(2, "track")).toBe("2 tracks"); expect(count(0, "track")).toBe("0 tracks"); });
it("takes the irregular and the compound noun as an argument rather than deriving it", () => { expect(count(1, "copy", "copies")).toBe("1 copy"); expect(count(3, "copy", "copies")).toBe("3 copies"); // A naive `+ "s"` on the head noun is the failure `song page` exists to survive. expect(count(1, "song page")).toBe("1 song page"); expect(count(4, "song page")).toBe("4 song pages"); });
it("groups library-scale counts the way the harvest's own status line groups them", () => { expect(count(12_304, "track")).toBe("12,304 tracks"); expect(count(999, "track")).toBe("999 tracks"); });
it("keeps the digit for zero unless the words are asked for", () => { // `0 records` is a ledger entry and a diagnosis; `no records` is a sentence. Only the // caller knows which of the two it is printing, so the default is the digit. expect(count(0, "record")).toBe("0 records"); expect(count(0, "match", "matches", "no matches")).toBe("no matches"); expect(count(3, "match", "matches", "no matches")).toBe("3 matches"); });});