Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 1 | " Tests for editing the command line. |
| 2 | |
Bram Moolenaar | 4facea3 | 2019-10-12 20:17:40 +0200 | [diff] [blame] | 3 | source check.vim |
| 4 | source screendump.vim |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 5 | source view_util.vim |
Bram Moolenaar | c82dd86 | 2020-06-07 17:30:33 +0200 | [diff] [blame] | 6 | source shared.vim |
Bram Moolenaar | 4facea3 | 2019-10-12 20:17:40 +0200 | [diff] [blame] | 7 | |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 8 | func Test_complete_tab() |
| 9 | call writefile(['testfile'], 'Xtestfile') |
| 10 | call feedkeys(":e Xtest\t\r", "tx") |
| 11 | call assert_equal('testfile', getline(1)) |
Albert Liu | 6024c04 | 2021-08-27 20:59:35 +0200 | [diff] [blame] | 12 | |
| 13 | " Pressing <Tab> after '%' completes the current file, also on MS-Windows |
| 14 | call feedkeys(":e %\t\r", "tx") |
| 15 | call assert_equal('e Xtestfile', @:) |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 16 | call delete('Xtestfile') |
| 17 | endfunc |
| 18 | |
| 19 | func Test_complete_list() |
| 20 | " We can't see the output, but at least we check the code runs properly. |
| 21 | call feedkeys(":e test\<C-D>\r", "tx") |
| 22 | call assert_equal('test', expand('%:t')) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 23 | |
| 24 | " If a command doesn't support completion, then CTRL-D should be literally |
| 25 | " used. |
| 26 | call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt') |
| 27 | call assert_equal("\"chistory \<C-D>", @:) |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 28 | endfunc |
| 29 | |
| 30 | func Test_complete_wildmenu() |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 31 | call mkdir('Xdir1/Xdir2', 'p') |
| 32 | call writefile(['testfile1'], 'Xdir1/Xtestfile1') |
| 33 | call writefile(['testfile2'], 'Xdir1/Xtestfile2') |
| 34 | call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3') |
| 35 | call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 36 | set wildmenu |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 37 | |
| 38 | " Pressing <Tab> completes, and moves to next files when pressing again. |
| 39 | call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx') |
| 40 | call assert_equal('testfile1', getline(1)) |
| 41 | call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 42 | call assert_equal('testfile2', getline(1)) |
| 43 | |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 44 | " <S-Tab> is like <Tab> but begin with the last match and then go to |
| 45 | " previous. |
| 46 | call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx') |
| 47 | call assert_equal('testfile2', getline(1)) |
| 48 | call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx') |
| 49 | call assert_equal('testfile1', getline(1)) |
| 50 | |
| 51 | " <Left>/<Right> to move to previous/next file. |
| 52 | call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx') |
| 53 | call assert_equal('testfile1', getline(1)) |
| 54 | call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx') |
| 55 | call assert_equal('testfile2', getline(1)) |
| 56 | call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx') |
| 57 | call assert_equal('testfile1', getline(1)) |
| 58 | |
| 59 | " <Up>/<Down> to go up/down directories. |
| 60 | call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx') |
| 61 | call assert_equal('testfile3', getline(1)) |
| 62 | call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx') |
| 63 | call assert_equal('testfile1', getline(1)) |
| 64 | |
Bram Moolenaar | 3e112ac | 2020-12-28 13:41:53 +0100 | [diff] [blame] | 65 | " this fails in some Unix GUIs, not sure why |
| 66 | if !has('unix') || !has('gui_running') |
| 67 | " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is |
| 68 | " different than 'wildchar'. |
| 69 | set wildcharm=<C-Z> |
| 70 | cnoremap <C-J> <Down><C-Z> |
| 71 | cnoremap <C-K> <Up><C-Z> |
| 72 | call feedkeys(":e Xdir1/\<Tab>\<C-J>\<CR>", 'tx') |
| 73 | call assert_equal('testfile3', getline(1)) |
| 74 | call feedkeys(":e Xdir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx') |
| 75 | call assert_equal('testfile1', getline(1)) |
| 76 | set wildcharm=0 |
| 77 | cunmap <C-J> |
| 78 | cunmap <C-K> |
| 79 | endif |
Bram Moolenaar | b0ac4ea | 2020-12-26 12:06:54 +0100 | [diff] [blame] | 80 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 81 | " Test for canceling the wild menu by adding a character |
| 82 | redrawstatus |
| 83 | call feedkeys(":e Xdir1/\<Tab>x\<C-B>\"\<CR>", 'xt') |
| 84 | call assert_equal('"e Xdir1/Xdir2/x', @:) |
| 85 | |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 86 | " Completion using a relative path |
| 87 | cd Xdir1/Xdir2 |
| 88 | call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx') |
| 89 | call assert_equal('"e Xtestfile3 Xtestfile4', @:) |
| 90 | cd - |
| 91 | |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 92 | cnoremap <expr> <F2> wildmenumode() |
| 93 | call feedkeys(":cd Xdir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx') |
| 94 | call assert_equal('"cd Xdir1/1', @:) |
| 95 | cunmap <F2> |
| 96 | |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 97 | " cleanup |
| 98 | %bwipe |
| 99 | call delete('Xdir1/Xdir2/Xtestfile4') |
| 100 | call delete('Xdir1/Xdir2/Xtestfile3') |
| 101 | call delete('Xdir1/Xtestfile2') |
| 102 | call delete('Xdir1/Xtestfile1') |
| 103 | call delete('Xdir1/Xdir2', 'd') |
| 104 | call delete('Xdir1', 'd') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 105 | set nowildmenu |
| 106 | endfunc |
Bram Moolenaar | 4b2ce12 | 2020-11-21 21:41:41 +0100 | [diff] [blame] | 107 | |
Bram Moolenaar | a60053b | 2020-09-03 16:50:13 +0200 | [diff] [blame] | 108 | func Test_wildmenu_screendump() |
| 109 | CheckScreendump |
| 110 | |
| 111 | let lines =<< trim [SCRIPT] |
| 112 | set wildmenu hlsearch |
| 113 | [SCRIPT] |
| 114 | call writefile(lines, 'XTest_wildmenu') |
| 115 | |
| 116 | let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8}) |
| 117 | call term_sendkeys(buf, ":vim\<Tab>") |
| 118 | call VerifyScreenDump(buf, 'Test_wildmenu_1', {}) |
| 119 | |
| 120 | call term_sendkeys(buf, "\<Tab>") |
| 121 | call VerifyScreenDump(buf, 'Test_wildmenu_2', {}) |
| 122 | |
| 123 | call term_sendkeys(buf, "\<Tab>") |
| 124 | call VerifyScreenDump(buf, 'Test_wildmenu_3', {}) |
| 125 | |
Bram Moolenaar | 39f3b14 | 2021-02-14 12:57:36 +0100 | [diff] [blame] | 126 | call term_sendkeys(buf, "\<Tab>\<Tab>") |
Bram Moolenaar | a60053b | 2020-09-03 16:50:13 +0200 | [diff] [blame] | 127 | call VerifyScreenDump(buf, 'Test_wildmenu_4', {}) |
| 128 | call term_sendkeys(buf, "\<Esc>") |
| 129 | |
| 130 | " clean up |
| 131 | call StopVimInTerminal(buf) |
| 132 | call delete('XTest_wildmenu') |
| 133 | endfunc |
| 134 | |
Bram Moolenaar | cf5fdf7 | 2017-03-02 23:05:51 +0100 | [diff] [blame] | 135 | func Test_map_completion() |
Bram Moolenaar | cf5fdf7 | 2017-03-02 23:05:51 +0100 | [diff] [blame] | 136 | call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt') |
| 137 | call assert_equal('"map <unique> <silent>', getreg(':')) |
| 138 | call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt') |
| 139 | call assert_equal('"map <script> <unique>', getreg(':')) |
| 140 | call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt') |
| 141 | call assert_equal('"map <expr> <script>', getreg(':')) |
| 142 | call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt') |
| 143 | call assert_equal('"map <buffer> <expr>', getreg(':')) |
| 144 | call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt') |
| 145 | call assert_equal('"map <nowait> <buffer>', getreg(':')) |
| 146 | call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt') |
| 147 | call assert_equal('"map <special> <nowait>', getreg(':')) |
| 148 | call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt') |
| 149 | call assert_equal('"map <silent> <special>', getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 150 | |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 151 | map <Middle>x middle |
| 152 | |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 153 | map ,f commaf |
| 154 | map ,g commaf |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 155 | map <Left> left |
| 156 | map <A-Left>x shiftleft |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 157 | call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt') |
| 158 | call assert_equal('"map ,f', getreg(':')) |
| 159 | call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt') |
| 160 | call assert_equal('"map ,g', getreg(':')) |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 161 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 162 | call assert_equal('"map <Left>', getreg(':')) |
| 163 | call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt') |
Bram Moolenaar | 92b9e60 | 2019-05-03 16:49:25 +0200 | [diff] [blame] | 164 | call assert_equal("\"map <A-Left>\<Tab>", getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 165 | unmap ,f |
| 166 | unmap ,g |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 167 | unmap <Left> |
| 168 | unmap <A-Left>x |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 169 | |
| 170 | set cpo-=< cpo-=B cpo-=k |
| 171 | map <Left> left |
| 172 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 173 | call assert_equal('"map <Left>', getreg(':')) |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 174 | call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt') |
Bram Moolenaar | 92b9e60 | 2019-05-03 16:49:25 +0200 | [diff] [blame] | 175 | call assert_equal("\"map <M\<Tab>", getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 176 | unmap <Left> |
| 177 | |
| 178 | set cpo+=< |
| 179 | map <Left> left |
Bram Moolenaar | 61df0c7 | 2019-05-03 21:10:36 +0200 | [diff] [blame] | 180 | exe "set t_k6=\<Esc>[17~" |
| 181 | call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt') |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 182 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 183 | call assert_equal('"map <Left>', getreg(':')) |
Bram Moolenaar | 510671a | 2019-05-04 19:26:56 +0200 | [diff] [blame] | 184 | if !has('gui_running') |
| 185 | call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt') |
| 186 | call assert_equal("\"map <F6>x", getreg(':')) |
| 187 | endif |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 188 | unmap <Left> |
Bram Moolenaar | 61df0c7 | 2019-05-03 21:10:36 +0200 | [diff] [blame] | 189 | call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt') |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 190 | set cpo-=< |
| 191 | |
| 192 | set cpo+=B |
| 193 | map <Left> left |
| 194 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 195 | call assert_equal('"map <Left>', getreg(':')) |
| 196 | unmap <Left> |
| 197 | set cpo-=B |
| 198 | |
| 199 | set cpo+=k |
| 200 | map <Left> left |
| 201 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 202 | call assert_equal('"map <Left>', getreg(':')) |
| 203 | unmap <Left> |
| 204 | set cpo-=k |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 205 | |
Bram Moolenaar | 531be47 | 2020-09-23 22:38:05 +0200 | [diff] [blame] | 206 | call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:') |
| 207 | |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 208 | unmap <Middle>x |
| 209 | set cpo&vim |
Bram Moolenaar | cf5fdf7 | 2017-03-02 23:05:51 +0100 | [diff] [blame] | 210 | endfunc |
| 211 | |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 212 | func Test_match_completion() |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 213 | hi Aardig ctermfg=green |
| 214 | call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt') |
| 215 | call assert_equal('"match Aardig', getreg(':')) |
| 216 | call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt') |
| 217 | call assert_equal('"match none', getreg(':')) |
| 218 | endfunc |
| 219 | |
| 220 | func Test_highlight_completion() |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 221 | hi Aardig ctermfg=green |
| 222 | call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt') |
| 223 | call assert_equal('"hi Aardig', getreg(':')) |
Bram Moolenaar | ea58815 | 2017-04-10 22:45:30 +0200 | [diff] [blame] | 224 | call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt') |
| 225 | call assert_equal('"hi default Aardig', getreg(':')) |
| 226 | call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt') |
| 227 | call assert_equal('"hi clear Aardig', getreg(':')) |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 228 | call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 229 | call assert_equal('"hi link', getreg(':')) |
| 230 | call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 231 | call assert_equal('"hi default', getreg(':')) |
| 232 | call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 233 | call assert_equal('"hi clear', getreg(':')) |
Bram Moolenaar | 75e1567 | 2020-06-28 13:10:22 +0200 | [diff] [blame] | 234 | call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt') |
| 235 | call assert_equal('"hi clear Aardig Aardig', getreg(':')) |
| 236 | call feedkeys(":hi Aardig \<Tab>\<C-B>\"\<CR>", 'xt') |
| 237 | call assert_equal("\"hi Aardig \t", getreg(':')) |
Bram Moolenaar | c96272e | 2017-03-26 13:50:09 +0200 | [diff] [blame] | 238 | |
| 239 | " A cleared group does not show up in completions. |
| 240 | hi Anders ctermfg=green |
| 241 | call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight')) |
| 242 | hi clear Aardig |
| 243 | call assert_equal(['Anders'], getcompletion('A', 'highlight')) |
| 244 | hi clear Anders |
| 245 | call assert_equal([], getcompletion('A', 'highlight')) |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 246 | endfunc |
| 247 | |
Bram Moolenaar | 75e1567 | 2020-06-28 13:10:22 +0200 | [diff] [blame] | 248 | " Test for command-line expansion of "hi Ni " (easter egg) |
| 249 | func Test_highlight_easter_egg() |
| 250 | call test_override('ui_delay', 1) |
| 251 | call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt') |
| 252 | call assert_equal("\"hi Ni \<Tab>", @:) |
| 253 | call test_override('ALL', 0) |
| 254 | endfunc |
| 255 | |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 256 | func Test_getcompletion() |
| 257 | let groupcount = len(getcompletion('', 'event')) |
| 258 | call assert_true(groupcount > 0) |
Bram Moolenaar | 4c313b1 | 2019-08-24 22:58:31 +0200 | [diff] [blame] | 259 | let matchcount = len('File'->getcompletion('event')) |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 260 | call assert_true(matchcount > 0) |
| 261 | call assert_true(groupcount > matchcount) |
| 262 | |
Bram Moolenaar | 0d3e24b | 2016-07-09 19:20:59 +0200 | [diff] [blame] | 263 | if has('menu') |
| 264 | source $VIMRUNTIME/menu.vim |
| 265 | let matchcount = len(getcompletion('', 'menu')) |
| 266 | call assert_true(matchcount > 0) |
| 267 | call assert_equal(['File.'], getcompletion('File', 'menu')) |
| 268 | call assert_true(matchcount > 0) |
| 269 | let matchcount = len(getcompletion('File.', 'menu')) |
| 270 | call assert_true(matchcount > 0) |
| 271 | endif |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 272 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 273 | let l = getcompletion('v:n', 'var') |
| 274 | call assert_true(index(l, 'v:null') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 275 | let l = getcompletion('v:notexists', 'var') |
| 276 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 277 | |
Bram Moolenaar | cd43eff | 2018-03-29 15:55:38 +0200 | [diff] [blame] | 278 | args a.c b.c |
| 279 | let l = getcompletion('', 'arglist') |
| 280 | call assert_equal(['a.c', 'b.c'], l) |
| 281 | %argdelete |
| 282 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 283 | let l = getcompletion('', 'augroup') |
| 284 | call assert_true(index(l, 'END') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 285 | let l = getcompletion('blahblah', 'augroup') |
| 286 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 287 | |
| 288 | let l = getcompletion('', 'behave') |
| 289 | call assert_true(index(l, 'mswin') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 290 | let l = getcompletion('not', 'behave') |
| 291 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 292 | |
| 293 | let l = getcompletion('', 'color') |
| 294 | call assert_true(index(l, 'default') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 295 | let l = getcompletion('dirty', 'color') |
| 296 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 297 | |
| 298 | let l = getcompletion('', 'command') |
| 299 | call assert_true(index(l, 'sleep') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 300 | let l = getcompletion('awake', 'command') |
| 301 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 302 | |
| 303 | let l = getcompletion('', 'dir') |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 304 | call assert_true(index(l, 'samples/') >= 0) |
| 305 | let l = getcompletion('NoMatch', 'dir') |
| 306 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 307 | |
Shougo Matsushita | ae38a9d | 2021-10-21 11:39:53 +0100 | [diff] [blame] | 308 | if glob('~/*') !=# '' |
| 309 | let l = getcompletion('~/', 'dir') |
| 310 | call assert_true(l[0][0] ==# '~') |
| 311 | endif |
| 312 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 313 | let l = getcompletion('exe', 'expression') |
| 314 | call assert_true(index(l, 'executable(') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 315 | let l = getcompletion('kill', 'expression') |
| 316 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 317 | |
| 318 | let l = getcompletion('tag', 'function') |
| 319 | call assert_true(index(l, 'taglist(') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 320 | let l = getcompletion('paint', 'function') |
| 321 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 322 | |
Bram Moolenaar | b49edc1 | 2016-07-23 15:47:34 +0200 | [diff] [blame] | 323 | let Flambda = {-> 'hello'} |
| 324 | let l = getcompletion('', 'function') |
| 325 | let l = filter(l, {i, v -> v =~ 'lambda'}) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 326 | call assert_equal([], l) |
Bram Moolenaar | b49edc1 | 2016-07-23 15:47:34 +0200 | [diff] [blame] | 327 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 328 | let l = getcompletion('run', 'file') |
| 329 | call assert_true(index(l, 'runtest.vim') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 330 | let l = getcompletion('walk', 'file') |
| 331 | call assert_equal([], l) |
Bram Moolenaar | e9d58a6 | 2016-08-13 15:07:41 +0200 | [diff] [blame] | 332 | set wildignore=*.vim |
| 333 | let l = getcompletion('run', 'file', 1) |
| 334 | call assert_true(index(l, 'runtest.vim') < 0) |
| 335 | set wildignore& |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 336 | |
| 337 | let l = getcompletion('ha', 'filetype') |
| 338 | call assert_true(index(l, 'hamster') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 339 | let l = getcompletion('horse', 'filetype') |
| 340 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 341 | |
| 342 | let l = getcompletion('z', 'syntax') |
| 343 | call assert_true(index(l, 'zimbu') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 344 | let l = getcompletion('emacs', 'syntax') |
| 345 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 346 | |
| 347 | let l = getcompletion('jikes', 'compiler') |
| 348 | call assert_true(index(l, 'jikes') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 349 | let l = getcompletion('break', 'compiler') |
| 350 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 351 | |
| 352 | let l = getcompletion('last', 'help') |
| 353 | call assert_true(index(l, ':tablast') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 354 | let l = getcompletion('giveup', 'help') |
| 355 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 356 | |
| 357 | let l = getcompletion('time', 'option') |
| 358 | call assert_true(index(l, 'timeoutlen') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 359 | let l = getcompletion('space', 'option') |
| 360 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 361 | |
| 362 | let l = getcompletion('er', 'highlight') |
| 363 | call assert_true(index(l, 'ErrorMsg') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 364 | let l = getcompletion('dark', 'highlight') |
| 365 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 366 | |
Bram Moolenaar | 9e507ca | 2016-10-15 15:39:39 +0200 | [diff] [blame] | 367 | let l = getcompletion('', 'messages') |
| 368 | call assert_true(index(l, 'clear') >= 0) |
| 369 | let l = getcompletion('not', 'messages') |
| 370 | call assert_equal([], l) |
| 371 | |
Bram Moolenaar | cae92dc | 2017-08-06 15:22:15 +0200 | [diff] [blame] | 372 | let l = getcompletion('', 'mapclear') |
| 373 | call assert_true(index(l, '<buffer>') >= 0) |
| 374 | let l = getcompletion('not', 'mapclear') |
| 375 | call assert_equal([], l) |
| 376 | |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 377 | let l = getcompletion('.', 'shellcmd') |
Bram Moolenaar | 6ab9e42 | 2018-07-28 19:20:13 +0200 | [diff] [blame] | 378 | call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"')) |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 379 | call assert_equal(-1, match(l[2:], '^\.\.\?/$')) |
| 380 | let root = has('win32') ? 'C:\\' : '/' |
| 381 | let l = getcompletion(root, 'shellcmd') |
| 382 | let expected = map(filter(glob(root . '*', 0, 1), |
| 383 | \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val') |
| 384 | call assert_equal(expected, l) |
| 385 | |
Bram Moolenaar | b650b98 | 2016-08-05 20:35:13 +0200 | [diff] [blame] | 386 | if has('cscope') |
| 387 | let l = getcompletion('', 'cscope') |
| 388 | let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show'] |
| 389 | call assert_equal(cmds, l) |
| 390 | " using cmdline completion must not change the result |
| 391 | call feedkeys(":cscope find \<c-d>\<c-c>", 'xt') |
| 392 | let l = getcompletion('', 'cscope') |
| 393 | call assert_equal(cmds, l) |
| 394 | let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't'] |
| 395 | let l = getcompletion('find ', 'cscope') |
| 396 | call assert_equal(keys, l) |
| 397 | endif |
| 398 | |
Bram Moolenaar | 7522f69 | 2016-08-06 14:12:50 +0200 | [diff] [blame] | 399 | if has('signs') |
| 400 | sign define Testing linehl=Comment |
| 401 | let l = getcompletion('', 'sign') |
| 402 | let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace'] |
| 403 | call assert_equal(cmds, l) |
| 404 | " using cmdline completion must not change the result |
| 405 | call feedkeys(":sign list \<c-d>\<c-c>", 'xt') |
| 406 | let l = getcompletion('', 'sign') |
| 407 | call assert_equal(cmds, l) |
| 408 | let l = getcompletion('list ', 'sign') |
| 409 | call assert_equal(['Testing'], l) |
| 410 | endif |
| 411 | |
Bram Moolenaar | 1f1fd44 | 2020-06-07 18:45:14 +0200 | [diff] [blame] | 412 | " Command line completion tests |
| 413 | let l = getcompletion('cd ', 'cmdline') |
| 414 | call assert_true(index(l, 'samples/') >= 0) |
| 415 | let l = getcompletion('cd NoMatch', 'cmdline') |
| 416 | call assert_equal([], l) |
| 417 | let l = getcompletion('let v:n', 'cmdline') |
| 418 | call assert_true(index(l, 'v:null') >= 0) |
| 419 | let l = getcompletion('let v:notexists', 'cmdline') |
| 420 | call assert_equal([], l) |
| 421 | let l = getcompletion('call tag', 'cmdline') |
| 422 | call assert_true(index(l, 'taglist(') >= 0) |
| 423 | let l = getcompletion('call paint', 'cmdline') |
| 424 | call assert_equal([], l) |
| 425 | |
Shougo Matsushita | ae38a9d | 2021-10-21 11:39:53 +0100 | [diff] [blame] | 426 | func T(a, c, p) |
ii14 | 4785fe0 | 2021-11-21 12:13:56 +0000 | [diff] [blame] | 427 | let g:cmdline_compl_params = [a:a, a:c, a:p] |
Shougo Matsushita | ae38a9d | 2021-10-21 11:39:53 +0100 | [diff] [blame] | 428 | return "oneA\noneB\noneC" |
| 429 | endfunc |
| 430 | command -nargs=1 -complete=custom,T MyCmd |
| 431 | let l = getcompletion('MyCmd ', 'cmdline') |
| 432 | call assert_equal(['oneA', 'oneB', 'oneC'], l) |
ii14 | 4785fe0 | 2021-11-21 12:13:56 +0000 | [diff] [blame] | 433 | call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params) |
Shougo Matsushita | ae38a9d | 2021-10-21 11:39:53 +0100 | [diff] [blame] | 434 | |
| 435 | delcommand MyCmd |
| 436 | delfunc T |
ii14 | 4785fe0 | 2021-11-21 12:13:56 +0000 | [diff] [blame] | 437 | unlet g:cmdline_compl_params |
Shougo Matsushita | ae38a9d | 2021-10-21 11:39:53 +0100 | [diff] [blame] | 438 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 439 | " For others test if the name is recognized. |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 440 | let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user'] |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 441 | if has('cmdline_hist') |
| 442 | call add(names, 'history') |
| 443 | endif |
| 444 | if has('gettext') |
| 445 | call add(names, 'locale') |
| 446 | endif |
| 447 | if has('profile') |
| 448 | call add(names, 'syntime') |
| 449 | endif |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 450 | |
| 451 | set tags=Xtags |
| 452 | call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags') |
| 453 | |
| 454 | for name in names |
| 455 | let matchcount = len(getcompletion('', name)) |
| 456 | call assert_true(matchcount >= 0, 'No matches for ' . name) |
| 457 | endfor |
| 458 | |
| 459 | call delete('Xtags') |
Bram Moolenaar | 0331faf | 2019-06-15 18:40:37 +0200 | [diff] [blame] | 460 | set tags& |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 461 | |
Bram Moolenaar | b7e2483 | 2020-06-24 13:37:35 +0200 | [diff] [blame] | 462 | call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:') |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 463 | call assert_fails('call getcompletion("", "burp")', 'E475:') |
Bram Moolenaar | 1f1fd44 | 2020-06-07 18:45:14 +0200 | [diff] [blame] | 464 | call assert_fails('call getcompletion("abc", [])', 'E475:') |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 465 | endfunc |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 466 | |
Bram Moolenaar | 038e09e | 2021-02-06 12:38:51 +0100 | [diff] [blame] | 467 | func Test_fullcommand() |
| 468 | let tests = { |
| 469 | \ '': '', |
| 470 | \ ':': '', |
| 471 | \ ':::': '', |
| 472 | \ ':::5': '', |
| 473 | \ 'not_a_cmd': '', |
| 474 | \ 'Check': '', |
| 475 | \ 'syntax': 'syntax', |
| 476 | \ ':syntax': 'syntax', |
| 477 | \ '::::syntax': 'syntax', |
| 478 | \ 'sy': 'syntax', |
| 479 | \ 'syn': 'syntax', |
| 480 | \ 'synt': 'syntax', |
| 481 | \ ':sy': 'syntax', |
| 482 | \ '::::sy': 'syntax', |
| 483 | \ 'match': 'match', |
| 484 | \ '2match': 'match', |
| 485 | \ '3match': 'match', |
| 486 | \ 'aboveleft': 'aboveleft', |
| 487 | \ 'abo': 'aboveleft', |
| 488 | \ 's': 'substitute', |
| 489 | \ '5s': 'substitute', |
| 490 | \ ':5s': 'substitute', |
| 491 | \ "'<,'>s": 'substitute', |
| 492 | \ ":'<,'>s": 'substitute', |
| 493 | \ 'CheckUni': 'CheckUnix', |
| 494 | \ 'CheckUnix': 'CheckUnix', |
| 495 | \ } |
| 496 | |
| 497 | for [in, want] in items(tests) |
| 498 | call assert_equal(want, fullcommand(in)) |
| 499 | endfor |
Bram Moolenaar | 4c8e8c6 | 2021-05-26 19:49:09 +0200 | [diff] [blame] | 500 | call assert_equal('', fullcommand(test_null_string())) |
Bram Moolenaar | 038e09e | 2021-02-06 12:38:51 +0100 | [diff] [blame] | 501 | |
| 502 | call assert_equal('syntax', 'syn'->fullcommand()) |
Bram Moolenaar | 80c88ea | 2021-09-08 14:29:46 +0200 | [diff] [blame] | 503 | |
| 504 | command -buffer BufferLocalCommand : |
| 505 | command GlobalCommand : |
| 506 | call assert_equal('GlobalCommand', fullcommand('GlobalCom')) |
| 507 | call assert_equal('BufferLocalCommand', fullcommand('BufferL')) |
| 508 | delcommand BufferLocalCommand |
| 509 | delcommand GlobalCommand |
Bram Moolenaar | 038e09e | 2021-02-06 12:38:51 +0100 | [diff] [blame] | 510 | endfunc |
| 511 | |
Bram Moolenaar | 6ab9e42 | 2018-07-28 19:20:13 +0200 | [diff] [blame] | 512 | func Test_shellcmd_completion() |
| 513 | let save_path = $PATH |
| 514 | |
| 515 | call mkdir('Xpathdir/Xpathsubdir', 'p') |
| 516 | call writefile([''], 'Xpathdir/Xfile.exe') |
| 517 | call setfperm('Xpathdir/Xfile.exe', 'rwx------') |
| 518 | |
| 519 | " Set PATH to example directory without trailing slash. |
| 520 | let $PATH = getcwd() . '/Xpathdir' |
| 521 | |
| 522 | " Test for the ":!<TAB>" case. Previously, this would include subdirs of |
| 523 | " dirs in the PATH, even though they won't be executed. We check that only |
| 524 | " subdirs of the PWD and executables from the PATH are included in the |
| 525 | " suggestions. |
| 526 | let actual = getcompletion('X', 'shellcmd') |
| 527 | let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"') |
| 528 | call insert(expected, 'Xfile.exe') |
| 529 | call assert_equal(expected, actual) |
| 530 | |
| 531 | call delete('Xpathdir', 'rf') |
| 532 | let $PATH = save_path |
| 533 | endfunc |
| 534 | |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 535 | func Test_expand_star_star() |
| 536 | call mkdir('a/b', 'p') |
| 537 | call writefile(['asdfasdf'], 'a/b/fileXname') |
| 538 | call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt') |
| 539 | call assert_equal('find a/b/fileXname', getreg(':')) |
Bram Moolenaar | 1773ddf | 2016-08-28 13:38:54 +0200 | [diff] [blame] | 540 | bwipe! |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 541 | call delete('a', 'rf') |
| 542 | endfunc |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 543 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 544 | func Test_cmdline_paste() |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 545 | let @a = "def" |
| 546 | call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx') |
| 547 | call assert_equal('"abc def ghi', @:) |
| 548 | |
| 549 | new |
| 550 | call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ') |
| 551 | |
| 552 | call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') |
| 553 | call assert_equal('"aaa asdf bbb', @:) |
| 554 | |
| 555 | call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx') |
| 556 | call assert_equal('"aaa /tmp/some bbb', @:) |
| 557 | |
Bram Moolenaar | e2c8d83 | 2018-05-01 19:24:03 +0200 | [diff] [blame] | 558 | call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx') |
| 559 | call assert_equal('"aaa '.getline(1).' bbb', @:) |
| 560 | |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 561 | set incsearch |
| 562 | call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') |
| 563 | call assert_equal('"aaa verylongword bbb', @:) |
| 564 | |
| 565 | call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx') |
| 566 | call assert_equal('"aaa a;b-c*d bbb', @:) |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 567 | |
| 568 | call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx') |
| 569 | call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:) |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 570 | bwipe! |
Bram Moolenaar | 72532d3 | 2018-04-07 19:09:09 +0200 | [diff] [blame] | 571 | |
| 572 | " Error while typing a command used to cause that it was not executed |
| 573 | " in the end. |
| 574 | new |
| 575 | try |
| 576 | call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx') |
| 577 | catch /^Vim\%((\a\+)\)\=:E32/ |
| 578 | " ignore error E32 |
| 579 | endtry |
| 580 | call assert_equal("Xtestfile", bufname("%")) |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 581 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 582 | " Try to paste an invalid register using <C-R> |
| 583 | call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt') |
| 584 | call assert_equal('"onetwo', @:) |
| 585 | |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 586 | " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 587 | let @a = "xy\<C-H>z" |
| 588 | call feedkeys(":\"\<C-R>a\<CR>", 'xt') |
| 589 | call assert_equal('"xz', @:) |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 590 | call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt') |
| 591 | call assert_equal("\"xy\<C-H>z", @:) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 592 | call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt') |
| 593 | call assert_equal("\"xy\<C-H>z", @:) |
| 594 | |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 595 | " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R |
| 596 | let @a = "xy\<C-V>z" |
| 597 | call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt') |
| 598 | call assert_equal('"xyz', @:) |
| 599 | call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt') |
| 600 | call assert_equal("\"xy\<C-V>z", @:) |
| 601 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 602 | call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")') |
| 603 | |
Bram Moolenaar | 72532d3 | 2018-04-07 19:09:09 +0200 | [diff] [blame] | 604 | bwipe! |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 605 | endfunc |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 606 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 607 | func Test_cmdline_remove_char() |
| 608 | let encoding_save = &encoding |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 609 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 610 | for e in ['utf8', 'latin1'] |
| 611 | exe 'set encoding=' . e |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 612 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 613 | call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx') |
| 614 | call assert_equal('"abc ef', @:, e) |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 615 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 616 | call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx') |
| 617 | call assert_equal('"abcdef', @:) |
| 618 | |
| 619 | call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx') |
| 620 | call assert_equal('"abc ghi', @:, e) |
| 621 | |
| 622 | call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx') |
| 623 | call assert_equal('"def', @:, e) |
| 624 | endfor |
| 625 | |
| 626 | let &encoding = encoding_save |
| 627 | endfunc |
| 628 | |
| 629 | func Test_cmdline_keymap_ctrl_hat() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 630 | CheckFeature keymap |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 631 | |
| 632 | set keymap=esperanto |
| 633 | call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx') |
| 634 | call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:) |
| 635 | set keymap= |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 636 | endfunc |
Bram Moolenaar | fe38b49 | 2016-12-11 21:34:23 +0100 | [diff] [blame] | 637 | |
Bram Moolenaar | f1f6f3f | 2017-02-09 22:28:20 +0100 | [diff] [blame] | 638 | func Test_illegal_address1() |
Bram Moolenaar | fe38b49 | 2016-12-11 21:34:23 +0100 | [diff] [blame] | 639 | new |
| 640 | 2;'( |
| 641 | 2;') |
| 642 | quit |
| 643 | endfunc |
Bram Moolenaar | ba47b51 | 2017-01-24 21:18:19 +0100 | [diff] [blame] | 644 | |
Bram Moolenaar | f1f6f3f | 2017-02-09 22:28:20 +0100 | [diff] [blame] | 645 | func Test_illegal_address2() |
| 646 | call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim') |
| 647 | new |
| 648 | source Xtest.vim |
| 649 | " Trigger calling validate_cursor() |
| 650 | diffsp Xtest.vim |
| 651 | quit! |
| 652 | bwipe! |
| 653 | call delete('Xtest.vim') |
| 654 | endfunc |
| 655 | |
Bram Moolenaar | ba47b51 | 2017-01-24 21:18:19 +0100 | [diff] [blame] | 656 | func Test_cmdline_complete_wildoptions() |
| 657 | help |
| 658 | call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') |
| 659 | let a = join(sort(split(@:)),' ') |
| 660 | set wildoptions=tagfile |
| 661 | call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') |
| 662 | let b = join(sort(split(@:)),' ') |
| 663 | call assert_equal(a, b) |
| 664 | bw! |
| 665 | endfunc |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 666 | |
Bram Moolenaar | a33ddbb | 2017-03-29 21:30:04 +0200 | [diff] [blame] | 667 | func Test_cmdline_complete_user_cmd() |
| 668 | command! -complete=color -nargs=1 Foo : |
| 669 | call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx') |
| 670 | call assert_equal('"Foo blue', @:) |
| 671 | call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx') |
| 672 | call assert_equal('"Foo blue', @:) |
| 673 | delcommand Foo |
| 674 | endfunc |
| 675 | |
Bram Moolenaar | cc390ff | 2020-02-29 22:06:30 +0100 | [diff] [blame] | 676 | func s:ScriptLocalFunction() |
| 677 | echo 'yes' |
| 678 | endfunc |
| 679 | |
| 680 | func Test_cmdline_complete_user_func() |
| 681 | call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx') |
naohiro ono | 5aec755 | 2021-08-19 21:20:41 +0200 | [diff] [blame] | 682 | call assert_match('"func Test_cmdline_complete_user_', @:) |
Bram Moolenaar | cc390ff | 2020-02-29 22:06:30 +0100 | [diff] [blame] | 683 | call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx') |
| 684 | call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:) |
Bram Moolenaar | 1bb4de5 | 2021-01-13 19:48:46 +0100 | [diff] [blame] | 685 | |
| 686 | " g: prefix also works |
| 687 | call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx') |
| 688 | call assert_match('"echo g:Test_cmdline_complete_user_func', @:) |
Bram Moolenaar | 069f908 | 2021-08-13 17:48:25 +0200 | [diff] [blame] | 689 | |
| 690 | " using g: prefix does not result in just "g:" matches from a lambda |
| 691 | let Fx = { a -> a } |
| 692 | call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx') |
| 693 | call assert_match('"echo g:[A-Z]', @:) |
naohiro ono | 5aec755 | 2021-08-19 21:20:41 +0200 | [diff] [blame] | 694 | |
| 695 | " existence of script-local dict function does not break user function name |
| 696 | " completion |
| 697 | function s:a_dict_func() dict |
| 698 | endfunction |
| 699 | call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx') |
| 700 | call assert_match('"call Test_cmdline_complete_user_', @:) |
| 701 | delfunction s:a_dict_func |
Bram Moolenaar | cc390ff | 2020-02-29 22:06:30 +0100 | [diff] [blame] | 702 | endfunc |
| 703 | |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 704 | func Test_cmdline_complete_user_names() |
| 705 | if has('unix') && executable('whoami') |
| 706 | let whoami = systemlist('whoami')[0] |
| 707 | let first_letter = whoami[0] |
| 708 | if len(first_letter) > 0 |
| 709 | " Trying completion of :e ~x where x is the first letter of |
| 710 | " the user name should complete to at least the user name. |
| 711 | call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx') |
| 712 | call assert_match('^"e \~.*\<' . whoami . '\>', @:) |
| 713 | endif |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 714 | elseif has('win32') |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 715 | " Just in case: check that the system has an Administrator account. |
| 716 | let names = system('net user') |
| 717 | if names =~ 'Administrator' |
| 718 | " Trying completion of :e ~A should complete to Administrator. |
Bram Moolenaar | 346d2a3 | 2019-01-27 20:43:41 +0100 | [diff] [blame] | 719 | " There could be other names starting with "A" before Administrator. |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 720 | call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx') |
Bram Moolenaar | 346d2a3 | 2019-01-27 20:43:41 +0100 | [diff] [blame] | 721 | call assert_match('^"e \~.*Administrator', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 722 | endif |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 723 | else |
| 724 | throw 'Skipped: does not work on this platform' |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 725 | endif |
| 726 | endfunc |
| 727 | |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 728 | func Test_cmdline_complete_bang() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 729 | CheckExecutable whoami |
| 730 | call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx') |
| 731 | call assert_match('^".*\<whoami\>', @:) |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 732 | endfunc |
| 733 | |
Bram Moolenaar | 8b63313 | 2020-03-20 18:20:51 +0100 | [diff] [blame] | 734 | func Test_cmdline_complete_languages() |
Bram Moolenaar | 84cf6bd | 2020-06-16 20:03:43 +0200 | [diff] [blame] | 735 | let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '') |
| 736 | call assert_equal(lang, v:lc_time) |
| 737 | |
| 738 | let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '') |
| 739 | call assert_equal(lang, v:ctype) |
| 740 | |
| 741 | let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '') |
| 742 | call assert_equal(lang, v:collate) |
| 743 | |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 744 | let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') |
Bram Moolenaar | 84cf6bd | 2020-06-16 20:03:43 +0200 | [diff] [blame] | 745 | call assert_equal(lang, v:lang) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 746 | |
| 747 | call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx') |
Bram Moolenaar | 84cf6bd | 2020-06-16 20:03:43 +0200 | [diff] [blame] | 748 | call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 749 | |
Bram Moolenaar | ec68028 | 2020-06-12 19:35:32 +0200 | [diff] [blame] | 750 | call assert_match('^"language .*\<' . lang . '\>', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 751 | |
Bram Moolenaar | ec68028 | 2020-06-12 19:35:32 +0200 | [diff] [blame] | 752 | call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx') |
| 753 | call assert_match('^"language .*\<' . lang . '\>', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 754 | |
Bram Moolenaar | ec68028 | 2020-06-12 19:35:32 +0200 | [diff] [blame] | 755 | call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx') |
| 756 | call assert_match('^"language .*\<' . lang . '\>', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 757 | |
Bram Moolenaar | ec68028 | 2020-06-12 19:35:32 +0200 | [diff] [blame] | 758 | call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx') |
| 759 | call assert_match('^"language .*\<' . lang . '\>', @:) |
Bram Moolenaar | 84cf6bd | 2020-06-16 20:03:43 +0200 | [diff] [blame] | 760 | |
| 761 | call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx') |
| 762 | call assert_match('^"language .*\<' . lang . '\>', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 763 | endfunc |
| 764 | |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 765 | func Test_cmdline_complete_env_variable() |
| 766 | let $X_VIM_TEST_COMPLETE_ENV = 'foo' |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 767 | call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx') |
| 768 | call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:) |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 769 | unlet $X_VIM_TEST_COMPLETE_ENV |
| 770 | endfunc |
| 771 | |
Bram Moolenaar | 4941b5e | 2020-12-24 17:15:53 +0100 | [diff] [blame] | 772 | func Test_cmdline_complete_expression() |
| 773 | let g:SomeVar = 'blah' |
| 774 | for cmd in ['exe', 'echo', 'echon', 'echomsg'] |
| 775 | call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx') |
| 776 | call assert_match('"' .. cmd .. ' SomeVar', @:) |
| 777 | call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx') |
| 778 | call assert_match('"' .. cmd .. ' foo SomeVar', @:) |
| 779 | endfor |
| 780 | unlet g:SomeVar |
| 781 | endfunc |
| 782 | |
Bram Moolenaar | 47016f5 | 2021-08-26 16:39:58 +0200 | [diff] [blame] | 783 | " Unique function name for completion below |
| 784 | func s:WeirdFunc() |
| 785 | echo 'weird' |
| 786 | endfunc |
| 787 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 788 | " Test for various command-line completion |
| 789 | func Test_cmdline_complete_various() |
| 790 | " completion for a command starting with a comment |
| 791 | call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt') |
| 792 | call assert_equal("\" :|\"\<C-A>", @:) |
| 793 | |
| 794 | " completion for a range followed by a comment |
| 795 | call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt') |
| 796 | call assert_equal("\"1,2\"\<C-A>", @:) |
| 797 | |
| 798 | " completion for :k command |
| 799 | call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt') |
| 800 | call assert_equal("\"ka\<C-A>", @:) |
| 801 | |
| 802 | " completion for short version of the :s command |
| 803 | call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt') |
| 804 | call assert_equal("\"sI \<C-A>", @:) |
| 805 | |
| 806 | " completion for :write command |
| 807 | call mkdir('Xdir') |
| 808 | call writefile(['one'], 'Xdir/Xfile1') |
| 809 | let save_cwd = getcwd() |
| 810 | cd Xdir |
| 811 | call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt') |
| 812 | call assert_equal("\"w >> Xfile1", @:) |
| 813 | call chdir(save_cwd) |
| 814 | call delete('Xdir', 'rf') |
| 815 | |
| 816 | " completion for :w ! and :r ! commands |
| 817 | call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') |
| 818 | call assert_equal("\"w !invalid_xyz_cmd", @:) |
| 819 | call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') |
| 820 | call assert_equal("\"r !invalid_xyz_cmd", @:) |
| 821 | |
| 822 | " completion for :>> and :<< commands |
| 823 | call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt') |
| 824 | call assert_equal("\">>>\<C-A>", @:) |
| 825 | call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt') |
| 826 | call assert_equal("\"<<<\<C-A>", @:) |
| 827 | |
| 828 | " completion for command with +cmd argument |
| 829 | call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt') |
| 830 | call assert_equal("\"buffer +/pat Xabc", @:) |
| 831 | call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt') |
| 832 | call assert_equal("\"buffer +/pat\<C-A>", @:) |
| 833 | |
| 834 | " completion for a command with a trailing comment |
| 835 | call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt') |
| 836 | call assert_equal("\"ls \" comment\<C-A>", @:) |
| 837 | |
| 838 | " completion for a command with a trailing command |
| 839 | call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt') |
| 840 | call assert_equal("\"ls | ls", @:) |
| 841 | |
| 842 | " completion for a command with an CTRL-V escaped argument |
| 843 | call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt') |
| 844 | call assert_equal("\"ls \<C-V>a\<C-A>", @:) |
| 845 | |
| 846 | " completion for a command that doesn't take additional arguments |
| 847 | call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt') |
| 848 | call assert_equal("\"all abc\<C-A>", @:) |
| 849 | |
| 850 | " completion for a command with a command modifier |
| 851 | call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt') |
| 852 | call assert_equal("\"topleft new", @:) |
| 853 | |
Bram Moolenaar | e70e12b | 2021-06-13 17:20:08 +0200 | [diff] [blame] | 854 | " completion for vim9 and legacy commands |
| 855 | call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt') |
| 856 | call assert_equal("\"vim9 call strlen(", @:) |
| 857 | call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt') |
| 858 | call assert_equal("\"legac call strlen(", @:) |
| 859 | |
Bram Moolenaar | 4ee9d8e | 2021-06-13 18:38:48 +0200 | [diff] [blame] | 860 | " completion for the :disassemble command |
| 861 | call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt') |
| 862 | call assert_equal("\"disas debug", @:) |
| 863 | call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt') |
| 864 | call assert_equal("\"disas profile", @:) |
| 865 | call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt') |
| 866 | call assert_equal("\"disas debug Test_cmdline_complete_various", @:) |
| 867 | call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt') |
| 868 | call assert_equal("\"disas profile Test_cmdline_complete_various", @:) |
naohiro ono | 9aecf79 | 2021-08-28 15:56:06 +0200 | [diff] [blame] | 869 | call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt') |
| 870 | call assert_equal("\"disas Test_cmdline_complete_various", @:) |
Bram Moolenaar | 4ee9d8e | 2021-06-13 18:38:48 +0200 | [diff] [blame] | 871 | |
Bram Moolenaar | 47016f5 | 2021-08-26 16:39:58 +0200 | [diff] [blame] | 872 | call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt') |
naohiro ono | 9aecf79 | 2021-08-28 15:56:06 +0200 | [diff] [blame] | 873 | call assert_match('"disas <SNR>\d\+_WeirdFunc', @:) |
Bram Moolenaar | 47016f5 | 2021-08-26 16:39:58 +0200 | [diff] [blame] | 874 | |
naohiro ono | dfe04db | 2021-09-12 15:45:10 +0200 | [diff] [blame] | 875 | call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt') |
| 876 | call assert_match('"disas <SNR>\d\+_', @:) |
| 877 | call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt') |
| 878 | call assert_match('"disas debug <SNR>\d\+_', @:) |
| 879 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 880 | " completion for the :match command |
| 881 | call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt') |
| 882 | call assert_equal("\"match Search /pat/\<C-A>", @:) |
| 883 | |
| 884 | " completion for the :s command |
| 885 | call feedkeys(":s/from/to/g\<C-A>\<C-B>\"\<CR>", 'xt') |
| 886 | call assert_equal("\"s/from/to/g\<C-A>", @:) |
| 887 | |
| 888 | " completion for the :dlist command |
| 889 | call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt') |
| 890 | call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:) |
| 891 | |
| 892 | " completion for the :doautocmd command |
| 893 | call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt') |
| 894 | call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:) |
| 895 | |
Bram Moolenaar | afe8cf6 | 2020-10-05 20:07:18 +0200 | [diff] [blame] | 896 | " completion of autocmd group after comma |
| 897 | call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt') |
| 898 | call assert_equal("\"doautocmd BufNew,BufEnter", @:) |
| 899 | |
Dominique Pelle | bfb2bb1 | 2021-08-14 21:11:51 +0200 | [diff] [blame] | 900 | " completion of file name in :doautocmd |
| 901 | call writefile([], 'Xfile1') |
| 902 | call writefile([], 'Xfile2') |
| 903 | call feedkeys(":doautocmd BufEnter Xfi\<C-A>\<C-B>\"\<CR>", 'xt') |
| 904 | call assert_equal("\"doautocmd BufEnter Xfile1 Xfile2", @:) |
| 905 | call delete('Xfile1') |
| 906 | call delete('Xfile2') |
| 907 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 908 | " completion for the :augroup command |
Bram Moolenaar | b4d82e2 | 2021-09-01 13:03:39 +0200 | [diff] [blame] | 909 | augroup XTest.test |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 910 | augroup END |
| 911 | call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt') |
Bram Moolenaar | b4d82e2 | 2021-09-01 13:03:39 +0200 | [diff] [blame] | 912 | call assert_equal("\"augroup XTest.test", @:) |
| 913 | call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt') |
| 914 | call assert_equal("\"au XTest.test", @:) |
| 915 | augroup! XTest.test |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 916 | |
| 917 | " completion for the :unlet command |
| 918 | call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt') |
| 919 | call assert_equal("\"unlet one two", @:) |
| 920 | |
Bram Moolenaar | 21c1a0c | 2021-10-17 17:20:23 +0100 | [diff] [blame] | 921 | " completion for the :buffer command with curlies |
Bram Moolenaar | 39c47c3 | 2021-10-17 18:05:26 +0100 | [diff] [blame] | 922 | " FIXME: what should happen on MS-Windows? |
| 923 | if !has('win32') |
| 924 | edit \{someFile} |
| 925 | call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt') |
| 926 | call assert_equal("\"buf {someFile}", @:) |
| 927 | bwipe {someFile} |
| 928 | endif |
Bram Moolenaar | 21c1a0c | 2021-10-17 17:20:23 +0100 | [diff] [blame] | 929 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 930 | " completion for the :bdelete command |
| 931 | call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt') |
| 932 | call assert_equal("\"bdel a b c", @:) |
| 933 | |
| 934 | " completion for the :mapclear command |
| 935 | call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt') |
| 936 | call assert_equal("\"mapclear <buffer>", @:) |
| 937 | |
| 938 | " completion for user defined commands with menu names |
| 939 | menu Test.foo :ls<CR> |
| 940 | com -nargs=* -complete=menu MyCmd |
| 941 | call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt') |
| 942 | call assert_equal('"MyCmd Test.', @:) |
| 943 | delcom MyCmd |
| 944 | unmenu Test |
| 945 | |
| 946 | " completion for user defined commands with mappings |
| 947 | mapclear |
| 948 | map <F3> :ls<CR> |
| 949 | com -nargs=* -complete=mapping MyCmd |
| 950 | call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt') |
| 951 | call assert_equal('"MyCmd <F3>', @:) |
| 952 | mapclear |
| 953 | delcom MyCmd |
| 954 | |
| 955 | " completion for :set path= with multiple backslashes |
| 956 | call feedkeys(":set path=a\\\\\\ b\<C-A>\<C-B>\"\<CR>", 'xt') |
| 957 | call assert_equal('"set path=a\\\ b', @:) |
| 958 | |
| 959 | " completion for :set dir= with a backslash |
| 960 | call feedkeys(":set dir=a\\ b\<C-A>\<C-B>\"\<CR>", 'xt') |
| 961 | call assert_equal('"set dir=a\ b', @:) |
| 962 | |
| 963 | " completion for the :py3 commands |
| 964 | call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt') |
| 965 | call assert_equal('"py3 py3do py3file', @:) |
| 966 | |
Bram Moolenaar | df749a2 | 2021-03-28 15:29:43 +0200 | [diff] [blame] | 967 | " completion for the :vim9 commands |
| 968 | call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt') |
| 969 | call assert_equal('"vim9cmd vim9script', @:) |
| 970 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 971 | " redir @" is not the start of a comment. So complete after that |
| 972 | call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt') |
| 973 | call assert_equal('"redir @" | cwindow', @:) |
| 974 | |
| 975 | " completion after a backtick |
| 976 | call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt') |
| 977 | call assert_equal('"e `a1b2c', @:) |
| 978 | |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 979 | " completion for :language command with an invalid argument |
| 980 | call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt') |
| 981 | call assert_equal("\"language dummy \t", @:) |
| 982 | |
| 983 | " completion for commands after a :global command |
Bram Moolenaar | 8b63313 | 2020-03-20 18:20:51 +0100 | [diff] [blame] | 984 | call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt') |
| 985 | call assert_equal('"g/a\xb/clearjumps', @:) |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 986 | |
| 987 | " completion with ambiguous user defined commands |
| 988 | com TCmd1 echo 'TCmd1' |
| 989 | com TCmd2 echo 'TCmd2' |
| 990 | call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt') |
| 991 | call assert_equal('"TCmd ', @:) |
| 992 | delcom TCmd1 |
| 993 | delcom TCmd2 |
| 994 | |
| 995 | " completion after a range followed by a pipe (|) character |
| 996 | call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt') |
| 997 | call assert_equal('"1,10 | chistory', @:) |
Bram Moolenaar | 9c92971 | 2020-09-07 22:05:28 +0200 | [diff] [blame] | 998 | |
| 999 | " use <Esc> as the 'wildchar' for completion |
| 1000 | set wildchar=<Esc> |
| 1001 | call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt') |
| 1002 | call assert_equal('"g/a\xb/clearjumps', @:) |
| 1003 | " pressing <esc> twice should cancel the command |
| 1004 | call feedkeys(":chist\<Esc>\<Esc>", 'xt') |
| 1005 | call assert_equal('"g/a\xb/clearjumps', @:) |
| 1006 | set wildchar& |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1007 | endfunc |
| 1008 | |
Bram Moolenaar | c312b8b | 2017-10-28 17:53:04 +0200 | [diff] [blame] | 1009 | func Test_cmdline_write_alternatefile() |
| 1010 | new |
| 1011 | call setline('.', ['one', 'two']) |
| 1012 | f foo.txt |
| 1013 | new |
| 1014 | f #-A |
| 1015 | call assert_equal('foo.txt-A', expand('%')) |
| 1016 | f #<-B.txt |
| 1017 | call assert_equal('foo-B.txt', expand('%')) |
| 1018 | f %< |
| 1019 | call assert_equal('foo-B', expand('%')) |
| 1020 | new |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1021 | call assert_fails('f #<', 'E95:') |
Bram Moolenaar | c312b8b | 2017-10-28 17:53:04 +0200 | [diff] [blame] | 1022 | bw! |
| 1023 | f foo-B.txt |
| 1024 | f %<-A |
| 1025 | call assert_equal('foo-B-A', expand('%')) |
| 1026 | bw! |
| 1027 | bw! |
| 1028 | endfunc |
| 1029 | |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 1030 | " using a leading backslash here |
| 1031 | set cpo+=C |
| 1032 | |
| 1033 | func Test_cmdline_search_range() |
| 1034 | new |
| 1035 | call setline(1, ['a', 'b', 'c', 'd']) |
| 1036 | /d |
| 1037 | 1,\/s/b/B/ |
| 1038 | call assert_equal('B', getline(2)) |
| 1039 | |
| 1040 | /a |
| 1041 | $ |
| 1042 | \?,4s/c/C/ |
| 1043 | call assert_equal('C', getline(3)) |
| 1044 | |
| 1045 | call setline(1, ['a', 'b', 'c', 'd']) |
| 1046 | %s/c/c/ |
| 1047 | 1,\&s/b/B/ |
| 1048 | call assert_equal('B', getline(2)) |
| 1049 | |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1050 | let @/ = 'apple' |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1051 | call assert_fails('\/print', ['E486:.*apple']) |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1052 | |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 1053 | bwipe! |
| 1054 | endfunc |
| 1055 | |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1056 | " Test for the tick mark (') in an excmd range |
| 1057 | func Test_tick_mark_in_range() |
| 1058 | " If only the tick is passed as a range and no command is specified, there |
| 1059 | " should not be an error |
| 1060 | call feedkeys(":'\<CR>", 'xt') |
| 1061 | call assert_equal("'", getreg(':')) |
| 1062 | call assert_fails("',print", 'E78:') |
| 1063 | endfunc |
| 1064 | |
| 1065 | " Test for using a line number followed by a search pattern as range |
| 1066 | func Test_lnum_and_pattern_as_range() |
| 1067 | new |
| 1068 | call setline(1, ['foo 1', 'foo 2', 'foo 3']) |
| 1069 | let @" = '' |
| 1070 | 2/foo/yank |
| 1071 | call assert_equal("foo 3\n", @") |
| 1072 | call assert_equal(1, line('.')) |
| 1073 | close! |
| 1074 | endfunc |
| 1075 | |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 1076 | " Tests for getcmdline(), getcmdpos() and getcmdtype() |
| 1077 | func Check_cmdline(cmdtype) |
| 1078 | call assert_equal('MyCmd a', getcmdline()) |
| 1079 | call assert_equal(8, getcmdpos()) |
| 1080 | call assert_equal(a:cmdtype, getcmdtype()) |
| 1081 | return '' |
| 1082 | endfunc |
| 1083 | |
Bram Moolenaar | 96e38a8 | 2019-09-09 18:35:33 +0200 | [diff] [blame] | 1084 | set cpo& |
| 1085 | |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 1086 | func Test_getcmdtype() |
| 1087 | call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt") |
| 1088 | |
| 1089 | let cmdtype = '' |
| 1090 | debuggreedy |
| 1091 | call feedkeys(":debug echo 'test'\<CR>", "t") |
| 1092 | call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t") |
| 1093 | call feedkeys("cont\<CR>", "xt") |
| 1094 | 0debuggreedy |
| 1095 | call assert_equal('>', cmdtype) |
| 1096 | |
| 1097 | call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt") |
| 1098 | call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt") |
| 1099 | |
| 1100 | call feedkeys(":call input('Answer?')\<CR>", "t") |
Bram Moolenaar | 31eb139 | 2017-02-09 21:44:03 +0100 | [diff] [blame] | 1101 | call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt") |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 1102 | |
| 1103 | call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt") |
| 1104 | |
| 1105 | cnoremap <expr> <F6> Check_cmdline('=') |
| 1106 | call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt") |
| 1107 | cunmap <F6> |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 1108 | |
| 1109 | call assert_equal('', getcmdline()) |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 1110 | endfunc |
| 1111 | |
Bram Moolenaar | 81612b7 | 2018-06-23 14:55:03 +0200 | [diff] [blame] | 1112 | func Test_getcmdwintype() |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 1113 | CheckFeature cmdwin |
| 1114 | |
Bram Moolenaar | 81612b7 | 2018-06-23 14:55:03 +0200 | [diff] [blame] | 1115 | call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 1116 | call assert_equal('/', a) |
| 1117 | |
| 1118 | call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 1119 | call assert_equal('?', a) |
| 1120 | |
| 1121 | call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 1122 | call assert_equal(':', a) |
| 1123 | |
| 1124 | call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') |
| 1125 | call assert_equal(':', a) |
| 1126 | |
| 1127 | call assert_equal('', getcmdwintype()) |
| 1128 | endfunc |
| 1129 | |
Bram Moolenaar | 96e38a8 | 2019-09-09 18:35:33 +0200 | [diff] [blame] | 1130 | func Test_getcmdwin_autocmd() |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 1131 | CheckFeature cmdwin |
| 1132 | |
Bram Moolenaar | 96e38a8 | 2019-09-09 18:35:33 +0200 | [diff] [blame] | 1133 | let s:seq = [] |
| 1134 | augroup CmdWin |
| 1135 | au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid()) |
| 1136 | au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid()) |
| 1137 | au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr()) |
| 1138 | au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr()) |
| 1139 | au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid()) |
| 1140 | au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid()) |
| 1141 | |
| 1142 | let org_winid = win_getid() |
| 1143 | let org_bufnr = bufnr() |
| 1144 | call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!') |
| 1145 | call assert_equal(':', a) |
| 1146 | call assert_equal([ |
| 1147 | \ 'WinLeave ' .. org_winid, |
| 1148 | \ 'WinEnter ' .. s:cmd_winid, |
| 1149 | \ 'BufLeave ' .. org_bufnr, |
| 1150 | \ 'BufEnter ' .. s:cmd_bufnr, |
| 1151 | \ 'CmdWinEnter ' .. s:cmd_winid, |
| 1152 | \ 'CmdWinLeave ' .. s:cmd_winid, |
| 1153 | \ 'BufLeave ' .. s:cmd_bufnr, |
| 1154 | \ 'WinLeave ' .. s:cmd_winid, |
| 1155 | \ 'WinEnter ' .. org_winid, |
| 1156 | \ 'BufEnter ' .. org_bufnr, |
| 1157 | \ ], s:seq) |
| 1158 | |
| 1159 | au! |
| 1160 | augroup END |
| 1161 | endfunc |
| 1162 | |
Bram Moolenaar | 52604f2 | 2017-04-07 16:17:39 +0200 | [diff] [blame] | 1163 | func Test_verbosefile() |
| 1164 | set verbosefile=Xlog |
| 1165 | echomsg 'foo' |
| 1166 | echomsg 'bar' |
| 1167 | set verbosefile= |
| 1168 | let log = readfile('Xlog') |
| 1169 | call assert_match("foo\nbar", join(log, "\n")) |
| 1170 | call delete('Xlog') |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 1171 | call mkdir('Xdir') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1172 | call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:']) |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 1173 | call delete('Xdir', 'd') |
Bram Moolenaar | 52604f2 | 2017-04-07 16:17:39 +0200 | [diff] [blame] | 1174 | endfunc |
| 1175 | |
Bram Moolenaar | 4facea3 | 2019-10-12 20:17:40 +0200 | [diff] [blame] | 1176 | func Test_verbose_option() |
| 1177 | CheckScreendump |
| 1178 | |
| 1179 | let lines =<< trim [SCRIPT] |
| 1180 | command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v |
| 1181 | call feedkeys("\r", 't') " for the hit-enter prompt |
| 1182 | set verbose=20 |
| 1183 | [SCRIPT] |
| 1184 | call writefile(lines, 'XTest_verbose') |
| 1185 | |
| 1186 | let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1187 | call TermWait(buf, 50) |
Bram Moolenaar | 4facea3 | 2019-10-12 20:17:40 +0200 | [diff] [blame] | 1188 | call term_sendkeys(buf, ":DoSomething\<CR>") |
| 1189 | call VerifyScreenDump(buf, 'Test_verbose_option_1', {}) |
| 1190 | |
| 1191 | " clean up |
| 1192 | call StopVimInTerminal(buf) |
| 1193 | call delete('XTest_verbose') |
| 1194 | endfunc |
| 1195 | |
Bram Moolenaar | ff3be4f | 2018-05-12 13:18:46 +0200 | [diff] [blame] | 1196 | func Test_setcmdpos() |
| 1197 | func InsertTextAtPos(text, pos) |
| 1198 | call assert_equal(0, setcmdpos(a:pos)) |
| 1199 | return a:text |
| 1200 | endfunc |
| 1201 | |
| 1202 | " setcmdpos() with position in the middle of the command line. |
| 1203 | call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') |
| 1204 | call assert_equal('"1ab2', @:) |
| 1205 | |
| 1206 | call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') |
| 1207 | call assert_equal('"1b2a', @:) |
| 1208 | |
| 1209 | " setcmdpos() with position beyond the end of the command line. |
| 1210 | call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt') |
| 1211 | call assert_equal('"12ab', @:) |
| 1212 | |
| 1213 | " setcmdpos() returns 1 when not editing the command line. |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 1214 | call assert_equal(1, 3->setcmdpos()) |
Bram Moolenaar | ff3be4f | 2018-05-12 13:18:46 +0200 | [diff] [blame] | 1215 | endfunc |
| 1216 | |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 1217 | func Test_cmdline_overstrike() |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 1218 | let encodings = ['latin1', 'utf8'] |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 1219 | let encoding_save = &encoding |
| 1220 | |
| 1221 | for e in encodings |
| 1222 | exe 'set encoding=' . e |
| 1223 | |
| 1224 | " Test overstrike in the middle of the command line. |
| 1225 | call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1226 | call assert_equal('"0ab1cd4', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 1227 | |
| 1228 | " Test overstrike going beyond end of command line. |
| 1229 | call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1230 | call assert_equal('"0ab1cdefgh', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 1231 | |
| 1232 | " Test toggling insert/overstrike a few times. |
| 1233 | call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1234 | call assert_equal('"ab0cd3ef4', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 1235 | endfor |
| 1236 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 1237 | " Test overstrike with multi-byte characters. |
| 1238 | call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1239 | call assert_equal('"テabキcdエディタ', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 1240 | |
| 1241 | let &encoding = encoding_save |
| 1242 | endfunc |
Bram Moolenaar | a046b37 | 2019-09-15 17:26:07 +0200 | [diff] [blame] | 1243 | |
| 1244 | func Test_cmdwin_bug() |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 1245 | CheckFeature cmdwin |
| 1246 | |
Bram Moolenaar | a046b37 | 2019-09-15 17:26:07 +0200 | [diff] [blame] | 1247 | let winid = win_getid() |
| 1248 | sp |
| 1249 | try |
| 1250 | call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!') |
| 1251 | catch /^Vim\%((\a\+)\)\=:E11/ |
| 1252 | endtry |
| 1253 | bw! |
| 1254 | endfunc |
Bram Moolenaar | 5241057 | 2019-10-27 05:12:45 +0100 | [diff] [blame] | 1255 | |
Bram Moolenaar | 1c329c0 | 2019-10-27 20:37:35 +0100 | [diff] [blame] | 1256 | func Test_cmdwin_restore() |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 1257 | CheckFeature cmdwin |
Bram Moolenaar | 1c329c0 | 2019-10-27 20:37:35 +0100 | [diff] [blame] | 1258 | CheckScreendump |
| 1259 | |
| 1260 | let lines =<< trim [SCRIPT] |
Egor Zvorykin | 125ffd2 | 2021-11-17 14:01:14 +0000 | [diff] [blame] | 1261 | augroup vimHints | au! | augroup END |
Bram Moolenaar | 1c329c0 | 2019-10-27 20:37:35 +0100 | [diff] [blame] | 1262 | call setline(1, range(30)) |
| 1263 | 2split |
| 1264 | [SCRIPT] |
| 1265 | call writefile(lines, 'XTest_restore') |
| 1266 | |
| 1267 | let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1268 | call TermWait(buf, 50) |
Bram Moolenaar | 1c329c0 | 2019-10-27 20:37:35 +0100 | [diff] [blame] | 1269 | call term_sendkeys(buf, "q:") |
| 1270 | call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {}) |
| 1271 | |
| 1272 | " normal restore |
| 1273 | call term_sendkeys(buf, ":q\<CR>") |
| 1274 | call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {}) |
| 1275 | |
| 1276 | " restore after setting 'lines' with one window |
| 1277 | call term_sendkeys(buf, ":close\<CR>") |
| 1278 | call term_sendkeys(buf, "q:") |
| 1279 | call term_sendkeys(buf, ":set lines=18\<CR>") |
| 1280 | call term_sendkeys(buf, ":q\<CR>") |
| 1281 | call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {}) |
| 1282 | |
| 1283 | " clean up |
| 1284 | call StopVimInTerminal(buf) |
| 1285 | call delete('XTest_restore') |
| 1286 | endfunc |
| 1287 | |
Bram Moolenaar | e5b4486 | 2021-05-30 13:54:03 +0200 | [diff] [blame] | 1288 | func Test_cmdwin_no_terminal() |
| 1289 | CheckFeature cmdwin |
| 1290 | CheckFeature terminal |
Bram Moolenaar | 0b49648 | 2021-05-30 14:21:57 +0200 | [diff] [blame] | 1291 | CheckNotMSWindows |
Bram Moolenaar | e5b4486 | 2021-05-30 13:54:03 +0200 | [diff] [blame] | 1292 | |
| 1293 | let buf = RunVimInTerminal('', {'rows': 12}) |
| 1294 | call TermWait(buf, 50) |
| 1295 | call term_sendkeys(buf, ":set cmdheight=2\<CR>") |
| 1296 | call term_sendkeys(buf, "q:") |
| 1297 | call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>") |
| 1298 | call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {}) |
| 1299 | call term_sendkeys(buf, ":q\<CR>") |
| 1300 | call StopVimInTerminal(buf) |
| 1301 | endfunc |
| 1302 | |
Bram Moolenaar | 5241057 | 2019-10-27 05:12:45 +0100 | [diff] [blame] | 1303 | func Test_buffers_lastused() |
| 1304 | " check that buffers are sorted by time when wildmode has lastused |
| 1305 | call test_settime(1550020000) " middle |
| 1306 | edit bufa |
| 1307 | enew |
| 1308 | call test_settime(1550030000) " newest |
| 1309 | edit bufb |
| 1310 | enew |
| 1311 | call test_settime(1550010000) " oldest |
| 1312 | edit bufc |
| 1313 | enew |
| 1314 | call test_settime(0) |
| 1315 | enew |
| 1316 | |
| 1317 | call assert_equal(['bufa', 'bufb', 'bufc'], |
| 1318 | \ getcompletion('', 'buffer')) |
| 1319 | |
| 1320 | let save_wildmode = &wildmode |
| 1321 | set wildmode=full:lastused |
| 1322 | |
| 1323 | let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>" |
| 1324 | call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') |
| 1325 | call assert_equal('b bufb', X) |
| 1326 | call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 1327 | call assert_equal('b bufa', X) |
| 1328 | call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 1329 | call assert_equal('b bufc', X) |
| 1330 | enew |
| 1331 | |
| 1332 | edit other |
| 1333 | call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') |
| 1334 | call assert_equal('b bufb', X) |
| 1335 | call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 1336 | call assert_equal('b bufa', X) |
| 1337 | call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 1338 | call assert_equal('b bufc', X) |
| 1339 | enew |
| 1340 | |
| 1341 | let &wildmode = save_wildmode |
| 1342 | |
| 1343 | bwipeout bufa |
| 1344 | bwipeout bufb |
| 1345 | bwipeout bufc |
| 1346 | endfunc |
Bram Moolenaar | 85db547 | 2019-12-04 15:11:08 +0100 | [diff] [blame] | 1347 | |
| 1348 | func Test_cmdwin_feedkeys() |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 1349 | CheckFeature cmdwin |
| 1350 | |
Bram Moolenaar | 85db547 | 2019-12-04 15:11:08 +0100 | [diff] [blame] | 1351 | " This should not generate E488 |
| 1352 | call feedkeys("q:\<CR>", 'x') |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1353 | " Using feedkeys with q: only should automatically close the cmd window |
| 1354 | call feedkeys('q:', 'xt') |
| 1355 | call assert_equal(1, winnr('$')) |
| 1356 | call assert_equal('', getcmdwintype()) |
Bram Moolenaar | 85db547 | 2019-12-04 15:11:08 +0100 | [diff] [blame] | 1357 | endfunc |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 1358 | |
| 1359 | " Tests for the issues fixed in 7.4.441. |
| 1360 | " When 'cedit' is set to Ctrl-C, opening the command window hangs Vim |
| 1361 | func Test_cmdwin_cedit() |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 1362 | CheckFeature cmdwin |
| 1363 | |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 1364 | exe "set cedit=\<C-c>" |
| 1365 | normal! : |
| 1366 | call assert_equal(1, winnr('$')) |
| 1367 | |
| 1368 | let g:cmd_wintype = '' |
| 1369 | func CmdWinType() |
| 1370 | let g:cmd_wintype = getcmdwintype() |
Bram Moolenaar | 00f3b4e | 2020-02-14 14:32:22 +0100 | [diff] [blame] | 1371 | let g:wintype = win_gettype() |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 1372 | return '' |
| 1373 | endfunc |
| 1374 | |
| 1375 | call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>") |
| 1376 | echo input('') |
| 1377 | call assert_equal('@', g:cmd_wintype) |
Bram Moolenaar | 00f3b4e | 2020-02-14 14:32:22 +0100 | [diff] [blame] | 1378 | call assert_equal('command', g:wintype) |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 1379 | |
| 1380 | set cedit&vim |
| 1381 | delfunc CmdWinType |
| 1382 | endfunc |
| 1383 | |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 1384 | " Test for CmdwinEnter autocmd |
| 1385 | func Test_cmdwin_autocmd() |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 1386 | CheckFeature cmdwin |
| 1387 | |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 1388 | augroup CmdWin |
| 1389 | au! |
Bram Moolenaar | b63f3ca | 2021-01-30 21:40:03 +0100 | [diff] [blame] | 1390 | autocmd BufLeave * if &buftype == '' | update | endif |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 1391 | autocmd CmdwinEnter * startinsert |
| 1392 | augroup END |
| 1393 | |
| 1394 | call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:') |
| 1395 | call assert_equal('xyz', @:) |
| 1396 | |
| 1397 | augroup CmdWin |
| 1398 | au! |
| 1399 | augroup END |
| 1400 | augroup! CmdWin |
| 1401 | endfunc |
| 1402 | |
Bram Moolenaar | 479950f | 2020-01-19 15:45:17 +0100 | [diff] [blame] | 1403 | func Test_cmdlineclear_tabenter() |
| 1404 | CheckScreendump |
| 1405 | |
| 1406 | let lines =<< trim [SCRIPT] |
| 1407 | call setline(1, range(30)) |
| 1408 | [SCRIPT] |
| 1409 | |
| 1410 | call writefile(lines, 'XtestCmdlineClearTabenter') |
| 1411 | let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1412 | call TermWait(buf, 25) |
Bram Moolenaar | 479950f | 2020-01-19 15:45:17 +0100 | [diff] [blame] | 1413 | " in one tab make the command line higher with CTRL-W - |
| 1414 | call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt") |
| 1415 | call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {}) |
| 1416 | |
| 1417 | call StopVimInTerminal(buf) |
| 1418 | call delete('XtestCmdlineClearTabenter') |
| 1419 | endfunc |
| 1420 | |
Yegappan Lakshmanan | 46aa6f9 | 2021-05-19 17:15:04 +0200 | [diff] [blame] | 1421 | " Test for expanding special keywords in cmdline |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1422 | func Test_cmdline_expand_special() |
| 1423 | %bwipe! |
Bram Moolenaar | b8bd2e6 | 2021-08-21 17:13:14 +0200 | [diff] [blame] | 1424 | call assert_fails('e #', 'E194:') |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1425 | call assert_fails('e <afile>', 'E495:') |
| 1426 | call assert_fails('e <abuf>', 'E496:') |
| 1427 | call assert_fails('e <amatch>', 'E497:') |
Yegappan Lakshmanan | 46aa6f9 | 2021-05-19 17:15:04 +0200 | [diff] [blame] | 1428 | |
| 1429 | call writefile([], 'Xfile.cpp') |
| 1430 | call writefile([], 'Xfile.java') |
| 1431 | new Xfile.cpp |
| 1432 | call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1433 | call assert_equal('"e Xfile.cpp Xfile.java', @:) |
| 1434 | close |
| 1435 | call delete('Xfile.cpp') |
| 1436 | call delete('Xfile.java') |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 1437 | endfunc |
| 1438 | |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1439 | func Test_cmdwin_jump_to_win() |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 1440 | CheckFeature cmdwin |
| 1441 | |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1442 | call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:') |
| 1443 | new |
| 1444 | set modified |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1445 | call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:']) |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1446 | close! |
| 1447 | call feedkeys("q/:close\<CR>", "xt") |
| 1448 | call assert_equal(1, winnr('$')) |
| 1449 | call feedkeys("q/:exit\<CR>", "xt") |
| 1450 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 1451 | |
| 1452 | " opening command window twice should fail |
| 1453 | call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")') |
| 1454 | call assert_equal(1, winnr('$')) |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1455 | endfunc |
| 1456 | |
Bram Moolenaar | 9b7cce2 | 2020-06-06 15:14:08 +0200 | [diff] [blame] | 1457 | func Test_cmdwin_interrupted() |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 1458 | CheckFeature cmdwin |
Bram Moolenaar | 9b7cce2 | 2020-06-06 15:14:08 +0200 | [diff] [blame] | 1459 | CheckScreendump |
| 1460 | |
| 1461 | " aborting the :smile output caused the cmdline window to use the current |
| 1462 | " buffer. |
| 1463 | let lines =<< trim [SCRIPT] |
| 1464 | au WinNew * smile |
| 1465 | [SCRIPT] |
| 1466 | call writefile(lines, 'XTest_cmdwin') |
| 1467 | |
| 1468 | let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18}) |
Bram Moolenaar | 9b7cce2 | 2020-06-06 15:14:08 +0200 | [diff] [blame] | 1469 | " open cmdwin |
| 1470 | call term_sendkeys(buf, "q:") |
Bram Moolenaar | c82dd86 | 2020-06-07 17:30:33 +0200 | [diff] [blame] | 1471 | call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))}) |
Bram Moolenaar | 9b7cce2 | 2020-06-06 15:14:08 +0200 | [diff] [blame] | 1472 | " quit more prompt for :smile command |
| 1473 | call term_sendkeys(buf, "q") |
Bram Moolenaar | c82dd86 | 2020-06-07 17:30:33 +0200 | [diff] [blame] | 1474 | call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))}) |
Bram Moolenaar | 9b7cce2 | 2020-06-06 15:14:08 +0200 | [diff] [blame] | 1475 | " execute a simple command |
| 1476 | call term_sendkeys(buf, "aecho 'done'\<CR>") |
| 1477 | call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {}) |
| 1478 | |
| 1479 | " clean up |
| 1480 | call StopVimInTerminal(buf) |
| 1481 | call delete('XTest_cmdwin') |
| 1482 | endfunc |
| 1483 | |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1484 | " Test for backtick expression in the command line |
| 1485 | func Test_cmd_backtick() |
| 1486 | %argd |
| 1487 | argadd `=['a', 'b', 'c']` |
| 1488 | call assert_equal(['a', 'b', 'c'], argv()) |
| 1489 | %argd |
Dominique Pelle | bfb2bb1 | 2021-08-14 21:11:51 +0200 | [diff] [blame] | 1490 | |
| 1491 | argadd `echo abc def` |
| 1492 | call assert_equal(['abc def'], argv()) |
| 1493 | %argd |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1494 | endfunc |
| 1495 | |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 1496 | " Test for the :! command |
| 1497 | func Test_cmd_bang() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1498 | CheckUnix |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 1499 | |
| 1500 | let lines =<< trim [SCRIPT] |
| 1501 | " Test for no previous command |
| 1502 | call assert_fails('!!', 'E34:') |
| 1503 | set nomore |
| 1504 | " Test for cmdline expansion with :! |
| 1505 | call setline(1, 'foo!') |
| 1506 | silent !echo <cWORD> > Xfile.out |
| 1507 | call assert_equal(['foo!'], readfile('Xfile.out')) |
| 1508 | " Test for using previous command |
| 1509 | silent !echo \! ! |
| 1510 | call assert_equal(['! echo foo!'], readfile('Xfile.out')) |
| 1511 | call writefile(v:errors, 'Xresult') |
| 1512 | call delete('Xfile.out') |
| 1513 | qall! |
| 1514 | [SCRIPT] |
| 1515 | call writefile(lines, 'Xscript') |
| 1516 | if RunVim([], [], '--clean -S Xscript') |
| 1517 | call assert_equal([], readfile('Xresult')) |
| 1518 | endif |
| 1519 | call delete('Xscript') |
| 1520 | call delete('Xresult') |
| 1521 | endfunc |
| 1522 | |
Bram Moolenaar | e0c3c3d | 2020-06-04 22:46:04 +0200 | [diff] [blame] | 1523 | " Test error: "E135: *Filter* Autocommands must not change current buffer" |
| 1524 | func Test_cmd_bang_E135() |
| 1525 | new |
| 1526 | call setline(1, ['a', 'b', 'c', 'd']) |
| 1527 | augroup test_cmd_filter_E135 |
| 1528 | au! |
| 1529 | autocmd FilterReadPost * help |
| 1530 | augroup END |
| 1531 | call assert_fails('2,3!echo "x"', 'E135:') |
| 1532 | |
| 1533 | augroup test_cmd_filter_E135 |
| 1534 | au! |
| 1535 | augroup END |
| 1536 | %bwipe! |
| 1537 | endfunc |
| 1538 | |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 1539 | " Test for using ~ for home directory in cmdline completion matches |
| 1540 | func Test_cmdline_expand_home() |
| 1541 | call mkdir('Xdir') |
| 1542 | call writefile([], 'Xdir/Xfile1') |
| 1543 | call writefile([], 'Xdir/Xfile2') |
| 1544 | cd Xdir |
| 1545 | let save_HOME = $HOME |
| 1546 | let $HOME = getcwd() |
| 1547 | call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1548 | call assert_equal('"e ~/Xfile1 ~/Xfile2', @:) |
| 1549 | let $HOME = save_HOME |
| 1550 | cd .. |
| 1551 | call delete('Xdir', 'rf') |
| 1552 | endfunc |
| 1553 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1554 | " Test for using CTRL-\ CTRL-G in the command line to go back to normal mode |
| 1555 | " or insert mode (when 'insertmode' is set) |
| 1556 | func Test_cmdline_ctrl_g() |
| 1557 | new |
| 1558 | call setline(1, 'abc') |
| 1559 | call cursor(1, 3) |
| 1560 | " If command line is entered from insert mode, using C-\ C-G should back to |
| 1561 | " insert mode |
| 1562 | call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt') |
| 1563 | call assert_equal('abxyc', getline(1)) |
| 1564 | call assert_equal(4, col('.')) |
| 1565 | |
| 1566 | " If command line is entered in 'insertmode', using C-\ C-G should back to |
| 1567 | " 'insertmode' |
| 1568 | call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt') |
| 1569 | call assert_equal('ab12xyc', getline(1)) |
| 1570 | close! |
| 1571 | endfunc |
| 1572 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1573 | " Test for 'wildmode' |
| 1574 | func Test_wildmode() |
| 1575 | func T(a, c, p) |
| 1576 | return "oneA\noneB\noneC" |
| 1577 | endfunc |
| 1578 | command -nargs=1 -complete=custom,T MyCmd |
| 1579 | |
| 1580 | func SaveScreenLine() |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1581 | let g:Sline = Screenline(&lines - 1) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1582 | return '' |
| 1583 | endfunc |
| 1584 | cnoremap <expr> <F2> SaveScreenLine() |
| 1585 | |
| 1586 | set nowildmenu |
| 1587 | set wildmode=full,list |
| 1588 | let g:Sline = '' |
| 1589 | call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt') |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1590 | call assert_equal('oneA oneB oneC', g:Sline) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1591 | call assert_equal('"MyCmd oneA', @:) |
| 1592 | |
| 1593 | set wildmode=longest,full |
| 1594 | call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') |
| 1595 | call assert_equal('"MyCmd one', @:) |
| 1596 | call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt') |
| 1597 | call assert_equal('"MyCmd oneC', @:) |
| 1598 | |
| 1599 | set wildmode=longest |
| 1600 | call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt') |
| 1601 | call assert_equal('"MyCmd one', @:) |
| 1602 | |
| 1603 | set wildmode=list:longest |
| 1604 | let g:Sline = '' |
| 1605 | call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt') |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1606 | call assert_equal('oneA oneB oneC', g:Sline) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1607 | call assert_equal('"MyCmd one', @:) |
| 1608 | |
| 1609 | set wildmode="" |
| 1610 | call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt') |
| 1611 | call assert_equal('"MyCmd oneA', @:) |
| 1612 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1613 | " Test for wildmode=longest with 'fileignorecase' set |
| 1614 | set wildmode=longest |
| 1615 | set fileignorecase |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 1616 | argadd AAA AAAA AAAAA |
| 1617 | call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt') |
| 1618 | call assert_equal('"buffer AAA', @:) |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1619 | set fileignorecase& |
| 1620 | |
| 1621 | " Test for listing files with wildmode=list |
| 1622 | set wildmode=list |
| 1623 | let g:Sline = '' |
| 1624 | call feedkeys(":b A\t\t\<F2>\<C-B>\"\<CR>", 'xt') |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 1625 | call assert_equal('AAA AAAA AAAAA', g:Sline) |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1626 | call assert_equal('"b A', @:) |
| 1627 | |
| 1628 | %argdelete |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1629 | delcommand MyCmd |
| 1630 | delfunc T |
| 1631 | delfunc SaveScreenLine |
| 1632 | cunmap <F2> |
| 1633 | set wildmode& |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1634 | %bwipe! |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1635 | endfunc |
| 1636 | |
| 1637 | " Test for interrupting the command-line completion |
| 1638 | func Test_interrupt_compl() |
| 1639 | func F(lead, cmdl, p) |
| 1640 | if a:lead =~ 'tw' |
| 1641 | call interrupt() |
| 1642 | return |
| 1643 | endif |
| 1644 | return "one\ntwo\nthree" |
| 1645 | endfunc |
| 1646 | command -nargs=1 -complete=custom,F Tcmd |
| 1647 | |
| 1648 | set nowildmenu |
| 1649 | set wildmode=full |
| 1650 | let interrupted = 0 |
| 1651 | try |
| 1652 | call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt') |
| 1653 | catch /^Vim:Interrupt$/ |
| 1654 | let interrupted = 1 |
| 1655 | endtry |
| 1656 | call assert_equal(1, interrupted) |
| 1657 | |
| 1658 | delcommand Tcmd |
| 1659 | delfunc F |
| 1660 | set wildmode& |
| 1661 | endfunc |
| 1662 | |
Bram Moolenaar | d30ae2f | 2020-02-29 14:23:58 +0100 | [diff] [blame] | 1663 | " Test for moving the cursor on the : command line |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1664 | func Test_cmdline_edit() |
Bram Moolenaar | d30ae2f | 2020-02-29 14:23:58 +0100 | [diff] [blame] | 1665 | let str = ":one two\<C-U>" |
| 1666 | let str ..= "one two\<C-W>\<C-W>" |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 1667 | let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" |
Bram Moolenaar | d30ae2f | 2020-02-29 14:23:58 +0100 | [diff] [blame] | 1668 | let str ..= "\<Left>five\<Right>" |
| 1669 | let str ..= "\<Home>two " |
| 1670 | let str ..= "\<C-Left>one " |
| 1671 | let str ..= "\<C-Right> three" |
| 1672 | let str ..= "\<End>\<S-Left>four " |
| 1673 | let str ..= "\<S-Right> six" |
| 1674 | let str ..= "\<C-B>\"\<C-E> seven\<CR>" |
| 1675 | call feedkeys(str, 'xt') |
| 1676 | call assert_equal("\"one two three four five six seven", @:) |
| 1677 | endfunc |
| 1678 | |
| 1679 | " Test for moving the cursor on the / command line in 'rightleft' mode |
| 1680 | func Test_cmdline_edit_rightleft() |
| 1681 | CheckFeature rightleft |
| 1682 | set rightleft |
| 1683 | set rightleftcmd=search |
| 1684 | let str = "/one two\<C-U>" |
| 1685 | let str ..= "one two\<C-W>\<C-W>" |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 1686 | let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" |
Bram Moolenaar | d30ae2f | 2020-02-29 14:23:58 +0100 | [diff] [blame] | 1687 | let str ..= "\<Right>five\<Left>" |
| 1688 | let str ..= "\<Home>two " |
| 1689 | let str ..= "\<C-Right>one " |
| 1690 | let str ..= "\<C-Left> three" |
| 1691 | let str ..= "\<End>\<S-Right>four " |
| 1692 | let str ..= "\<S-Left> six" |
| 1693 | let str ..= "\<C-B>\"\<C-E> seven\<CR>" |
| 1694 | call assert_fails("call feedkeys(str, 'xt')", 'E486:') |
| 1695 | call assert_equal("\"one two three four five six seven", @/) |
| 1696 | set rightleftcmd& |
| 1697 | set rightleft& |
| 1698 | endfunc |
| 1699 | |
| 1700 | " Test for using <C-\>e in the command line to evaluate an expression |
| 1701 | func Test_cmdline_expr() |
| 1702 | " Evaluate an expression from the beginning of a command line |
| 1703 | call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt') |
| 1704 | call assert_equal('"hello', @:) |
| 1705 | |
| 1706 | " Use an invalid expression for <C-\>e |
| 1707 | call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")') |
| 1708 | |
| 1709 | " Insert literal <CTRL-\> in the command line |
| 1710 | call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt') |
| 1711 | call assert_equal("\"e \<C-\>\<C-Y>", @:) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1712 | endfunc |
| 1713 | |
Bram Moolenaar | 0546d7d | 2020-03-01 16:53:09 +0100 | [diff] [blame] | 1714 | " Test for 'imcmdline' and 'imsearch' |
| 1715 | " This test doesn't actually test the input method functionality. |
| 1716 | func Test_cmdline_inputmethod() |
| 1717 | new |
| 1718 | call setline(1, ['', 'abc', '']) |
| 1719 | set imcmdline |
| 1720 | |
| 1721 | call feedkeys(":\"abc\<CR>", 'xt') |
| 1722 | call assert_equal("\"abc", @:) |
| 1723 | call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt') |
| 1724 | call assert_equal("\"abc", @:) |
| 1725 | call feedkeys("/abc\<CR>", 'xt') |
| 1726 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1727 | call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') |
| 1728 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1729 | |
| 1730 | set imsearch=2 |
| 1731 | call cursor(1, 1) |
| 1732 | call feedkeys("/abc\<CR>", 'xt') |
| 1733 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1734 | call cursor(1, 1) |
| 1735 | call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') |
| 1736 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1737 | set imdisable |
| 1738 | call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') |
| 1739 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 1740 | set imdisable& |
| 1741 | set imsearch& |
| 1742 | |
| 1743 | set imcmdline& |
| 1744 | %bwipe! |
| 1745 | endfunc |
| 1746 | |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 1747 | " Test for recursively getting multiple command line inputs |
| 1748 | func Test_cmdwin_multi_input() |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 1749 | CheckFeature cmdwin |
| 1750 | |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 1751 | call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt') |
| 1752 | call assert_equal('"cyan', @:) |
| 1753 | endfunc |
| 1754 | |
| 1755 | " Test for using CTRL-_ in the command line with 'allowrevins' |
| 1756 | func Test_cmdline_revins() |
| 1757 | CheckNotMSWindows |
| 1758 | CheckFeature rightleft |
| 1759 | call feedkeys(":\"abc\<c-_>\<cr>", 'xt') |
| 1760 | call assert_equal("\"abc\<c-_>", @:) |
| 1761 | set allowrevins |
| 1762 | call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt') |
| 1763 | call assert_equal('"abcñèæ', @:) |
| 1764 | set allowrevins& |
| 1765 | endfunc |
| 1766 | |
| 1767 | " Test for typing UTF-8 composing characters in the command line |
| 1768 | func Test_cmdline_composing_chars() |
| 1769 | call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt') |
| 1770 | call assert_equal('"ゔ', @:) |
| 1771 | endfunc |
| 1772 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1773 | " Test for normal mode commands not supported in the cmd window |
| 1774 | func Test_cmdwin_blocked_commands() |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 1775 | CheckFeature cmdwin |
| 1776 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1777 | call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:') |
| 1778 | call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:') |
| 1779 | call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:') |
| 1780 | call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:') |
| 1781 | call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:') |
| 1782 | call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:') |
Bram Moolenaar | 951a2fb | 2020-06-07 19:38:10 +0200 | [diff] [blame] | 1783 | call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:') |
| 1784 | call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:') |
| 1785 | call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:') |
| 1786 | call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:') |
| 1787 | call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:') |
| 1788 | call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:') |
| 1789 | call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:') |
| 1790 | call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:') |
| 1791 | call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:') |
| 1792 | call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:') |
| 1793 | call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:') |
| 1794 | call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:') |
| 1795 | call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:') |
| 1796 | call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:') |
| 1797 | call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:') |
| 1798 | call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:') |
| 1799 | call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:') |
| 1800 | call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:') |
| 1801 | call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:') |
| 1802 | call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:') |
| 1803 | call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:') |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1804 | endfunc |
| 1805 | |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 1806 | " Close the Cmd-line window in insert mode using CTRL-C |
| 1807 | func Test_cmdwin_insert_mode_close() |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 1808 | CheckFeature cmdwin |
| 1809 | |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame] | 1810 | %bw! |
| 1811 | let s = '' |
| 1812 | exe "normal q:a\<C-C>let s='Hello'\<CR>" |
| 1813 | call assert_equal('Hello', s) |
| 1814 | call assert_equal(1, winnr('$')) |
| 1815 | endfunc |
| 1816 | |
Bram Moolenaar | 0e71704 | 2020-04-27 19:29:01 +0200 | [diff] [blame] | 1817 | " test that ";" works to find a match at the start of the first line |
| 1818 | func Test_zero_line_search() |
| 1819 | new |
| 1820 | call setline(1, ["1, pattern", "2, ", "3, pattern"]) |
| 1821 | call cursor(1,1) |
| 1822 | 0;/pattern/d |
| 1823 | call assert_equal(["2, ", "3, pattern"], getline(1,'$')) |
| 1824 | q! |
| 1825 | endfunc |
| 1826 | |
Bram Moolenaar | c8cb883 | 2020-06-18 21:14:30 +0200 | [diff] [blame] | 1827 | func Test_read_shellcmd() |
| 1828 | CheckUnix |
| 1829 | if executable('ls') |
| 1830 | " There should be ls in the $PATH |
| 1831 | call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx') |
| 1832 | call assert_match('^"r! .*\<ls\>', @:) |
| 1833 | endif |
| 1834 | |
| 1835 | if executable('rm') |
| 1836 | call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx') |
| 1837 | call assert_notmatch('^"r!.*\<runtest.vim\>', @:) |
| 1838 | call assert_match('^"r!.*\<rm\>', @:) |
Bram Moolenaar | 743d062 | 2020-07-03 18:15:06 +0200 | [diff] [blame] | 1839 | |
| 1840 | call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx') |
| 1841 | call assert_notmatch('^"r.*\<runtest.vim\>', @:) |
| 1842 | call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:) |
Bram Moolenaar | c8cb883 | 2020-06-18 21:14:30 +0200 | [diff] [blame] | 1843 | endif |
| 1844 | endfunc |
| 1845 | |
Bram Moolenaar | 4b2ce12 | 2020-11-21 21:41:41 +0100 | [diff] [blame] | 1846 | " Test for going up and down the directory tree using 'wildmenu' |
| 1847 | func Test_wildmenu_dirstack() |
| 1848 | CheckUnix |
| 1849 | %bw! |
| 1850 | call mkdir('Xdir1/dir2/dir3', 'p') |
| 1851 | call writefile([], 'Xdir1/file1_1.txt') |
| 1852 | call writefile([], 'Xdir1/file1_2.txt') |
| 1853 | call writefile([], 'Xdir1/dir2/file2_1.txt') |
| 1854 | call writefile([], 'Xdir1/dir2/file2_2.txt') |
| 1855 | call writefile([], 'Xdir1/dir2/dir3/file3_1.txt') |
| 1856 | call writefile([], 'Xdir1/dir2/dir3/file3_2.txt') |
| 1857 | cd Xdir1/dir2/dir3 |
| 1858 | set wildmenu |
| 1859 | |
| 1860 | call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt') |
| 1861 | call assert_equal('"e file3_1.txt', @:) |
| 1862 | call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt') |
| 1863 | call assert_equal('"e ../dir3/', @:) |
| 1864 | call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt') |
| 1865 | call assert_equal('"e ../../dir2/', @:) |
| 1866 | call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt') |
| 1867 | call assert_equal('"e ../../dir2/dir3/', @:) |
| 1868 | call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt') |
| 1869 | call assert_equal('"e ../../dir2/dir3/file3_1.txt', @:) |
| 1870 | |
| 1871 | cd - |
| 1872 | call delete('Xdir1', 'rf') |
| 1873 | set wildmenu& |
| 1874 | endfunc |
| 1875 | |
obcat | 71c6f7a | 2021-05-13 20:23:10 +0200 | [diff] [blame] | 1876 | " Test for recalling newer or older cmdline from history with <Up>, <Down>, |
| 1877 | " <S-Up>, <S-Down>, <PageUp>, <PageDown>, <C-p>, or <C-n>. |
| 1878 | func Test_recalling_cmdline() |
| 1879 | CheckFeature cmdline_hist |
| 1880 | |
| 1881 | let g:cmdlines = [] |
| 1882 | cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR> |
| 1883 | |
| 1884 | let histories = [ |
| 1885 | \ {'name': 'cmd', 'enter': ':', 'exit': "\<Esc>"}, |
| 1886 | \ {'name': 'search', 'enter': '/', 'exit': "\<Esc>"}, |
| 1887 | \ {'name': 'expr', 'enter': ":\<C-r>=", 'exit': "\<Esc>\<Esc>"}, |
| 1888 | \ {'name': 'input', 'enter': ":call input('')\<CR>", 'exit': "\<CR>"}, |
| 1889 | "\ TODO: {'name': 'debug', ...} |
| 1890 | \] |
| 1891 | let keypairs = [ |
| 1892 | \ {'older': "\<Up>", 'newer': "\<Down>", 'prefixmatch': v:true}, |
| 1893 | \ {'older': "\<S-Up>", 'newer': "\<S-Down>", 'prefixmatch': v:false}, |
| 1894 | \ {'older': "\<PageUp>", 'newer': "\<PageDown>", 'prefixmatch': v:false}, |
| 1895 | \ {'older': "\<C-p>", 'newer': "\<C-n>", 'prefixmatch': v:false}, |
| 1896 | \] |
| 1897 | let prefix = 'vi' |
| 1898 | for h in histories |
| 1899 | call histadd(h.name, 'vim') |
| 1900 | call histadd(h.name, 'virtue') |
| 1901 | call histadd(h.name, 'Virgo') |
| 1902 | call histadd(h.name, 'vogue') |
| 1903 | call histadd(h.name, 'emacs') |
| 1904 | for k in keypairs |
| 1905 | let g:cmdlines = [] |
| 1906 | let keyseqs = h.enter |
| 1907 | \ .. prefix |
| 1908 | \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2) |
| 1909 | \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2) |
| 1910 | \ .. h.exit |
| 1911 | call feedkeys(keyseqs, 'xt') |
| 1912 | call histdel(h.name, -1) " delete the history added by feedkeys above |
| 1913 | let expect = k.prefixmatch |
| 1914 | \ ? ['virtue', 'vim', 'virtue', prefix] |
| 1915 | \ : ['emacs', 'vogue', 'emacs', prefix] |
| 1916 | call assert_equal(expect, g:cmdlines) |
| 1917 | endfor |
| 1918 | endfor |
| 1919 | |
| 1920 | unlet g:cmdlines |
| 1921 | cunmap <Plug>(save-cmdline) |
| 1922 | endfunc |
| 1923 | |
Bram Moolenaar | 847fe7d | 2021-05-15 13:19:16 +0200 | [diff] [blame] | 1924 | func Test_cmd_map_cmdlineChanged() |
| 1925 | let g:log = [] |
| 1926 | cnoremap <F1> l<Cmd><CR>s |
| 1927 | augroup test |
| 1928 | autocmd! |
| 1929 | autocmd CmdlineChanged : let g:log += [getcmdline()] |
| 1930 | augroup END |
| 1931 | |
| 1932 | call feedkeys(":\<F1>\<CR>", 'xt') |
| 1933 | call assert_equal(['l', 'ls'], g:log) |
| 1934 | |
Bram Moolenaar | 796139a | 2021-05-18 21:38:45 +0200 | [diff] [blame] | 1935 | let @b = 'b' |
| 1936 | cnoremap <F1> a<C-R>b |
| 1937 | let g:log = [] |
| 1938 | call feedkeys(":\<F1>\<CR>", 'xt') |
| 1939 | call assert_equal(['a', 'ab'], g:log) |
| 1940 | |
Bram Moolenaar | 847fe7d | 2021-05-15 13:19:16 +0200 | [diff] [blame] | 1941 | unlet g:log |
| 1942 | cunmap <F1> |
| 1943 | augroup test |
| 1944 | autocmd! |
| 1945 | augroup END |
| 1946 | endfunc |
| 1947 | |
Yegappan Lakshmanan | 46aa6f9 | 2021-05-19 17:15:04 +0200 | [diff] [blame] | 1948 | " Test for the 'suffixes' option |
| 1949 | func Test_suffixes_opt() |
| 1950 | call writefile([], 'Xfile') |
| 1951 | call writefile([], 'Xfile.c') |
| 1952 | call writefile([], 'Xfile.o') |
| 1953 | set suffixes= |
| 1954 | call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1955 | call assert_equal('"e Xfile Xfile.c Xfile.o', @:) |
| 1956 | set suffixes=.c |
| 1957 | call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1958 | call assert_equal('"e Xfile Xfile.o Xfile.c', @:) |
| 1959 | set suffixes=,, |
| 1960 | call feedkeys(":e Xfi*\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1961 | call assert_equal('"e Xfile.c Xfile.o Xfile', @:) |
| 1962 | set suffixes& |
| 1963 | call delete('Xfile') |
| 1964 | call delete('Xfile.c') |
| 1965 | call delete('Xfile.o') |
| 1966 | endfunc |
Bram Moolenaar | 847fe7d | 2021-05-15 13:19:16 +0200 | [diff] [blame] | 1967 | |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 1968 | " Test for using a popup menu for the command line completion matches |
| 1969 | " (wildoptions=pum) |
| 1970 | func Test_wildmenu_pum() |
| 1971 | CheckRunVimInTerminal |
| 1972 | |
| 1973 | let commands =<< trim [CODE] |
| 1974 | set wildmenu |
| 1975 | set wildoptions=pum |
| 1976 | set shm+=I |
| 1977 | set noruler |
| 1978 | set noshowcmd |
| 1979 | [CODE] |
| 1980 | call writefile(commands, 'Xtest') |
| 1981 | |
| 1982 | let buf = RunVimInTerminal('-S Xtest', #{rows: 10}) |
| 1983 | |
| 1984 | call term_sendkeys(buf, ":sign \<Tab>") |
| 1985 | call TermWait(buf) |
| 1986 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {}) |
| 1987 | |
| 1988 | call term_sendkeys(buf, "\<Down>\<Down>") |
| 1989 | call TermWait(buf) |
| 1990 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {}) |
| 1991 | |
| 1992 | call term_sendkeys(buf, "\<C-N>") |
| 1993 | call TermWait(buf) |
| 1994 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {}) |
| 1995 | |
| 1996 | call term_sendkeys(buf, "\<C-P>") |
| 1997 | call TermWait(buf) |
| 1998 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {}) |
| 1999 | |
| 2000 | call term_sendkeys(buf, "\<Up>") |
| 2001 | call TermWait(buf) |
| 2002 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {}) |
| 2003 | |
| 2004 | " pressing <C-E> should end completion and go back to the original match |
| 2005 | call term_sendkeys(buf, "\<C-E>") |
| 2006 | call TermWait(buf) |
| 2007 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {}) |
| 2008 | |
| 2009 | " pressing <C-Y> should select the current match and end completion |
| 2010 | call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>") |
| 2011 | call TermWait(buf) |
| 2012 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {}) |
| 2013 | |
| 2014 | " With 'wildmode' set to 'longest,full', completing a match should display |
| 2015 | " the longest match, the wildmenu should not be displayed. |
| 2016 | call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>") |
| 2017 | call TermWait(buf) |
| 2018 | call term_sendkeys(buf, ":sign u\<Tab>") |
| 2019 | call TermWait(buf) |
| 2020 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {}) |
| 2021 | |
| 2022 | " pressing <Tab> should display the wildmenu |
| 2023 | call term_sendkeys(buf, "\<Tab>") |
| 2024 | call TermWait(buf) |
| 2025 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {}) |
| 2026 | |
| 2027 | " pressing <Tab> second time should select the next entry in the menu |
| 2028 | call term_sendkeys(buf, "\<Tab>") |
| 2029 | call TermWait(buf) |
| 2030 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {}) |
| 2031 | |
| 2032 | call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>") |
| 2033 | " " showing popup menu in different columns in the cmdline |
| 2034 | call term_sendkeys(buf, ":sign define \<Tab>") |
| 2035 | call TermWait(buf) |
| 2036 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {}) |
| 2037 | |
| 2038 | call term_sendkeys(buf, " \<Tab>") |
| 2039 | call TermWait(buf) |
| 2040 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {}) |
| 2041 | |
| 2042 | call term_sendkeys(buf, " \<Tab>") |
| 2043 | call TermWait(buf) |
| 2044 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {}) |
| 2045 | |
| 2046 | " Directory name completion |
| 2047 | call mkdir('Xdir/XdirA/XdirB', 'p') |
| 2048 | call writefile([], 'Xdir/XfileA') |
| 2049 | call writefile([], 'Xdir/XdirA/XfileB') |
| 2050 | call writefile([], 'Xdir/XdirA/XdirB/XfileC') |
| 2051 | |
| 2052 | call term_sendkeys(buf, "\<C-U>e Xdi\<Tab>\<Tab>") |
| 2053 | call TermWait(buf) |
| 2054 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {}) |
| 2055 | |
| 2056 | " Pressing <Right> on a directory name should go into that directory |
| 2057 | call term_sendkeys(buf, "\<Right>") |
| 2058 | call TermWait(buf) |
| 2059 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {}) |
| 2060 | |
| 2061 | " Pressing <Left> on a directory name should go to the parent directory |
| 2062 | call term_sendkeys(buf, "\<Left>") |
| 2063 | call TermWait(buf) |
| 2064 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {}) |
| 2065 | |
| 2066 | " Pressing <C-A> when the popup menu is displayed should list all the |
| 2067 | " matches and remove the popup menu |
| 2068 | call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>") |
| 2069 | call TermWait(buf) |
| 2070 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {}) |
| 2071 | |
| 2072 | " Pressing <C-D> when the popup menu is displayed should remove the popup |
| 2073 | " menu |
| 2074 | call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>") |
| 2075 | call TermWait(buf) |
| 2076 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {}) |
| 2077 | |
| 2078 | " Pressing <S-Tab> should open the popup menu with the last entry selected |
| 2079 | call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>") |
| 2080 | call TermWait(buf) |
| 2081 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {}) |
| 2082 | |
| 2083 | " Pressing <Esc> should close the popup menu and cancel the cmd line |
| 2084 | call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>") |
| 2085 | call TermWait(buf) |
| 2086 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {}) |
| 2087 | |
| 2088 | " Typing a character when the popup is open, should close the popup |
| 2089 | call term_sendkeys(buf, ":sign \<Tab>x") |
| 2090 | call TermWait(buf) |
| 2091 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {}) |
| 2092 | |
| 2093 | " When the popup is open, entering the cmdline window should close the popup |
| 2094 | call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>") |
| 2095 | call TermWait(buf) |
| 2096 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {}) |
| 2097 | call term_sendkeys(buf, ":q\<CR>") |
| 2098 | |
| 2099 | " After the last popup menu item, <C-N> should show the original string |
| 2100 | call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>") |
| 2101 | call TermWait(buf) |
| 2102 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {}) |
| 2103 | |
| 2104 | " Use the popup menu for the command name |
| 2105 | call term_sendkeys(buf, "\<C-U>bu\<Tab>") |
| 2106 | call TermWait(buf) |
| 2107 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {}) |
| 2108 | |
| 2109 | " Pressing the left arrow should remove the popup menu |
| 2110 | call term_sendkeys(buf, "\<Left>\<Left>") |
| 2111 | call TermWait(buf) |
| 2112 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {}) |
| 2113 | |
| 2114 | " Pressing <BS> should remove the popup menu and erase the last character |
| 2115 | call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>") |
| 2116 | call TermWait(buf) |
| 2117 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {}) |
| 2118 | |
| 2119 | " Pressing <C-W> should remove the popup menu and erase the previous word |
| 2120 | call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>") |
| 2121 | call TermWait(buf) |
| 2122 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {}) |
| 2123 | |
| 2124 | " Pressing <C-U> should remove the popup menu and erase the entire line |
| 2125 | call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>") |
| 2126 | call TermWait(buf) |
| 2127 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {}) |
| 2128 | |
| 2129 | " Using <C-E> to cancel the popup menu and then pressing <Up> should recall |
| 2130 | " the cmdline from history |
| 2131 | call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>") |
| 2132 | call TermWait(buf) |
| 2133 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {}) |
| 2134 | |
| 2135 | call term_sendkeys(buf, "\<C-U>\<CR>") |
| 2136 | call StopVimInTerminal(buf) |
| 2137 | call delete('Xtest') |
| 2138 | call delete('Xdir', 'rf') |
| 2139 | endfunc |
| 2140 | |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 2141 | " vim: shiftwidth=2 sts=2 expandtab |