Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/test/electron-browser/voiceChatActions.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
8
import { parseNextChatResponseChunk } from '../../electron-browser/actions/voiceChatActions.js';
9
10
suite('VoiceChatActions', function () {
11
12
function assertChunk(text: string, expected: string | undefined, offset: number): { chunk: string | undefined; offset: number } {
13
const res = parseNextChatResponseChunk(text, offset);
14
assert.strictEqual(res.chunk, expected);
15
16
return res;
17
}
18
19
test('parseNextChatResponseChunk', function () {
20
21
// Simple, no offset
22
assertChunk('Hello World', undefined, 0);
23
assertChunk('Hello World.', undefined, 0);
24
assertChunk('Hello World. ', 'Hello World.', 0);
25
assertChunk('Hello World? ', 'Hello World?', 0);
26
assertChunk('Hello World! ', 'Hello World!', 0);
27
assertChunk('Hello World: ', 'Hello World:', 0);
28
29
// Ensure chunks are parsed from the end, no offset
30
assertChunk('Hello World. How is your day? And more...', 'Hello World. How is your day?', 0);
31
32
// Ensure chunks are parsed from the end, with offset
33
let offset = assertChunk('Hello World. How is your ', 'Hello World.', 0).offset;
34
offset = assertChunk('Hello World. How is your day? And more...', 'How is your day?', offset).offset;
35
offset = assertChunk('Hello World. How is your day? And more to come! ', 'And more to come!', offset).offset;
36
assertChunk('Hello World. How is your day? And more to come! ', undefined, offset);
37
38
// Sparted by newlines
39
offset = assertChunk('Hello World.\nHow is your', 'Hello World.', 0).offset;
40
assertChunk('Hello World.\nHow is your day?\n', 'How is your day?', offset);
41
});
42
43
ensureNoDisposablesAreLeakedInTestSuite();
44
});
45
46