1import { describe, expect, it } from "vitest";
2import {
3 atomsToText,
4 formatDateAtom,
5 parseInlineAtoms,
6 STATUS_COLORS,
7 STATUS_VALUES
8} from "./inline-atoms.js";
9
10describe("inline atoms (T-148)", () => {
11 it("parses date/status/label tokens", () => {
12 const segs = parseInlineAtoms("Due @date(2026-10-11) and @status(done) for @label(Q3)");
13 expect(segs).toEqual([
14 { type: "text", text: "Due " },
15 { type: "atom", kind: "date", value: "2026-10-11" },
16 { type: "text", text: " and " },
17 { type: "atom", kind: "status", value: "done" },
18 { type: "text", text: " for " },
19 { type: "atom", kind: "label", value: "Q3" }
20 ]);
21 });
22
23 it("passes plain text through unchanged (legacy docs)", () => {
24 expect(parseInlineAtoms("no atoms here")).toEqual([{ type: "text", text: "no atoms here" }]);
25 expect(parseInlineAtoms("")).toEqual([]);
26 });
27
28 it("rejects malformed dates / unknown status values (kept as literal text)", () => {
29 expect(parseInlineAtoms("bad @date(2026-13-99) @status(maybe)")).toEqual([
30 { type: "text", text: "bad @date(2026-13-99) @status(maybe)" }
31 ]);
32
33 expect(parseInlineAtoms("hi @alice")).toEqual([{ type: "text", text: "hi @alice" }]);
34 });
35
36 it("round-trips through atomsToText", () => {
37 const original = "a @status(to-do) b @date(2026-01-01) c @label(x y) d";
38 expect(atomsToText(parseInlineAtoms(original))).toBe(original);
39 });
40
41 it("exposes the status palette", () => {
42 for (const s of STATUS_VALUES) expect(typeof STATUS_COLORS[s]).toBe("string");
43 expect(STATUS_COLORS["blocked"]).toBe("red");
44 expect(STATUS_COLORS["done"]).toBe("green");
45 });
46
47 it("formatDateAtom is a no-op for invalid ISO", () => {
48 expect(formatDateAtom("2026-10-11")).toBe("2026-10-11");
49 });
50});
51