From 3be03afd1d3f2a7f44646f490fefbabd2fdbb4f9 Mon Sep 17 00:00:00 2001 From: Owen Date: Thu, 1 Aug 2024 07:26:31 +0100 Subject: [PATCH] better bracket match + test towns --- src/api/squaremap/parser.ts | 2 +- tests/squaremap/nations.test.ts | 2 -- tests/squaremap/towns.test.ts | 15 +++++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/api/squaremap/parser.ts b/src/api/squaremap/parser.ts index 07a9a67..cf178bd 100644 --- a/src/api/squaremap/parser.ts +++ b/src/api/squaremap/parser.ts @@ -89,7 +89,7 @@ export const parsePopup = (popup: string): ParsedPopup => { const residentsDetails = residentsMatch ? residentsMatch[1].trim() : null // Matches everything before last set of brackets, and everything inside last set of brackets. - const bracketMatch = spanContent.match(/^(.*)\s\(([^)]+)\)$/) + const bracketMatch = spanContent.match(/^(.*)\s\((.*)\)\s*$/) //#region Extract town and nation const townStr = bracketMatch ? bracketMatch[1].trim() : spanContent.trim() diff --git a/tests/squaremap/nations.test.ts b/tests/squaremap/nations.test.ts index 067515e..749074f 100644 --- a/tests/squaremap/nations.test.ts +++ b/tests/squaremap/nations.test.ts @@ -32,8 +32,6 @@ describe('[Squaremap/Aurora] Nations', () => { it('can get multiple nations', async () => { const nations = await Aurora.Nations.get('SiBeRia', 'veNICE', 'verMOnt', 'fAroe_ISlanDs') as SquaremapNation[] - console.log(nations) - expect(nations).toBeTruthy() expect(nations.length).toBe(4) expect(nations.some(n => n instanceof NotFoundError)).toBe(false) diff --git a/tests/squaremap/towns.test.ts b/tests/squaremap/towns.test.ts index 131494c..07c11cc 100644 --- a/tests/squaremap/towns.test.ts +++ b/tests/squaremap/towns.test.ts @@ -5,7 +5,7 @@ import { } from 'vitest' import { SquaremapTown } from '../../src/types' -import { Aurora } from '../../src/main' +import { Aurora, NotFoundError } from '../../src/main' describe('[Squaremap/Aurora] Towns', () => { let towns: SquaremapTown[] = null @@ -23,7 +23,6 @@ describe('[Squaremap/Aurora] Towns', () => { it('can get single town', async () => { const town = await Aurora.Towns.get('Hengyang') expect(town).toBeTruthy() - expect(town).toBeDefined() //@ts-expect-error assertType(town) @@ -31,6 +30,18 @@ describe('[Squaremap/Aurora] Towns', () => { expect((town as SquaremapTown).nation).not.toBe("No Nation") }) + it('can get multiple towns', async () => { + const towns = await Aurora.Towns.get('veNICE', 'troSt_(KhaRkiv)', 'HuaNGyan_IsLANd') as SquaremapTown[] + expect(towns).toBeTruthy() + + expect(towns.some(n => n instanceof NotFoundError)).toBe(false) + expect(towns.length).toBe(3) + + //console.log(towns) + + assertType(towns) + }) + // it('can get towns invitable to specified nation', async () => { // const invitableTowns = await Aurora.Towns.invitable('sudan')