orbit/dev/world-names.test.mjs

38 lines
1.7 KiB
JavaScript

/**
* dev/world-names.test.mjs — casing-safe world-name resolution.
*
* The comms panel displays names uppercased; that display casing must
* never leak into the landing handoff, because name-keyed world state
* (build records, tether labels) is keyed by the world's canonical
* spelling. Run: `node dev/world-names.test.mjs`.
*/
import assert from 'node:assert/strict';
import { canonicalPlanetName } from '../js/utils/WorldNames.js';
// The user's exact case: display-cased surface name → canonical world.
assert.equal(canonicalPlanetName('ALKHAQO', ['Alkhaqo']), 'Alkhaqo');
assert.equal(canonicalPlanetName('alkhaqo', ['Alkhaqo']), 'Alkhaqo');
// Exact match passes through untouched (spelling preserved).
assert.equal(canonicalPlanetName('Alkhaqo', ['Alkhaqo']), 'Alkhaqo');
assert.equal(canonicalPlanetName('VRYNNEX', ['VRYNNEX', 'Other']), 'VRYNNEX');
// Case-insensitive match returns the list's canonical spelling.
assert.equal(canonicalPlanetName('DRAONVEXUS', ['Other', 'Draonvexus']), 'Draonvexus');
// Unknown names pass through untouched (no crash, no rewrite).
assert.equal(canonicalPlanetName('Zzz-9', ['Alkhaqo']), 'Zzz-9');
// Degenerate inputs.
assert.equal(canonicalPlanetName('', ['Alkhaqo']), '');
assert.equal(canonicalPlanetName(null, ['Alkhaqo']), '');
assert.equal(canonicalPlanetName(undefined, ['Alkhaqo']), '');
assert.equal(canonicalPlanetName('ALKHAQO', null), 'ALKHAQO');
assert.equal(canonicalPlanetName('ALKHAQO', undefined), 'ALKHAQO');
// Whitespace is trimmed before matching; null/blank entries are skipped.
assert.equal(canonicalPlanetName(' ALKHAQO ', ['Alkhaqo']), 'Alkhaqo');
assert.equal(canonicalPlanetName('ALKHAQO', [null, '', ' ', 'Alkhaqo']), 'Alkhaqo');
console.log('world-names: all checks passed ✔');