Skip to content

Commit f363994

Browse files
committed
✅ add test for ideal TLAs
1 parent bc2c9b7 commit f363994

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

delegates.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ Nikolaus Papaspyrou (NPU)
336336
Noah Tye (NTE)
337337
Norbert Lindenberg (NL)
338338
Oliver Hunt (OH)
339-
Pablo Gorostiaga Belio (PGB)
339+
Pablo Gorostiaga Belio (PBO)
340340
Paolo Severini (PSI)
341341
Patrick Soquet (PST)
342342
Paul Leather (PLR)

scripts/check-delegates-test.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ const twoLetter = `Chris de Almeida (CDA)\nRob Palmer (RP)\nUjjwal Sharma (USA)`
88
const threeLetter = `Chris de Almeida (CDA)\nRob Palmer (ROBPALMER)\nUjjwal Sharma (USA)`;
99
const duplicate = `Chris de Almeida (CDA)\nRob Palmer (RPR)\nUjjwal Sharma (USA)\nUjjwal Sharma (USA)`;
1010
const valid = `Chris de Almeida (CDA)\nMichael Ficarra (MF)\nRob Palmer (RPR)\nUjjwal Sharma (USA)`;
11+
const mononymous = `Chris de Almeida (CDA)\nYee (YEE)\nRob Palmer (RPR)\nUjjwal Sharma (USA)`;
12+
const idealTLA = `Chris de Almeida (CAA)\nMichael Ficarra (MF)\nRob Palmer (RPR)\nUjjwal Sharma (USA)`;
1113

1214
assert.throws(() => checkDelegates(lex), { message: 'Line 3: Not in lexicographic order.' }); // also validates expected line number
1315
assert.throws(() => checkDelegates(missing), { message: /Missing abbreviation for/ });
1416
assert.throws(() => checkDelegates(uppercaseLatin), { message: /Abbreviations must be all uppercase Latin letters/ });
1517
assert.throws(() => checkDelegates(twoLetter), { message: /not in allowlist. New delegate abbreviations must be three letters/ });
1618
assert.throws(() => checkDelegates(threeLetter), { message: /New delegate abbreviations must be three letters/ });
1719
assert.throws(() => checkDelegates(duplicate), { message: /Conflicting usage on line/ });
20+
assert.throws(() => checkDelegates(mononymous), { message: /Unexpected mononymous delegate/ });
21+
assert.throws(() => checkDelegates(idealTLA), { message: /Should be using ideal TLA \(CDA\)/ });
1822

1923
assert.doesNotThrow(() => checkDelegates(valid));

scripts/check-delegates.mjs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,44 @@ export function checkDelegates(contents = fs.readFileSync('./delegates.txt', 'ut
1919
'VM', 'WH', 'YK', 'ZB',
2020
]);
2121

22+
// list of abbreviations that are not ideal.
23+
// most of these are here because they are grandfathered in.
24+
// new elements should only be false positives.
25+
const NON_IDEAL_ABBRS = new Set([
26+
'AVP', 'AC', 'AK', 'AEC', 'AS', 'AR', 'ASH', 'AWB', 'ARB', 'ACB',
27+
'AVK', 'ABU', 'ALH', 'AEH', 'AVC', 'AYS', 'BM', 'RTM', 'BZ',
28+
'BG', 'BB', 'BE', 'BRK', 'BT', 'BNG', 'CJT', 'CP', 'CZW', 'CM',
29+
'CHU', 'LCP', 'CJI', 'CF', 'CJR', 'CCN', 'DHC', 'DDC', 'DJF',
30+
'DLM', 'DAS', 'DE', 'DVE', 'DH', 'DMP', 'DEN', 'DTL', 'DJW',
31+
'DFS', 'DT', 'DFV', 'DL', 'DS', 'DD', 'DMM', 'EDB', 'EY', 'EF',
32+
'ET', 'EA', 'REK', 'FED', 'FP', 'FN', 'FRT', 'FYT', 'GI', 'GN',
33+
'GKZ', 'GY', 'GRS', 'GPT', 'GCW', 'LGY', 'GB', 'HUG', 'IH', 'IT',
34+
'IOA', 'IVH', 'IS', 'JBS', 'JPG', 'JH', 'JRB', 'JSL', 'JK',
35+
'JXF', 'JAN', 'JTO', 'JS', 'JFP', 'JHL', 'JSW', 'JZY', 'JAZ',
36+
'JMN', 'YJM', 'JN', 'JP', 'JDD', 'JT', 'JPB', 'KGO', 'KZM', 'KM',
37+
'KCD', 'KG', 'KR', 'KS', 'XAX', 'KHG', 'KOT', 'KBK', 'LB', 'LZH',
38+
'LM', 'LWT', 'LEO', 'LIU', 'LL', 'LCA', 'LFP', 'MJN', 'MHA',
39+
'MPC', 'MED', 'MH', 'MM', 'MJS', 'MWS', 'MAR', 'MS', 'MAG', 'MF',
40+
'MLS', 'MZG', 'MP', 'MCW', 'JXZ', 'MQW', 'WMM', 'MYC', 'MGR',
41+
'MCM', 'NH', 'SNS', 'NC', 'NLY', 'NM', 'NL', 'OH', 'PBO', 'PL',
42+
'PFM', 'PJ', 'PZE', 'PFC', 'PLH', 'PMD', 'RX', 'JHJ', 'RB', 'RH',
43+
'ROF', 'ZRJ', 'STH', 'SC', 'SM', 'SMK', 'SYH', 'SFC', 'SJY',
44+
'SRK', 'SYP', 'SP', 'SRL', 'SZH', 'SJL', 'SSA', 'SZT', 'TAB',
45+
'TEK', 'TS', 'TW', 'TOC', 'YTX', 'XTY', 'TJC', 'TD', 'TC', 'TVC',
46+
'VM', 'WH', 'XWC', 'LWW', 'WES', 'WWW', 'WXK', 'HUX', 'WYJ',
47+
'YKZ', 'YIY', 'YKL', 'YRL', 'YYC', 'LZM', 'ZYY', 'LZJ', 'ZB',
48+
'ZJL',
49+
]);
50+
51+
// delegates with only one name. this list should be as close to zero as possible...
52+
const MONONYMOUS = new Set([
53+
'Cuili',
54+
'Surma',
55+
]);
56+
57+
const allAbbrs = new Set(contents.match(/(?<=\()[^)]*(?=\))/g));
2258

23-
const re = /^(?<name>[^(]+)(?: \((?<abbr>[^)]*)\))?$/;
59+
const re = /^(?<firstName>[^( ]+) ?(?<lastName>[^(]+)?(?: \((?<abbr>[^)]*)\))?$/;
2460
const abbrs = new Map;
2561
const lines = contents.split('\n');
2662

@@ -30,7 +66,7 @@ export function checkDelegates(contents = fs.readFileSync('./delegates.txt', 'ut
3066
for (const line of lines) {
3167
if (line.length === 0) continue;
3268
const match = re.exec(line);
33-
const { abbr } = match.groups;
69+
const { abbr, firstName, lastName } = match.groups;
3470

3571
if (previousLine.localeCompare(line, 'en') > 0) {
3672
throw new Error(`Line ${lineNumber}: Not in lexicographic order.`);
@@ -57,9 +93,29 @@ export function checkDelegates(contents = fs.readFileSync('./delegates.txt', 'ut
5793
}
5894
abbrs.set(abbr, lineNumber);
5995

96+
const idealTLA = getIdealTLA(firstName, lastName);
97+
98+
if (idealTLA){
99+
if (!allAbbrs.has(idealTLA) && !NON_IDEAL_ABBRS.has(abbr)){
100+
throw new Error(`Line ${lineNumber}: Should be using ideal TLA (${idealTLA}). Note: because code cannot distinguish between a middle name vs a two-part last name, this may be a false positive.`)
101+
}
102+
} else if (!MONONYMOUS.has(firstName)) {
103+
throw new Error(`Line ${lineNumber}: Unexpected mononymous delegate.`)
104+
}
105+
60106
previousLine = line;
61107
++lineNumber;
62108
}
63109

64110
console.debug('...delegates are valid\n');
65111
}
112+
113+
function getIdealTLA(firstName, lastName) {
114+
115+
if (lastName) {
116+
return `${firstName.slice(0, 1)}${lastName.slice(0, 1)}${lastName.slice(lastName.length - 1)}`.toUpperCase();
117+
}
118+
119+
return null;
120+
121+
}

0 commit comments

Comments
 (0)