gram/packages/renderer/tests/step-spacing.test.ts
abiwab 229f017c23
All checks were successful
CI / Build & Test (pull_request) Successful in 3m59s
fix(renderer): put a space between two elements in a row in a step
2026-11-15 10:14:39 +01:00

36 lines
1.2 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from "bun:test";
import { getAST } from "@gram-lang/parser";
import { compile } from "@gram-lang/kitchen";
import { toHTML, toMarkdown, toText } from "../src/index";
// The parser keeps no whitespace after an element, so the views put the space
// back. Two elements in a row (`@flour{500 g} ~{1h}`) need one too, or the
// step reads "flour (500 g)1 h".
const compiled = compile(
getAST(
"## Dough\n\nKnead @flour{500 g} ~{1h}.\n\nPut @flour{1 kg} #bowl{} aside.\n\nAdd @salt{1 g}, then stir. // to taste\n",
),
);
const plain = (s: string) =>
s
.replace(/<svg[\s\S]*?<\/svg> ?/g, "")
.replace(/<[^>]+>/g, "")
.replace(/[*_]/g, "")
.replace(/⏲️ /g, "")
.replace(/ /g, " ");
describe("two elements in a row are separated by a space", () => {
for (const [name, render] of [
["Markdown", () => toMarkdown(compiled)],
["HTML", () => toHTML(compiled)],
["text", () => toText(compiled, { color: false })],
] as const) {
it(name, () => {
const out = plain(render());
expect(out).toContain("flour (500 g) 1 h.");
expect(out).toContain("flour (1 kg) bowl aside.");
expect(out).toContain("salt (1 g), then stir");
});
}
});