highlight.test.ts
Raw
1import { describe, test, expect, beforeAll } from "bun:test";
2import { detectLang, highlightStartup } from "../src/services/highlight.ts";
3
4beforeAll(async () => {
5 await highlightStartup();
6});
7
8describe("detectLang", () => {
9 // Extensions
10 test("detects TypeScript", () => expect(detectLang("foo.ts")).toBe("typescript"));
11 test("detects TSX", () => expect(detectLang("foo.tsx")).toBe("tsx"));
12 test("detects JavaScript", () => expect(detectLang("foo.js")).toBe("javascript"));
13 test("detects Python", () => expect(detectLang("foo.py")).toBe("python"));
14 test("detects Rust", () => expect(detectLang("foo.rs")).toBe("rust"));
15 test("detects Go", () => expect(detectLang("foo.go")).toBe("go"));
16 test("detects C", () => expect(detectLang("foo.c")).toBe("c"));
17 test("detects C++", () => expect(detectLang("foo.cpp")).toBe("cpp"));
18 test("detects C header", () => expect(detectLang("foo.h")).toBe("c"));
19 test("detects YAML", () => expect(detectLang("foo.yml")).toBe("yaml"));
20 test("detects TOML", () => expect(detectLang("foo.toml")).toBe("toml"));
21 test("detects JSON", () => expect(detectLang("foo.json")).toBe("json"));
22 test("detects Markdown", () => expect(detectLang("foo.md")).toBe("markdown"));
23 test("detects Shell", () => expect(detectLang("foo.sh")).toBe("shellscript"));
24 test("detects diff/patch", () => expect(detectLang("foo.patch")).toBe("diff"));
25
26 // Specific filenames
27 test("detects Dockerfile by filename", () => expect(detectLang("Dockerfile")).toBe("docker"));
28 test("detects Makefile by filename", () => expect(detectLang("Makefile")).toBe("make"));
29
30 // Path stripping
31 test("strips path before detecting", () => expect(detectLang("src/foo/bar.ts")).toBe("typescript"));
32 test("strips path for Dockerfile", () => expect(detectLang("infra/Dockerfile")).toBe("docker"));
33
34 // Fallback
35 test("falls back to text for unknown extension", () => expect(detectLang("foo.xyz")).toBe("text"));
36 test("falls back to text for no extension", () => expect(detectLang("LICENSE")).toBe("text"));
37});
38