-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathPestV2Fixer.ts
More file actions
59 lines (47 loc) · 1.68 KB
/
Copy pathPestV2Fixer.ts
File metadata and controls
59 lines (47 loc) · 1.68 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
const PREFIX = '__pest_evaluable_';
function hasPrefix(id?: string) {
return id?.includes(PREFIX) ?? false;
}
function decodeWords(encoded: string): string[] {
return encoded
.replace(/__/g, '\0')
.split('_')
.map((s) => s.replace(/\0/g, '_'));
}
function decodeDescribePart(inner: string): string {
const words = decodeWords(inner);
const isFQN = words.every((p) => /^[A-Z]/.test(p));
return `\`${words.join(isFQN ? '\\' : ' ')}\``;
}
function decodeEvaluable(encoded: string): string {
const prefixIdx = encoded.indexOf(PREFIX);
if (prefixIdx === -1) {
return encoded;
}
const methodFull = encoded.slice(prefixIdx + PREFIX.length);
const datasetIdx = methodFull.search(/\s+with\s+data\s+set\s+/);
const [methodPart, datasetSuffix] =
datasetIdx >= 0
? [methodFull.slice(0, datasetIdx), methodFull.slice(datasetIdx)]
: [methodFull, ''];
const segments = methodPart.split('_\u2192_');
const testPart = segments[segments.length - 1];
const describeParts = segments.slice(0, -1);
const decoded = [
...describeParts.map((part) => decodeDescribePart(part.replace(/^_|_$/g, ''))),
decodeWords(testPart).join(' '),
].join(' \u2192 ');
return decoded + datasetSuffix;
}
export const PestV2Fixer = {
fixId(location: string, name: string) {
if (!hasPrefix(name)) {
return location;
}
const idx = name.indexOf('::');
const methodPart = idx >= 0 ? name.substring(idx + 2) : name;
const decoded = decodeEvaluable(methodPart);
const file = location.split('::')[0];
return `${file}::${decoded}`;
},
};