From ca524f9a987b8ad0a047544fc9ed9abae0c39401 Mon Sep 17 00:00:00 2001 From: Adrienne Walker Date: Thu, 30 Nov 2023 16:59:27 -0800 Subject: [PATCH] raidboss/test: improve testing of timeline netregex This is a follow-up to #5962, which itself is related to #5939. I forgot that `find_missing_timeline_translations.ts` is only half of the testing picture and `test_timeline.ts` needed to be updated too. This was found by trying to test more lines and having test timeline complain that InCombat regex lines were not translated. --- test/helper/test_timeline.ts | 23 ++++++++++++++++++++++- ui/raidboss/timeline_parser.ts | 27 +++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/test/helper/test_timeline.ts b/test/helper/test_timeline.ts index 091e6cde39..7629ca2d77 100644 --- a/test/helper/test_timeline.ts +++ b/test/helper/test_timeline.ts @@ -3,6 +3,7 @@ import path from 'path'; import { assert } from 'chai'; +import { keysThatRequireTranslation } from '../../resources/netregexes'; import Regexes from '../../resources/regexes'; import { translateWithReplacements } from '../../resources/translations'; import { LooseTriggerSet } from '../../types/trigger'; @@ -75,10 +76,30 @@ const getTestCases = ( for (const [key, replaceText] of Object.entries(trans.replaceText ?? {})) textMap.set(Regexes.parse(key), replaceText); + // Add all original regexes to the set of things to do replacement on + // and add all translatable parameters as well. + const syncStrings: Set = new Set(); + for (const sync of timeline.syncStarts) { + if (typeof sync.origInput === 'string') { + syncStrings.add(sync.origInput); + continue; + } + for (const [key, value] of Object.entries(sync.origInput)) { + if (!keysThatRequireTranslation.includes(key)) + continue; + if (typeof value === 'object') { + for (const innerValue of value) + syncStrings.add(innerValue); + } else { + syncStrings.add(value); + } + } + } + const testCases: TestCase[] = [ { type: 'replaceSync', - items: new Set(timeline.syncStarts.map((x) => x.regex.source)), + items: syncStrings, replace: new Map(syncMap), replaceWithoutCommon: new Map(syncMap), }, diff --git a/ui/raidboss/timeline_parser.ts b/ui/raidboss/timeline_parser.ts index 912e69a673..dc4b54a83f 100644 --- a/ui/raidboss/timeline_parser.ts +++ b/ui/raidboss/timeline_parser.ts @@ -6,7 +6,6 @@ import { buildNetRegexForTrigger } from '../../resources/netregexes'; import { UnreachableCode } from '../../resources/not_reached'; import Regexes from '../../resources/regexes'; import { - AnonNetRegexParams, translateRegex, translateRegexBuildParamAnon, translateText, @@ -33,6 +32,18 @@ const isStringOrStringArray = (value: unknown): value is string | string[] => { return typeof value === 'string'; }; +export type TimelineNetParams = { [key: string]: string | string[] }; +const isTimelineNetParams = (value: unknown): value is TimelineNetParams => { + if (typeof value !== 'object' || Array.isArray(value)) + return false; + const obj = value as { [key: string]: unknown }; + for (const innerValue of Object.values(obj)) { + if (!isStringOrStringArray(innerValue)) + return false; + } + return true; +}; + const isValidNetParams = ( type: T, params: Record, @@ -44,6 +55,9 @@ const isValidNetParams = ( // Make sure our value is either a string/int or an array of strings/ints if (!isStringOrStringArray(params[key])) return false; + // These should never be specified on a timeline net regex. + if (key === 'capture' || key === 'timestamp') + return false; } return true; }; @@ -87,7 +101,7 @@ export type Error = { export type Sync = { id: number; - origInput: string | AnonNetRegexParams; + origInput: string | TimelineNetParams; regexType: 'parsed' | 'net'; regex: RegExp; start: number; @@ -512,10 +526,15 @@ export class TimelineParser { this.options.ParserLanguage, this.replacements, ).params; + + // The original params should be TimelineNetParams, thus so should the output. + if (!isTimelineNetParams(translatedParams)) + throw new UnreachableCode(); + return this.buildRegexSync( uniqueid, 'net', - params, + translatedParams, Regexes.parse(buildNetRegexForTrigger(netRegexType, translatedParams)), syncCommand.args, seconds, @@ -555,7 +574,7 @@ export class TimelineParser { private buildRegexSync( uniqueid: number, regexType: 'parsed' | 'net', - origInput: string | AnonNetRegexParams, + origInput: string | TimelineNetParams, parsedRegex: RegExp, args: string | undefined, seconds: number,