Skip to content

Commit 7be8d0d

Browse files
committed
Simplify assertion in prompt input model tests
1 parent f04bd7d commit 7be8d0d

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/vs/platform/terminal/test/common/capabilities/commandDetection/promptInputModel.test.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TestPromptInputModel extends PromptInputModel {
1919
}
2020
}
2121

22-
suite('PromptInputModel', () => {
22+
suite.only('PromptInputModel', () => {
2323
const store = ensureNoDisposablesAreLeakedInTestSuite();
2424
let promptInputModel: TestPromptInputModel;
2525
let xterm: Terminal;
@@ -40,6 +40,23 @@ suite('PromptInputModel', () => {
4040
}
4141
}
4242

43+
function assertPromptInput(valueWithCursor: string) {
44+
if (!valueWithCursor.includes('|')) {
45+
throw new Error('assertPromptInput must contain | character');
46+
}
47+
const actualValueWithCursor = promptInputModel.value.substring(0, promptInputModel.cursorIndex) + '|' + promptInputModel.value.substring(promptInputModel.cursorIndex);
48+
strictEqual(
49+
actualValueWithCursor.replaceAll('\n', '\u23CE'),
50+
valueWithCursor.replaceAll('\n', '\u23CE')
51+
);
52+
53+
// This shouldn't be needed but include as a sanity check
54+
const value = valueWithCursor.replace('|', '');
55+
const cursorIndex = valueWithCursor.indexOf('|');
56+
strictEqual(promptInputModel.value, value);
57+
strictEqual(promptInputModel.cursorIndex, cursorIndex,);
58+
}
59+
4360
suite('Windows, pwsh 7.4.2, starship prompt', () => {
4461
test('input with ignored ghost text', async () => {
4562
await replayEvents([
@@ -52,7 +69,7 @@ suite('PromptInputModel', () => {
5269
]);
5370
onCommandStart.fire({ marker: xterm.registerMarker() } as ITerminalCommand);
5471
promptInputModel.forceSync();
55-
strictEqual(promptInputModel.value, '');
72+
assertPromptInput('|');
5673

5774
await replayEvents([
5875
'[?25lfakecommand[?25h',
@@ -63,8 +80,7 @@ suite('PromptInputModel', () => {
6380
'',
6481
]);
6582
promptInputModel.forceSync();
66-
strictEqual(promptInputModel.value, 'foo');
67-
strictEqual(promptInputModel.cursorIndex, 3);
83+
assertPromptInput('foo|');
6884
});
6985
});
7086
});

0 commit comments

Comments
 (0)