Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { markdownTree } from "../../markdown/wordsHast";
4import { isClosedCodeFence } from "./MarkdownCodeBlock.logic";
5
6describe("isClosedCodeFence", () => {
7 it.each(["\n", "\r\n", "\r"])("tells closed from unclosed fences with %j line endings", (eol) => {
8 for (const closed of [false, true]) {
9 const source = ["```sh", "echo hi", ...(closed ? ["```"] : [])].join(eol);
10 const [pre] = markdownTree(source).children;
11 const code = pre?.type === "element" ? pre.children[0] : undefined;
12 const content = code?.type === "element" ? code.children[0] : undefined;
13 if (pre?.type !== "element" || content?.type !== "text") {
14 throw new Error("Expected a parsed code block");
15 }
16 expect(isClosedCodeFence(pre, source, content.value)).toBe(closed);
17 }
18 });
19});