import { describe, it, expect } from "bun:test"; import { getAST } from "@gram-lang/parser"; import { compile } from "@gram-lang/kitchen"; import { toHTML, toMarkdown, toPrintHTML } from "../src/index"; // Both HTML and print HTML render the section ingredient list inside the same // wrapper markup — factored out since every HTML/print assertion below needs it. function extractSectionIngredientsBlock(html: string): string | undefined { return html.match(/
[\s\S]*?<\/div>/)?.[0]; } // @jus{2cl}<@citron{1/2}: a composite child ("jus") of a parent ("citron"). // Section/mise-en-place ingredient lists should show "jus (citron)" so the // parent stays traceable even when the child is written with a short name, // while the shopping list (already parent-nested) and the inline step text // (parent already visible via <@citron in the source) must stay unchanged. const source = "## Prep\n[Squeeze] the @jus{2cl}<@citron{1/2} into the bowl.\n"; const compiled = compile(getAST(source)); describe("composite parent display in section/mise-en-place ingredient lists", () => { it("Markdown section ingredients show the parent next to the short child name", () => { const md = toMarkdown(compiled); expect(md).toContain("**jus** (citron) (2 cl)"); }); it("HTML section ingredients show the parent as visible text and a data attribute", () => { const sectionBlock = extractSectionIngredientsBlock(toHTML(compiled)); expect(sectionBlock).toContain('data-parent="citron"'); expect(sectionBlock).toContain( '(citron)', ); }); it("Print HTML section ingredients also show the parent, despite print.ts never setting formatMode", () => { const sectionBlock = extractSectionIngredientsBlock(toPrintHTML(compiled)); expect(sectionBlock).toContain( '(citron)', ); }); it("Markdown shopping list keeps its existing nested composite structure, unaffected", () => { const md = toMarkdown(compiled); expect(md).toContain("**citron** (1/2) **(Composite)**:"); expect(md).toContain("- **jus** (2 cl)"); // The nested shopping-list child must not also gain a "(citron)" suffix. expect(md).not.toContain("**jus** (citron) (2 cl)\n "); }); it("HTML shopping list: one checkbox on the parent, its parts as sub-lines", () => { const html = toHTML(compiled); expect(html).toContain( '
  • ', ); expect(html).toContain( '
  • jus2 cl
  • ', ); expect(html).not.toContain("composite-badge"); const usageList = html.match( /