Skip to content

Commit 6995969

Browse files
committed
refactor: simplify PestV2Fixer and remove PestV3Fixer indirection
- Remove PestV3Fixer object: truncatedId() was only used internally by AliasMap.set() in the same file; replace with a module-level private function - Remove PestV3Fixer re-export from PestFixer barrel (no external consumer) - Simplify decodeDescribePart: replace 17-line while-loop tokenizer with placeholder approach (__ → \0, split _, restore \0) - Merge double ternary on datasetIdx into a single destructure
1 parent 41294d5 commit 6995969

3 files changed

Lines changed: 17 additions & 30 deletions

File tree

packages/phpunit/src/TestIdentifier/PestFixer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { TestResultCache } from '../TestOutput/TestResultCache';
33

44
export { PestV1Fixer } from './PestV1Fixer';
55
export { PestV2Fixer } from './PestV2Fixer';
6-
export { AliasMap, PestV3Fixer } from './PestV3Fixer';
6+
export { AliasMap } from './PestV3Fixer';
77

88
export const PestFixer = {
99
fixNoTestStarted(cache: TestResultCache, testResult: TestFailed | TestIgnored) {

packages/phpunit/src/TestIdentifier/PestV2Fixer.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,10 @@ function hasPrefix(id?: string) {
55
}
66

77
function decodeDescribePart(inner: string): string {
8-
const segments: string[] = [];
9-
let current = '';
10-
let i = 0;
11-
while (i < inner.length) {
12-
if (inner[i] === '_' && inner[i + 1] === '_') {
13-
current += '_';
14-
i += 2;
15-
} else if (inner[i] === '_') {
16-
segments.push(current);
17-
current = '';
18-
i++;
19-
} else {
20-
current += inner[i];
21-
i++;
22-
}
23-
}
24-
segments.push(current);
8+
const segments = inner
9+
.replace(/__/g, '\0')
10+
.split('_')
11+
.map((s) => s.replace(/\0/g, '_'));
2512
const isFQN = segments.every((p) => /^[A-Z]/.test(p));
2613
return `\`${segments.join(isFQN ? '\\' : ' ')}\``;
2714
}
@@ -36,8 +23,10 @@ function decodeEvaluable(encoded: string): string {
3623
const methodFull = encoded.slice(prefixIdx + PREFIX.length);
3724

3825
const datasetIdx = methodFull.search(/\s+with\s+data\s+set\s+/);
39-
const methodPart = datasetIdx >= 0 ? methodFull.slice(0, datasetIdx) : methodFull;
40-
const datasetSuffix = datasetIdx >= 0 ? methodFull.slice(datasetIdx) : '';
26+
const [methodPart, datasetSuffix] =
27+
datasetIdx >= 0
28+
? [methodFull.slice(0, datasetIdx), methodFull.slice(datasetIdx)]
29+
: [methodFull, ''];
4130

4231
const segments = methodPart.split('_\u2192_');
4332
if (segments.length < 2) {

packages/phpunit/src/TestIdentifier/PestV3Fixer.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
// Pest v3 bug: Str::beforeLast uses mb_strrpos (char offset) with substr (byte offset).
22
// The → character (U+2192) is 3 UTF-8 bytes but 1 char, so names are truncated
33
// by 2 bytes per → character.
4-
export const PestV3Fixer = {
5-
truncatedId(id: string): string | undefined {
6-
const count = (id.match(/\u2192/g) ?? []).length;
7-
if (count === 0) {
8-
return undefined;
9-
}
4+
function truncatedId(id: string): string | undefined {
5+
const count = (id.match(/\u2192/g) ?? []).length;
6+
if (count === 0) {
7+
return undefined;
8+
}
109

11-
return id.slice(0, -count * 2);
12-
},
13-
};
10+
return id.slice(0, -count * 2);
11+
}
1412

1513
export class AliasMap<T> extends Map<string, T> {
1614
override set(id: string, item: T): this {
1715
super.set(id, item);
18-
const truncated = PestV3Fixer.truncatedId(id);
16+
const truncated = truncatedId(id);
1917
if (truncated) {
2018
super.set(truncated, item);
2119
}

0 commit comments

Comments
 (0)