import { describe, expect, it } from "vitest"; import { parseCount, parseDuration, tokenize, canonicalUrl } from "./util.ts"; describe("parseCount", () => { it("handles fr/en thousands, decimals, suffixes and unicode spaces", () => { expect(parseCount("3 624 visionnements")).toBe(3624); expect(parseCount("3 624 vues")).toBe(3624); expect(parseCount("12,345 views")).toBe(12345); expect(parseCount("1,2 M de vues")).toBe(1_200_000); expect(parseCount("48 k vues")).toBe(48_000); expect(parseCount("483")).toBe(483); expect(parseCount("17 k")).toBe(17_000); expect(parseCount("no number")).toBeUndefined(); }); }); describe("parseDuration", () => { it("parses mm:ss and h:mm:ss", () => { expect(parseDuration("12:34")).toBe(754); expect(parseDuration("1:02:03")).toBe(3723); }); }); describe("tokenize", () => { it("keeps 2-letter domain tokens and drops stopwords", () => { const t = tokenize("Discover public Quebec creators discussing AI"); expect(t.has("ai")).toBe(true); expect(t.has("quebec")).toBe(true); expect(t.has("public")).toBe(false); }); }); describe("canonicalUrl", () => { it("strips tracking params and www", () => { expect(canonicalUrl("https://www.youtube.com/watch?v=abc&si=xyz&t=10")).toBe("https://youtube.com/watch?v=abc"); }); });