-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfileTypeMap.test.ts
More file actions
131 lines (125 loc) · 3.87 KB
/
Copy pathfileTypeMap.test.ts
File metadata and controls
131 lines (125 loc) · 3.87 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { resolveFileTypeIcon } from "./fileTypeMap";
describe("resolveFileTypeIcon", () => {
describe("extension resolution", () => {
const cases: [string, string][] = [
["main.go", "go"],
["app.py", "python"],
["lib.rs", "rust"],
["App.java", "java"],
["main.kt", "kotlin"],
["hello.scala", "scala"],
["main.swift", "swift"],
["main.c", "c"],
["main.cpp", "cpp"],
["Program.cs", "csharp"],
["script.pl", "perl"],
["init.lua", "lua"],
["analysis.r", "r"],
["Main.hs", "haskell"],
["main.dart", "dart"],
["app.ex", "elixir"],
["server.erl", "erlang"],
["index.ts", "ts"],
["index.tsx", "ts"],
["app.js", "js"],
["app.jsx", "js"],
["config.yaml", "yaml"],
["config.yml", "yaml"],
["data.json", "json"],
["config.toml", "toml"],
["settings.ini", "ini"],
["main.tf", "terraform"],
["vars.tfvars", "terraform"],
["index.html", "html"],
["style.css", "css"],
["style.scss", "css"],
["App.vue", "vue"],
["App.svelte", "svelte"],
["query.sql", "sql"],
["data.csv", "csv"],
["schema.proto", "protobuf"],
["schema.graphql", "graphql"],
["README.md", "markdown"],
["report.pdf", "pdf"],
["doc.docx", "docx"],
["data.xlsx", "xlsx"],
["notes.txt", "txt"],
["output.log", "log"],
["deploy.sh", "shell"],
["script.ps1", "powershell"],
["archive.zip", "zip"],
["backup.tar", "gz"],
["package.deb", "deb"],
["app.jar", "jar"],
["photo.png", "png"],
["photo.jpg", "png"],
["icon.gif", "gif"],
["cert.pem", "pem"],
["ca.crt", "certificate"],
["changes.diff", "diff"],
["yarn.lock", "lock"],
["site.xml", "xml"],
];
for (const [input, expected] of cases) {
it(`"${input}" -> "${expected}"`, () => {
assert.equal(resolveFileTypeIcon(input), expected);
});
}
});
describe("special filenames", () => {
const cases: [string, string][] = [
["Dockerfile", "docker"],
["dockerfile", "docker"],
["DOCKERFILE", "docker"],
["docker-compose.yml", "docker"],
["docker-compose.yaml", "docker"],
["Makefile", "makefile-icon"],
["makefile", "makefile-icon"],
["CMakeLists.txt", "cmake"],
["Jenkinsfile", "jenkins"],
["Vagrantfile", "vagrant"],
["Cargo.toml", "rust"],
["go.mod", "go"],
["go.sum", "go"],
["Gemfile", "ruby"],
["helmfile.yaml", "helm"],
["Chart.yaml", "helm"],
["values.yaml", "helm"],
["kustomization.yaml", "kustomize"],
[".gitignore", "git"],
[".dockerignore", "docker"],
[".env", "dotenv"],
[".env.local", "dotenv"],
[".env.production", "dotenv"],
["LICENSE", "certificate"],
["pom.xml", "maven"],
["nginx.conf", "nginx"],
];
for (const [input, expected] of cases) {
it(`"${input}" -> "${expected}"`, () => {
assert.equal(resolveFileTypeIcon(input), expected);
});
}
});
describe("path stripping", () => {
it("strips directory path", () => {
assert.equal(resolveFileTypeIcon("src/lib/config.yaml"), "yaml");
});
it("strips nested path for special file", () => {
assert.equal(resolveFileTypeIcon("deploy/Dockerfile"), "docker");
});
});
describe("fallback", () => {
it("returns default-file for unknown extension", () => {
assert.equal(resolveFileTypeIcon("data.xyz"), "default-file");
});
it("returns default-file for empty string", () => {
assert.equal(resolveFileTypeIcon(""), "default-file");
});
it("returns default-file for extensionless file", () => {
assert.equal(resolveFileTypeIcon("README"), "default-file");
});
});
});