Skip to content

Commit

Permalink
better bracket match + test towns
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Aug 1, 2024
1 parent 771e32c commit 3be03af
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/api/squaremap/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions tests/squaremap/nations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions tests/squaremap/towns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,14 +23,25 @@ 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<SquaremapTown | SquaremapTown[]>(town)

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<SquaremapTown[]>(towns)
})

// it('can get towns invitable to specified nation', async () => {
// const invitableTowns = await Aurora.Towns.invitable('sudan')

Expand Down

0 comments on commit 3be03af

Please sign in to comment.