Skip to content

Commit

Permalink
raidboss/test: improve testing of timeline netregex (#5968)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
quisquous authored Dec 1, 2023
1 parent e6255c3 commit 6a3869f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
25 changes: 24 additions & 1 deletion test/helper/test_timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<string> = new Set<string>();
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),
},
Expand Down Expand Up @@ -314,6 +335,8 @@ const testTimelineFiles = (timelineFiles: string[]): void => {
it('should have proper sealed sync', () => {
for (const sync of timeline.syncStarts) {
const regex = sync.regex.source;
if (sync.regexType === 'net')
continue;
if (regex.includes('is no longer sealed')) {
assert.isArray(
/00:0839::\.\*is no longer sealed/.exec(regex),
Expand Down
27 changes: 23 additions & 4 deletions ui/raidboss/timeline_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = <T extends LogDefinitionTypes>(
type: T,
params: Record<string, unknown>,
Expand All @@ -44,6 +55,9 @@ const isValidNetParams = <T extends LogDefinitionTypes>(
// 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;
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6a3869f

Please sign in to comment.