Mercurial > vim
comparison src/testdir/test_cmdline.vim @ 19679:9199f34d838e v8.2.0396
patch 8.2.0396: cmdexpand.c insufficiently tested
Commit: https://github.com/vim/vim/commit/24ebd83e030e1c6f9a6be1f06232756ba4d00a8c
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Mar 16 21:25:24 2020 +0100
patch 8.2.0396: cmdexpand.c insufficiently tested
Problem: Cmdexpand.c insufficiently tested.
Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5789)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 16 Mar 2020 21:30:04 +0100 |
parents | f70a3c1000bb |
children | da98d2ed8dc5 |
comparison
equal
deleted
inserted
replaced
19678:ef2d704798ba | 19679:9199f34d838e |
---|---|
1 " Tests for editing the command line. | 1 " Tests for editing the command line. |
2 | 2 |
3 source check.vim | 3 source check.vim |
4 source screendump.vim | 4 source screendump.vim |
5 source view_util.vim | |
5 | 6 |
6 func Test_complete_tab() | 7 func Test_complete_tab() |
7 call writefile(['testfile'], 'Xtestfile') | 8 call writefile(['testfile'], 'Xtestfile') |
8 call feedkeys(":e Xtest\t\r", "tx") | 9 call feedkeys(":e Xtest\t\r", "tx") |
9 call assert_equal('testfile', getline(1)) | 10 call assert_equal('testfile', getline(1)) |
399 | 400 |
400 call delete('Xtags') | 401 call delete('Xtags') |
401 set tags& | 402 set tags& |
402 | 403 |
403 call assert_fails('call getcompletion("", "burp")', 'E475:') | 404 call assert_fails('call getcompletion("", "burp")', 'E475:') |
405 call assert_fails('call getcompletion("abc", [])', 'E474:') | |
404 endfunc | 406 endfunc |
405 | 407 |
406 func Test_shellcmd_completion() | 408 func Test_shellcmd_completion() |
407 let save_path = $PATH | 409 let save_path = $PATH |
408 | 410 |
637 | 639 |
638 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx') | 640 call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx') |
639 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:) | 641 call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:) |
640 | 642 |
641 unlet $X_VIM_TEST_COMPLETE_ENV | 643 unlet $X_VIM_TEST_COMPLETE_ENV |
644 endfunc | |
645 | |
646 " Test for various command-line completion | |
647 func Test_cmdline_complete_various() | |
648 " completion for a command starting with a comment | |
649 call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt') | |
650 call assert_equal("\" :|\"\<C-A>", @:) | |
651 | |
652 " completion for a range followed by a comment | |
653 call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt') | |
654 call assert_equal("\"1,2\"\<C-A>", @:) | |
655 | |
656 " completion for :k command | |
657 call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt') | |
658 call assert_equal("\"ka\<C-A>", @:) | |
659 | |
660 " completion for short version of the :s command | |
661 call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt') | |
662 call assert_equal("\"sI \<C-A>", @:) | |
663 | |
664 " completion for :write command | |
665 call mkdir('Xdir') | |
666 call writefile(['one'], 'Xdir/Xfile1') | |
667 let save_cwd = getcwd() | |
668 cd Xdir | |
669 call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt') | |
670 call assert_equal("\"w >> Xfile1", @:) | |
671 call chdir(save_cwd) | |
672 call delete('Xdir', 'rf') | |
673 | |
674 " completion for :w ! and :r ! commands | |
675 call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') | |
676 call assert_equal("\"w !invalid_xyz_cmd", @:) | |
677 call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') | |
678 call assert_equal("\"r !invalid_xyz_cmd", @:) | |
679 | |
680 " completion for :>> and :<< commands | |
681 call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt') | |
682 call assert_equal("\">>>\<C-A>", @:) | |
683 call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt') | |
684 call assert_equal("\"<<<\<C-A>", @:) | |
685 | |
686 " completion for command with +cmd argument | |
687 call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt') | |
688 call assert_equal("\"buffer +/pat Xabc", @:) | |
689 call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt') | |
690 call assert_equal("\"buffer +/pat\<C-A>", @:) | |
691 | |
692 " completion for a command with a trailing comment | |
693 call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt') | |
694 call assert_equal("\"ls \" comment\<C-A>", @:) | |
695 | |
696 " completion for a command with a trailing command | |
697 call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt') | |
698 call assert_equal("\"ls | ls", @:) | |
699 | |
700 " completion for a command with an CTRL-V escaped argument | |
701 call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt') | |
702 call assert_equal("\"ls \<C-V>a\<C-A>", @:) | |
703 | |
704 " completion for a command that doesn't take additional arguments | |
705 call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt') | |
706 call assert_equal("\"all abc\<C-A>", @:) | |
707 | |
708 " completion for a command with a command modifier | |
709 call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt') | |
710 call assert_equal("\"topleft new", @:) | |
711 | |
712 " completion for the :match command | |
713 call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt') | |
714 call assert_equal("\"match Search /pat/\<C-A>", @:) | |
715 | |
716 " completion for the :s command | |
717 call feedkeys(":s/from/to/g\<C-A>\<C-B>\"\<CR>", 'xt') | |
718 call assert_equal("\"s/from/to/g\<C-A>", @:) | |
719 | |
720 " completion for the :dlist command | |
721 call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt') | |
722 call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:) | |
723 | |
724 " completion for the :doautocmd command | |
725 call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt') | |
726 call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:) | |
727 | |
728 " completion for the :augroup command | |
729 augroup XTest | |
730 augroup END | |
731 call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt') | |
732 call assert_equal("\"augroup XTest", @:) | |
733 augroup! XTest | |
734 | |
735 " completion for the :unlet command | |
736 call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt') | |
737 call assert_equal("\"unlet one two", @:) | |
738 | |
739 " completion for the :bdelete command | |
740 call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt') | |
741 call assert_equal("\"bdel a b c", @:) | |
742 | |
743 " completion for the :mapclear command | |
744 call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt') | |
745 call assert_equal("\"mapclear <buffer>", @:) | |
746 | |
747 " completion for user defined commands with menu names | |
748 menu Test.foo :ls<CR> | |
749 com -nargs=* -complete=menu MyCmd | |
750 call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt') | |
751 call assert_equal('"MyCmd Test.', @:) | |
752 delcom MyCmd | |
753 unmenu Test | |
754 | |
755 " completion for user defined commands with mappings | |
756 mapclear | |
757 map <F3> :ls<CR> | |
758 com -nargs=* -complete=mapping MyCmd | |
759 call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt') | |
760 call assert_equal('"MyCmd <F3>', @:) | |
761 mapclear | |
762 delcom MyCmd | |
763 | |
764 " completion for :set path= with multiple backslashes | |
765 call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt') | |
766 call assert_equal('"set path=a\\\ b', @:) | |
767 | |
768 " completion for :set dir= with a backslash | |
769 call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt') | |
770 call assert_equal('"set dir=a\ b', @:) | |
771 | |
772 " completion for the :py3 commands | |
773 call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt') | |
774 call assert_equal('"py3 py3do py3file', @:) | |
775 | |
776 " redir @" is not the start of a comment. So complete after that | |
777 call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt') | |
778 call assert_equal('"redir @" | cwindow', @:) | |
779 | |
780 " completion after a backtick | |
781 call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt') | |
782 call assert_equal('"e `a1b2c', @:) | |
783 | |
784 " completion for the expression register | |
785 call feedkeys(":\"\<C-R>=float2\t\"\<C-B>\"\<CR>", 'xt') | |
786 call assert_equal('"float2nr("', @=) | |
642 endfunc | 787 endfunc |
643 | 788 |
644 func Test_cmdline_write_alternatefile() | 789 func Test_cmdline_write_alternatefile() |
645 new | 790 new |
646 call setline('.', ['one', 'two']) | 791 call setline('.', ['one', 'two']) |
1114 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt') | 1259 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt') |
1115 call assert_equal('ab12xyc', getline(1)) | 1260 call assert_equal('ab12xyc', getline(1)) |
1116 close! | 1261 close! |
1117 endfunc | 1262 endfunc |
1118 | 1263 |
1119 " Return the 'len' characters in screen starting from (row,col) | |
1120 func s:ScreenLine(row, col, len) | |
1121 let s = '' | |
1122 for i in range(a:len) | |
1123 let s .= nr2char(screenchar(a:row, a:col + i)) | |
1124 endfor | |
1125 return s | |
1126 endfunc | |
1127 | |
1128 " Test for 'wildmode' | 1264 " Test for 'wildmode' |
1129 func Test_wildmode() | 1265 func Test_wildmode() |
1130 func T(a, c, p) | 1266 func T(a, c, p) |
1131 return "oneA\noneB\noneC" | 1267 return "oneA\noneB\noneC" |
1132 endfunc | 1268 endfunc |
1133 command -nargs=1 -complete=custom,T MyCmd | 1269 command -nargs=1 -complete=custom,T MyCmd |
1134 | 1270 |
1135 func SaveScreenLine() | 1271 func SaveScreenLine() |
1136 let g:Sline = s:ScreenLine(&lines - 1, 1, 20) | 1272 let g:Sline = Screenline(&lines - 1) |
1137 return '' | 1273 return '' |
1138 endfunc | 1274 endfunc |
1139 cnoremap <expr> <F2> SaveScreenLine() | 1275 cnoremap <expr> <F2> SaveScreenLine() |
1140 | 1276 |
1141 set nowildmenu | 1277 set nowildmenu |
1142 set wildmode=full,list | 1278 set wildmode=full,list |
1143 let g:Sline = '' | 1279 let g:Sline = '' |
1144 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt') | 1280 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt') |
1145 call assert_equal('oneA oneB oneC ', g:Sline) | 1281 call assert_equal('oneA oneB oneC', g:Sline) |
1146 call assert_equal('"MyCmd oneA', @:) | 1282 call assert_equal('"MyCmd oneA', @:) |
1147 | 1283 |
1148 set wildmode=longest,full | 1284 set wildmode=longest,full |
1149 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') | 1285 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') |
1150 call assert_equal('"MyCmd one', @:) | 1286 call assert_equal('"MyCmd one', @:) |
1156 call assert_equal('"MyCmd one', @:) | 1292 call assert_equal('"MyCmd one', @:) |
1157 | 1293 |
1158 set wildmode=list:longest | 1294 set wildmode=list:longest |
1159 let g:Sline = '' | 1295 let g:Sline = '' |
1160 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt') | 1296 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt') |
1161 call assert_equal('oneA oneB oneC ', g:Sline) | 1297 call assert_equal('oneA oneB oneC', g:Sline) |
1162 call assert_equal('"MyCmd one', @:) | 1298 call assert_equal('"MyCmd one', @:) |
1163 | 1299 |
1164 set wildmode="" | 1300 set wildmode="" |
1165 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt') | 1301 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt') |
1166 call assert_equal('"MyCmd oneA', @:) | 1302 call assert_equal('"MyCmd oneA', @:) |
1167 | 1303 |
1304 " Test for wildmode=longest with 'fileignorecase' set | |
1305 set wildmode=longest | |
1306 set fileignorecase | |
1307 argadd AA AAA AAAA | |
1308 call feedkeys(":buffer \t\<C-B>\"\<CR>", 'xt') | |
1309 call assert_equal('"buffer AA', @:) | |
1310 set fileignorecase& | |
1311 | |
1312 " Test for listing files with wildmode=list | |
1313 set wildmode=list | |
1314 let g:Sline = '' | |
1315 call feedkeys(":b A\t\t\<F2>\<C-B>\"\<CR>", 'xt') | |
1316 call assert_equal('AA AAA AAAA', g:Sline) | |
1317 call assert_equal('"b A', @:) | |
1318 | |
1319 %argdelete | |
1168 delcommand MyCmd | 1320 delcommand MyCmd |
1169 delfunc T | 1321 delfunc T |
1170 delfunc SaveScreenLine | 1322 delfunc SaveScreenLine |
1171 cunmap <F2> | 1323 cunmap <F2> |
1172 set wildmode& | 1324 set wildmode& |
1325 %bwipe! | |
1173 endfunc | 1326 endfunc |
1174 | 1327 |
1175 " Test for interrupting the command-line completion | 1328 " Test for interrupting the command-line completion |
1176 func Test_interrupt_compl() | 1329 func Test_interrupt_compl() |
1177 func F(lead, cmdl, p) | 1330 func F(lead, cmdl, p) |