Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history

highlight.test.ts

Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.

highlight.test.tsBlame85 lines · 1 contributor
06d5ffeClaude1import { describe, it, expect } from "bun:test";
2import { highlightCode } from "../lib/highlight";
3
4describe("syntax highlighting", () => {
5 it("should highlight TypeScript code", () => {
6 const code = 'const x: number = 42;\nconsole.log(x);';
7 const result = highlightCode(code, "index.ts");
8
9 expect(result.language).toBe("typescript");
10 expect(result.html).toContain("hljs-");
11 expect(result.html).toContain("42");
12 });
13
14 it("should highlight Python code", () => {
15 const code = 'def hello():\n print("hello world")';
16 const result = highlightCode(code, "main.py");
17
18 expect(result.language).toBe("python");
19 expect(result.html).toContain("hljs-");
20 });
21
22 it("should highlight JSON", () => {
23 const code = '{"key": "value", "count": 42}';
24 const result = highlightCode(code, "config.json");
25
26 expect(result.language).toBe("json");
27 expect(result.html).toContain("hljs-");
28 });
29
30 it("should highlight Go code", () => {
31 const code = 'package main\n\nimport "fmt"\n\nfunc main() {\n\tfmt.Println("hello")\n}';
32 const result = highlightCode(code, "main.go");
33
34 expect(result.language).toBe("go");
35 expect(result.html).toContain("hljs-");
36 });
37
38 it("should highlight Rust code", () => {
39 const code = 'fn main() {\n println!("hello");\n}';
40 const result = highlightCode(code, "main.rs");
41
42 expect(result.language).toBe("rust");
43 expect(result.html).toContain("hljs-");
44 });
45
46 it("should handle unknown extensions gracefully", () => {
47 const code = "just some plain text";
48 const result = highlightCode(code, "readme.xyz");
49
50 // Should return escaped HTML
51 expect(result.html).toContain("just some plain text");
52 });
53
54 it("should escape HTML in plain text", () => {
55 const code = '<script>alert("xss")</script>';
56 const result = highlightCode(code, "file.xyz");
57
58 expect(result.html).not.toContain("<script>");
59 expect(result.html).toContain("&lt;script&gt;");
60 });
61
62 it("should highlight CSS", () => {
63 const code = "body { color: red; font-size: 14px; }";
64 const result = highlightCode(code, "style.css");
65
66 expect(result.language).toBe("css");
67 expect(result.html).toContain("hljs-");
68 });
69
70 it("should highlight SQL", () => {
71 const code = "SELECT * FROM users WHERE id = 1;";
72 const result = highlightCode(code, "query.sql");
73
74 expect(result.language).toBe("sql");
75 expect(result.html).toContain("hljs-");
76 });
77
78 it("should highlight Dockerfile", () => {
79 const code = "FROM node:20\nRUN npm install\nCMD [\"node\", \"index.js\"]";
80 const result = highlightCode(code, "Dockerfile");
81
82 // Dockerfile extension is lowercase 'dockerfile'
83 expect(result.html).toContain("node");
84 });
85});