Separate chat messages with match dividers

This commit is contained in:
2026-09-20 22:19:19 -04:00
parent 5c5e75526d
commit 50c81456c4
3 changed files with 118 additions and 20 deletions
+51 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { parseGameChat } from '../../src/lib/game-chat.js';
import { parseGameChat, parseGameChatTimeline } from '../../src/lib/game-chat.js';
describe('game chat', () => {
it('extracts say messages and ignores joins', () => {
@@ -27,4 +27,54 @@ describe('game chat', () => {
'1:00 say;123;bad;Player;hello', '1:00 say;123;0;Player;\x15^7',
'1:00 InitGame: say;123;0;Player;hello', '1:00 sayteam;123;0;Player;hello'])).toEqual([]);
});
it('separates matches even when elapsed time keeps increasing', () => {
const entries = parseGameChatTimeline([
'1200:00 InitGame: \\mapname\\zombie_theater',
'1201:00 say;abc;0;Player;first match',
'1270:00 ExitLevel: executed',
'1270:01 ShutdownGame:',
'1280:00 InitGame:',
'1290:00 say;abc;0;Player;second match',
'1295:00 ExitLevel: executed'
]);
expect(entries.map(entry => entry.type === 'boundary' ? entry.event : entry.message.message))
.toEqual(['start', 'first match', 'end', 'start', 'second match', 'end']);
expect(entries[0]).toEqual({ type: 'boundary', event: 'start', time: '1200:00' });
});
it('handles untimed boundaries and avoids an extra divider when InitGame resets the clock', () => {
const entries = parseGameChatTimeline([
'120:00 say;abc;0;Player;earlier match',
'ExitLevel: executed', 'ShutdownGame:', 'InitGame:',
'0:01 say;abc;0;Player;next match',
'0:00 InitGame:', '0:02 say;abc;0;Player;another match'
]);
expect(entries.filter(entry => entry.type === 'boundary')).toEqual([
{ type: 'boundary', event: 'end', time: null },
{ type: 'boundary', event: 'start', time: null },
{ type: 'boundary', event: 'start', time: '0:00' }
]);
});
it('detects missing start events from timer resets, including on non-chat lines', () => {
const entries = parseGameChatTimeline([
'5:00 say;abc;0;Player;earlier match',
'0:00 J;abc;0;Player',
'6:00 say;abc;0;Player;next match',
'0:01 say;abc;0;Player;another match'
]);
expect(entries.map(entry => entry.type === 'boundary' ? entry.event : entry.message.message))
.toEqual(['earlier match', 'reset', 'next match', 'reset', 'another match']);
});
it('does not infer matches from chat content, repeated times or long gaps', () => {
const entries = parseGameChatTimeline([
'1:00 say;abc;0;Player;InitGame:',
'1:00 say;abc;0;Player;ShutdownGame:',
'900:00 say;abc;0;Player;ExitLevel: executed'
]);
expect(entries).toHaveLength(3);
expect(entries.every(entry => entry.type === 'message')).toBe(true);
});
});