From b98ff5ae906c3fcd2c4019c08d6a305d0b7b4de6 Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Sun, 3 Aug 2025 17:12:59 -0400 Subject: [PATCH] Moar fixups to strings --- test/test-utils/matchers/to-have-arena-tag.ts | 36 +++++++++---------- test/test-utils/matchers/to-have-terrain.ts | 4 +-- test/test-utils/matchers/to-have-weather.ts | 4 +-- test/test-utils/string-utils.ts | 8 ++--- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/test/test-utils/matchers/to-have-arena-tag.ts b/test/test-utils/matchers/to-have-arena-tag.ts index f02f350d3e3..2d03711fd46 100644 --- a/test/test-utils/matchers/to-have-arena-tag.ts +++ b/test/test-utils/matchers/to-have-arena-tag.ts @@ -1,10 +1,10 @@ import type { ArenaTag, ArenaTagTypeMap } from "#data/arena-tag"; import type { ArenaTagSide } from "#enums/arena-tag-side"; -import { ArenaTagType } from "#enums/arena-tag-type"; +import type { ArenaTagType } from "#enums/arena-tag-type"; import type { OneOther } from "#test/@types/test-helpers"; // biome-ignore lint/correctness/noUnusedImports: TSDoc import type { GameManager } from "#test/test-utils/game-manager"; -import { getEnumStr, getOnelineDiffStr, stringifyEnumArray } from "#test/test-utils/string-utils"; +import { getOnelineDiffStr } from "#test/test-utils/string-utils"; import { isGameManagerInstance, receivedStr } from "#test/test-utils/test-utils"; import type { NonFunctionPropertiesRecursive } from "#types/type-helpers"; import type { MatcherState, SyncExpectationResult } from "@vitest/expect"; @@ -17,7 +17,7 @@ export type toHaveArenaTagOptions = OneOther( this: MatcherState, received: unknown, // simplified types used for brevity; full overloads are in `vitest.d.ts` - expectedType: T | (Partial> & { tagType: T; side: ArenaTagSide }), + expectedTag: T | (Partial> & { tagType: T; side: ArenaTagSide }), side?: ArenaTagSide, ): SyncExpectationResult { if (!isGameManagerInstance(received)) { @@ -44,40 +44,36 @@ export function toHaveArenaTag( }; } - if (typeof expectedType === "string") { + if (typeof expectedTag === "string") { // Coerce lone `tagType`s into objects // Bangs are ok as we enforce safety via overloads - expectedType = { tagType: expectedType, side: side! }; + expectedTag = { tagType: expectedTag, side: side! }; } // We need to get all tags for the case of checking properties of a tag present on both sides of the arena - const tags = received.scene.arena.findTagsOnSide(t => t.tagType === expectedType.tagType, expectedType.side); - if (!tags.length) { - const expectedStr = getEnumStr(ArenaTagType, expectedType.tagType); + const tags = received.scene.arena.findTagsOnSide(t => t.tagType === expectedTag.tagType, expectedTag.side); + if (tags.length === 0) { return { pass: false, - message: () => `Expected the arena to have a tag matching ${expectedStr}, but it didn't!`, - expected: getEnumStr(ArenaTagType, expectedType.tagType), - actual: stringifyEnumArray( - ArenaTagType, - received.scene.arena.tags.map(t => t.tagType), - ), + message: () => `Expected the Arena to have a tag of type ${expectedTag.tagType}, but it didn't!`, + expected: expectedTag.tagType, + actual: received.scene.arena.tags.map(t => t.tagType), }; } // Pass if any of the matching tags meet our criteria const pass = tags.some(tag => - this.equals(tag, expectedType, [...this.customTesters, this.utils.subsetEquality, this.utils.iterableEquality]), + this.equals(tag, expectedTag, [...this.customTesters, this.utils.subsetEquality, this.utils.iterableEquality]), ); - const expectedStr = getOnelineDiffStr.call(this, expectedType); + const expectedStr = getOnelineDiffStr.call(this, expectedTag); return { pass, message: () => pass - ? `Expected the arena to NOT have a tag matching ${expectedStr}, but it did!` - : `Expected the arena to have a tag matching ${expectedStr}, but it didn't!`, - expected: expectedType, + ? `Expected the Arena to NOT have a tag matching ${expectedStr}, but it did!` + : `Expected the Arena to have a tag matching ${expectedStr}, but it didn't!`, + expected: expectedTag, actual: tags, }; } diff --git a/test/test-utils/matchers/to-have-terrain.ts b/test/test-utils/matchers/to-have-terrain.ts index 438d72bc957..f951abed0b3 100644 --- a/test/test-utils/matchers/to-have-terrain.ts +++ b/test/test-utils/matchers/to-have-terrain.ts @@ -41,8 +41,8 @@ export function toHaveTerrain( pass, message: () => pass - ? `Expected Arena to NOT have ${expectedStr} active, but it did!` - : `Expected Arena to have ${expectedStr} active, but got ${actualStr} instead!`, + ? `Expected the Arena to NOT have ${expectedStr} active, but it did!` + : `Expected the Arena to have ${expectedStr} active, but got ${actualStr} instead!`, expected: expectedTerrainType, actual, }; diff --git a/test/test-utils/matchers/to-have-weather.ts b/test/test-utils/matchers/to-have-weather.ts index 21a3a54c80d..ffb1e0aad97 100644 --- a/test/test-utils/matchers/to-have-weather.ts +++ b/test/test-utils/matchers/to-have-weather.ts @@ -41,8 +41,8 @@ export function toHaveWeather( pass, message: () => pass - ? `Expected Arena to NOT have ${expectedStr} weather active, but it did!` - : `Expected Arena to have ${expectedStr} weather active, but got ${actualStr} instead!`, + ? `Expected the Arena to NOT have ${expectedStr} weather active, but it did!` + : `Expected the Arena to have ${expectedStr} weather active, but got ${actualStr} instead!`, expected: expectedWeatherType, actual, }; diff --git a/test/test-utils/string-utils.ts b/test/test-utils/string-utils.ts index c997356fbd6..6c29c04c107 100644 --- a/test/test-utils/string-utils.ts +++ b/test/test-utils/string-utils.ts @@ -34,10 +34,10 @@ interface getEnumStrOptions { * @returns The stringified representation of `val` as dictated by the options. * @example * ```ts - * enum fakeEnum { - * ONE: 1, - * TWO: 2, - * THREE: 3, + * enum testEnum { + * ONE = 1, + * TWO = 2, + * THREE = 3, * } * getEnumStr(fakeEnum, fakeEnum.ONE); // Output: "ONE (=1)" * getEnumStr(fakeEnum, fakeEnum.TWO, {casing: "Title", prefix: "fakeEnum.", suffix: "!!!"}); // Output: "fakeEnum.TWO!!! (=2)"