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