forked from bots-garden/ori
| ✨ Workspace panel, selectors, previews, desktop app, sandbox template, resizable file tree, light/dark theme | 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { kindForPath, languageForPath } from "./lang"; | |
| 3 | ||
| 4 | describe("languageForPath", () => { | |
| 5 | it("maps common extensions to Monaco language ids", () => { | |
| 6 | expect(languageForPath("/w/main.go")).toBe("go"); | |
| 7 | expect(languageForPath("src/App.tsx")).toBe("typescript"); | |
| 8 | expect(languageForPath("script.py")).toBe("python"); | |
| 9 | expect(languageForPath("style.css")).toBe("css"); | |
| 10 | expect(languageForPath("run.sh")).toBe("shell"); | |
| 11 | expect(languageForPath("doc.md")).toBe("markdown"); | |
| 12 | }); | |
| 13 | ||
| 14 | it("recognises well-known extensionless files", () => { | |
| 15 | expect(languageForPath("/w/Makefile")).toBe("makefile"); | |
| 16 | expect(languageForPath("/w/Dockerfile")).toBe("dockerfile"); | |
| 17 | }); | |
| 18 | ||
| 19 | it("falls back to plaintext", () => { | |
| 20 | expect(languageForPath("notes.xyz")).toBe("plaintext"); | |
| 21 | expect(languageForPath("LICENSE")).toBe("plaintext"); | |
| 22 | expect(languageForPath(".gitignore")).toBe("plaintext"); | |
| 23 | }); | |
| 24 | }); | |
| 25 | ||
| 26 | describe("kindForPath", () => { | |
| 27 | it("detects markdown and asciidoc", () => { | |
| 28 | expect(kindForPath("README.md")).toBe("markdown"); | |
| 29 | expect(kindForPath("book.adoc")).toBe("asciidoc"); | |
| 30 | expect(kindForPath("book.asciidoc")).toBe("asciidoc"); | |
| 31 | }); | |
| 32 | ||
| 33 | it("detects images, including draw.io exports", () => { | |
| 34 | for (const name of [ | |
| 35 | "a.png", | |
| 36 | "b.JPG", | |
| 37 | "c.jpeg", | |
| 38 | "d.gif", | |
| 39 | "e.webp", | |
| 40 | "f.svg", | |
| 41 | "g.bmp", | |
| 42 | "h.ico", | |
| 43 | "i.avif", | |
| 44 | "diagram.drawio.svg", | |
| 45 | "diagram.drawio.png", | |
| 46 | ]) { | |
| 47 | expect(kindForPath(name), name).toBe("image"); | |
| 48 | } | |
| 49 | }); | |
| 50 | ||
| 51 | it("detects draw.io XML diagrams", () => { | |
| 52 | expect(kindForPath("docs/diagrams/packages.drawio")).toBe("drawio"); | |
| 53 | expect(kindForPath("flow.dio")).toBe("drawio"); | |
| 54 | expect(languageForPath("flow.drawio")).toBe("xml"); | |
| 55 | }); | |
| 56 | ||
| 57 | it("treats everything else as code", () => { | |
| 58 | expect(kindForPath("main.go")).toBe("code"); | |
| 59 | expect(kindForPath("LICENSE")).toBe("code"); | |
| 60 | }); | |
| 61 | }); |