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