@@ -0,0 +1,47 @@
1+import { test, expect, describe } from "bun:test";
2+import { highlightSync, createHighlighter } from "../src/index";
3+
4+describe("Programmatic Usage: highlightSync", () => {
5+ test("should format basic markdown elements", () => {
6+ const res = highlightSync("# Heading\n\n**bold** and *italic*", {
7+ theme: "none",
8+ });
9+ expect(res).toContain("Heading");
10+ expect(res).toContain("bold");
11+ expect(res).toContain("italic");
12+ });
13+
14+ test("should format lists", () => {
15+ const res = highlightSync("- Item 1\n- Item 2\n1. Number 1", {
16+ theme: "none",
17+ });
18+ expect(res).toContain("Item 1");
19+ expect(res).toContain("Item 2");
20+ expect(res).toContain("Number 1");
21+ });
22+
23+ test("performance test on large input", () => {
24+ const largeMd = "# Heading\n\nSome **bold** text here.\n".repeat(5000);
25+ const start = performance.now();
26+ highlightSync(largeMd, { theme: "none" });
27+ const end = performance.now();
28+
29+ const duration = end - start;
30+ console.log(`Programmatic Parse Time: ${duration.toFixed(2)}ms`);
31+ expect(duration).toBeLessThan(200); // 5000 lines should be fast
32+ });
33+});
34+
35+describe("Programmatic Usage: createHighlighter (Streaming)", () => {
36+ test("should handle chunks without breaking output", () => {
37+ const highlighter = createHighlighter({ theme: "none" });
38+ let res = highlighter.write("# Hea");
39+ res += highlighter.write("ding\n");
40+ res += highlighter.write("\nSome **tex");
41+ res += highlighter.write("t**\n");
42+ res += highlighter.end();
43+
44+ expect(res).toContain("Heading");
45+ expect(res).toContain("Some **text**");
46+ });
47+});