Skip to content

Commit

Permalink
✅ add test for ideal TLAs
Browse files Browse the repository at this point in the history
  • Loading branch information
ctcpip committed Aug 28, 2023
1 parent bc2c9b7 commit 353a4d1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion delegates.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ Nikolaus Papaspyrou (NPU)
Noah Tye (NTE)
Norbert Lindenberg (NL)
Oliver Hunt (OH)
Pablo Gorostiaga Belio (PGB)
Pablo Gorostiaga Belio (PBO)
Paolo Severini (PSI)
Patrick Soquet (PST)
Paul Leather (PLR)
Expand Down
4 changes: 4 additions & 0 deletions scripts/check-delegates-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ const twoLetter = `Chris de Almeida (CDA)\nRob Palmer (RP)\nUjjwal Sharma (USA)`
const threeLetter = `Chris de Almeida (CDA)\nRob Palmer (ROBPALMER)\nUjjwal Sharma (USA)`;
const duplicate = `Chris de Almeida (CDA)\nRob Palmer (RPR)\nUjjwal Sharma (USA)\nUjjwal Sharma (USA)`;
const valid = `Chris de Almeida (CDA)\nMichael Ficarra (MF)\nRob Palmer (RPR)\nUjjwal Sharma (USA)`;
const mononymous = `Chris de Almeida (CDA)\nYee (YEE)\nRob Palmer (RPR)\nUjjwal Sharma (USA)`;
const idealTLA = `Chris de Almeida (CAA)\nMichael Ficarra (MF)\nRob Palmer (RPR)\nUjjwal Sharma (USA)`;

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

assert.doesNotThrow(() => checkDelegates(valid));
53 changes: 51 additions & 2 deletions scripts/check-delegates.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,37 @@ export function checkDelegates(contents = fs.readFileSync('./delegates.txt', 'ut
'VM', 'WH', 'YK', 'ZB',
]);

// list of abbreviations that are not ideal.
// most of these are here because they are grandfathered in.
// new elements should only be false positives.
const NON_IDEAL_ABBRS = new Set([
'ABU', 'ACB', 'AEC', 'AEH', 'ALH', 'ARB', 'ASH', 'AVC', 'AVK',
'AVP', 'AWB', 'AYS', 'BNG', 'BRK', 'CCN', 'CHU', 'CJI', 'CJR',
'CJT', 'CZW', 'DAS', 'DDC', 'DEN', 'DFS', 'DFV', 'DHC', 'DJF',
'DJW', 'DLM', 'DMM', 'DMP', 'DTL', 'DVE', 'EDB', 'FED', 'FRT',
'FYT', 'GCW', 'GKZ', 'GPT', 'GRS', 'HUG', 'HUX', 'IOA', 'IVH',
'JAN', 'JAZ', 'JBS', 'JDD', 'JFP', 'JHJ', 'JHL', 'JMN', 'JPB',
'JPG', 'JRB', 'JSL', 'JSW', 'JTO', 'JXF', 'JXZ', 'JZY', 'KBK',
'KCD', 'KGO', 'KHG', 'KOT', 'KZM', 'LCA', 'LCP', 'LEO', 'LFP',
'LGY', 'LIU', 'LWT', 'LWW', 'LZH', 'LZJ', 'LZM', 'MAG', 'MAR',
'MCM', 'MCW', 'MED', 'MGR', 'MHA', 'MJN', 'MJS', 'MLS', 'MPC',
'MQW', 'MWS', 'MYC', 'MZG', 'NLY', 'PBO', 'PFC', 'PFM', 'PLH',
'PMD', 'PZE', 'REK', 'ROF', 'RTM', 'SFC', 'SJL', 'SJY', 'SMK',
'SNS', 'SRK', 'SRL', 'SSA', 'STH', 'SYH', 'SYP', 'SZH', 'SZT',
'TAB', 'TEK', 'TJC', 'TOC', 'TVC', 'WES', 'WMM', 'WWW', 'WXK',
'WYJ', 'XAX', 'XTY', 'XWC', 'YIY', 'YJM', 'YKL', 'YKZ', 'YRL',
'YTX', 'YYC', 'ZJL', 'ZRJ', 'ZYY',
]);

// delegates with only one name. this list should be as close to zero as possible...
const MONONYMOUS = new Set([
'Cuili',
'Surma',
]);

const allAbbrs = new Set(contents.match(/(?<=\()[^)]*(?=\))/g));

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

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

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

const idealTLA = getIdealTLA(firstName, lastName);

if (idealTLA){
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
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.`)
}
} else if (!MONONYMOUS.has(firstName)) {
throw new Error(`Line ${lineNumber}: Unexpected mononymous delegate.`)
}

previousLine = line;
++lineNumber;
}

console.debug('...delegates are valid\n');
}

function getIdealTLA(firstName, lastName) {

if (lastName) {
return `${firstName.slice(0, 1)}${lastName.slice(0, 1)}${lastName.slice(lastName.length - 1)}`.toUpperCase();
}

return null;

}

0 comments on commit 353a4d1

Please sign in to comment.