Skip to content

Commit 353a4d1

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

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-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: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,37 @@ 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+
'ABU', 'ACB', 'AEC', 'AEH', 'ALH', 'ARB', 'ASH', 'AVC', 'AVK',
27+
'AVP', 'AWB', 'AYS', 'BNG', 'BRK', 'CCN', 'CHU', 'CJI', 'CJR',
28+
'CJT', 'CZW', 'DAS', 'DDC', 'DEN', 'DFS', 'DFV', 'DHC', 'DJF',
29+
'DJW', 'DLM', 'DMM', 'DMP', 'DTL', 'DVE', 'EDB', 'FED', 'FRT',
30+
'FYT', 'GCW', 'GKZ', 'GPT', 'GRS', 'HUG', 'HUX', 'IOA', 'IVH',
31+
'JAN', 'JAZ', 'JBS', 'JDD', 'JFP', 'JHJ', 'JHL', 'JMN', 'JPB',
32+
'JPG', 'JRB', 'JSL', 'JSW', 'JTO', 'JXF', 'JXZ', 'JZY', 'KBK',
33+
'KCD', 'KGO', 'KHG', 'KOT', 'KZM', 'LCA', 'LCP', 'LEO', 'LFP',
34+
'LGY', 'LIU', 'LWT', 'LWW', 'LZH', 'LZJ', 'LZM', 'MAG', 'MAR',
35+
'MCM', 'MCW', 'MED', 'MGR', 'MHA', 'MJN', 'MJS', 'MLS', 'MPC',
36+
'MQW', 'MWS', 'MYC', 'MZG', 'NLY', 'PBO', 'PFC', 'PFM', 'PLH',
37+
'PMD', 'PZE', 'REK', 'ROF', 'RTM', 'SFC', 'SJL', 'SJY', 'SMK',
38+
'SNS', 'SRK', 'SRL', 'SSA', 'STH', 'SYH', 'SYP', 'SZH', 'SZT',
39+
'TAB', 'TEK', 'TJC', 'TOC', 'TVC', 'WES', 'WMM', 'WWW', 'WXK',
40+
'WYJ', 'XAX', 'XTY', 'XWC', 'YIY', 'YJM', 'YKL', 'YKZ', 'YRL',
41+
'YTX', 'YYC', 'ZJL', 'ZRJ', 'ZYY',
42+
]);
43+
44+
// delegates with only one name. this list should be as close to zero as possible...
45+
const MONONYMOUS = new Set([
46+
'Cuili',
47+
'Surma',
48+
]);
49+
50+
const allAbbrs = new Set(contents.match(/(?<=\()[^)]*(?=\))/g));
2251

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

@@ -30,7 +59,7 @@ export function checkDelegates(contents = fs.readFileSync('./delegates.txt', 'ut
3059
for (const line of lines) {
3160
if (line.length === 0) continue;
3261
const match = re.exec(line);
33-
const { abbr } = match.groups;
62+
const { abbr, firstName, lastName } = match.groups;
3463

3564
if (previousLine.localeCompare(line, 'en') > 0) {
3665
throw new Error(`Line ${lineNumber}: Not in lexicographic order.`);
@@ -57,9 +86,29 @@ export function checkDelegates(contents = fs.readFileSync('./delegates.txt', 'ut
5786
}
5887
abbrs.set(abbr, lineNumber);
5988

89+
const idealTLA = getIdealTLA(firstName, lastName);
90+
91+
if (idealTLA){
92+
if (!allAbbrs.has(idealTLA) && !NON_IDEAL_ABBRS.has(abbr) && !TWO_LETTER_ABBRS.has(abbr)){ // duplicates the 2-letter check, but helpful to distinguish these issues
93+
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.`)
94+
}
95+
} else if (!MONONYMOUS.has(firstName)) {
96+
throw new Error(`Line ${lineNumber}: Unexpected mononymous delegate.`)
97+
}
98+
6099
previousLine = line;
61100
++lineNumber;
62101
}
63102

64103
console.debug('...delegates are valid\n');
65104
}
105+
106+
function getIdealTLA(firstName, lastName) {
107+
108+
if (lastName) {
109+
return `${firstName.slice(0, 1)}${lastName.slice(0, 1)}${lastName.slice(lastName.length - 1)}`.toUpperCase();
110+
}
111+
112+
return null;
113+
114+
}

0 commit comments

Comments
 (0)