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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
import {test, assert} from 'vitest';
import {
getConversationNumber,
parseTag,
compareNames,
getLatestVersionTag,
} from './index.js';
test('getConversationNumber', () => {
const pairs = new Map<string, number | undefined>([
[
'https://github.com',
undefined,
],
[
'https://gist.github.com/',
undefined,
],
[
'https://github.com/settings/developers',
undefined,
],
[
'https://github.com/refined-github/refined-github',
undefined,
],
[
'https://github.com/refined-github/refined-github/',
undefined,
],
[
'https://github.com/refined-github/refined-github/blame/main/package.json',
undefined,
],
[
'https://github.com/refined-github/refined-github/commit/57bf4',
undefined,
],
[
'https://github.com/refined-github/refined-github/compare/test-branch?quick_pull=0',
undefined,
],
[
'https://github.com/refined-github/refined-github/tree/main/distribution',
undefined,
],
[
'https://github.com/refined-github/refined-github/pull/148/commits/0019603b83bd97c2f7ef240969f49e6126c5ec85',
148,
],
[
'https://github.com/refined-github/refined-github/pull/148/commits/00196',
148,
],
[
'https://github.com/refined-github/refined-github/pull/148/commits',
148,
],
[
'https://github.com/refined-github/refined-github/pull/148',
148,
],
[
'https://github.com/refined-github/refined-github/issues/146',
146,
],
[
'https://github.com/refined-github/refined-github/issues',
undefined,
],
]);
for (const [url, result] of pairs) {
location.href = url;
assert.equal(result, getConversationNumber());
}
});
test('parseTag', () => {
assert.deepEqual(parseTag(''), {namespace: '', version: ''});
assert.deepEqual(parseTag('1.2.3'), {namespace: '', version: '1.2.3'});
assert.deepEqual(parseTag('@1.2.3'), {namespace: '', version: '1.2.3'});
assert.deepEqual(parseTag('hi@1.2.3'), {namespace: 'hi', version: '1.2.3'});
assert.deepEqual(parseTag('hi/you@1.2.3'), {namespace: 'hi/you', version: '1.2.3'});
assert.deepEqual(parseTag('@hi/you@1.2.3'), {namespace: '@hi/you', version: '1.2.3'});
});
test('compareNames', () => {
assert.isTrue(compareNames('johndoe', 'John Doe'));
assert.isTrue(compareNames('john-doe', 'John Doe'));
assert.isTrue(compareNames('john-wdoe', 'John W. Doe'));
assert.isTrue(compareNames('john-doe-jr', 'John Doe Jr.'));
assert.isTrue(compareNames('nicolo', 'Nicolò'));
assert.isFalse(compareNames('dotconnor', 'Connor Love'));
assert.isFalse(compareNames('fregante ', 'Federico Brigante'));
});
test('getLatestVersionTag', () => {
assert.equal(getLatestVersionTag([
'0.0.0',
'v1.1',
'r2.0',
'3.0',
]), '3.0', 'Tags should be sorted by version');
assert.equal(getLatestVersionTag([
'v2.1-0',
'v2.0',
'r1.5.5',
'r1.0',
'v1.0-1',
]), 'v2.0', 'Prereleases should be ignored');
assert.equal(getLatestVersionTag([
'lol v0.0.0',
'2.0',
'2020-10-10',
'v1.0-1',
]), 'lol v0.0.0', 'Non-version tags should short-circuit the sorting and return the first tag');
});
|