Elffuss BraidHub

kikocis/continue public

40e213760c51 · 4.4 KiBRawPermalink
1import { patchNestedMarkdown } from "./patchNestedMarkdown";
2
3describe("patchNestedMarkdown", () => {
4 it("should return unchanged content when no markdown codeblocks are present", () => {
5 const source = 'Regular text\n```javascript\nconsole.log("hello");\n```';
6 expect(patchNestedMarkdown(source)).toBe(source);
7 });
8
9 it("should replace backticks with tildes for markdown codeblocks", () => {
10 const source = "```markdown\n# Header\nSome text\n```";
11 const expected = "~~~markdown\n# Header\nSome text\n~~~";
12 expect(patchNestedMarkdown(source)).toBe(expected);
13 });
14
15 it("should handle nested codeblocks within markdown blocks", () => {
16 const source =
17 '```markdown\n# Example\n```js\nconsole.log("nested");\n```\n```';
18 const expected =
19 '~~~markdown\n# Example\n```js\nconsole.log("nested");\n```\n~~~';
20 expect(patchNestedMarkdown(source)).toBe(expected);
21 });
22
23 it("should handle .md file extension", () => {
24 const source = "```test.md\nContent\n```";
25 const expected = "~~~test.md\nContent\n~~~";
26 expect(patchNestedMarkdown(source)).toBe(expected);
27 });
28
29 it("should handle multiple levels of nesting", () => {
30 const source =
31 '```markdown\n# Doc\n```js\nlet x = "```nested```";\n```\n```';
32 const expected =
33 '~~~markdown\n# Doc\n```js\nlet x = "```nested```";\n```\n~~~';
34 expect(patchNestedMarkdown(source)).toBe(expected);
35 });
36
37 it("should handle blocks that start with md", () => {
38 const source = "```md\n# Header\nSome text\n```";
39 const expected = "~~~md\n# Header\nSome text\n~~~";
40 expect(patchNestedMarkdown(source)).toBe(expected);
41 });
42
43 it("should handle blocks with language specifier followed by md", () => {
44 const source = "```lang md\n# Header\nSome text\n```";
45 const expected = "~~~lang md\n# Header\nSome text\n~~~";
46 expect(patchNestedMarkdown(source)).toBe(expected);
47 });
48
49 it("should handle blocks with language specifier followed by markdown", () => {
50 const source = "```lang markdown\n# Header\nSome text\n```";
51 const expected = "~~~lang markdown\n# Header\nSome text\n~~~";
52 expect(patchNestedMarkdown(source)).toBe(expected);
53 });
54
55 it("should not replace backticks for non-markdown file extensions", () => {
56 const source = "```test.js\nContent\n```";
57 expect(patchNestedMarkdown(source)).toBe(source);
58 });
59
60 it("should check the file extension branch when extension is not md/markdown/gfm", () => {
61 // This tests the extension check branch with an unrecognized extension
62 const source = "```test.txt\nContent with md keyword\n```";
63 expect(patchNestedMarkdown(source)).toBe(source);
64 });
65
66 it("should handle empty file name in code block header", () => {
67 // This covers the branch where file is empty or undefined
68 const source = "``` \nSome content\n```";
69 expect(patchNestedMarkdown(source)).toBe(source);
70 });
71
72 it("should handle file names with no extension", () => {
73 // This covers the branch where ext might be undefined
74 const source = "```filename\nContent\n```";
75 expect(patchNestedMarkdown(source)).toBe(source);
76 });
77
78 it("should correctly identify .markdown extension", () => {
79 // This specifically tests the ext === "markdown" condition in the extension check
80 const source = "```example.markdown\n# Some markdown content\n```";
81 const expected = "~~~example.markdown\n# Some markdown content\n~~~";
82 expect(patchNestedMarkdown(source)).toBe(expected);
83 });
84
85 // GitHub-specific tests
86 it("should handle gfm language identifier", () => {
87 const source = "```gfm\n# Header\nSome text\n```";
88 const expected = "~~~gfm\n# Header\nSome text\n~~~";
89 expect(patchNestedMarkdown(source)).toBe(expected);
90 });
91
92 it("should handle github-markdown language identifier", () => {
93 const source = "```github-markdown\n# Header\nSome text\n```";
94 const expected = "~~~github-markdown\n# Header\nSome text\n~~~";
95 expect(patchNestedMarkdown(source)).toBe(expected);
96 });
97
98 it("should handle language specifier followed by gfm", () => {
99 const source = "```lang gfm\n# Header\nSome text\n```";
100 const expected = "~~~lang gfm\n# Header\nSome text\n~~~";
101 expect(patchNestedMarkdown(source)).toBe(expected);
102 });
103
104 it("should handle .gfm file extension", () => {
105 const source = "```example.gfm\n# Some GitHub markdown content\n```";
106 const expected = "~~~example.gfm\n# Some GitHub markdown content\n~~~";
107 expect(patchNestedMarkdown(source)).toBe(expected);
108 });
109});