Skip to content

Commit 3e8fa3d

Browse files
committed
refactor: unify decode paths and eliminate dead code in PestV2Fixer
- Extract decodeWords(): shared decode primitive used by both decodeDescribePart and the test-part decoding, removing duplication - Remove early return for segments.length < 2: the describe-less path is now handled by the unified single path (describeParts = []) - Remove `before` variable: always '' since hasPrefix() guarantees methodPart starts with PREFIX (prefixIdx === 0)
1 parent 6995969 commit 3e8fa3d

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

packages/phpunit/src/TestIdentifier/PestV2Fixer.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ function hasPrefix(id?: string) {
44
return id?.includes(PREFIX) ?? false;
55
}
66

7-
function decodeDescribePart(inner: string): string {
8-
const segments = inner
7+
function decodeWords(encoded: string): string[] {
8+
return encoded
99
.replace(/__/g, '\0')
1010
.split('_')
1111
.map((s) => s.replace(/\0/g, '_'));
12-
const isFQN = segments.every((p) => /^[A-Z]/.test(p));
13-
return `\`${segments.join(isFQN ? '\\' : ' ')}\``;
12+
}
13+
14+
function decodeDescribePart(inner: string): string {
15+
const words = decodeWords(inner);
16+
const isFQN = words.every((p) => /^[A-Z]/.test(p));
17+
return `\`${words.join(isFQN ? '\\' : ' ')}\``;
1418
}
1519

1620
function decodeEvaluable(encoded: string): string {
@@ -19,7 +23,6 @@ function decodeEvaluable(encoded: string): string {
1923
return encoded;
2024
}
2125

22-
const before = encoded.slice(0, prefixIdx);
2326
const methodFull = encoded.slice(prefixIdx + PREFIX.length);
2427

2528
const datasetIdx = methodFull.search(/\s+with\s+data\s+set\s+/);
@@ -29,22 +32,17 @@ function decodeEvaluable(encoded: string): string {
2932
: [methodFull, ''];
3033

3134
const segments = methodPart.split('_\u2192_');
32-
if (segments.length < 2) {
33-
const decoded = methodPart.replace(/__|_/g, (m) => (m === '__' ? '_' : ' '));
34-
return before + decoded + datasetSuffix;
35-
}
36-
37-
const describeParts = segments.slice(0, -1);
3835
const testPart = segments[segments.length - 1];
36+
const describeParts = segments.slice(0, -1);
3937

40-
const decodedDescribes = describeParts.map((part) => {
41-
const inner = part.replace(/^_/, '').replace(/_$/, '');
42-
return decodeDescribePart(inner);
43-
});
44-
45-
const decodedTest = testPart.replace(/__|_/g, (m) => (m === '__' ? '_' : ' '));
38+
const decoded = [
39+
...describeParts.map((part) =>
40+
decodeDescribePart(part.replace(/^_/, '').replace(/_$/, '')),
41+
),
42+
decodeWords(testPart).join(' '),
43+
].join(' \u2192 ');
4644

47-
return before + [...decodedDescribes, decodedTest].join(' \u2192 ') + datasetSuffix;
45+
return decoded + datasetSuffix;
4846
}
4947

5048
export const PestV2Fixer = {

0 commit comments

Comments
 (0)