nandi/oripublic Fork 0
f5c963af3c1597c0274ce4a99705dbd92a7d1cba
Commits
Clone
git clone https://git.rickub.com/nandi/ori.git
git clone ssh://git@rickub.com/nandi/ori.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

forked from bots-garden/ori

lang.test.ts · 61 lines · 1.8 KBTypeScript Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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");
	});
});