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