Mercurial > vim
comparison src/testdir/test_ins_complete.vim @ 20285:bce10d039e06 v8.2.0698
patch 8.2.0698: insert mode completion not fully tested
Commit: https://github.com/vim/vim/commit/f9ab52e155dc13f59b654d754041fe78e17b9074
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 5 19:57:18 2020 +0200
patch 8.2.0698: insert mode completion not fully tested
Problem: Insert mode completion not fully tested.
Solution: Add a few more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/6041)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 05 May 2020 20:00:05 +0200 |
parents | 06a1dd50463e |
children | 08940efa6b4e |
comparison
equal
deleted
inserted
replaced
20284:7b7c9d3abf7c | 20285:bce10d039e06 |
---|---|
491 endfunc | 491 endfunc |
492 set completefunc=CompleteFunc2 | 492 set completefunc=CompleteFunc2 |
493 call setline(1, ['', 'abcd', '']) | 493 call setline(1, ['', 'abcd', '']) |
494 call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:') | 494 call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:') |
495 | 495 |
496 " Jump to a different window from the complete function | |
497 " TODO: The following test causes an ASAN failure. Once this issue is | |
498 " addressed, enable the following test. | |
499 "func! CompleteFunc(findstart, base) | |
500 " if a:findstart == 1 | |
501 " return col('.') - 1 | |
502 " endif | |
503 " wincmd p | |
504 " return ['a', 'b'] | |
505 "endfunc | |
506 "set completefunc=CompleteFunc | |
507 "new | |
508 "call assert_fails('exe "normal a\<C-X>\<C-U>"', 'E839:') | |
509 "close! | |
510 | |
496 set completefunc& | 511 set completefunc& |
497 delfunc CompleteFunc | 512 delfunc CompleteFunc |
498 delfunc CompleteFunc2 | 513 delfunc CompleteFunc2 |
514 close! | |
515 endfunc | |
516 | |
517 " Test for returning non-string values from 'completefunc' | |
518 func Test_completefunc_invalid_data() | |
519 new | |
520 func! CompleteFunc(findstart, base) | |
521 if a:findstart == 1 | |
522 return col('.') - 1 | |
523 endif | |
524 return [{}, '', 'moon'] | |
525 endfunc | |
526 set completefunc=CompleteFunc | |
527 exe "normal i\<C-X>\<C-U>" | |
528 call assert_equal('moon', getline(1)) | |
529 set completefunc& | |
499 close! | 530 close! |
500 endfunc | 531 endfunc |
501 | 532 |
502 " Test for errors in using complete() function | 533 " Test for errors in using complete() function |
503 func Test_complete_func_error() | 534 func Test_complete_func_error() |
511 endfunc | 542 endfunc |
512 call assert_fails('exe "normal i\<C-R>=ListMonths()\<CR>"', 'E474:') | 543 call assert_fails('exe "normal i\<C-R>=ListMonths()\<CR>"', 'E474:') |
513 delfunc ListColors | 544 delfunc ListColors |
514 delfunc ListMonths | 545 delfunc ListMonths |
515 call assert_fails('call complete_info({})', 'E714:') | 546 call assert_fails('call complete_info({})', 'E714:') |
547 call assert_equal([], complete_info(['items']).items) | |
516 endfunc | 548 endfunc |
517 | 549 |
518 " Test for completing words following a completed word in a line | 550 " Test for completing words following a completed word in a line |
519 func Test_complete_wrapscan() | 551 func Test_complete_wrapscan() |
520 " complete words from another buffer | 552 " complete words from another buffer |
533 call feedkeys("ion\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>", 'xt') | 565 call feedkeys("ion\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>", 'xt') |
534 call assert_equal('one two one two', getline(2)) | 566 call assert_equal('one two one two', getline(2)) |
535 close! | 567 close! |
536 endfunc | 568 endfunc |
537 | 569 |
570 " Test for completing special characters | |
571 func Test_complete_special_chars() | |
572 new | |
573 call setline(1, 'int .*[-\^$ func float') | |
574 call feedkeys("oin\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>", 'xt') | |
575 call assert_equal('int .*[-\^$ func float', getline(2)) | |
576 close! | |
577 endfunc | |
578 | |
579 " Test for completion when text is wrapped across lines. | |
580 func Test_complete_across_line() | |
581 new | |
582 call setline(1, ['red green blue', 'one two three']) | |
583 setlocal textwidth=20 | |
584 exe "normal 2G$a re\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>" | |
585 call assert_equal(['one two three red', 'green blue one'], getline(2, '$')) | |
586 close! | |
587 endfunc | |
588 | |
589 " Test for using CTRL-L to add one character when completing matching | |
590 func Test_complete_add_onechar() | |
591 new | |
592 call setline(1, ['wool', 'woodwork']) | |
593 call feedkeys("Gowoo\<C-P>\<C-P>\<C-P>\<C-L>f", 'xt') | |
594 call assert_equal('woof', getline(3)) | |
595 | |
596 " use 'ignorecase' and backspace to erase characters from the prefix string | |
597 " and then add letters using CTRL-L | |
598 %d | |
599 set ignorecase backspace=2 | |
600 setlocal complete=. | |
601 call setline(1, ['workhorse', 'workload']) | |
602 normal Go | |
603 exe "normal aWOR\<C-P>\<bs>\<bs>\<bs>\<bs>\<bs>\<bs>\<C-L>r\<C-L>\<C-L>" | |
604 call assert_equal('workh', getline(3)) | |
605 set ignorecase& backspace& | |
606 close! | |
607 endfunc | |
608 | |
609 " Test insert completion with 'cindent' (adjust the indent) | |
610 func Test_complete_with_cindent() | |
611 new | |
612 setlocal cindent | |
613 call setline(1, ['if (i == 1)', " j = 2;"]) | |
614 exe "normal Go{\<CR>i\<C-X>\<C-L>\<C-X>\<C-L>\<CR>}" | |
615 call assert_equal(['{', "\tif (i == 1)", "\t\tj = 2;", '}'], getline(3, '$')) | |
616 | |
617 %d | |
618 call setline(1, ['when while', '{', '']) | |
619 setlocal cinkeys+==while | |
620 exe "normal Giwh\<C-P> " | |
621 call assert_equal("\twhile ", getline('$')) | |
622 close! | |
623 endfunc | |
624 | |
625 " Test for <CTRL-X> <CTRL-V> completion. Complete commands and functions | |
626 func Test_complete_cmdline() | |
627 new | |
628 exe "normal icaddb\<C-X>\<C-V>" | |
629 call assert_equal('caddbuffer', getline(1)) | |
630 exe "normal ocall getqf\<C-X>\<C-V>" | |
631 call assert_equal('call getqflist(', getline(2)) | |
632 exe "normal oabcxyz(\<C-X>\<C-V>" | |
633 call assert_equal('abcxyz(', getline(3)) | |
634 close! | |
635 endfunc | |
636 | |
538 " vim: shiftwidth=2 sts=2 expandtab | 637 " vim: shiftwidth=2 sts=2 expandtab |