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