/
LanguageIds.test.ts
127 lines (119 loc) · 4.5 KB
/
LanguageIds.test.ts
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
import { describe, expect, test } from 'vitest';
import * as LangId from './LanguageIds.js';
describe('Validate LanguageIds', () => {
test.each`
ext | expected
${'ts'} | ${['typescript']}
${'.tex'} | ${['latex']}
${'.jpg'} | ${['image']}
${'.jsonc'} | ${['json', 'jsonc']}
${'tex'} | ${['latex']}
${'hs'} | ${['haskell']}
${'PNG'} | ${['image']}
`('getLanguagesForExt $ext', ({ ext, expected }) => {
expect(LangId.getLanguagesForExt(ext)).toEqual(expected);
});
test.each`
filename | expected
${'code.ts'} | ${['typescript']}
${'base.r'} | ${['r']}
${'base.R'} | ${['r']}
${'doc.tex'} | ${['latex']}
${'image.jpg'} | ${['image']}
${'workspace.code-workspace'} | ${['jsonc']}
${'.cspellcache'} | ${['cache_files']}
${'Gemfile'} | ${['ruby']}
${'path/Gemfile'} | ${[]}
${'my-cert.pem'} | ${['pem']}
${'my-private-cert.private-key.pem'} | ${['pem', 'pem-private-key']}
${'Dockerfile'} | ${['dockerfile']}
${'Dockerfile.dev'} | ${['dockerfile']}
${'code.jl'} | ${['julia']}
`('getLanguagesForBasename $filename', ({ filename, expected }) => {
expect(LangId.getLanguagesForBasename(filename)).toEqual(expected);
});
test('that all extensions start with a .', () => {
for (const def of LangId.languageExtensionDefinitions) {
const extsWithoutPeriod = def.extensions.filter((ext) => ext[0] !== '.');
expect(extsWithoutPeriod).toEqual([]);
}
});
test.each`
ext | expected
${'.md'} | ${false}
${'.exe'} | ${true}
${'.obj'} | ${true}
${'.dll'} | ${true}
${'.gif'} | ${true}
${'.jpeg'} | ${true}
${'.jpg'} | ${true}
${'.txt'} | ${false}
${'md'} | ${false}
${'exe'} | ${true}
${'obj'} | ${true}
${'dll'} | ${true}
${'gif'} | ${true}
${'txt'} | ${false}
`('isBinaryExt $ext => $expected', ({ ext, expected }) => {
expect(LangId.isBinaryExt(ext)).toBe(expected);
});
test.each`
ext | expected
${'.md'} | ${false}
${'.exe'} | ${true}
${'.obj'} | ${true}
${'.dll'} | ${true}
${'.gif'} | ${true}
${'.jpeg'} | ${true}
${'.jpg'} | ${true}
${'.txt'} | ${false}
${'md'} | ${false}
${'exe'} | ${true}
${'obj'} | ${true}
${'dll'} | ${true}
${'gif'} | ${true}
${'txt'} | ${false}
${'pdf'} | ${true}
${'lock'} | ${true}
`('isGeneratedExt $ext => $expected', ({ ext, expected }) => {
expect(LangId.isGeneratedExt(ext)).toBe(expected);
});
test.each`
filename | expected
${'README.md'} | ${false}
${'run.exe'} | ${true}
${'lib.obj'} | ${true}
${'lib.dll'} | ${true}
${'lib.o'} | ${true}
${'image.gif'} | ${true}
${'picture.jpeg'} | ${true}
${'picture.jpg'} | ${true}
${'doc.txt'} | ${false}
${'lock'} | ${false}
${'Gemfile'} | ${false}
${'.cspellcache'} | ${true}
`('isGeneratedExt $filename => $expected', ({ filename, expected }) => {
expect(LangId.isGeneratedFile(filename)).toBe(expected);
});
test.each`
filename | expected
${'README.md'} | ${false}
${'run.exe'} | ${true}
${'lib.obj'} | ${true}
${'lib.dll'} | ${true}
${'lib.o'} | ${true}
${'image.PNG'} | ${true}
${'image.JPG'} | ${true}
${'image.gif'} | ${true}
${'picture.jpeg'} | ${true}
${'picture.jpg'} | ${true}
${'doc.txt'} | ${false}
${'lock'} | ${false}
${'Gemfile'} | ${false}
${'.cspellcache'} | ${false}
${'my-video.webm'} | ${true}
${'my-logo.svg'} | ${false}
`('isGeneratedExt $filename => $expected', ({ filename, expected }) => {
expect(LangId.isBinaryFile(filename)).toBe(expected);
});
});