fix: handle no-space after dot separator, tighten T-prefix to uppercase only

This commit is contained in:
Chris Parsons 2026-04-12 14:15:55 -07:00
parent 6988b8c1c0
commit a3c6e7ab09
2 changed files with 8 additions and 2 deletions

View file

@ -8,6 +8,12 @@ describe("parseResultsText", () => {
{ placement: 1, rawName: "Gerwyn Price" }, { placement: 1, rawName: "Gerwyn Price" },
]); ]);
}); });
it("parses '1.Player Name' (no space after dot)", () => {
expect(parseResultsText("1.Gerwyn Price")).toEqual([
{ placement: 1, rawName: "Gerwyn Price" },
]);
});
}); });
describe("comma separator", () => { describe("comma separator", () => {

View file

@ -27,7 +27,7 @@ export function parseResultsText(text: string): ParsedLine[] {
// Try to match: optional T, digits, optional separator (. or ,), then whitespace and the name // Try to match: optional T, digits, optional separator (. or ,), then whitespace and the name
// Pattern 1: "1. Name", "1, Name", "T3. Name", "T3, Name" // Pattern 1: "1. Name", "1, Name", "T3. Name", "T3, Name"
const match = line.match(/^[Tt]?(\d+)[.,]\s+(.+)$/); const match = line.match(/^T?(\d+)[.,]\s*(.+)$/);
if (match) { if (match) {
results.push({ results.push({
placement: parseInt(match[1], 10), placement: parseInt(match[1], 10),
@ -37,7 +37,7 @@ export function parseResultsText(text: string): ParsedLine[] {
} }
// Pattern 2: "1 Name", "T3 Name" (space-only separator) // Pattern 2: "1 Name", "T3 Name" (space-only separator)
const spaceMatch = line.match(/^[Tt]?(\d+)\s+(.+)$/); const spaceMatch = line.match(/^T?(\d+)\s+(.+)$/);
if (spaceMatch) { if (spaceMatch) {
results.push({ results.push({
placement: parseInt(spaceMatch[1], 10), placement: parseInt(spaceMatch[1], 10),