Elffuss BraidHub

kikocis/continue public

9df0fa5d79c7 · 2.7 KiBRawPermalink
1import { headerIsMarkdown } from "./headerIsMarkdown";
2
3describe("headerIsMarkdown", () => {
4 // Test exact match with common Markdown identifiers
5 it("should identify exact matches with common Markdown identifiers", () => {
6 expect(headerIsMarkdown("md")).toBe(true);
7 expect(headerIsMarkdown("markdown")).toBe(true);
8 expect(headerIsMarkdown("gfm")).toBe(true);
9 expect(headerIsMarkdown("github-markdown")).toBe(true);
10 });
11
12 // Test identifiers preceded by a space
13 it("should identify identifiers preceded by a space", () => {
14 expect(headerIsMarkdown("lang md")).toBe(true);
15 expect(headerIsMarkdown("something markdown")).toBe(true);
16 expect(headerIsMarkdown("language gfm")).toBe(true);
17 expect(headerIsMarkdown("spec github-markdown")).toBe(true);
18 });
19
20 // Test file extensions
21 it("should identify file names with markdown extensions", () => {
22 expect(headerIsMarkdown("example.md")).toBe(true);
23 expect(headerIsMarkdown("document.markdown")).toBe(true);
24 expect(headerIsMarkdown("readme.gfm")).toBe(true);
25 });
26
27 // Test more complex cases with extensions
28 it("should identify file names with markdown extensions followed by other text", () => {
29 expect(headerIsMarkdown("example.md additional text")).toBe(true);
30 expect(headerIsMarkdown("document.markdown with some description")).toBe(
31 true,
32 );
33 expect(headerIsMarkdown("readme.gfm v2.0")).toBe(true);
34 });
35
36 // Test non-markdown cases
37 it("should not identify non-markdown headers", () => {
38 expect(headerIsMarkdown("javascript")).toBe(false);
39 expect(headerIsMarkdown("typescript")).toBe(false);
40 expect(headerIsMarkdown("plain")).toBe(false);
41 expect(headerIsMarkdown("python")).toBe(false);
42 });
43
44 // Test edge cases
45 it("should handle edge cases correctly", () => {
46 expect(headerIsMarkdown("")).toBe(false);
47 expect(headerIsMarkdown("mdx")).toBe(false); // Similar but not exactly "md"
48 expect(headerIsMarkdown("readme md")).toBe(true);
49 expect(headerIsMarkdown("md.js")).toBe(false); // "md" is not the extension
50 });
51
52 // Test case sensitivity
53 it("should respect case sensitivity", () => {
54 expect(headerIsMarkdown("MD")).toBe(false);
55 expect(headerIsMarkdown("MARKDOWN")).toBe(false);
56 expect(headerIsMarkdown("example.MD")).toBe(false);
57 expect(headerIsMarkdown("lang MD")).toBe(false);
58 });
59
60 // Test with special characters and spacing
61 it("should handle special characters and spacing correctly", () => {
62 expect(headerIsMarkdown(" md")).toBe(true); // Space before "md"
63 expect(headerIsMarkdown("md ")).toBe(true); // Space after "md"
64 expect(headerIsMarkdown("hello-md")).toBe(false); // "md" with hyphen prefix
65 expect(headerIsMarkdown("markdown:")).toBe(false); // "markdown" with suffix
66 });
67});