Skip to content

Commit c8716ef

Browse files
committed
Add tests for prompt input model whitespace
1 parent 4c4c692 commit c8716ef

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,57 @@ suite('PromptInputModel', () => {
491491
});
492492

493493
suite('trailing whitespace', () => {
494+
test('cursor index calculation with whitespace', async () => {
495+
await writePromise('$ ');
496+
fireCommandStart();
497+
await assertPromptInput('|');
498+
499+
await writePromise('echo ');
500+
await assertPromptInput('echo |');
501+
502+
await writePromise('\x1b[3D');
503+
await assertPromptInput('echo| ');
504+
505+
await writePromise('\x1b[C');
506+
await assertPromptInput('echo | ');
507+
508+
await writePromise('\x1b[C');
509+
await assertPromptInput('echo | ');
510+
511+
await writePromise('\x1b[C');
512+
await assertPromptInput('echo |');
513+
});
514+
515+
test('cursor index should not exceed command line length', async () => {
516+
await writePromise('$ ');
517+
fireCommandStart();
518+
await assertPromptInput('|');
519+
520+
await writePromise('cmd');
521+
await assertPromptInput('cmd|');
522+
523+
await writePromise('\x1b[10C');
524+
await assertPromptInput('cmd|');
525+
});
526+
527+
test('whitespace preservation in cursor calculation', async () => {
528+
await writePromise('$ ');
529+
fireCommandStart();
530+
await assertPromptInput('|');
531+
532+
await writePromise('ls -la');
533+
await assertPromptInput('ls -la|');
534+
535+
await writePromise('\x1b[3D');
536+
await assertPromptInput('ls |-la');
537+
538+
await writePromise('\x1b[3D');
539+
await assertPromptInput('ls| -la');
540+
541+
await writePromise('\x1b[2C');
542+
await assertPromptInput('ls | -la');
543+
});
544+
494545
test('delete whitespace with backspace', async () => {
495546
await writePromise('$ ');
496547
fireCommandStart();

0 commit comments

Comments
 (0)