Path: blob/main/src/vs/workbench/contrib/chat/test/electron-browser/voiceChatActions.test.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';7import { parseNextChatResponseChunk } from '../../electron-browser/actions/voiceChatActions.js';89suite('VoiceChatActions', function () {1011function assertChunk(text: string, expected: string | undefined, offset: number): { chunk: string | undefined; offset: number } {12const res = parseNextChatResponseChunk(text, offset);13assert.strictEqual(res.chunk, expected);1415return res;16}1718test('parseNextChatResponseChunk', function () {1920// Simple, no offset21assertChunk('Hello World', undefined, 0);22assertChunk('Hello World.', undefined, 0);23assertChunk('Hello World. ', 'Hello World.', 0);24assertChunk('Hello World? ', 'Hello World?', 0);25assertChunk('Hello World! ', 'Hello World!', 0);26assertChunk('Hello World: ', 'Hello World:', 0);2728// Ensure chunks are parsed from the end, no offset29assertChunk('Hello World. How is your day? And more...', 'Hello World. How is your day?', 0);3031// Ensure chunks are parsed from the end, with offset32let offset = assertChunk('Hello World. How is your ', 'Hello World.', 0).offset;33offset = assertChunk('Hello World. How is your day? And more...', 'How is your day?', offset).offset;34offset = assertChunk('Hello World. How is your day? And more to come! ', 'And more to come!', offset).offset;35assertChunk('Hello World. How is your day? And more to come! ', undefined, offset);3637// Sparted by newlines38offset = assertChunk('Hello World.\nHow is your', 'Hello World.', 0).offset;39assertChunk('Hello World.\nHow is your day?\n', 'How is your day?', offset);40});4142ensureNoDisposablesAreLeakedInTestSuite();43});444546