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