Skip to content

Commit 14666ac

Browse files
committed
Improves autolink performance
Avoids static methods (screws with tree-shaking)
1 parent 2eee0c1 commit 14666ac

File tree

5 files changed

+189
-183
lines changed

5 files changed

+189
-183
lines changed

src/autolinks/__tests__/autolinks.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as assert from 'assert';
22
import { suite, test } from 'mocha';
33
import { map } from '../../system/iterable';
44
import type { Autolink, RefSet } from '../autolinks';
5-
import { Autolinks } from '../autolinks';
5+
import { getAutolinks, getBranchAutolinks } from '../autolinks';
66

77
const mockRefSets = (prefixes: string[] = ['']): RefSet[] =>
88
prefixes.map(prefix => [
@@ -25,27 +25,27 @@ function assertAutolinks(actual: Map<string, Autolink>, expected: Array<string>)
2525

2626
suite('Autolinks Test Suite', () => {
2727
test('Branch name autolinks', () => {
28-
assertAutolinks(Autolinks._getBranchAutolinks('123', mockRefSets()), ['test/123']);
29-
assertAutolinks(Autolinks._getBranchAutolinks('feature/123', mockRefSets()), ['test/123']);
30-
assertAutolinks(Autolinks._getBranchAutolinks('feature/PRE-123', mockRefSets()), ['test/123']);
31-
assertAutolinks(Autolinks._getBranchAutolinks('123.2', mockRefSets()), ['test/123', 'test/2']);
32-
assertAutolinks(Autolinks._getBranchAutolinks('123', mockRefSets(['PRE-'])), []);
33-
assertAutolinks(Autolinks._getBranchAutolinks('feature/123', mockRefSets(['PRE-'])), []);
34-
assertAutolinks(Autolinks._getBranchAutolinks('feature/2-fa/123', mockRefSets([''])), ['test/123', 'test/2']);
35-
assertAutolinks(Autolinks._getBranchAutolinks('feature/2-fa/123', mockRefSets([''])), ['test/123', 'test/2']);
36-
// incorrectly solved case, maybe it worths to compare the blocks length so that the less block size (without possible link) is more likely a link
37-
assertAutolinks(Autolinks._getBranchAutolinks('feature/2-fa/3', mockRefSets([''])), ['test/2', 'test/3']);
38-
assertAutolinks(Autolinks._getBranchAutolinks('feature/PRE-123', mockRefSets(['PRE-'])), ['test/123']);
39-
assertAutolinks(Autolinks._getBranchAutolinks('feature/PRE-123.2', mockRefSets(['PRE-'])), ['test/123']);
40-
assertAutolinks(Autolinks._getBranchAutolinks('feature/3-123-PRE-123', mockRefSets(['PRE-'])), ['test/123']);
28+
assertAutolinks(getBranchAutolinks('123', mockRefSets()), ['test/123']);
29+
assertAutolinks(getBranchAutolinks('feature/123', mockRefSets()), ['test/123']);
30+
assertAutolinks(getBranchAutolinks('feature/PRE-123', mockRefSets()), ['test/123']);
31+
assertAutolinks(getBranchAutolinks('123.2', mockRefSets()), ['test/123', 'test/2']);
32+
assertAutolinks(getBranchAutolinks('123', mockRefSets(['PRE-'])), []);
33+
assertAutolinks(getBranchAutolinks('feature/123', mockRefSets(['PRE-'])), []);
34+
assertAutolinks(getBranchAutolinks('feature/2-fa/123', mockRefSets([''])), ['test/123', 'test/2']);
35+
assertAutolinks(getBranchAutolinks('feature/2-fa/123', mockRefSets([''])), ['test/123', 'test/2']);
36+
// incorrectly solved cat worths to compare the blocks length so that the less block size (without possible link) is more likely a link
37+
assertAutolinks(getBranchAutolinks('feature/2-fa/3', mockRefSets([''])), ['test/2', 'test/3']);
38+
assertAutolinks(getBranchAutolinks('feature/PRE-123', mockRefSets(['PRE-'])), ['test/123']);
39+
assertAutolinks(getBranchAutolinks('feature/PRE-123.2', mockRefSets(['PRE-'])), ['test/123']);
40+
assertAutolinks(getBranchAutolinks('feature/3-123-PRE-123', mockRefSets(['PRE-'])), ['test/123']);
4141
assertAutolinks(
42-
Autolinks._getBranchAutolinks('feature/3-123-PRE-123', mockRefSets(['', 'PRE-'])),
42+
getBranchAutolinks('feature/3-123-PRE-123', mockRefSets(['', 'PRE-'])),
4343

4444
['test/123', 'test/3'],
4545
);
4646
});
4747

4848
test('Commit message autolinks', () => {
49-
assertAutolinks(Autolinks._getAutolinks('test message 123 sd', mockRefSets()), ['test/123']);
49+
assertAutolinks(getAutolinks('test message 123 sd', mockRefSets()), ['test/123']);
5050
});
5151
});

0 commit comments

Comments
 (0)