Skip to content

Commit db04879

Browse files
committed
refactor: inline truncatedId and simplify trim regex
- Inline truncatedId() into AliasMap.set(): single-use private function with simple logic, inlining removes unnecessary indirection - Simplify part.replace(/^_/, '').replace(/_$/, '') to part.replace(/^_|_$/g, '')
1 parent 3e8fa3d commit db04879

2 files changed

Lines changed: 4 additions & 15 deletions

File tree

packages/phpunit/src/TestIdentifier/PestV2Fixer.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ function decodeEvaluable(encoded: string): string {
3636
const describeParts = segments.slice(0, -1);
3737

3838
const decoded = [
39-
...describeParts.map((part) =>
40-
decodeDescribePart(part.replace(/^_/, '').replace(/_$/, '')),
41-
),
39+
...describeParts.map((part) => decodeDescribePart(part.replace(/^_|_$/g, ''))),
4240
decodeWords(testPart).join(' '),
4341
].join(' \u2192 ');
4442

packages/phpunit/src/TestIdentifier/PestV3Fixer.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
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-
function truncatedId(id: string): string | undefined {
5-
const count = (id.match(/\u2192/g) ?? []).length;
6-
if (count === 0) {
7-
return undefined;
8-
}
9-
10-
return id.slice(0, -count * 2);
11-
}
12-
134
export class AliasMap<T> extends Map<string, T> {
145
override set(id: string, item: T): this {
156
super.set(id, item);
16-
const truncated = truncatedId(id);
17-
if (truncated) {
18-
super.set(truncated, item);
7+
const count = id.match(/\u2192/g)?.length ?? 0;
8+
if (count > 0) {
9+
super.set(id.slice(0, -count * 2), item);
1910
}
2011

2112
return this;

0 commit comments

Comments
 (0)