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