test: add coaster name matching test suite
Extract matching logic into lib/coaster-match.ts (isCoasterMatch + normalizeForMatch) so it can be imported by both the scraper and tests without duplication. Add tests/coaster-matching.test.ts covering all known match/false-positive cases: - Trademark symbols, leading THE, possessives, punctuation - Subtitle variants in both directions (Apocalypse, New Revolution - Classic) - Space-split brand words (BAT GIRL vs Batgirl) - 4D subtitle extension (THE JOKER™ 4D Free Fly Coaster vs Joker) - False positives: Joker y Harley Quinn, conjunction connectors Run with: npm test Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -65,15 +65,8 @@ export function areCoastersStale(entry: ParkMeta): boolean {
|
||||
* 4. Collapse runs of whitespace
|
||||
* 5. Lowercase and trim
|
||||
*/
|
||||
export function normalizeRideName(name: string): string {
|
||||
return name
|
||||
.replace(/[\u2122\u00ae\u00a9™®©]/g, "")
|
||||
.replace(/^the\s+/i, "")
|
||||
.replace(/[^\w\s]/g, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.toLowerCase()
|
||||
.trim();
|
||||
}
|
||||
export { normalizeForMatch as normalizeRideName } from "./coaster-match.ts";
|
||||
import { normalizeForMatch } from "./coaster-match.ts";
|
||||
|
||||
/**
|
||||
* Returns a Set of normalized coaster names for fast membership checks.
|
||||
@@ -82,5 +75,5 @@ export function normalizeRideName(name: string): string {
|
||||
export function getCoasterSet(parkId: string, meta: ParkMetaMap): Set<string> | null {
|
||||
const entry = meta[parkId];
|
||||
if (!entry || entry.coasters.length === 0) return null;
|
||||
return new Set(entry.coasters.map(normalizeRideName));
|
||||
return new Set(entry.coasters.map(normalizeForMatch));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user