gram/packages/renderer/tests/shopping-range.test.ts
abiwab 858e01ff39
All checks were successful
CI / Build & Test (pull_request) Successful in 4m19s
fix(kitchen): list each mention of a section as written, adding up only in the shopping list
2026-11-15 18:15:22 +01:00

27 lines
1 KiB
TypeScript

import { describe, it, expect } from "bun:test";
import { getAST } from "@gram-lang/parser";
import { compile } from "@gram-lang/kitchen";
import { toMarkdown } from "../src/index";
// Since 1.5.0 ranges add up by their bounds: a shopping entry keeps its
// middle in `qty` and its bounds in `range`, shown by its bounds, never the
// middle. A section lists each mention as written.
function markdownOf(body: string): string {
const source = `---\ntitle: 'T'\n---\n\n## Section\n\n${body}\n`;
return toMarkdown(compile(getAST(source)));
}
describe("ranges added up by their bounds", () => {
const md = markdownOf("Add @salt{2-3 g} then @salt{200 g}.");
it("shows a shopping entry's bounds", () => {
const shopping = md.slice(0, md.indexOf("## Instructions"));
expect(shopping).toContain("**salt** (202-203 g)");
expect(shopping).not.toContain("202.5");
});
it("lists a section's mentions as written, the range included", () => {
const section = md.slice(md.indexOf("## Instructions"));
expect(section).toContain("**salt** (2-3 g + 200 g)");
});
});