import { describe, expect, it } from "vitest"; import { number, roundForDisplay, titleCase } from "./format"; describe("display number formatting", () => { it("uses two decimal places for ordinary values", () => { expect(number(12.3456)).toBe("12.35"); expect(roundForDisplay(12.3456)).toBe(12.35); }); it("uses three decimal places for small nonzero values", () => { expect(number(0.0964)).toBe("0.096"); expect(roundForDisplay(0.0964)).toBe(0.096); }); it("does not add insignificant trailing zeroes", () => { expect(number(2)).toBe("2"); expect(number(0)).toBe("0"); }); }); describe("title case formatting", () => { it("capitalizes the first letter of each word without lowercasing source data", () => { expect(titleCase("baking powder, double-acting")).toBe("Baking Powder, Double-acting"); expect(titleCase("USDA choice beef")).toBe("USDA Choice Beef"); }); it("preserves punctuation and whitespace-separated numeric tokens", () => { expect(titleCase("2% milk")).toBe("2% Milk"); }); });