import { describe, test, expect, beforeAll } from "bun:test"; import { detectLang, highlightStartup } from "../src/services/highlight.ts"; beforeAll(async () => { await highlightStartup(); }); describe("detectLang", () => { // Extensions test("detects TypeScript", () => expect(detectLang("foo.ts")).toBe("typescript")); test("detects TSX", () => expect(detectLang("foo.tsx")).toBe("tsx")); test("detects JavaScript", () => expect(detectLang("foo.js")).toBe("javascript")); test("detects Python", () => expect(detectLang("foo.py")).toBe("python")); test("detects Rust", () => expect(detectLang("foo.rs")).toBe("rust")); test("detects Go", () => expect(detectLang("foo.go")).toBe("go")); test("detects C", () => expect(detectLang("foo.c")).toBe("c")); test("detects C++", () => expect(detectLang("foo.cpp")).toBe("cpp")); test("detects C header", () => expect(detectLang("foo.h")).toBe("c")); test("detects YAML", () => expect(detectLang("foo.yml")).toBe("yaml")); test("detects TOML", () => expect(detectLang("foo.toml")).toBe("toml")); test("detects JSON", () => expect(detectLang("foo.json")).toBe("json")); test("detects Markdown", () => expect(detectLang("foo.md")).toBe("markdown")); test("detects Shell", () => expect(detectLang("foo.sh")).toBe("shellscript")); test("detects diff/patch", () => expect(detectLang("foo.patch")).toBe("diff")); // Specific filenames test("detects Dockerfile by filename", () => expect(detectLang("Dockerfile")).toBe("docker")); test("detects Makefile by filename", () => expect(detectLang("Makefile")).toBe("make")); // Path stripping test("strips path before detecting", () => expect(detectLang("src/foo/bar.ts")).toBe("typescript")); test("strips path for Dockerfile", () => expect(detectLang("infra/Dockerfile")).toBe("docker")); // Fallback test("falls back to text for unknown extension", () => expect(detectLang("foo.xyz")).toBe("text")); test("falls back to text for no extension", () => expect(detectLang("LICENSE")).toBe("text")); });