import { describe, expect, it } from "vitest"; import { kindForPath, languageForPath } from "./lang"; describe("languageForPath", () => { it("maps common extensions to Monaco language ids", () => { expect(languageForPath("/w/main.go")).toBe("go"); expect(languageForPath("src/App.tsx")).toBe("typescript"); expect(languageForPath("script.py")).toBe("python"); expect(languageForPath("style.css")).toBe("css"); expect(languageForPath("run.sh")).toBe("shell"); expect(languageForPath("doc.md")).toBe("markdown"); }); it("recognises well-known extensionless files", () => { expect(languageForPath("/w/Makefile")).toBe("makefile"); expect(languageForPath("/w/Dockerfile")).toBe("dockerfile"); }); it("falls back to plaintext", () => { expect(languageForPath("notes.xyz")).toBe("plaintext"); expect(languageForPath("LICENSE")).toBe("plaintext"); expect(languageForPath(".gitignore")).toBe("plaintext"); }); }); describe("kindForPath", () => { it("detects markdown and asciidoc", () => { expect(kindForPath("README.md")).toBe("markdown"); expect(kindForPath("book.adoc")).toBe("asciidoc"); expect(kindForPath("book.asciidoc")).toBe("asciidoc"); }); it("detects images, including draw.io exports", () => { for (const name of [ "a.png", "b.JPG", "c.jpeg", "d.gif", "e.webp", "f.svg", "g.bmp", "h.ico", "i.avif", "diagram.drawio.svg", "diagram.drawio.png", ]) { expect(kindForPath(name), name).toBe("image"); } }); it("detects draw.io XML diagrams", () => { expect(kindForPath("docs/diagrams/packages.drawio")).toBe("drawio"); expect(kindForPath("flow.dio")).toBe("drawio"); expect(languageForPath("flow.drawio")).toBe("xml"); }); it("treats everything else as code", () => { expect(kindForPath("main.go")).toBe("code"); expect(kindForPath("LICENSE")).toBe("code"); }); });