Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 1 | " Tests for editing the command line. |
| 2 | |
Christian Brabandt | eb380b9 | 2025-07-07 20:53:55 +0200 | [diff] [blame] | 3 | source util/screendump.vim |
| 4 | import './util/vim9.vim' as v9 |
Bram Moolenaar | 4facea3 | 2019-10-12 20:17:40 +0200 | [diff] [blame] | 5 | |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 6 | func SetUp() |
| 7 | func SaveLastScreenLine() |
| 8 | let g:Sline = Screenline(&lines - 1) |
| 9 | return '' |
| 10 | endfunc |
| 11 | cnoremap <expr> <F4> SaveLastScreenLine() |
| 12 | endfunc |
| 13 | |
| 14 | func TearDown() |
| 15 | delfunc SaveLastScreenLine |
| 16 | cunmap <F4> |
| 17 | endfunc |
| 18 | |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 19 | func Test_complete_tab() |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 20 | call writefile(['testfile'], 'Xtestfile', 'D') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 21 | call feedkeys(":e Xtest\t\r", "tx") |
| 22 | call assert_equal('testfile', getline(1)) |
Albert Liu | 6024c04 | 2021-08-27 20:59:35 +0200 | [diff] [blame] | 23 | |
| 24 | " Pressing <Tab> after '%' completes the current file, also on MS-Windows |
| 25 | call feedkeys(":e %\t\r", "tx") |
| 26 | call assert_equal('e Xtestfile', @:) |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 27 | endfunc |
| 28 | |
| 29 | func Test_complete_list() |
| 30 | " We can't see the output, but at least we check the code runs properly. |
| 31 | call feedkeys(":e test\<C-D>\r", "tx") |
| 32 | call assert_equal('test', expand('%:t')) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 33 | |
| 34 | " If a command doesn't support completion, then CTRL-D should be literally |
| 35 | " used. |
| 36 | call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt') |
| 37 | call assert_equal("\"chistory \<C-D>", @:) |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 38 | |
| 39 | " Test for displaying the tail of the completion matches |
| 40 | set wildmode=longest,full |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 41 | call mkdir('Xtest', 'R') |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 42 | call writefile([], 'Xtest/a.c') |
| 43 | call writefile([], 'Xtest/a.h') |
| 44 | let g:Sline = '' |
| 45 | call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt') |
| 46 | call assert_equal('a.c a.h', g:Sline) |
| 47 | call assert_equal('"e Xtest/', @:) |
| 48 | if has('win32') |
| 49 | " Test for 'completeslash' |
| 50 | set completeslash=backslash |
| 51 | call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt') |
| 52 | call assert_equal('"e Xtest\', @:) |
Yegappan Lakshmanan | b31aec3 | 2022-02-16 12:44:29 +0000 | [diff] [blame] | 53 | call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt') |
| 54 | call assert_equal('"e Xtest\a.', @:) |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 55 | set completeslash=slash |
| 56 | call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt') |
| 57 | call assert_equal('"e Xtest/', @:) |
Yegappan Lakshmanan | b31aec3 | 2022-02-16 12:44:29 +0000 | [diff] [blame] | 58 | call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt') |
| 59 | call assert_equal('"e Xtest/a.', @:) |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 60 | set completeslash& |
| 61 | endif |
| 62 | |
| 63 | " Test for displaying the tail with wildcards |
| 64 | let g:Sline = '' |
| 65 | call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt') |
| 66 | call assert_equal('Xtest/a.c Xtest/a.h', g:Sline) |
| 67 | call assert_equal('"e Xtes?/', @:) |
| 68 | let g:Sline = '' |
| 69 | call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt') |
| 70 | call assert_equal('Xtest/a.c Xtest/a.h', g:Sline) |
| 71 | call assert_equal('"e Xtes*/', @:) |
| 72 | let g:Sline = '' |
| 73 | call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt') |
| 74 | call assert_equal(':e Xtes[/', g:Sline) |
| 75 | call assert_equal('"e Xtes[/', @:) |
| 76 | |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 77 | set wildmode& |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 78 | endfunc |
| 79 | |
| 80 | func Test_complete_wildmenu() |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 81 | call mkdir('Xwilddir1/Xdir2', 'pR') |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 82 | call writefile(['testfile1'], 'Xwilddir1/Xtestfile1') |
| 83 | call writefile(['testfile2'], 'Xwilddir1/Xtestfile2') |
| 84 | call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3') |
| 85 | call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 86 | set wildmenu |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 87 | |
| 88 | " Pressing <Tab> completes, and moves to next files when pressing again. |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 89 | call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx') |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 90 | call assert_equal('testfile1', getline(1)) |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 91 | call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx') |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 92 | call assert_equal('testfile2', getline(1)) |
| 93 | |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 94 | " <S-Tab> is like <Tab> but begin with the last match and then go to |
| 95 | " previous. |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 96 | call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx') |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 97 | call assert_equal('testfile2', getline(1)) |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 98 | call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx') |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 99 | call assert_equal('testfile1', getline(1)) |
| 100 | |
| 101 | " <Left>/<Right> to move to previous/next file. |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 102 | call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx') |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 103 | call assert_equal('testfile1', getline(1)) |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 104 | call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx') |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 105 | call assert_equal('testfile2', getline(1)) |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 106 | call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx') |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 107 | call assert_equal('testfile1', getline(1)) |
| 108 | |
| 109 | " <Up>/<Down> to go up/down directories. |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 110 | call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx') |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 111 | call assert_equal('testfile3', getline(1)) |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 112 | call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx') |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 113 | call assert_equal('testfile1', getline(1)) |
| 114 | |
Bram Moolenaar | 3e112ac | 2020-12-28 13:41:53 +0100 | [diff] [blame] | 115 | " this fails in some Unix GUIs, not sure why |
| 116 | if !has('unix') || !has('gui_running') |
| 117 | " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is |
| 118 | " different than 'wildchar'. |
| 119 | set wildcharm=<C-Z> |
| 120 | cnoremap <C-J> <Down><C-Z> |
| 121 | cnoremap <C-K> <Up><C-Z> |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 122 | call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx') |
Bram Moolenaar | 3e112ac | 2020-12-28 13:41:53 +0100 | [diff] [blame] | 123 | call assert_equal('testfile3', getline(1)) |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 124 | call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx') |
Bram Moolenaar | 3e112ac | 2020-12-28 13:41:53 +0100 | [diff] [blame] | 125 | call assert_equal('testfile1', getline(1)) |
| 126 | set wildcharm=0 |
| 127 | cunmap <C-J> |
| 128 | cunmap <C-K> |
| 129 | endif |
Bram Moolenaar | b0ac4ea | 2020-12-26 12:06:54 +0100 | [diff] [blame] | 130 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 131 | " Test for canceling the wild menu by adding a character |
| 132 | redrawstatus |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 133 | call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt') |
| 134 | call assert_equal('"e Xwilddir1/Xdir2/x', @:) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 135 | |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 136 | " Completion using a relative path |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 137 | cd Xwilddir1/Xdir2 |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 138 | call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx') |
| 139 | call assert_equal('"e Xtestfile3 Xtestfile4', @:) |
| 140 | cd - |
| 141 | |
Yegappan Lakshmanan | b31aec3 | 2022-02-16 12:44:29 +0000 | [diff] [blame] | 142 | " test for wildmenumode() |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 143 | cnoremap <expr> <F2> wildmenumode() |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 144 | call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx') |
| 145 | call assert_equal('"cd Xwilddir1/0', @:) |
| 146 | call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx') |
| 147 | call assert_equal('"e Xwilddir1/Xdir2/1', @:) |
Bram Moolenaar | 0e05de4 | 2020-03-25 22:23:46 +0100 | [diff] [blame] | 148 | cunmap <F2> |
| 149 | |
Yegappan Lakshmanan | 5cffa8d | 2022-03-16 13:33:53 +0000 | [diff] [blame] | 150 | " Test for canceling the wild menu by pressing <PageDown> or <PageUp>. |
| 151 | " After this pressing <Left> or <Right> should not change the selection. |
| 152 | call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx') |
| 153 | call assert_equal('"sign define', @:) |
| 154 | call histadd('cmd', 'TestWildMenu') |
| 155 | call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx') |
| 156 | call assert_equal('"TestWildMenu', @:) |
| 157 | |
Yee Cheng Chin | 209ec90 | 2023-10-17 10:56:25 +0200 | [diff] [blame] | 158 | " Test for Ctrl-E/Ctrl-Y being able to cancel / accept a match |
| 159 | call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<C-E> yy\<C-B>\"\<CR>", 'tx') |
| 160 | call assert_equal('"sign un yy zz', @:) |
| 161 | |
| 162 | call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<Tab>\<C-Y> yy\<C-B>\"\<CR>", 'tx') |
| 163 | call assert_equal('"sign unplace yy zz', @:) |
| 164 | |
Bram Moolenaar | 37db642 | 2019-03-28 21:26:23 +0100 | [diff] [blame] | 165 | " cleanup |
| 166 | %bwipe |
Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 167 | set nowildmenu |
| 168 | endfunc |
Bram Moolenaar | 4b2ce12 | 2020-11-21 21:41:41 +0100 | [diff] [blame] | 169 | |
Bram Moolenaar | a60053b | 2020-09-03 16:50:13 +0200 | [diff] [blame] | 170 | func Test_wildmenu_screendump() |
| 171 | CheckScreendump |
| 172 | |
| 173 | let lines =<< trim [SCRIPT] |
| 174 | set wildmenu hlsearch |
| 175 | [SCRIPT] |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 176 | call writefile(lines, 'XTest_wildmenu', 'D') |
Bram Moolenaar | a60053b | 2020-09-03 16:50:13 +0200 | [diff] [blame] | 177 | |
Yee Cheng Chin | 8f4fb00 | 2023-10-17 10:06:56 +0200 | [diff] [blame] | 178 | " Test simple wildmenu |
Bram Moolenaar | a60053b | 2020-09-03 16:50:13 +0200 | [diff] [blame] | 179 | let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8}) |
| 180 | call term_sendkeys(buf, ":vim\<Tab>") |
| 181 | call VerifyScreenDump(buf, 'Test_wildmenu_1', {}) |
| 182 | |
| 183 | call term_sendkeys(buf, "\<Tab>") |
| 184 | call VerifyScreenDump(buf, 'Test_wildmenu_2', {}) |
| 185 | |
| 186 | call term_sendkeys(buf, "\<Tab>") |
| 187 | call VerifyScreenDump(buf, 'Test_wildmenu_3', {}) |
| 188 | |
Yee Cheng Chin | 8f4fb00 | 2023-10-17 10:06:56 +0200 | [diff] [blame] | 189 | " Looped back to the original value |
Bram Moolenaar | 39f3b14 | 2021-02-14 12:57:36 +0100 | [diff] [blame] | 190 | call term_sendkeys(buf, "\<Tab>\<Tab>") |
Bram Moolenaar | a60053b | 2020-09-03 16:50:13 +0200 | [diff] [blame] | 191 | call VerifyScreenDump(buf, 'Test_wildmenu_4', {}) |
Yee Cheng Chin | 8f4fb00 | 2023-10-17 10:06:56 +0200 | [diff] [blame] | 192 | |
| 193 | " Test that the wild menu is cleared properly |
| 194 | call term_sendkeys(buf, " ") |
| 195 | call VerifyScreenDump(buf, 'Test_wildmenu_5', {}) |
| 196 | |
| 197 | " Test that a different wildchar still works |
| 198 | call term_sendkeys(buf, "\<Esc>:set wildchar=<Esc>\<CR>") |
| 199 | call term_sendkeys(buf, ":vim\<Esc>") |
| 200 | call VerifyScreenDump(buf, 'Test_wildmenu_1', {}) |
| 201 | |
| 202 | " Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make |
| 203 | " sure clean up is properly done in edge case like this. |
Bram Moolenaar | a60053b | 2020-09-03 16:50:13 +0200 | [diff] [blame] | 204 | call term_sendkeys(buf, "\<Esc>") |
Yee Cheng Chin | 8f4fb00 | 2023-10-17 10:06:56 +0200 | [diff] [blame] | 205 | call VerifyScreenDump(buf, 'Test_wildmenu_6', {}) |
Bram Moolenaar | a60053b | 2020-09-03 16:50:13 +0200 | [diff] [blame] | 206 | |
| 207 | " clean up |
| 208 | call StopVimInTerminal(buf) |
Bram Moolenaar | a60053b | 2020-09-03 16:50:13 +0200 | [diff] [blame] | 209 | endfunc |
| 210 | |
zeertzjq | 1830e78 | 2025-03-13 20:29:13 +0100 | [diff] [blame] | 211 | func Test_wildmenu_with_input_func() |
| 212 | CheckScreendump |
| 213 | |
| 214 | let buf = RunVimInTerminal('-c "set wildmenu"', {'rows': 8}) |
| 215 | |
| 216 | call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>") |
| 217 | call VerifyScreenDump(buf, 'Test_wildmenu_input_func_1', {}) |
| 218 | call term_sendkeys(buf, "ech\<Tab>") |
| 219 | call VerifyScreenDump(buf, 'Test_wildmenu_input_func_2', {}) |
| 220 | call term_sendkeys(buf, "\<Space>") |
| 221 | call VerifyScreenDump(buf, 'Test_wildmenu_input_func_3', {}) |
| 222 | call term_sendkeys(buf, "bufn\<Tab>") |
| 223 | call VerifyScreenDump(buf, 'Test_wildmenu_input_func_4', {}) |
| 224 | call term_sendkeys(buf, "\<CR>") |
| 225 | |
| 226 | call term_sendkeys(buf, ":set wildoptions+=pum\<CR>") |
| 227 | |
| 228 | call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>") |
| 229 | call VerifyScreenDump(buf, 'Test_wildmenu_input_func_5', {}) |
| 230 | call term_sendkeys(buf, "ech\<Tab>") |
| 231 | call VerifyScreenDump(buf, 'Test_wildmenu_input_func_6', {}) |
| 232 | call term_sendkeys(buf, "\<Space>") |
| 233 | call VerifyScreenDump(buf, 'Test_wildmenu_input_func_7', {}) |
| 234 | call term_sendkeys(buf, "bufn\<Tab>") |
| 235 | call VerifyScreenDump(buf, 'Test_wildmenu_input_func_8', {}) |
| 236 | call term_sendkeys(buf, "\<CR>") |
| 237 | |
| 238 | " clean up |
| 239 | call StopVimInTerminal(buf) |
| 240 | endfunc |
| 241 | |
Bram Moolenaar | a653e53 | 2022-04-19 11:38:24 +0100 | [diff] [blame] | 242 | func Test_redraw_in_autocmd() |
| 243 | CheckScreendump |
| 244 | |
| 245 | let lines =<< trim END |
| 246 | set cmdheight=2 |
| 247 | autocmd CmdlineChanged * redraw |
| 248 | END |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 249 | call writefile(lines, 'XTest_redraw', 'D') |
Bram Moolenaar | a653e53 | 2022-04-19 11:38:24 +0100 | [diff] [blame] | 250 | |
| 251 | let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8}) |
| 252 | call term_sendkeys(buf, ":for i in range(3)\<CR>") |
| 253 | call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {}) |
| 254 | |
| 255 | call term_sendkeys(buf, "let i =") |
| 256 | call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {}) |
| 257 | |
| 258 | " clean up |
| 259 | call term_sendkeys(buf, "\<CR>") |
| 260 | call StopVimInTerminal(buf) |
Bram Moolenaar | a653e53 | 2022-04-19 11:38:24 +0100 | [diff] [blame] | 261 | endfunc |
| 262 | |
Bram Moolenaar | bcd6924 | 2022-09-19 21:16:12 +0100 | [diff] [blame] | 263 | func Test_redrawstatus_in_autocmd() |
| 264 | CheckScreendump |
| 265 | |
| 266 | let lines =<< trim END |
zeertzjq | c14bfc3 | 2022-09-20 13:17:57 +0100 | [diff] [blame] | 267 | set laststatus=2 |
| 268 | set statusline=%=:%{getcmdline()} |
zeertzjq | 320d910 | 2022-09-20 17:12:13 +0100 | [diff] [blame] | 269 | autocmd CmdlineChanged * redrawstatus |
Bram Moolenaar | bcd6924 | 2022-09-19 21:16:12 +0100 | [diff] [blame] | 270 | END |
| 271 | call writefile(lines, 'XTest_redrawstatus', 'D') |
| 272 | |
| 273 | let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8}) |
zeertzjq | c14bfc3 | 2022-09-20 13:17:57 +0100 | [diff] [blame] | 274 | " :redrawstatus is postponed if messages have scrolled |
Bram Moolenaar | bcd6924 | 2022-09-19 21:16:12 +0100 | [diff] [blame] | 275 | call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>") |
| 276 | call term_sendkeys(buf, ":foobar") |
| 277 | call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {}) |
zeertzjq | c14bfc3 | 2022-09-20 13:17:57 +0100 | [diff] [blame] | 278 | " it is not postponed if messages have not scrolled |
zeertzjq | 320d910 | 2022-09-20 17:12:13 +0100 | [diff] [blame] | 279 | call term_sendkeys(buf, "\<Esc>:for in in range(3)") |
zeertzjq | c14bfc3 | 2022-09-20 13:17:57 +0100 | [diff] [blame] | 280 | call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {}) |
zeertzjq | 320d910 | 2022-09-20 17:12:13 +0100 | [diff] [blame] | 281 | " with cmdheight=1 messages have scrolled when typing :endfor |
| 282 | call term_sendkeys(buf, "\<CR>:endfor") |
| 283 | call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {}) |
| 284 | call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>") |
| 285 | " with cmdheight=2 messages haven't scrolled when typing :for or :endfor |
| 286 | call term_sendkeys(buf, ":for in in range(3)") |
| 287 | call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {}) |
| 288 | call term_sendkeys(buf, "\<CR>:endfor") |
| 289 | call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {}) |
Bram Moolenaar | bcd6924 | 2022-09-19 21:16:12 +0100 | [diff] [blame] | 290 | |
| 291 | " clean up |
| 292 | call term_sendkeys(buf, "\<CR>") |
| 293 | call StopVimInTerminal(buf) |
| 294 | endfunc |
| 295 | |
Bram Moolenaar | f797e30 | 2022-08-11 13:17:30 +0100 | [diff] [blame] | 296 | func Test_changing_cmdheight() |
| 297 | CheckScreendump |
| 298 | |
| 299 | let lines =<< trim END |
| 300 | set cmdheight=1 laststatus=2 |
nwounkn | 2e48567 | 2024-11-11 21:48:30 +0100 | [diff] [blame] | 301 | func EchoOne() |
| 302 | set laststatus=2 cmdheight=1 |
| 303 | echo 'foo' |
| 304 | echo 'bar' |
| 305 | set cmdheight=2 |
| 306 | endfunc |
Bram Moolenaar | 0816f47 | 2022-10-05 15:42:32 +0100 | [diff] [blame] | 307 | func EchoTwo() |
| 308 | set laststatus=2 |
| 309 | set cmdheight=5 |
| 310 | echo 'foo' |
| 311 | echo 'bar' |
| 312 | set cmdheight=1 |
| 313 | endfunc |
Bram Moolenaar | f797e30 | 2022-08-11 13:17:30 +0100 | [diff] [blame] | 314 | END |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 315 | call writefile(lines, 'XTest_cmdheight', 'D') |
Bram Moolenaar | f797e30 | 2022-08-11 13:17:30 +0100 | [diff] [blame] | 316 | |
| 317 | let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8}) |
| 318 | call term_sendkeys(buf, ":resize -3\<CR>") |
| 319 | call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {}) |
| 320 | |
Luuk van Baal | e15cbc1 | 2025-01-04 17:18:08 +0100 | [diff] [blame] | 321 | " :resize now also changes 'cmdheight' accordingly |
| 322 | call term_sendkeys(buf, ":set cmdheight+=1\<CR>") |
Bram Moolenaar | f797e30 | 2022-08-11 13:17:30 +0100 | [diff] [blame] | 323 | call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {}) |
| 324 | |
| 325 | " using more space moves the status line up |
| 326 | call term_sendkeys(buf, ":set cmdheight+=1\<CR>") |
| 327 | call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {}) |
| 328 | |
| 329 | " reducing cmdheight moves status line down |
Luuk van Baal | c97e869 | 2025-01-06 18:58:21 +0100 | [diff] [blame] | 330 | call term_sendkeys(buf, ":set cmdheight-=3\<CR>") |
Bram Moolenaar | f797e30 | 2022-08-11 13:17:30 +0100 | [diff] [blame] | 331 | call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {}) |
| 332 | |
Bram Moolenaar | a9a6b03 | 2023-02-05 18:00:42 +0000 | [diff] [blame] | 333 | " reducing window size and then setting cmdheight |
Bram Moolenaar | d4cf9fc | 2022-08-11 14:13:37 +0100 | [diff] [blame] | 334 | call term_sendkeys(buf, ":resize -1\<CR>") |
| 335 | call term_sendkeys(buf, ":set cmdheight=1\<CR>") |
| 336 | call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {}) |
| 337 | |
Bram Moolenaar | 0816f47 | 2022-10-05 15:42:32 +0100 | [diff] [blame] | 338 | " setting 'cmdheight' works after outputting two messages |
| 339 | call term_sendkeys(buf, ":call EchoTwo()\<CR>") |
| 340 | call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {}) |
| 341 | |
Luuk van Baal | c97e869 | 2025-01-06 18:58:21 +0100 | [diff] [blame] | 342 | " increasing 'cmdheight' doesn't clear the messages that need hit-enter |
nwounkn | 2e48567 | 2024-11-11 21:48:30 +0100 | [diff] [blame] | 343 | call term_sendkeys(buf, ":call EchoOne()\<CR>") |
| 344 | call VerifyScreenDump(buf, 'Test_changing_cmdheight_7', {}) |
| 345 | |
Luuk van Baal | c97e869 | 2025-01-06 18:58:21 +0100 | [diff] [blame] | 346 | " window commands do not reduce 'cmdheight' to value lower than :set by user |
| 347 | call term_sendkeys(buf, "\<CR>:wincmd _\<CR>") |
| 348 | call VerifyScreenDump(buf, 'Test_changing_cmdheight_8', {}) |
| 349 | |
Bram Moolenaar | f797e30 | 2022-08-11 13:17:30 +0100 | [diff] [blame] | 350 | " clean up |
| 351 | call StopVimInTerminal(buf) |
Bram Moolenaar | f797e30 | 2022-08-11 13:17:30 +0100 | [diff] [blame] | 352 | endfunc |
| 353 | |
Bram Moolenaar | c9f5f73 | 2022-10-06 11:39:06 +0100 | [diff] [blame] | 354 | func Test_cmdheight_tabline() |
| 355 | CheckScreendump |
| 356 | |
| 357 | let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6}) |
| 358 | call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {}) |
| 359 | |
| 360 | " clean up |
| 361 | call StopVimInTerminal(buf) |
| 362 | endfunc |
| 363 | |
Bram Moolenaar | cf5fdf7 | 2017-03-02 23:05:51 +0100 | [diff] [blame] | 364 | func Test_map_completion() |
Bram Moolenaar | cf5fdf7 | 2017-03-02 23:05:51 +0100 | [diff] [blame] | 365 | call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt') |
| 366 | call assert_equal('"map <unique> <silent>', getreg(':')) |
| 367 | call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt') |
| 368 | call assert_equal('"map <script> <unique>', getreg(':')) |
| 369 | call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt') |
| 370 | call assert_equal('"map <expr> <script>', getreg(':')) |
| 371 | call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt') |
| 372 | call assert_equal('"map <buffer> <expr>', getreg(':')) |
| 373 | call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt') |
| 374 | call assert_equal('"map <nowait> <buffer>', getreg(':')) |
| 375 | call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt') |
| 376 | call assert_equal('"map <special> <nowait>', getreg(':')) |
| 377 | call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt') |
| 378 | call assert_equal('"map <silent> <special>', getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 379 | |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 380 | map <Middle>x middle |
| 381 | |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 382 | map ,f commaf |
| 383 | map ,g commaf |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 384 | map <Left> left |
| 385 | map <A-Left>x shiftleft |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 386 | call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt') |
| 387 | call assert_equal('"map ,f', getreg(':')) |
| 388 | call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt') |
| 389 | call assert_equal('"map ,g', getreg(':')) |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 390 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 391 | call assert_equal('"map <Left>', getreg(':')) |
| 392 | call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt') |
Bram Moolenaar | 92b9e60 | 2019-05-03 16:49:25 +0200 | [diff] [blame] | 393 | call assert_equal("\"map <A-Left>\<Tab>", getreg(':')) |
zeertzjq | c3a26c6 | 2023-02-17 16:40:20 +0000 | [diff] [blame] | 394 | call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt') |
| 395 | call assert_equal("\"map <M-Left>x", getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 396 | unmap ,f |
| 397 | unmap ,g |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 398 | unmap <Left> |
| 399 | unmap <A-Left>x |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 400 | |
zeertzjq | c3a26c6 | 2023-02-17 16:40:20 +0000 | [diff] [blame] | 401 | set cpo-=< cpo-=k |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 402 | map <Left> left |
| 403 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 404 | call assert_equal('"map <Left>', getreg(':')) |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 405 | call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt') |
Bram Moolenaar | 92b9e60 | 2019-05-03 16:49:25 +0200 | [diff] [blame] | 406 | call assert_equal("\"map <M\<Tab>", getreg(':')) |
zeertzjq | c3a26c6 | 2023-02-17 16:40:20 +0000 | [diff] [blame] | 407 | call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt') |
| 408 | call assert_equal("\"map \<C-V><Middle>x", getreg(':')) |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 409 | unmap <Left> |
| 410 | |
| 411 | set cpo+=< |
| 412 | map <Left> left |
Bram Moolenaar | 61df0c7 | 2019-05-03 21:10:36 +0200 | [diff] [blame] | 413 | exe "set t_k6=\<Esc>[17~" |
| 414 | call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt') |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 415 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 416 | call assert_equal('"map <Left>', getreg(':')) |
Bram Moolenaar | 510671a | 2019-05-04 19:26:56 +0200 | [diff] [blame] | 417 | if !has('gui_running') |
| 418 | call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt') |
| 419 | call assert_equal("\"map <F6>x", getreg(':')) |
| 420 | endif |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 421 | unmap <Left> |
Bram Moolenaar | 61df0c7 | 2019-05-03 21:10:36 +0200 | [diff] [blame] | 422 | call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt') |
Bram Moolenaar | 2cb9f02 | 2019-05-03 15:13:57 +0200 | [diff] [blame] | 423 | set cpo-=< |
| 424 | |
| 425 | set cpo+=B |
| 426 | map <Left> left |
| 427 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 428 | call assert_equal('"map <Left>', getreg(':')) |
| 429 | unmap <Left> |
| 430 | set cpo-=B |
| 431 | |
| 432 | set cpo+=k |
| 433 | map <Left> left |
| 434 | call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt') |
| 435 | call assert_equal('"map <Left>', getreg(':')) |
| 436 | unmap <Left> |
| 437 | set cpo-=k |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 438 | |
Bram Moolenaar | 531be47 | 2020-09-23 22:38:05 +0200 | [diff] [blame] | 439 | call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:') |
| 440 | |
Bram Moolenaar | 1776a28 | 2019-05-03 16:05:41 +0200 | [diff] [blame] | 441 | unmap <Middle>x |
| 442 | set cpo&vim |
Bram Moolenaar | cf5fdf7 | 2017-03-02 23:05:51 +0100 | [diff] [blame] | 443 | endfunc |
| 444 | |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 445 | func Test_match_completion() |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 446 | hi Aardig ctermfg=green |
| 447 | call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt') |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 448 | call assert_equal('"match Aardig', @:) |
Yee Cheng Chin | a7b8120 | 2025-02-23 09:32:47 +0100 | [diff] [blame] | 449 | call feedkeys(":match NON\<Tab>\<Home>\"\<CR>", 'xt') |
| 450 | call assert_equal('"match NONE', @:) |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 451 | call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt') |
| 452 | call assert_equal('"match | chistory', @:) |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 453 | endfunc |
| 454 | |
| 455 | func Test_highlight_completion() |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 456 | hi Aardig ctermfg=green |
| 457 | call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt') |
| 458 | call assert_equal('"hi Aardig', getreg(':')) |
Yee Cheng Chin | a7b8120 | 2025-02-23 09:32:47 +0100 | [diff] [blame] | 459 | |
| 460 | " hi default |
Bram Moolenaar | ea58815 | 2017-04-10 22:45:30 +0200 | [diff] [blame] | 461 | call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt') |
| 462 | call assert_equal('"hi default Aardig', getreg(':')) |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 463 | call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 464 | call assert_equal('"hi default', getreg(':')) |
Yee Cheng Chin | a7b8120 | 2025-02-23 09:32:47 +0100 | [diff] [blame] | 465 | call feedkeys(":hi default link Aa\<Tab>\<Home>\"\<CR>", 'xt') |
| 466 | call assert_equal('"hi default link Aardig', getreg(':')) |
| 467 | |
| 468 | " hi clear only accepts one parameter |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 469 | call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 470 | call assert_equal('"hi clear', getreg(':')) |
Yee Cheng Chin | a7b8120 | 2025-02-23 09:32:47 +0100 | [diff] [blame] | 471 | call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt') |
| 472 | call assert_equal('"hi clear Aardig', getreg(':')) |
Bram Moolenaar | 75e1567 | 2020-06-28 13:10:22 +0200 | [diff] [blame] | 473 | call feedkeys(":hi clear Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt') |
Yee Cheng Chin | a7b8120 | 2025-02-23 09:32:47 +0100 | [diff] [blame] | 474 | call assert_equal("\"hi clear Aardig Aard\<Tab>", getreg(':')) |
| 475 | " hi link accepts up to two parameters |
| 476 | call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt') |
| 477 | call assert_equal('"hi link', getreg(':')) |
| 478 | call assert_equal('"hi link', getreg(':')) |
| 479 | call feedkeys(":hi link Aa\<Tab>\<Home>\"\<CR>", 'xt') |
| 480 | call assert_equal('"hi link Aardig', getreg(':')) |
| 481 | call feedkeys(":hi link Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt') |
| 482 | call assert_equal("\"hi link Aardig Aardig", getreg(':')) |
| 483 | call feedkeys(":hi link Aardig Aardig Aard\<Tab>\<C-B>\"\<CR>", 'xt') |
| 484 | call assert_equal("\"hi link Aardig Aardig Aard\<Tab>", getreg(':')) |
| 485 | " hi link will complete to "NONE" for second parameter |
| 486 | call feedkeys(":hi link NON\<Tab>\<Home>\"\<CR>", 'xt') |
| 487 | call assert_equal("\"hi link NonText", getreg(':')) |
| 488 | call feedkeys(":hi link Aardig NON\<Tab>\<Home>\"\<CR>", 'xt') |
| 489 | call assert_equal("\"hi link Aardig NONE", getreg(':')) |
Bram Moolenaar | c96272e | 2017-03-26 13:50:09 +0200 | [diff] [blame] | 490 | |
| 491 | " A cleared group does not show up in completions. |
| 492 | hi Anders ctermfg=green |
| 493 | call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight')) |
| 494 | hi clear Aardig |
| 495 | call assert_equal(['Anders'], getcompletion('A', 'highlight')) |
| 496 | hi clear Anders |
| 497 | call assert_equal([], getcompletion('A', 'highlight')) |
Bram Moolenaar | 15eedf1 | 2017-01-22 19:25:33 +0100 | [diff] [blame] | 498 | endfunc |
| 499 | |
Bram Moolenaar | 75e1567 | 2020-06-28 13:10:22 +0200 | [diff] [blame] | 500 | " Test for command-line expansion of "hi Ni " (easter egg) |
| 501 | func Test_highlight_easter_egg() |
| 502 | call test_override('ui_delay', 1) |
| 503 | call feedkeys(":hi Ni \<Tab>\<C-B>\"\<CR>", 'xt') |
| 504 | call assert_equal("\"hi Ni \<Tab>", @:) |
| 505 | call test_override('ALL', 0) |
| 506 | endfunc |
| 507 | |
Yee Cheng Chin | a7b8120 | 2025-02-23 09:32:47 +0100 | [diff] [blame] | 508 | func Test_highlight_group_completion() |
| 509 | " Test completing keys |
| 510 | call assert_equal('term=', getcompletion('hi Foo ', 'cmdline')[0]) |
| 511 | call assert_equal('ctermfg=', getcompletion('hi Foo c*fg', 'cmdline')[0]) |
| 512 | call assert_equal('NONE', getcompletion('hi Foo NON', 'cmdline')[0]) |
| 513 | set wildoptions+=fuzzy |
| 514 | call assert_equal('ctermbg=', getcompletion('hi Foo cmbg', 'cmdline')[0]) |
| 515 | set wildoptions-=fuzzy |
| 516 | |
| 517 | " Test completing the current value |
| 518 | hi FooBar term=bold,underline cterm=undercurl ctermfg=lightgray ctermbg=12 ctermul=34 |
Yee Cheng Chin | 9b41e8f | 2025-02-25 20:41:52 +0100 | [diff] [blame] | 519 | hi AlmostEmpty term=bold |
Yee Cheng Chin | a7b8120 | 2025-02-23 09:32:47 +0100 | [diff] [blame] | 520 | call assert_equal('bold,underline', getcompletion('hi FooBar term=', 'cmdline')[0]) |
| 521 | call assert_equal('undercurl', getcompletion('hi FooBar cterm=', 'cmdline')[0]) |
| 522 | call assert_equal('7', getcompletion('hi FooBar ctermfg=', 'cmdline')[0]) |
| 523 | call assert_equal('12', getcompletion('hi FooBar ctermbg=', 'cmdline')[0]) |
| 524 | call assert_equal('34', getcompletion('hi FooBar ctermul=', 'cmdline')[0]) |
| 525 | |
Yee Cheng Chin | 9b41e8f | 2025-02-25 20:41:52 +0100 | [diff] [blame] | 526 | " highlight group exists, but no value was set. Should not complete to |
| 527 | " existing value |
| 528 | call assert_equal('fg', getcompletion('hi AlmostEmpty ctermfg=', 'cmdline')[0]) |
| 529 | call assert_equal('fg', getcompletion('hi AlmostEmpty ctermbg=', 'cmdline')[0]) |
| 530 | call assert_equal('fg', getcompletion('hi AlmostEmpty ctermul=', 'cmdline')[0]) |
| 531 | call assert_equal('bold', getcompletion('hi AlmostEmpty cterm=', 'cmdline')[0]) |
| 532 | |
| 533 | " "bold,underline" is unique and creates an extra item. "undercurl" isn't |
| 534 | " and should be de-duplicated. |
Yee Cheng Chin | a7b8120 | 2025-02-23 09:32:47 +0100 | [diff] [blame] | 535 | call assert_equal(len(getcompletion('hi FooBar term=', 'cmdline')), |
| 536 | \ 1 + len(getcompletion('hi FooBar cterm=', 'cmdline'))) |
| 537 | |
| 538 | " don't complete original value if we have user input already, similar to |
| 539 | " behavior in :set <option>=<pattern> |
| 540 | call assert_equal(['bold'], getcompletion('hi FooBar term=bol', 'cmdline')) |
| 541 | call assert_equal([], getcompletion('hi FooBar ctermfg=1', 'cmdline')) |
| 542 | |
| 543 | " start/stop do not fill their current value now as they are more |
| 544 | " complicated |
| 545 | hi FooBar start=123 stop=234 |
| 546 | call assert_equal([], getcompletion('hi FooBar start=', 'cmdline')) |
| 547 | call assert_equal([], getcompletion('hi FooBar stop=', 'cmdline')) |
| 548 | |
| 549 | if has("gui") || has("termguicolors") |
| 550 | hi FooBar gui=italic guifg=#112233 guibg=brown1 guisp=green |
| 551 | call assert_equal('italic', getcompletion('hi FooBar gui=', 'cmdline')[0]) |
| 552 | call assert_equal('#112233', getcompletion('hi FooBar guifg=', 'cmdline')[0]) |
| 553 | call assert_equal('brown1', getcompletion('hi FooBar guibg=', 'cmdline')[0]) |
| 554 | call assert_equal('green', getcompletion('hi FooBar guisp=', 'cmdline')[0]) |
| 555 | |
| 556 | " Check that existing value is de-duplicated and doesn't show up later |
| 557 | call assert_equal(1, count(getcompletion('hi FooBar guibg=', 'cmdline'), 'brown1')) |
Yee Cheng Chin | 9b41e8f | 2025-02-25 20:41:52 +0100 | [diff] [blame] | 558 | |
| 559 | " highlight group exists, but no value was set. Should not complete to |
| 560 | " existing value |
| 561 | call assert_equal('fg', getcompletion('hi AlmostEmpty guifg=', 'cmdline')[0]) |
| 562 | call assert_equal('fg', getcompletion('hi AlmostEmpty guibg=', 'cmdline')[0]) |
| 563 | call assert_equal('fg', getcompletion('hi AlmostEmpty guisp=', 'cmdline')[0]) |
| 564 | call assert_equal('bold', getcompletion('hi AlmostEmpty gui=', 'cmdline')[0]) |
Yee Cheng Chin | a7b8120 | 2025-02-23 09:32:47 +0100 | [diff] [blame] | 565 | endif |
| 566 | |
| 567 | " Test completing attributes |
| 568 | call assert_equal(['underdouble', 'underdotted'], getcompletion('hi DoesNotExist term=un*erdo*', 'cmdline')) |
| 569 | call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=NON', 'cmdline')[0]) |
| 570 | call assert_equal('NONE', getcompletion('hi DoesNotExist cterm=', 'cmdline')[-1]) " NONE should be at the end and not sorted |
| 571 | call assert_equal('bold', getcompletion('hi DoesNotExist cterm=underline,bo', 'cmdline')[0]) " complete after comma |
| 572 | if has("gui") || has("termguicolors") |
| 573 | set wildoptions+=fuzzy |
| 574 | call assert_equal('italic', getcompletion('hi DoesNotExist gui=itic', 'cmdline')[0]) |
| 575 | set wildoptions-=fuzzy |
| 576 | endif |
| 577 | |
| 578 | " Test completing cterm colors |
| 579 | call assert_equal('fg', getcompletion('hi FooBar ctermbg=f*g', 'cmdline')[0]) |
| 580 | call assert_equal('fg', getcompletion('hi DoesNotExist ctermbg=f*g', 'cmdline')[0]) |
| 581 | call assert_equal('NONE', getcompletion('hi FooBar ctermfg=NON', 'cmdline')[0]) |
| 582 | call assert_equal('NONE', getcompletion('hi DoesNotExist ctermfg=NON', 'cmdline')[0]) |
| 583 | set wildoptions+=fuzzy |
| 584 | call assert_equal('Black', getcompletion('hi FooBar ctermul=blck', 'cmdline')[0]) |
| 585 | call assert_equal('Black', getcompletion('hi DoesNotExist ctermul=blck', 'cmdline')[0]) |
| 586 | set wildoptions-=fuzzy |
| 587 | |
| 588 | " Test completing gui colors |
| 589 | if has("gui") || has("termguicolors") |
| 590 | call assert_equal('fg', getcompletion('hi FooBar guibg=f*g', 'cmdline')[0]) |
| 591 | call assert_equal('fg', getcompletion('hi DoesNotExist guibg=f*g', 'cmdline')[0]) |
| 592 | call assert_equal('NONE', getcompletion('hi FooBar guifg=NON', 'cmdline')[0]) |
| 593 | call assert_equal('NONE', getcompletion('hi DoesNotExist guifg=NON', 'cmdline')[0]) |
| 594 | set wildoptions=fuzzy |
| 595 | call assert_equal('limegreen', getcompletion('hi FooBar guisp=limgrn', 'cmdline')[0]) |
| 596 | call assert_equal('limegreen', getcompletion('hi DoesNotExist guisp=limgrn', 'cmdline')[0]) |
| 597 | set wildoptions-=fuzzy |
| 598 | |
| 599 | " Test pruning bad color names with space. Vim doesn't support them. |
| 600 | let v:colornames['foobar with space'] = '#123456' |
| 601 | let v:colornames['foobarwithoutspace'] = '#234567' |
| 602 | call assert_equal(['foobarwithoutspace'], getcompletion('hi FooBar guibg=foobarw', 'cmdline')) |
| 603 | |
| 604 | " Test specialized sorting. First few items are special values that |
| 605 | " go first, after that it's a sorted list of color names. |
| 606 | call assert_equal(['fg','bg','NONE'], getcompletion('hi DoesNotExist guifg=', 'cmdline')[0:2]) |
| 607 | let completed_colors=getcompletion('hi DoesNotExist guifg=', 'cmdline')[3:] |
| 608 | let gui_colors_no_space=filter(copy(v:colornames), {key,val -> match(key, ' ')==-1}) |
| 609 | call assert_equal(len(gui_colors_no_space), len(completed_colors)) |
| 610 | call assert_equal(sort(copy(completed_colors)), completed_colors) |
| 611 | |
| 612 | " Test that the specialized sorting still works if we have some pattern matches |
| 613 | let completed_colors=getcompletion('hi DoesNotExist guifg=*blue*', 'cmdline') |
| 614 | call assert_equal(sort(copy(completed_colors)), completed_colors) |
| 615 | call assert_equal('aliceblue', completed_colors[0]) |
| 616 | endif |
| 617 | endfunc |
| 618 | |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 619 | func Test_getcompletion() |
| 620 | let groupcount = len(getcompletion('', 'event')) |
| 621 | call assert_true(groupcount > 0) |
Bram Moolenaar | 4c313b1 | 2019-08-24 22:58:31 +0200 | [diff] [blame] | 622 | let matchcount = len('File'->getcompletion('event')) |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 623 | call assert_true(matchcount > 0) |
| 624 | call assert_true(groupcount > matchcount) |
| 625 | |
Bram Moolenaar | 0d3e24b | 2016-07-09 19:20:59 +0200 | [diff] [blame] | 626 | if has('menu') |
| 627 | source $VIMRUNTIME/menu.vim |
| 628 | let matchcount = len(getcompletion('', 'menu')) |
| 629 | call assert_true(matchcount > 0) |
| 630 | call assert_equal(['File.'], getcompletion('File', 'menu')) |
| 631 | call assert_true(matchcount > 0) |
| 632 | let matchcount = len(getcompletion('File.', 'menu')) |
| 633 | call assert_true(matchcount > 0) |
zeertzjq | 145a6af | 2023-01-22 12:41:55 +0000 | [diff] [blame] | 634 | source $VIMRUNTIME/delmenu.vim |
Bram Moolenaar | 0d3e24b | 2016-07-09 19:20:59 +0200 | [diff] [blame] | 635 | endif |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 636 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 637 | let l = getcompletion('v:n', 'var') |
| 638 | call assert_true(index(l, 'v:null') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 639 | let l = getcompletion('v:notexists', 'var') |
| 640 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 641 | |
Bram Moolenaar | cd43eff | 2018-03-29 15:55:38 +0200 | [diff] [blame] | 642 | args a.c b.c |
| 643 | let l = getcompletion('', 'arglist') |
| 644 | call assert_equal(['a.c', 'b.c'], l) |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 645 | let l = getcompletion('a.', 'buffer') |
| 646 | call assert_equal(['a.c'], l) |
Bram Moolenaar | cd43eff | 2018-03-29 15:55:38 +0200 | [diff] [blame] | 647 | %argdelete |
| 648 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 649 | let l = getcompletion('', 'augroup') |
| 650 | call assert_true(index(l, 'END') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 651 | let l = getcompletion('blahblah', 'augroup') |
| 652 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 653 | |
| 654 | let l = getcompletion('', 'behave') |
| 655 | call assert_true(index(l, 'mswin') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 656 | let l = getcompletion('not', 'behave') |
| 657 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 658 | |
| 659 | let l = getcompletion('', 'color') |
| 660 | call assert_true(index(l, 'default') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 661 | let l = getcompletion('dirty', 'color') |
| 662 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 663 | |
| 664 | let l = getcompletion('', 'command') |
| 665 | call assert_true(index(l, 'sleep') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 666 | let l = getcompletion('awake', 'command') |
| 667 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 668 | |
| 669 | let l = getcompletion('', 'dir') |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 670 | call assert_true(index(l, 'samples/') >= 0) |
| 671 | let l = getcompletion('NoMatch', 'dir') |
| 672 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 673 | |
Shougo Matsushita | ae38a9d | 2021-10-21 11:39:53 +0100 | [diff] [blame] | 674 | if glob('~/*') !=# '' |
| 675 | let l = getcompletion('~/', 'dir') |
| 676 | call assert_true(l[0][0] ==# '~') |
| 677 | endif |
| 678 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 679 | let l = getcompletion('exe', 'expression') |
| 680 | call assert_true(index(l, 'executable(') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 681 | let l = getcompletion('kill', 'expression') |
| 682 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 683 | |
Christian Brabandt | a3422aa | 2025-04-23 21:04:24 +0200 | [diff] [blame] | 684 | let l = getcompletion('', 'filetypecmd') |
| 685 | call assert_equal(["indent", "off", "on", "plugin"], l) |
| 686 | let l = getcompletion('not', 'filetypecmd') |
| 687 | call assert_equal([], l) |
| 688 | let l = getcompletion('o', 'filetypecmd') |
| 689 | call assert_equal(['off', 'on'], l) |
| 690 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 691 | let l = getcompletion('tag', 'function') |
| 692 | call assert_true(index(l, 'taglist(') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 693 | let l = getcompletion('paint', 'function') |
| 694 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 695 | |
Kota Kato | 90c2353 | 2023-01-18 15:27:38 +0000 | [diff] [blame] | 696 | if !has('ruby') |
Bram Moolenaar | a9a6b03 | 2023-02-05 18:00:42 +0000 | [diff] [blame] | 697 | " global_functions[] has an entry but it doesn't have an implementation |
Kota Kato | 90c2353 | 2023-01-18 15:27:38 +0000 | [diff] [blame] | 698 | let l = getcompletion('ruby', 'function') |
| 699 | call assert_equal([], l) |
| 700 | endif |
| 701 | |
Bram Moolenaar | b49edc1 | 2016-07-23 15:47:34 +0200 | [diff] [blame] | 702 | let Flambda = {-> 'hello'} |
| 703 | let l = getcompletion('', 'function') |
| 704 | let l = filter(l, {i, v -> v =~ 'lambda'}) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 705 | call assert_equal([], l) |
Bram Moolenaar | b49edc1 | 2016-07-23 15:47:34 +0200 | [diff] [blame] | 706 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 707 | let l = getcompletion('run', 'file') |
| 708 | call assert_true(index(l, 'runtest.vim') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 709 | let l = getcompletion('walk', 'file') |
| 710 | call assert_equal([], l) |
Bram Moolenaar | e9d58a6 | 2016-08-13 15:07:41 +0200 | [diff] [blame] | 711 | set wildignore=*.vim |
| 712 | let l = getcompletion('run', 'file', 1) |
| 713 | call assert_true(index(l, 'runtest.vim') < 0) |
| 714 | set wildignore& |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 715 | " Directory name with space character |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 716 | call mkdir('Xdir with space', 'D') |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 717 | call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd')) |
| 718 | call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd')) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 719 | |
| 720 | let l = getcompletion('ha', 'filetype') |
| 721 | call assert_true(index(l, 'hamster') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 722 | let l = getcompletion('horse', 'filetype') |
| 723 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 724 | |
Doug Kearns | 81642d9 | 2024-01-04 22:37:44 +0100 | [diff] [blame] | 725 | if has('keymap') |
| 726 | let l = getcompletion('acc', 'keymap') |
| 727 | call assert_true(index(l, 'accents') >= 0) |
| 728 | let l = getcompletion('nullkeymap', 'keymap') |
| 729 | call assert_equal([], l) |
| 730 | endif |
| 731 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 732 | let l = getcompletion('z', 'syntax') |
| 733 | call assert_true(index(l, 'zimbu') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 734 | let l = getcompletion('emacs', 'syntax') |
| 735 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 736 | |
| 737 | let l = getcompletion('jikes', 'compiler') |
| 738 | call assert_true(index(l, 'jikes') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 739 | let l = getcompletion('break', 'compiler') |
| 740 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 741 | |
| 742 | let l = getcompletion('last', 'help') |
| 743 | call assert_true(index(l, ':tablast') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 744 | let l = getcompletion('giveup', 'help') |
| 745 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 746 | |
| 747 | let l = getcompletion('time', 'option') |
| 748 | call assert_true(index(l, 'timeoutlen') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 749 | let l = getcompletion('space', 'option') |
| 750 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 751 | |
| 752 | let l = getcompletion('er', 'highlight') |
| 753 | call assert_true(index(l, 'ErrorMsg') >= 0) |
Bram Moolenaar | b56195e | 2016-07-28 22:53:37 +0200 | [diff] [blame] | 754 | let l = getcompletion('dark', 'highlight') |
| 755 | call assert_equal([], l) |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 756 | |
Bram Moolenaar | 9e507ca | 2016-10-15 15:39:39 +0200 | [diff] [blame] | 757 | let l = getcompletion('', 'messages') |
| 758 | call assert_true(index(l, 'clear') >= 0) |
| 759 | let l = getcompletion('not', 'messages') |
| 760 | call assert_equal([], l) |
| 761 | |
Bram Moolenaar | cae92dc | 2017-08-06 15:22:15 +0200 | [diff] [blame] | 762 | let l = getcompletion('', 'mapclear') |
| 763 | call assert_true(index(l, '<buffer>') >= 0) |
| 764 | let l = getcompletion('not', 'mapclear') |
| 765 | call assert_equal([], l) |
| 766 | |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 767 | let l = getcompletion('.', 'shellcmd') |
Bram Moolenaar | 6ab9e42 | 2018-07-28 19:20:13 +0200 | [diff] [blame] | 768 | call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"')) |
Bram Moolenaar | 62fe66f | 2018-05-22 16:58:47 +0200 | [diff] [blame] | 769 | call assert_equal(-1, match(l[2:], '^\.\.\?/$')) |
| 770 | let root = has('win32') ? 'C:\\' : '/' |
| 771 | let l = getcompletion(root, 'shellcmd') |
| 772 | let expected = map(filter(glob(root . '*', 0, 1), |
| 773 | \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val') |
| 774 | call assert_equal(expected, l) |
| 775 | |
Bram Moolenaar | b650b98 | 2016-08-05 20:35:13 +0200 | [diff] [blame] | 776 | if has('cscope') |
| 777 | let l = getcompletion('', 'cscope') |
| 778 | let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show'] |
| 779 | call assert_equal(cmds, l) |
| 780 | " using cmdline completion must not change the result |
| 781 | call feedkeys(":cscope find \<c-d>\<c-c>", 'xt') |
| 782 | let l = getcompletion('', 'cscope') |
| 783 | call assert_equal(cmds, l) |
| 784 | let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't'] |
| 785 | let l = getcompletion('find ', 'cscope') |
| 786 | call assert_equal(keys, l) |
| 787 | endif |
| 788 | |
Bram Moolenaar | 7522f69 | 2016-08-06 14:12:50 +0200 | [diff] [blame] | 789 | if has('signs') |
| 790 | sign define Testing linehl=Comment |
| 791 | let l = getcompletion('', 'sign') |
| 792 | let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace'] |
| 793 | call assert_equal(cmds, l) |
| 794 | " using cmdline completion must not change the result |
| 795 | call feedkeys(":sign list \<c-d>\<c-c>", 'xt') |
| 796 | let l = getcompletion('', 'sign') |
| 797 | call assert_equal(cmds, l) |
| 798 | let l = getcompletion('list ', 'sign') |
| 799 | call assert_equal(['Testing'], l) |
Yegappan Lakshmanan | 4d03d87 | 2022-02-13 11:45:09 +0000 | [diff] [blame] | 800 | let l = getcompletion('de*', 'sign') |
| 801 | call assert_equal(['define'], l) |
| 802 | let l = getcompletion('p?', 'sign') |
| 803 | call assert_equal(['place'], l) |
| 804 | let l = getcompletion('j.', 'sign') |
| 805 | call assert_equal(['jump'], l) |
Bram Moolenaar | 7522f69 | 2016-08-06 14:12:50 +0200 | [diff] [blame] | 806 | endif |
| 807 | |
Bram Moolenaar | 1f1fd44 | 2020-06-07 18:45:14 +0200 | [diff] [blame] | 808 | " Command line completion tests |
| 809 | let l = getcompletion('cd ', 'cmdline') |
| 810 | call assert_true(index(l, 'samples/') >= 0) |
| 811 | let l = getcompletion('cd NoMatch', 'cmdline') |
| 812 | call assert_equal([], l) |
| 813 | let l = getcompletion('let v:n', 'cmdline') |
| 814 | call assert_true(index(l, 'v:null') >= 0) |
| 815 | let l = getcompletion('let v:notexists', 'cmdline') |
| 816 | call assert_equal([], l) |
| 817 | let l = getcompletion('call tag', 'cmdline') |
| 818 | call assert_true(index(l, 'taglist(') >= 0) |
| 819 | let l = getcompletion('call paint', 'cmdline') |
| 820 | call assert_equal([], l) |
zeertzjq | e4c79d3 | 2023-08-15 22:41:53 +0200 | [diff] [blame] | 821 | let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline') |
| 822 | call assert_equal(['<buffer>'], l) |
Bram Moolenaar | 1f1fd44 | 2020-06-07 18:45:14 +0200 | [diff] [blame] | 823 | |
Shougo Matsushita | ae38a9d | 2021-10-21 11:39:53 +0100 | [diff] [blame] | 824 | func T(a, c, p) |
ii14 | 4785fe0 | 2021-11-21 12:13:56 +0000 | [diff] [blame] | 825 | let g:cmdline_compl_params = [a:a, a:c, a:p] |
Shougo Matsushita | ae38a9d | 2021-10-21 11:39:53 +0100 | [diff] [blame] | 826 | return "oneA\noneB\noneC" |
| 827 | endfunc |
| 828 | command -nargs=1 -complete=custom,T MyCmd |
| 829 | let l = getcompletion('MyCmd ', 'cmdline') |
| 830 | call assert_equal(['oneA', 'oneB', 'oneC'], l) |
ii14 | 4785fe0 | 2021-11-21 12:13:56 +0000 | [diff] [blame] | 831 | call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params) |
Shougo Matsushita | ae38a9d | 2021-10-21 11:39:53 +0100 | [diff] [blame] | 832 | |
| 833 | delcommand MyCmd |
| 834 | delfunc T |
ii14 | 4785fe0 | 2021-11-21 12:13:56 +0000 | [diff] [blame] | 835 | unlet g:cmdline_compl_params |
Shougo Matsushita | ae38a9d | 2021-10-21 11:39:53 +0100 | [diff] [blame] | 836 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 837 | " For others test if the name is recognized. |
LemonBoy | a20bf69 | 2024-07-11 22:35:53 +0200 | [diff] [blame] | 838 | let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag', |
| 839 | \ 'tag_listfiles', 'user'] |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 840 | if has('cmdline_hist') |
| 841 | call add(names, 'history') |
| 842 | endif |
| 843 | if has('gettext') |
| 844 | call add(names, 'locale') |
| 845 | endif |
| 846 | if has('profile') |
| 847 | call add(names, 'syntime') |
| 848 | endif |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 849 | |
| 850 | set tags=Xtags |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 851 | 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] | 852 | |
| 853 | for name in names |
| 854 | let matchcount = len(getcompletion('', name)) |
| 855 | call assert_true(matchcount >= 0, 'No matches for ' . name) |
| 856 | endfor |
| 857 | |
Bram Moolenaar | 0331faf | 2019-06-15 18:40:37 +0200 | [diff] [blame] | 858 | set tags& |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 859 | |
Yegappan Lakshmanan | 4d03d87 | 2022-02-13 11:45:09 +0000 | [diff] [blame] | 860 | edit a~b |
| 861 | enew |
| 862 | call assert_equal(['a~b'], getcompletion('a~', 'buffer')) |
| 863 | bw a~b |
| 864 | |
| 865 | if has('unix') |
| 866 | edit Xtest\ |
| 867 | enew |
| 868 | call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer')) |
| 869 | bw Xtest\ |
| 870 | endif |
| 871 | |
Christian Brabandt | 0dc0bff | 2024-02-24 14:12:13 +0100 | [diff] [blame] | 872 | call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:') |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 873 | call assert_fails('call getcompletion("", "burp")', 'E475:') |
Yegappan Lakshmanan | 8deb2b3 | 2022-09-02 15:15:27 +0100 | [diff] [blame] | 874 | call assert_fails('call getcompletion("abc", [])', 'E1174:') |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 875 | endfunc |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 876 | |
Hirohito Higashi | 96b3ef2 | 2025-07-05 15:31:23 +0200 | [diff] [blame] | 877 | func Test_getcompletiontype() |
| 878 | call assert_fails('call getcompletiontype()', 'E119:') |
| 879 | call assert_fails('call getcompletiontype({})', 'E1174:') |
zeertzjq | e2c0f81 | 2025-07-06 20:26:56 +0200 | [diff] [blame] | 880 | call assert_equal('command', getcompletiontype('')) |
| 881 | call assert_equal('', getcompletiontype('dummy ')) |
| 882 | call assert_equal('', getcompletiontype('ls ')) |
| 883 | call assert_equal('dir_in_path', getcompletiontype('cd ')) |
| 884 | call assert_equal('var', getcompletiontype('let v:n')) |
| 885 | call assert_equal('function', getcompletiontype('call tag')) |
| 886 | call assert_equal('help', getcompletiontype('help ')) |
Hirohito Higashi | 96b3ef2 | 2025-07-05 15:31:23 +0200 | [diff] [blame] | 887 | endfunc |
| 888 | |
Bram Moolenaar | c32949b | 2023-01-04 15:56:51 +0000 | [diff] [blame] | 889 | func Test_multibyte_expression() |
Bram Moolenaar | 2468add | 2023-01-04 18:59:57 +0000 | [diff] [blame] | 890 | " Get a dialog in the GUI |
| 891 | CheckNotGui |
| 892 | |
Bram Moolenaar | c32949b | 2023-01-04 15:56:51 +0000 | [diff] [blame] | 893 | " This was using uninitialized memory. |
| 894 | let lines =<< trim END |
| 895 | set verbose=6 |
| 896 | norm @=ٷ |
| 897 | qall! |
| 898 | END |
| 899 | call writefile(lines, 'XmultiScript', 'D') |
| 900 | call RunVim('', '', '-u NONE -n -e -s -S XmultiScript') |
| 901 | endfunc |
| 902 | |
Yegappan Lakshmanan | e7dd0fa | 2022-03-22 16:06:31 +0000 | [diff] [blame] | 903 | " Test for getcompletion() with "fuzzy" in 'wildoptions' |
| 904 | func Test_getcompletion_wildoptions() |
| 905 | let save_wildoptions = &wildoptions |
| 906 | set wildoptions& |
| 907 | let l = getcompletion('space', 'option') |
| 908 | call assert_equal([], l) |
| 909 | let l = getcompletion('ier', 'command') |
| 910 | call assert_equal([], l) |
| 911 | set wildoptions=fuzzy |
| 912 | let l = getcompletion('space', 'option') |
| 913 | call assert_true(index(l, 'backspace') >= 0) |
| 914 | let l = getcompletion('ier', 'command') |
| 915 | call assert_true(index(l, 'compiler') >= 0) |
| 916 | let &wildoptions = save_wildoptions |
| 917 | endfunc |
| 918 | |
Bram Moolenaar | fe8e9f6 | 2022-03-16 13:09:15 +0000 | [diff] [blame] | 919 | func Test_complete_autoload_error() |
| 920 | let save_rtp = &rtp |
| 921 | let lines =<< trim END |
| 922 | vim9script |
| 923 | export def Complete(..._): string |
| 924 | return 'match' |
| 925 | enddef |
| 926 | echo this will cause an error |
| 927 | END |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 928 | call mkdir('Xdir/autoload', 'pR') |
Bram Moolenaar | fe8e9f6 | 2022-03-16 13:09:15 +0000 | [diff] [blame] | 929 | call writefile(lines, 'Xdir/autoload/script.vim') |
| 930 | exe 'set rtp+=' .. getcwd() .. '/Xdir' |
| 931 | |
| 932 | let lines =<< trim END |
| 933 | vim9script |
| 934 | import autoload 'script.vim' |
| 935 | command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0 |
| 936 | &wildcharm = char2nr("\<Tab>") |
| 937 | feedkeys(":Cmd \<Tab>", 'xt') |
| 938 | END |
| 939 | call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this') |
| 940 | |
| 941 | let &rtp = save_rtp |
Bram Moolenaar | fe8e9f6 | 2022-03-16 13:09:15 +0000 | [diff] [blame] | 942 | endfunc |
| 943 | |
Bram Moolenaar | 038e09e | 2021-02-06 12:38:51 +0100 | [diff] [blame] | 944 | func Test_fullcommand() |
| 945 | let tests = { |
| 946 | \ '': '', |
| 947 | \ ':': '', |
| 948 | \ ':::': '', |
| 949 | \ ':::5': '', |
| 950 | \ 'not_a_cmd': '', |
| 951 | \ 'Check': '', |
| 952 | \ 'syntax': 'syntax', |
| 953 | \ ':syntax': 'syntax', |
| 954 | \ '::::syntax': 'syntax', |
| 955 | \ 'sy': 'syntax', |
| 956 | \ 'syn': 'syntax', |
| 957 | \ 'synt': 'syntax', |
| 958 | \ ':sy': 'syntax', |
| 959 | \ '::::sy': 'syntax', |
| 960 | \ 'match': 'match', |
| 961 | \ '2match': 'match', |
| 962 | \ '3match': 'match', |
| 963 | \ 'aboveleft': 'aboveleft', |
| 964 | \ 'abo': 'aboveleft', |
Bram Moolenaar | aa53414 | 2022-09-15 21:46:02 +0100 | [diff] [blame] | 965 | \ 'en': 'endif', |
| 966 | \ 'end': 'endif', |
| 967 | \ 'endi': 'endif', |
Bram Moolenaar | 038e09e | 2021-02-06 12:38:51 +0100 | [diff] [blame] | 968 | \ 's': 'substitute', |
| 969 | \ '5s': 'substitute', |
| 970 | \ ':5s': 'substitute', |
| 971 | \ "'<,'>s": 'substitute', |
| 972 | \ ":'<,'>s": 'substitute', |
LemonBoy | cc766a8 | 2022-04-04 15:46:58 +0100 | [diff] [blame] | 973 | \ 'CheckLin': 'CheckLinux', |
| 974 | \ 'CheckLinux': 'CheckLinux', |
Bram Moolenaar | 038e09e | 2021-02-06 12:38:51 +0100 | [diff] [blame] | 975 | \ } |
| 976 | |
| 977 | for [in, want] in items(tests) |
| 978 | call assert_equal(want, fullcommand(in)) |
| 979 | endfor |
Bram Moolenaar | 4c8e8c6 | 2021-05-26 19:49:09 +0200 | [diff] [blame] | 980 | call assert_equal('', fullcommand(test_null_string())) |
Bram Moolenaar | 038e09e | 2021-02-06 12:38:51 +0100 | [diff] [blame] | 981 | |
| 982 | call assert_equal('syntax', 'syn'->fullcommand()) |
Bram Moolenaar | 80c88ea | 2021-09-08 14:29:46 +0200 | [diff] [blame] | 983 | |
| 984 | command -buffer BufferLocalCommand : |
| 985 | command GlobalCommand : |
| 986 | call assert_equal('GlobalCommand', fullcommand('GlobalCom')) |
| 987 | call assert_equal('BufferLocalCommand', fullcommand('BufferL')) |
| 988 | delcommand BufferLocalCommand |
| 989 | delcommand GlobalCommand |
Bram Moolenaar | 038e09e | 2021-02-06 12:38:51 +0100 | [diff] [blame] | 990 | endfunc |
| 991 | |
Bram Moolenaar | 6ab9e42 | 2018-07-28 19:20:13 +0200 | [diff] [blame] | 992 | func Test_shellcmd_completion() |
| 993 | let save_path = $PATH |
| 994 | |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 995 | call mkdir('Xpathdir/Xpathsubdir', 'pR') |
Bram Moolenaar | 6ab9e42 | 2018-07-28 19:20:13 +0200 | [diff] [blame] | 996 | call writefile([''], 'Xpathdir/Xfile.exe') |
| 997 | call setfperm('Xpathdir/Xfile.exe', 'rwx------') |
| 998 | |
| 999 | " Set PATH to example directory without trailing slash. |
| 1000 | let $PATH = getcwd() . '/Xpathdir' |
| 1001 | |
| 1002 | " Test for the ":!<TAB>" case. Previously, this would include subdirs of |
| 1003 | " dirs in the PATH, even though they won't be executed. We check that only |
| 1004 | " subdirs of the PWD and executables from the PATH are included in the |
| 1005 | " suggestions. |
| 1006 | let actual = getcompletion('X', 'shellcmd') |
| 1007 | let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"') |
| 1008 | call insert(expected, 'Xfile.exe') |
| 1009 | call assert_equal(expected, actual) |
| 1010 | |
Bram Moolenaar | 6ab9e42 | 2018-07-28 19:20:13 +0200 | [diff] [blame] | 1011 | let $PATH = save_path |
| 1012 | endfunc |
| 1013 | |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 1014 | func Test_expand_star_star() |
Bram Moolenaar | bf63011 | 2023-05-19 21:41:02 +0100 | [diff] [blame] | 1015 | call mkdir('a/b/c', 'pR') |
| 1016 | call writefile(['asdfasdf'], 'a/b/c/fileXname') |
| 1017 | call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt') |
| 1018 | call assert_equal('find a/b/c/fileXname', @:) |
Bram Moolenaar | 1773ddf | 2016-08-28 13:38:54 +0200 | [diff] [blame] | 1019 | bwipe! |
Bram Moolenaar | 73d4e4c | 2016-08-27 21:55:13 +0200 | [diff] [blame] | 1020 | endfunc |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 1021 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1022 | func Test_cmdline_paste() |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 1023 | let @a = "def" |
| 1024 | call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx') |
| 1025 | call assert_equal('"abc def ghi', @:) |
| 1026 | |
| 1027 | new |
| 1028 | call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ') |
| 1029 | |
| 1030 | call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') |
| 1031 | call assert_equal('"aaa asdf bbb', @:) |
| 1032 | |
| 1033 | call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx') |
| 1034 | call assert_equal('"aaa /tmp/some bbb', @:) |
| 1035 | |
Bram Moolenaar | e2c8d83 | 2018-05-01 19:24:03 +0200 | [diff] [blame] | 1036 | call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx') |
| 1037 | call assert_equal('"aaa '.getline(1).' bbb', @:) |
| 1038 | |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 1039 | set incsearch |
| 1040 | call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') |
| 1041 | call assert_equal('"aaa verylongword bbb', @:) |
| 1042 | |
| 1043 | call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx') |
| 1044 | call assert_equal('"aaa a;b-c*d bbb', @:) |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 1045 | |
| 1046 | call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx') |
| 1047 | call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:) |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 1048 | bwipe! |
Bram Moolenaar | 72532d3 | 2018-04-07 19:09:09 +0200 | [diff] [blame] | 1049 | |
| 1050 | " Error while typing a command used to cause that it was not executed |
| 1051 | " in the end. |
| 1052 | new |
| 1053 | try |
| 1054 | call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx') |
| 1055 | catch /^Vim\%((\a\+)\)\=:E32/ |
| 1056 | " ignore error E32 |
| 1057 | endtry |
| 1058 | call assert_equal("Xtestfile", bufname("%")) |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 1059 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1060 | " Try to paste an invalid register using <C-R> |
| 1061 | call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt') |
| 1062 | call assert_equal('"onetwo', @:) |
| 1063 | |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 1064 | " 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] | 1065 | let @a = "xy\<C-H>z" |
| 1066 | call feedkeys(":\"\<C-R>a\<CR>", 'xt') |
| 1067 | call assert_equal('"xz', @:) |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 1068 | call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt') |
| 1069 | call assert_equal("\"xy\<C-H>z", @:) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1070 | call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt') |
| 1071 | call assert_equal("\"xy\<C-H>z", @:) |
| 1072 | |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 1073 | " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R |
| 1074 | let @a = "xy\<C-V>z" |
| 1075 | call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt') |
| 1076 | call assert_equal('"xyz', @:) |
| 1077 | call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt') |
| 1078 | call assert_equal("\"xy\<C-V>z", @:) |
| 1079 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 1080 | call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")') |
| 1081 | |
Bram Moolenaar | 72532d3 | 2018-04-07 19:09:09 +0200 | [diff] [blame] | 1082 | bwipe! |
Bram Moolenaar | 21efc36 | 2016-12-03 14:05:49 +0100 | [diff] [blame] | 1083 | endfunc |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 1084 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1085 | func Test_cmdline_remove_char() |
| 1086 | let encoding_save = &encoding |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 1087 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1088 | for e in ['utf8', 'latin1'] |
| 1089 | exe 'set encoding=' . e |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 1090 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1091 | call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx') |
| 1092 | call assert_equal('"abc ef', @:, e) |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 1093 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1094 | call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx') |
| 1095 | call assert_equal('"abcdef', @:) |
| 1096 | |
| 1097 | call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx') |
| 1098 | call assert_equal('"abc ghi', @:, e) |
| 1099 | |
| 1100 | call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx') |
| 1101 | call assert_equal('"def', @:, e) |
Bram Moolenaar | ef02f16 | 2022-05-07 10:49:10 +0100 | [diff] [blame] | 1102 | |
| 1103 | " This was going before the start in latin1. |
| 1104 | call feedkeys(": \<C-W>\<CR>", 'tx') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1105 | endfor |
| 1106 | |
| 1107 | let &encoding = encoding_save |
| 1108 | endfunc |
| 1109 | |
zeertzjq | ff2b79d | 2024-02-26 20:38:36 +0100 | [diff] [blame] | 1110 | func Test_cmdline_del_utf8() |
| 1111 | let @s = '⒌' |
| 1112 | call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx') |
| 1113 | call assert_equal('",,', @:) |
| 1114 | |
| 1115 | let @s = 'a̳' |
| 1116 | call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx') |
| 1117 | call assert_equal('",,', @:) |
| 1118 | |
| 1119 | let @s = 'β̳' |
| 1120 | call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx') |
| 1121 | call assert_equal('",,', @:) |
| 1122 | |
| 1123 | if has('arabic') |
| 1124 | let @s = 'لا' |
| 1125 | call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx') |
| 1126 | call assert_equal('",,', @:) |
| 1127 | endif |
| 1128 | endfunc |
| 1129 | |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1130 | func Test_cmdline_keymap_ctrl_hat() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1131 | CheckFeature keymap |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1132 | |
| 1133 | set keymap=esperanto |
| 1134 | call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx') |
| 1135 | call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:) |
| 1136 | set keymap= |
Bram Moolenaar | eaaa9bb | 2016-12-09 18:42:20 +0100 | [diff] [blame] | 1137 | endfunc |
Bram Moolenaar | fe38b49 | 2016-12-11 21:34:23 +0100 | [diff] [blame] | 1138 | |
Bram Moolenaar | f1f6f3f | 2017-02-09 22:28:20 +0100 | [diff] [blame] | 1139 | func Test_illegal_address1() |
Bram Moolenaar | fe38b49 | 2016-12-11 21:34:23 +0100 | [diff] [blame] | 1140 | new |
| 1141 | 2;'( |
| 1142 | 2;') |
| 1143 | quit |
| 1144 | endfunc |
Bram Moolenaar | ba47b51 | 2017-01-24 21:18:19 +0100 | [diff] [blame] | 1145 | |
Bram Moolenaar | f1f6f3f | 2017-02-09 22:28:20 +0100 | [diff] [blame] | 1146 | func Test_illegal_address2() |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 1147 | call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim', 'D') |
Bram Moolenaar | f1f6f3f | 2017-02-09 22:28:20 +0100 | [diff] [blame] | 1148 | new |
| 1149 | source Xtest.vim |
| 1150 | " Trigger calling validate_cursor() |
| 1151 | diffsp Xtest.vim |
| 1152 | quit! |
| 1153 | bwipe! |
Bram Moolenaar | f1f6f3f | 2017-02-09 22:28:20 +0100 | [diff] [blame] | 1154 | endfunc |
| 1155 | |
Bram Moolenaar | f7c7c3f | 2022-06-22 19:08:38 +0100 | [diff] [blame] | 1156 | func Test_mark_from_line_zero() |
| 1157 | " this was reading past the end of the first (empty) line |
| 1158 | new |
| 1159 | norm oxxxx |
| 1160 | call assert_fails("0;'(", 'E20:') |
| 1161 | bwipe! |
| 1162 | endfunc |
| 1163 | |
Bram Moolenaar | ba47b51 | 2017-01-24 21:18:19 +0100 | [diff] [blame] | 1164 | func Test_cmdline_complete_wildoptions() |
| 1165 | help |
| 1166 | call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') |
| 1167 | let a = join(sort(split(@:)),' ') |
| 1168 | set wildoptions=tagfile |
| 1169 | call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') |
| 1170 | let b = join(sort(split(@:)),' ') |
| 1171 | call assert_equal(a, b) |
| 1172 | bw! |
| 1173 | endfunc |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 1174 | |
Bram Moolenaar | a33ddbb | 2017-03-29 21:30:04 +0200 | [diff] [blame] | 1175 | func Test_cmdline_complete_user_cmd() |
| 1176 | command! -complete=color -nargs=1 Foo : |
| 1177 | call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx') |
| 1178 | call assert_equal('"Foo blue', @:) |
| 1179 | call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx') |
| 1180 | call assert_equal('"Foo blue', @:) |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 1181 | call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx') |
| 1182 | call assert_equal('"Foo a blue', @:) |
| 1183 | call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx') |
| 1184 | call assert_equal('"Foo b\', @:) |
| 1185 | call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx') |
| 1186 | call assert_equal('"Foo b\x', @:) |
Bram Moolenaar | a33ddbb | 2017-03-29 21:30:04 +0200 | [diff] [blame] | 1187 | delcommand Foo |
Bram Moolenaar | 300175f | 2022-08-21 18:38:21 +0100 | [diff] [blame] | 1188 | |
| 1189 | redraw |
| 1190 | call assert_equal('~', Screenline(&lines - 1)) |
| 1191 | command! FooOne : |
| 1192 | command! FooTwo : |
| 1193 | |
| 1194 | set nowildmenu |
| 1195 | call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx') |
| 1196 | call assert_equal('"FooOne', @:) |
| 1197 | call assert_equal('~', Screenline(&lines - 1)) |
| 1198 | |
| 1199 | call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx') |
| 1200 | call assert_equal('"FooTwo', @:) |
| 1201 | call assert_equal('~', Screenline(&lines - 1)) |
| 1202 | |
| 1203 | delcommand FooOne |
| 1204 | delcommand FooTwo |
| 1205 | set wildmenu& |
Bram Moolenaar | a33ddbb | 2017-03-29 21:30:04 +0200 | [diff] [blame] | 1206 | endfunc |
| 1207 | |
Bram Moolenaar | c2842ad | 2022-07-26 17:23:47 +0100 | [diff] [blame] | 1208 | func Test_complete_user_cmd() |
| 1209 | command FooBar echo 'global' |
| 1210 | command -buffer FooBar echo 'local' |
| 1211 | call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx') |
| 1212 | call assert_equal('"FooBar', @:) |
| 1213 | |
| 1214 | delcommand -buffer FooBar |
| 1215 | delcommand FooBar |
| 1216 | endfunc |
| 1217 | |
Bram Moolenaar | cc390ff | 2020-02-29 22:06:30 +0100 | [diff] [blame] | 1218 | func s:ScriptLocalFunction() |
| 1219 | echo 'yes' |
| 1220 | endfunc |
| 1221 | |
| 1222 | func Test_cmdline_complete_user_func() |
| 1223 | call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx') |
naohiro ono | 5aec755 | 2021-08-19 21:20:41 +0200 | [diff] [blame] | 1224 | call assert_match('"func Test_cmdline_complete_user_', @:) |
Bram Moolenaar | cc390ff | 2020-02-29 22:06:30 +0100 | [diff] [blame] | 1225 | call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx') |
| 1226 | call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:) |
Bram Moolenaar | 1bb4de5 | 2021-01-13 19:48:46 +0100 | [diff] [blame] | 1227 | |
| 1228 | " g: prefix also works |
| 1229 | call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx') |
| 1230 | call assert_match('"echo g:Test_cmdline_complete_user_func', @:) |
Bram Moolenaar | 069f908 | 2021-08-13 17:48:25 +0200 | [diff] [blame] | 1231 | |
| 1232 | " using g: prefix does not result in just "g:" matches from a lambda |
| 1233 | let Fx = { a -> a } |
| 1234 | call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx') |
| 1235 | call assert_match('"echo g:[A-Z]', @:) |
naohiro ono | 5aec755 | 2021-08-19 21:20:41 +0200 | [diff] [blame] | 1236 | |
| 1237 | " existence of script-local dict function does not break user function name |
| 1238 | " completion |
| 1239 | function s:a_dict_func() dict |
| 1240 | endfunction |
| 1241 | call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx') |
| 1242 | call assert_match('"call Test_cmdline_complete_user_', @:) |
| 1243 | delfunction s:a_dict_func |
Bram Moolenaar | cc390ff | 2020-02-29 22:06:30 +0100 | [diff] [blame] | 1244 | endfunc |
| 1245 | |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 1246 | func Test_cmdline_complete_user_names() |
| 1247 | if has('unix') && executable('whoami') |
| 1248 | let whoami = systemlist('whoami')[0] |
| 1249 | let first_letter = whoami[0] |
| 1250 | if len(first_letter) > 0 |
| 1251 | " Trying completion of :e ~x where x is the first letter of |
| 1252 | " the user name should complete to at least the user name. |
| 1253 | call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx') |
| 1254 | call assert_match('^"e \~.*\<' . whoami . '\>', @:) |
| 1255 | endif |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1256 | elseif has('win32') |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 1257 | " Just in case: check that the system has an Administrator account. |
| 1258 | let names = system('net user') |
| 1259 | if names =~ 'Administrator' |
| 1260 | " Trying completion of :e ~A should complete to Administrator. |
Bram Moolenaar | 346d2a3 | 2019-01-27 20:43:41 +0100 | [diff] [blame] | 1261 | " There could be other names starting with "A" before Administrator. |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 1262 | call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx') |
Bram Moolenaar | 346d2a3 | 2019-01-27 20:43:41 +0100 | [diff] [blame] | 1263 | call assert_match('^"e \~.*Administrator', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 1264 | endif |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1265 | else |
| 1266 | throw 'Skipped: does not work on this platform' |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 1267 | endif |
| 1268 | endfunc |
| 1269 | |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 1270 | func Test_cmdline_complete_shellcmdline() |
| 1271 | CheckExecutable whoami |
| 1272 | command -nargs=1 -complete=shellcmdline MyCmd |
| 1273 | |
| 1274 | call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx') |
| 1275 | call assert_match('^".*\<whoami\>', @:) |
zeertzjq | 85f36d6 | 2024-10-10 19:14:13 +0200 | [diff] [blame] | 1276 | let l = getcompletion('whoam', 'shellcmdline') |
| 1277 | call assert_match('\<whoami\>', join(l, ' ')) |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 1278 | |
| 1279 | delcommand MyCmd |
| 1280 | endfunc |
| 1281 | |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 1282 | func Test_cmdline_complete_bang() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1283 | CheckExecutable whoami |
| 1284 | call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx') |
| 1285 | call assert_match('^".*\<whoami\>', @:) |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 1286 | endfunc |
| 1287 | |
Bram Moolenaar | 8b63313 | 2020-03-20 18:20:51 +0100 | [diff] [blame] | 1288 | func Test_cmdline_complete_languages() |
Bram Moolenaar | 84cf6bd | 2020-06-16 20:03:43 +0200 | [diff] [blame] | 1289 | let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '') |
| 1290 | call assert_equal(lang, v:lc_time) |
| 1291 | |
| 1292 | let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '') |
| 1293 | call assert_equal(lang, v:ctype) |
| 1294 | |
| 1295 | let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '') |
| 1296 | call assert_equal(lang, v:collate) |
| 1297 | |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 1298 | let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') |
Bram Moolenaar | 84cf6bd | 2020-06-16 20:03:43 +0200 | [diff] [blame] | 1299 | call assert_equal(lang, v:lang) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 1300 | |
| 1301 | call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx') |
Bram Moolenaar | 84cf6bd | 2020-06-16 20:03:43 +0200 | [diff] [blame] | 1302 | call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 1303 | |
Bram Moolenaar | ec68028 | 2020-06-12 19:35:32 +0200 | [diff] [blame] | 1304 | call assert_match('^"language .*\<' . lang . '\>', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 1305 | |
Bram Moolenaar | ec68028 | 2020-06-12 19:35:32 +0200 | [diff] [blame] | 1306 | call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx') |
| 1307 | call assert_match('^"language .*\<' . lang . '\>', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 1308 | |
Bram Moolenaar | ec68028 | 2020-06-12 19:35:32 +0200 | [diff] [blame] | 1309 | call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx') |
| 1310 | call assert_match('^"language .*\<' . lang . '\>', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 1311 | |
Bram Moolenaar | ec68028 | 2020-06-12 19:35:32 +0200 | [diff] [blame] | 1312 | call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx') |
| 1313 | call assert_match('^"language .*\<' . lang . '\>', @:) |
Bram Moolenaar | 84cf6bd | 2020-06-16 20:03:43 +0200 | [diff] [blame] | 1314 | |
| 1315 | call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx') |
| 1316 | call assert_match('^"language .*\<' . lang . '\>', @:) |
Bram Moolenaar | 5f8f2d3 | 2018-06-19 19:09:09 +0200 | [diff] [blame] | 1317 | endfunc |
| 1318 | |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 1319 | func Test_cmdline_complete_env_variable() |
| 1320 | let $X_VIM_TEST_COMPLETE_ENV = 'foo' |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 1321 | call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx') |
| 1322 | call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:) |
Bram Moolenaar | 297610b | 2019-12-27 17:20:55 +0100 | [diff] [blame] | 1323 | unlet $X_VIM_TEST_COMPLETE_ENV |
| 1324 | endfunc |
| 1325 | |
Bram Moolenaar | 4941b5e | 2020-12-24 17:15:53 +0100 | [diff] [blame] | 1326 | func Test_cmdline_complete_expression() |
| 1327 | let g:SomeVar = 'blah' |
| 1328 | for cmd in ['exe', 'echo', 'echon', 'echomsg'] |
| 1329 | call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx') |
| 1330 | call assert_match('"' .. cmd .. ' SomeVar', @:) |
| 1331 | call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx') |
| 1332 | call assert_match('"' .. cmd .. ' foo SomeVar', @:) |
| 1333 | endfor |
| 1334 | unlet g:SomeVar |
| 1335 | endfunc |
| 1336 | |
Yee Cheng Chin | 989426b | 2023-10-14 11:46:51 +0200 | [diff] [blame] | 1337 | func Test_cmdline_complete_argopt() |
| 1338 | " completion for ++opt=arg for file commands |
| 1339 | call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0]) |
| 1340 | call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0]) |
| 1341 | call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0]) |
| 1342 | |
| 1343 | call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline')) |
Yee Cheng Chin | 209ec90 | 2023-10-17 10:56:25 +0200 | [diff] [blame] | 1344 | " Test ++ff in the middle of the cmdline |
| 1345 | call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1346 | call assert_equal("\"edit ++fileformat= zz", @:) |
Yee Cheng Chin | 989426b | 2023-10-14 11:46:51 +0200 | [diff] [blame] | 1347 | |
| 1348 | call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0]) |
| 1349 | call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0]) |
| 1350 | call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0]) |
| 1351 | call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0]) |
| 1352 | call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0]) |
| 1353 | |
| 1354 | call assert_equal([], getcompletion('edit ++bogus=', 'cmdline')) |
| 1355 | |
| 1356 | " completion should skip the ++opt and continue |
| 1357 | call writefile([], 'Xaaaaa.txt', 'D') |
| 1358 | call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1359 | call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:) |
| 1360 | |
| 1361 | if has('terminal') |
| 1362 | " completion for terminal's [options] |
| 1363 | call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0]) |
| 1364 | call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0]) |
| 1365 | call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0]) |
| 1366 | |
| 1367 | call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline')) |
| 1368 | |
| 1369 | " :terminal completion should skip the ++opt when considering what is the |
| 1370 | " first option, which is a list of shell commands, unlike second option |
| 1371 | " onwards. |
| 1372 | let first_param = getcompletion('terminal ', 'cmdline') |
| 1373 | let second_param = getcompletion('terminal foo ', 'cmdline') |
| 1374 | let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline') |
| 1375 | call assert_equal(first_param, skipped_opt_param) |
| 1376 | call assert_notequal(first_param, second_param) |
| 1377 | endif |
| 1378 | endfunc |
| 1379 | |
Bram Moolenaar | 47016f5 | 2021-08-26 16:39:58 +0200 | [diff] [blame] | 1380 | " Unique function name for completion below |
| 1381 | func s:WeirdFunc() |
| 1382 | echo 'weird' |
| 1383 | endfunc |
| 1384 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1385 | " Test for various command-line completion |
| 1386 | func Test_cmdline_complete_various() |
| 1387 | " completion for a command starting with a comment |
| 1388 | call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1389 | call assert_equal("\" :|\"\<C-A>", @:) |
| 1390 | |
| 1391 | " completion for a range followed by a comment |
| 1392 | call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1393 | call assert_equal("\"1,2\"\<C-A>", @:) |
| 1394 | |
| 1395 | " completion for :k command |
| 1396 | call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1397 | call assert_equal("\"ka\<C-A>", @:) |
| 1398 | |
Doug Kearns | ea84202 | 2024-09-29 17:17:41 +0200 | [diff] [blame] | 1399 | " completion for :keepmarks command |
| 1400 | call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1401 | call assert_equal("\"kee edit", @:) |
| 1402 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1403 | " completion for short version of the :s command |
| 1404 | call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt') |
| 1405 | call assert_equal("\"sI \<C-A>", @:) |
| 1406 | |
| 1407 | " completion for :write command |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 1408 | call mkdir('Xcwdir', 'R') |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 1409 | call writefile(['one'], 'Xcwdir/Xfile1') |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1410 | let save_cwd = getcwd() |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 1411 | cd Xcwdir |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1412 | call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt') |
| 1413 | call assert_equal("\"w >> Xfile1", @:) |
| 1414 | call chdir(save_cwd) |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1415 | |
| 1416 | " completion for :w ! and :r ! commands |
| 1417 | call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1418 | call assert_equal("\"w !invalid_xyz_cmd", @:) |
| 1419 | call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1420 | call assert_equal("\"r !invalid_xyz_cmd", @:) |
| 1421 | |
| 1422 | " completion for :>> and :<< commands |
| 1423 | call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1424 | call assert_equal("\">>>\<C-A>", @:) |
| 1425 | call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1426 | call assert_equal("\"<<<\<C-A>", @:) |
| 1427 | |
| 1428 | " completion for command with +cmd argument |
| 1429 | call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1430 | call assert_equal("\"buffer +/pat Xabc", @:) |
| 1431 | call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1432 | call assert_equal("\"buffer +/pat\<C-A>", @:) |
| 1433 | |
| 1434 | " completion for a command with a trailing comment |
| 1435 | call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1436 | call assert_equal("\"ls \" comment\<C-A>", @:) |
| 1437 | |
| 1438 | " completion for a command with a trailing command |
| 1439 | call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1440 | call assert_equal("\"ls | ls", @:) |
| 1441 | |
| 1442 | " completion for a command with an CTRL-V escaped argument |
| 1443 | call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1444 | call assert_equal("\"ls \<C-V>a\<C-A>", @:) |
| 1445 | |
| 1446 | " completion for a command that doesn't take additional arguments |
| 1447 | call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1448 | call assert_equal("\"all abc\<C-A>", @:) |
| 1449 | |
zeertzjq | d3de178 | 2022-09-01 12:58:52 +0100 | [diff] [blame] | 1450 | " completion for :wincmd with :horizontal modifier |
| 1451 | call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1452 | call assert_equal("\"horizontal wincmd", @:) |
| 1453 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1454 | " completion for a command with a command modifier |
| 1455 | call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1456 | call assert_equal("\"topleft new", @:) |
| 1457 | |
Bram Moolenaar | e70e12b | 2021-06-13 17:20:08 +0200 | [diff] [blame] | 1458 | " completion for vim9 and legacy commands |
| 1459 | call feedkeys(":vim9 call strle\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1460 | call assert_equal("\"vim9 call strlen(", @:) |
| 1461 | call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1462 | call assert_equal("\"legac call strlen(", @:) |
| 1463 | |
Bram Moolenaar | 4ee9d8e | 2021-06-13 18:38:48 +0200 | [diff] [blame] | 1464 | " completion for the :disassemble command |
| 1465 | call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1466 | call assert_equal("\"disas debug", @:) |
| 1467 | call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1468 | call assert_equal("\"disas profile", @:) |
| 1469 | call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1470 | call assert_equal("\"disas debug Test_cmdline_complete_various", @:) |
| 1471 | call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1472 | call assert_equal("\"disas profile Test_cmdline_complete_various", @:) |
naohiro ono | 9aecf79 | 2021-08-28 15:56:06 +0200 | [diff] [blame] | 1473 | call feedkeys(":disas Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1474 | call assert_equal("\"disas Test_cmdline_complete_various", @:) |
Bram Moolenaar | 4ee9d8e | 2021-06-13 18:38:48 +0200 | [diff] [blame] | 1475 | |
Bram Moolenaar | 47016f5 | 2021-08-26 16:39:58 +0200 | [diff] [blame] | 1476 | call feedkeys(":disas s:WeirdF\<C-A>\<C-B>\"\<CR>", 'xt') |
naohiro ono | 9aecf79 | 2021-08-28 15:56:06 +0200 | [diff] [blame] | 1477 | call assert_match('"disas <SNR>\d\+_WeirdFunc', @:) |
Bram Moolenaar | 47016f5 | 2021-08-26 16:39:58 +0200 | [diff] [blame] | 1478 | |
naohiro ono | dfe04db | 2021-09-12 15:45:10 +0200 | [diff] [blame] | 1479 | call feedkeys(":disas \<S-Tab>\<C-B>\"\<CR>", 'xt') |
| 1480 | call assert_match('"disas <SNR>\d\+_', @:) |
| 1481 | call feedkeys(":disas debug \<S-Tab>\<C-B>\"\<CR>", 'xt') |
| 1482 | call assert_match('"disas debug <SNR>\d\+_', @:) |
| 1483 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1484 | " completion for the :match command |
| 1485 | call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1486 | call assert_equal("\"match Search /pat/\<C-A>", @:) |
| 1487 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1488 | " completion for the :doautocmd command |
| 1489 | call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1490 | call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:) |
| 1491 | |
Bram Moolenaar | afe8cf6 | 2020-10-05 20:07:18 +0200 | [diff] [blame] | 1492 | " completion of autocmd group after comma |
| 1493 | call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1494 | call assert_equal("\"doautocmd BufNew,BufEnter", @:) |
| 1495 | |
Dominique Pelle | bfb2bb1 | 2021-08-14 21:11:51 +0200 | [diff] [blame] | 1496 | " completion of file name in :doautocmd |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 1497 | call writefile([], 'Xvarfile1', 'D') |
| 1498 | call writefile([], 'Xvarfile2', 'D') |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 1499 | call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1500 | call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:) |
Dominique Pelle | bfb2bb1 | 2021-08-14 21:11:51 +0200 | [diff] [blame] | 1501 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1502 | " completion for the :augroup command |
Bram Moolenaar | b4d82e2 | 2021-09-01 13:03:39 +0200 | [diff] [blame] | 1503 | augroup XTest.test |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1504 | augroup END |
| 1505 | call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt') |
Bram Moolenaar | b4d82e2 | 2021-09-01 13:03:39 +0200 | [diff] [blame] | 1506 | call assert_equal("\"augroup XTest.test", @:) |
Yegappan Lakshmanan | 00e977c | 2022-06-01 12:31:53 +0100 | [diff] [blame] | 1507 | |
| 1508 | " group name completion in :autocmd |
Bram Moolenaar | b4d82e2 | 2021-09-01 13:03:39 +0200 | [diff] [blame] | 1509 | call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1510 | call assert_equal("\"au XTest.test", @:) |
Yegappan Lakshmanan | 00e977c | 2022-06-01 12:31:53 +0100 | [diff] [blame] | 1511 | call feedkeys(":au XTest.test\<Tab>\<C-B>\"\<CR>", 'xt') |
| 1512 | call assert_equal("\"au XTest.test", @:) |
| 1513 | |
Bram Moolenaar | b4d82e2 | 2021-09-01 13:03:39 +0200 | [diff] [blame] | 1514 | augroup! XTest.test |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1515 | |
Yegappan Lakshmanan | 00e977c | 2022-06-01 12:31:53 +0100 | [diff] [blame] | 1516 | " autocmd pattern completion |
| 1517 | call feedkeys(":au BufEnter *.py\<Tab>\<C-B>\"\<CR>", 'xt') |
| 1518 | call assert_equal("\"au BufEnter *.py\t", @:) |
| 1519 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1520 | " completion for the :unlet command |
| 1521 | call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1522 | call assert_equal("\"unlet one two", @:) |
| 1523 | |
Bram Moolenaar | 21c1a0c | 2021-10-17 17:20:23 +0100 | [diff] [blame] | 1524 | " completion for the :buffer command with curlies |
Bram Moolenaar | 39c47c3 | 2021-10-17 18:05:26 +0100 | [diff] [blame] | 1525 | " FIXME: what should happen on MS-Windows? |
| 1526 | if !has('win32') |
| 1527 | edit \{someFile} |
| 1528 | call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1529 | call assert_equal("\"buf {someFile}", @:) |
| 1530 | bwipe {someFile} |
| 1531 | endif |
Bram Moolenaar | 21c1a0c | 2021-10-17 17:20:23 +0100 | [diff] [blame] | 1532 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1533 | " completion for the :bdelete command |
| 1534 | call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1535 | call assert_equal("\"bdel a b c", @:) |
| 1536 | |
| 1537 | " completion for the :mapclear command |
| 1538 | call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt') |
| 1539 | call assert_equal("\"mapclear <buffer>", @:) |
| 1540 | |
| 1541 | " completion for user defined commands with menu names |
| 1542 | menu Test.foo :ls<CR> |
| 1543 | com -nargs=* -complete=menu MyCmd |
| 1544 | call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1545 | call assert_equal('"MyCmd Test.', @:) |
| 1546 | delcom MyCmd |
| 1547 | unmenu Test |
| 1548 | |
| 1549 | " completion for user defined commands with mappings |
| 1550 | mapclear |
| 1551 | map <F3> :ls<CR> |
| 1552 | com -nargs=* -complete=mapping MyCmd |
| 1553 | call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt') |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 1554 | call assert_equal('"MyCmd <F3> <F4>', @:) |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1555 | mapclear |
| 1556 | delcom MyCmd |
| 1557 | |
Yee Cheng Chin | 5484485 | 2023-10-09 18:12:31 +0200 | [diff] [blame] | 1558 | " Prepare for path completion |
| 1559 | call mkdir('Xa b c', 'D') |
| 1560 | defer delete('Xcomma,foobar.txt') |
| 1561 | call writefile([], 'Xcomma,foobar.txt') |
| 1562 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1563 | " completion for :set path= with multiple backslashes |
Yee Cheng Chin | 5484485 | 2023-10-09 18:12:31 +0200 | [diff] [blame] | 1564 | call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1565 | call assert_equal('"set path=Xa\\\ b\\\ c/', @:) |
| 1566 | set path& |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1567 | |
| 1568 | " completion for :set dir= with a backslash |
Yee Cheng Chin | 5484485 | 2023-10-09 18:12:31 +0200 | [diff] [blame] | 1569 | call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1570 | call assert_equal('"set dir=Xa\ b\ c/', @:) |
| 1571 | set dir& |
| 1572 | |
| 1573 | " completion for :set tags= / set dictionary= with escaped commas |
| 1574 | if has('win32') |
| 1575 | " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to |
| 1576 | " '\,' |
| 1577 | call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1578 | call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:) |
| 1579 | |
| 1580 | call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1581 | call assert_equal('"set tags=Xcomma\,foobar.txt', @:) |
| 1582 | |
| 1583 | call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1584 | call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match |
| 1585 | |
| 1586 | " completion for :set dictionary= with escaped commas (same behavior, but |
| 1587 | " different internal code path from 'set tags=' for escaping the output) |
| 1588 | call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1589 | call assert_equal('"set tags=Xcomma\,foobar.txt', @:) |
| 1590 | else |
| 1591 | " In other platforms, backslashes are rounded down (since '\,' itself will |
| 1592 | " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'. |
| 1593 | call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1594 | call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match |
| 1595 | |
| 1596 | call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1597 | call assert_equal('"set tags=Xcomma\\,foobar.txt', @:) |
| 1598 | |
| 1599 | call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1600 | call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:) |
| 1601 | |
| 1602 | " completion for :set dictionary= with escaped commas (same behavior, but |
| 1603 | " different internal code path from 'set tags=' for escaping the output) |
| 1604 | call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1605 | call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:) |
| 1606 | endif |
| 1607 | set tags& |
| 1608 | set dictionary& |
| 1609 | |
| 1610 | " completion for :set makeprg= with no escaped commas |
| 1611 | call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1612 | call assert_equal('"set makeprg=Xcomma,foobar.txt', @:) |
| 1613 | |
| 1614 | if !has('win32') |
| 1615 | " Cannot create file with backslash in file name in Windows, so only test |
| 1616 | " this elsewhere. |
| 1617 | defer delete('Xcomma\,fooslash.txt') |
| 1618 | call writefile([], 'Xcomma\,fooslash.txt') |
| 1619 | call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1620 | call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:) |
| 1621 | endif |
| 1622 | set makeprg& |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1623 | |
| 1624 | " completion for the :py3 commands |
| 1625 | call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1626 | call assert_equal('"py3 py3do py3file', @:) |
| 1627 | |
Bram Moolenaar | df749a2 | 2021-03-28 15:29:43 +0200 | [diff] [blame] | 1628 | " completion for the :vim9 commands |
| 1629 | call feedkeys(":vim9\<C-A>\<C-B>\"\<CR>", 'xt') |
| 1630 | call assert_equal('"vim9cmd vim9script', @:) |
| 1631 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1632 | " redir @" is not the start of a comment. So complete after that |
| 1633 | call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt') |
| 1634 | call assert_equal('"redir @" | cwindow', @:) |
| 1635 | |
| 1636 | " completion after a backtick |
| 1637 | call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt') |
| 1638 | call assert_equal('"e `a1b2c', @:) |
| 1639 | |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 1640 | " completion for :language command with an invalid argument |
| 1641 | call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt') |
| 1642 | call assert_equal("\"language dummy \t", @:) |
| 1643 | |
| 1644 | " completion for commands after a :global command |
Bram Moolenaar | 8b63313 | 2020-03-20 18:20:51 +0100 | [diff] [blame] | 1645 | call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt') |
| 1646 | call assert_equal('"g/a\xb/clearjumps', @:) |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 1647 | |
| 1648 | " completion with ambiguous user defined commands |
| 1649 | com TCmd1 echo 'TCmd1' |
| 1650 | com TCmd2 echo 'TCmd2' |
| 1651 | call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt') |
| 1652 | call assert_equal('"TCmd ', @:) |
| 1653 | delcom TCmd1 |
| 1654 | delcom TCmd2 |
| 1655 | |
| 1656 | " completion after a range followed by a pipe (|) character |
| 1657 | call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt') |
| 1658 | call assert_equal('"1,10 | chistory', @:) |
Bram Moolenaar | 9c92971 | 2020-09-07 22:05:28 +0200 | [diff] [blame] | 1659 | |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 1660 | " completion after a :global command |
| 1661 | call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt') |
| 1662 | call assert_equal('"g/a/chistory', @:) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 1663 | set wildchar=0 |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 1664 | call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt') |
| 1665 | call assert_equal("\"g/a\\/chist\t", @:) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 1666 | set wildchar& |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 1667 | |
Bram Moolenaar | 9c92971 | 2020-09-07 22:05:28 +0200 | [diff] [blame] | 1668 | " use <Esc> as the 'wildchar' for completion |
| 1669 | set wildchar=<Esc> |
| 1670 | call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt') |
| 1671 | call assert_equal('"g/a\xb/clearjumps', @:) |
| 1672 | " pressing <esc> twice should cancel the command |
| 1673 | call feedkeys(":chist\<Esc>\<Esc>", 'xt') |
| 1674 | call assert_equal('"g/a\xb/clearjumps', @:) |
| 1675 | set wildchar& |
Yegappan Lakshmanan | 4d03d87 | 2022-02-13 11:45:09 +0000 | [diff] [blame] | 1676 | |
Yegappan Lakshmanan | 4d03d87 | 2022-02-13 11:45:09 +0000 | [diff] [blame] | 1677 | if has('unix') |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 1678 | " should be able to complete a file name that starts with a '~'. |
Yegappan Lakshmanan | 4d03d87 | 2022-02-13 11:45:09 +0000 | [diff] [blame] | 1679 | call writefile([], '~Xtest') |
| 1680 | call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt') |
| 1681 | call assert_equal('"e \~Xtest', @:) |
| 1682 | call delete('~Xtest') |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 1683 | |
| 1684 | " should be able to complete a file name that has a '*' |
| 1685 | call writefile([], 'Xx*Yy') |
| 1686 | call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt') |
| 1687 | call assert_equal('"e Xx\*Yy', @:) |
| 1688 | call delete('Xx*Yy') |
Yegappan Lakshmanan | b31aec3 | 2022-02-16 12:44:29 +0000 | [diff] [blame] | 1689 | |
| 1690 | " use a literal star |
| 1691 | call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt') |
| 1692 | call assert_equal('"e \*', @:) |
Yegappan Lakshmanan | 4d03d87 | 2022-02-13 11:45:09 +0000 | [diff] [blame] | 1693 | endif |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 1694 | |
| 1695 | call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt') |
| 1696 | call assert_equal('"py3file', @:) |
Yegappan Lakshmanan | 4d03d87 | 2022-02-13 11:45:09 +0000 | [diff] [blame] | 1697 | endfunc |
| 1698 | |
zeertzjq | 094dd15 | 2023-06-15 22:51:57 +0100 | [diff] [blame] | 1699 | " Test that expanding a pattern doesn't interfere with cmdline completion. |
| 1700 | func Test_expand_during_cmdline_completion() |
| 1701 | func ExpandStuff() |
| 1702 | badd <script>:p:h/README.* |
| 1703 | call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$')) |
| 1704 | $bwipe |
| 1705 | call assert_equal('README.txt', expand('README.*')) |
| 1706 | call assert_equal(['README.txt'], getcompletion('README.*', 'file')) |
| 1707 | endfunc |
| 1708 | augroup test_CmdlineChanged |
| 1709 | autocmd! |
| 1710 | autocmd CmdlineChanged * call ExpandStuff() |
| 1711 | augroup END |
| 1712 | |
| 1713 | call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 1714 | call assert_equal('"sign place', @:) |
| 1715 | |
| 1716 | augroup test_CmdlineChanged |
| 1717 | au! |
| 1718 | augroup END |
| 1719 | augroup! test_CmdlineChanged |
| 1720 | delfunc ExpandStuff |
| 1721 | endfunc |
| 1722 | |
Yegappan Lakshmanan | 4d03d87 | 2022-02-13 11:45:09 +0000 | [diff] [blame] | 1723 | " Test for 'wildignorecase' |
| 1724 | func Test_cmdline_wildignorecase() |
| 1725 | CheckUnix |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 1726 | call writefile([], 'XTEST', 'D') |
Yegappan Lakshmanan | 4d03d87 | 2022-02-13 11:45:09 +0000 | [diff] [blame] | 1727 | set wildignorecase |
| 1728 | call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt') |
| 1729 | call assert_equal('"e XTEST', @:) |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 1730 | call assert_equal(['XTEST'], getcompletion('xt', 'file')) |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 1731 | let g:Sline = '' |
| 1732 | call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt') |
| 1733 | call assert_equal('"e xt', @:) |
| 1734 | call assert_equal('XTEST', g:Sline) |
Yegappan Lakshmanan | 4d03d87 | 2022-02-13 11:45:09 +0000 | [diff] [blame] | 1735 | set wildignorecase& |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 1736 | endfunc |
| 1737 | |
Bram Moolenaar | c312b8b | 2017-10-28 17:53:04 +0200 | [diff] [blame] | 1738 | func Test_cmdline_write_alternatefile() |
| 1739 | new |
| 1740 | call setline('.', ['one', 'two']) |
| 1741 | f foo.txt |
| 1742 | new |
| 1743 | f #-A |
| 1744 | call assert_equal('foo.txt-A', expand('%')) |
| 1745 | f #<-B.txt |
| 1746 | call assert_equal('foo-B.txt', expand('%')) |
| 1747 | f %< |
| 1748 | call assert_equal('foo-B', expand('%')) |
| 1749 | new |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 1750 | call assert_fails('f #<', 'E95:') |
Bram Moolenaar | c312b8b | 2017-10-28 17:53:04 +0200 | [diff] [blame] | 1751 | bw! |
| 1752 | f foo-B.txt |
| 1753 | f %<-A |
| 1754 | call assert_equal('foo-B-A', expand('%')) |
| 1755 | bw! |
| 1756 | bw! |
| 1757 | endfunc |
| 1758 | |
Bram Moolenaar | f572437 | 2022-09-02 19:45:15 +0100 | [diff] [blame] | 1759 | func Test_cmdline_expand_cur_alt_file() |
| 1760 | enew |
| 1761 | file http://some.com/file.txt |
| 1762 | call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt') |
| 1763 | call assert_equal('"e http://some.com/file.txt', @:) |
| 1764 | edit another |
| 1765 | call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt') |
| 1766 | call assert_equal('"e http://some.com/file.txt', @:) |
| 1767 | bwipe |
| 1768 | bwipe http://some.com/file.txt |
| 1769 | endfunc |
| 1770 | |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 1771 | " using a leading backslash here |
| 1772 | set cpo+=C |
| 1773 | |
| 1774 | func Test_cmdline_search_range() |
| 1775 | new |
| 1776 | call setline(1, ['a', 'b', 'c', 'd']) |
| 1777 | /d |
| 1778 | 1,\/s/b/B/ |
| 1779 | call assert_equal('B', getline(2)) |
| 1780 | |
| 1781 | /a |
| 1782 | $ |
| 1783 | \?,4s/c/C/ |
| 1784 | call assert_equal('C', getline(3)) |
| 1785 | |
| 1786 | call setline(1, ['a', 'b', 'c', 'd']) |
| 1787 | %s/c/c/ |
| 1788 | 1,\&s/b/B/ |
| 1789 | call assert_equal('B', getline(2)) |
| 1790 | |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1791 | let @/ = 'apple' |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1792 | call assert_fails('\/print', ['E486:.*apple']) |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1793 | |
Bram Moolenaar | cbf20fb | 2017-02-03 21:19:04 +0100 | [diff] [blame] | 1794 | bwipe! |
| 1795 | endfunc |
| 1796 | |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1797 | " Test for the tick mark (') in an excmd range |
| 1798 | func Test_tick_mark_in_range() |
| 1799 | " If only the tick is passed as a range and no command is specified, there |
| 1800 | " should not be an error |
| 1801 | call feedkeys(":'\<CR>", 'xt') |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 1802 | call assert_equal("'", @:) |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 1803 | call assert_fails("',print", 'E78:') |
| 1804 | endfunc |
| 1805 | |
| 1806 | " Test for using a line number followed by a search pattern as range |
| 1807 | func Test_lnum_and_pattern_as_range() |
| 1808 | new |
| 1809 | call setline(1, ['foo 1', 'foo 2', 'foo 3']) |
| 1810 | let @" = '' |
| 1811 | 2/foo/yank |
| 1812 | call assert_equal("foo 3\n", @") |
| 1813 | call assert_equal(1, line('.')) |
| 1814 | close! |
| 1815 | endfunc |
| 1816 | |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 1817 | " Tests for getcmdline(), getcmdpos() and getcmdtype() |
| 1818 | func Check_cmdline(cmdtype) |
| 1819 | call assert_equal('MyCmd a', getcmdline()) |
| 1820 | call assert_equal(8, getcmdpos()) |
| 1821 | call assert_equal(a:cmdtype, getcmdtype()) |
| 1822 | return '' |
| 1823 | endfunc |
| 1824 | |
Bram Moolenaar | 96e38a8 | 2019-09-09 18:35:33 +0200 | [diff] [blame] | 1825 | set cpo& |
| 1826 | |
Shougo Matsushita | 6908428 | 2024-09-23 20:34:47 +0200 | [diff] [blame] | 1827 | func Test_getcmdtype_getcmdprompt() |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 1828 | call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt") |
| 1829 | |
| 1830 | let cmdtype = '' |
| 1831 | debuggreedy |
| 1832 | call feedkeys(":debug echo 'test'\<CR>", "t") |
| 1833 | call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t") |
| 1834 | call feedkeys("cont\<CR>", "xt") |
| 1835 | 0debuggreedy |
| 1836 | call assert_equal('>', cmdtype) |
| 1837 | |
| 1838 | call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt") |
| 1839 | call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt") |
| 1840 | |
| 1841 | call feedkeys(":call input('Answer?')\<CR>", "t") |
Bram Moolenaar | 31eb139 | 2017-02-09 21:44:03 +0100 | [diff] [blame] | 1842 | call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt") |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 1843 | |
| 1844 | call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt") |
| 1845 | |
| 1846 | cnoremap <expr> <F6> Check_cmdline('=') |
| 1847 | call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt") |
| 1848 | cunmap <F6> |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 1849 | |
| 1850 | call assert_equal('', getcmdline()) |
Shougo Matsushita | 6908428 | 2024-09-23 20:34:47 +0200 | [diff] [blame] | 1851 | |
| 1852 | call assert_equal('', getcmdprompt()) |
| 1853 | augroup test_CmdlineEnter |
| 1854 | autocmd! |
| 1855 | autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt() |
| 1856 | augroup END |
| 1857 | call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt") |
| 1858 | call assert_equal('Answer?', g:cmdprompt) |
| 1859 | call assert_equal('', getcmdprompt()) |
h-east | 25876a6 | 2024-09-26 16:01:57 +0200 | [diff] [blame] | 1860 | call feedkeys(":\<CR>\<ESC>", "xt") |
| 1861 | call assert_equal('', g:cmdprompt) |
| 1862 | call assert_equal('', getcmdprompt()) |
| 1863 | |
| 1864 | let str = "C" .. repeat("c", 1023) .. "xyz" |
| 1865 | call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt") |
| 1866 | call assert_equal(str, g:cmdprompt) |
| 1867 | |
| 1868 | call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt") |
| 1869 | call assert_equal('Ans?', g:cmdprompt) |
| 1870 | call assert_equal('', getcmdprompt()) |
Shougo Matsushita | 6908428 | 2024-09-23 20:34:47 +0200 | [diff] [blame] | 1871 | |
| 1872 | augroup test_CmdlineEnter |
| 1873 | au! |
| 1874 | augroup END |
| 1875 | augroup! test_CmdlineEnter |
Bram Moolenaar | 65189a1 | 2017-02-06 22:22:17 +0100 | [diff] [blame] | 1876 | endfunc |
| 1877 | |
Bram Moolenaar | 52604f2 | 2017-04-07 16:17:39 +0200 | [diff] [blame] | 1878 | func Test_verbosefile() |
| 1879 | set verbosefile=Xlog |
| 1880 | echomsg 'foo' |
| 1881 | echomsg 'bar' |
| 1882 | set verbosefile= |
| 1883 | let log = readfile('Xlog') |
| 1884 | call assert_match("foo\nbar", join(log, "\n")) |
| 1885 | call delete('Xlog') |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 1886 | |
| 1887 | call mkdir('Xdir', 'D') |
Bram Moolenaar | 9b7bf9e | 2020-07-11 22:14:59 +0200 | [diff] [blame] | 1888 | call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:']) |
Bram Moolenaar | 52604f2 | 2017-04-07 16:17:39 +0200 | [diff] [blame] | 1889 | endfunc |
| 1890 | |
Bram Moolenaar | 4facea3 | 2019-10-12 20:17:40 +0200 | [diff] [blame] | 1891 | func Test_verbose_option() |
| 1892 | CheckScreendump |
| 1893 | |
| 1894 | let lines =<< trim [SCRIPT] |
Christian Brabandt | 2abec43 | 2024-10-27 21:33:09 +0100 | [diff] [blame] | 1895 | " clear the TermResponse autocommand from defaults.vim |
| 1896 | au! vimStartup TermResponse |
Bram Moolenaar | 4facea3 | 2019-10-12 20:17:40 +0200 | [diff] [blame] | 1897 | command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v |
| 1898 | call feedkeys("\r", 't') " for the hit-enter prompt |
| 1899 | set verbose=20 |
| 1900 | [SCRIPT] |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 1901 | call writefile(lines, 'XTest_verbose', 'D') |
Bram Moolenaar | 4facea3 | 2019-10-12 20:17:40 +0200 | [diff] [blame] | 1902 | |
| 1903 | let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 1904 | call TermWait(buf, 50) |
Bram Moolenaar | 4facea3 | 2019-10-12 20:17:40 +0200 | [diff] [blame] | 1905 | call term_sendkeys(buf, ":DoSomething\<CR>") |
| 1906 | call VerifyScreenDump(buf, 'Test_verbose_option_1', {}) |
| 1907 | |
| 1908 | " clean up |
| 1909 | call StopVimInTerminal(buf) |
Bram Moolenaar | 4facea3 | 2019-10-12 20:17:40 +0200 | [diff] [blame] | 1910 | endfunc |
| 1911 | |
Bram Moolenaar | ff3be4f | 2018-05-12 13:18:46 +0200 | [diff] [blame] | 1912 | func Test_setcmdpos() |
| 1913 | func InsertTextAtPos(text, pos) |
| 1914 | call assert_equal(0, setcmdpos(a:pos)) |
| 1915 | return a:text |
| 1916 | endfunc |
| 1917 | |
| 1918 | " setcmdpos() with position in the middle of the command line. |
| 1919 | call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') |
| 1920 | call assert_equal('"1ab2', @:) |
| 1921 | |
| 1922 | call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') |
| 1923 | call assert_equal('"1b2a', @:) |
| 1924 | |
| 1925 | " setcmdpos() with position beyond the end of the command line. |
| 1926 | call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt') |
| 1927 | call assert_equal('"12ab', @:) |
| 1928 | |
| 1929 | " setcmdpos() returns 1 when not editing the command line. |
Bram Moolenaar | 196b466 | 2019-09-06 21:34:30 +0200 | [diff] [blame] | 1930 | call assert_equal(1, 3->setcmdpos()) |
Bram Moolenaar | ff3be4f | 2018-05-12 13:18:46 +0200 | [diff] [blame] | 1931 | endfunc |
| 1932 | |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 1933 | func Test_cmdline_overstrike() |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 1934 | let encodings = ['latin1', 'utf8'] |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 1935 | let encoding_save = &encoding |
| 1936 | |
| 1937 | for e in encodings |
| 1938 | exe 'set encoding=' . e |
| 1939 | |
| 1940 | " Test overstrike in the middle of the command line. |
| 1941 | call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1942 | call assert_equal('"0ab1cd4', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 1943 | |
| 1944 | " Test overstrike going beyond end of command line. |
| 1945 | call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1946 | call assert_equal('"0ab1cdefgh', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 1947 | |
| 1948 | " Test toggling insert/overstrike a few times. |
| 1949 | 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] | 1950 | call assert_equal('"ab0cd3ef4', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 1951 | endfor |
| 1952 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 1953 | " Test overstrike with multi-byte characters. |
| 1954 | call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') |
Bram Moolenaar | 59cb041 | 2019-12-18 22:26:31 +0100 | [diff] [blame] | 1955 | call assert_equal('"テabキcdエディタ', @:, e) |
Bram Moolenaar | c0676ba | 2018-12-31 21:03:02 +0100 | [diff] [blame] | 1956 | |
| 1957 | let &encoding = encoding_save |
| 1958 | endfunc |
Bram Moolenaar | a046b37 | 2019-09-15 17:26:07 +0200 | [diff] [blame] | 1959 | |
Bram Moolenaar | 5241057 | 2019-10-27 05:12:45 +0100 | [diff] [blame] | 1960 | func Test_buffers_lastused() |
| 1961 | " check that buffers are sorted by time when wildmode has lastused |
| 1962 | call test_settime(1550020000) " middle |
| 1963 | edit bufa |
| 1964 | enew |
| 1965 | call test_settime(1550030000) " newest |
| 1966 | edit bufb |
| 1967 | enew |
| 1968 | call test_settime(1550010000) " oldest |
| 1969 | edit bufc |
| 1970 | enew |
| 1971 | call test_settime(0) |
| 1972 | enew |
| 1973 | |
| 1974 | call assert_equal(['bufa', 'bufb', 'bufc'], |
| 1975 | \ getcompletion('', 'buffer')) |
| 1976 | |
| 1977 | let save_wildmode = &wildmode |
| 1978 | set wildmode=full:lastused |
| 1979 | |
| 1980 | let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>" |
| 1981 | call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') |
| 1982 | call assert_equal('b bufb', X) |
| 1983 | call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 1984 | call assert_equal('b bufa', X) |
| 1985 | call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 1986 | call assert_equal('b bufc', X) |
| 1987 | enew |
| 1988 | |
| 1989 | edit other |
| 1990 | call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt') |
| 1991 | call assert_equal('b bufb', X) |
| 1992 | call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 1993 | call assert_equal('b bufa', X) |
| 1994 | call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt') |
| 1995 | call assert_equal('b bufc', X) |
| 1996 | enew |
| 1997 | |
| 1998 | let &wildmode = save_wildmode |
| 1999 | |
| 2000 | bwipeout bufa |
| 2001 | bwipeout bufb |
| 2002 | bwipeout bufc |
| 2003 | endfunc |
Bram Moolenaar | 85db547 | 2019-12-04 15:11:08 +0100 | [diff] [blame] | 2004 | |
Bram Moolenaar | 479950f | 2020-01-19 15:45:17 +0100 | [diff] [blame] | 2005 | func Test_cmdlineclear_tabenter() |
| 2006 | CheckScreendump |
| 2007 | |
| 2008 | let lines =<< trim [SCRIPT] |
| 2009 | call setline(1, range(30)) |
| 2010 | [SCRIPT] |
| 2011 | |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 2012 | call writefile(lines, 'XtestCmdlineClearTabenter', 'D') |
Bram Moolenaar | 479950f | 2020-01-19 15:45:17 +0100 | [diff] [blame] | 2013 | let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 2014 | call TermWait(buf, 25) |
Bram Moolenaar | 479950f | 2020-01-19 15:45:17 +0100 | [diff] [blame] | 2015 | " in one tab make the command line higher with CTRL-W - |
| 2016 | call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt") |
| 2017 | call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {}) |
| 2018 | |
| 2019 | call StopVimInTerminal(buf) |
Bram Moolenaar | 479950f | 2020-01-19 15:45:17 +0100 | [diff] [blame] | 2020 | endfunc |
| 2021 | |
Yegappan Lakshmanan | 46aa6f9 | 2021-05-19 17:15:04 +0200 | [diff] [blame] | 2022 | " Test for expanding special keywords in cmdline |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 2023 | func Test_cmdline_expand_special() |
| 2024 | %bwipe! |
Bram Moolenaar | b8bd2e6 | 2021-08-21 17:13:14 +0200 | [diff] [blame] | 2025 | call assert_fails('e #', 'E194:') |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 2026 | call assert_fails('e <afile>', 'E495:') |
| 2027 | call assert_fails('e <abuf>', 'E496:') |
| 2028 | call assert_fails('e <amatch>', 'E497:') |
Yegappan Lakshmanan | 46aa6f9 | 2021-05-19 17:15:04 +0200 | [diff] [blame] | 2029 | |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 2030 | call writefile([], 'Xfile.cpp', 'D') |
| 2031 | call writefile([], 'Xfile.java', 'D') |
Yegappan Lakshmanan | 46aa6f9 | 2021-05-19 17:15:04 +0200 | [diff] [blame] | 2032 | new Xfile.cpp |
| 2033 | call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt') |
| 2034 | call assert_equal('"e Xfile.cpp Xfile.java', @:) |
| 2035 | close |
Bram Moolenaar | 9f6277b | 2020-02-11 22:04:02 +0100 | [diff] [blame] | 2036 | endfunc |
| 2037 | |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 2038 | " Test for backtick expression in the command line |
| 2039 | func Test_cmd_backtick() |
| 2040 | %argd |
| 2041 | argadd `=['a', 'b', 'c']` |
| 2042 | call assert_equal(['a', 'b', 'c'], argv()) |
| 2043 | %argd |
Dominique Pelle | bfb2bb1 | 2021-08-14 21:11:51 +0200 | [diff] [blame] | 2044 | |
| 2045 | argadd `echo abc def` |
| 2046 | call assert_equal(['abc def'], argv()) |
| 2047 | %argd |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 2048 | endfunc |
| 2049 | |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 2050 | " Test for the :! command |
| 2051 | func Test_cmd_bang() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 2052 | CheckUnix |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 2053 | |
| 2054 | let lines =<< trim [SCRIPT] |
| 2055 | " Test for no previous command |
| 2056 | call assert_fails('!!', 'E34:') |
| 2057 | set nomore |
| 2058 | " Test for cmdline expansion with :! |
| 2059 | call setline(1, 'foo!') |
| 2060 | silent !echo <cWORD> > Xfile.out |
| 2061 | call assert_equal(['foo!'], readfile('Xfile.out')) |
| 2062 | " Test for using previous command |
| 2063 | silent !echo \! ! |
| 2064 | call assert_equal(['! echo foo!'], readfile('Xfile.out')) |
| 2065 | call writefile(v:errors, 'Xresult') |
| 2066 | call delete('Xfile.out') |
| 2067 | qall! |
| 2068 | [SCRIPT] |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 2069 | call writefile(lines, 'Xscript', 'D') |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 2070 | if RunVim([], [], '--clean -S Xscript') |
| 2071 | call assert_equal([], readfile('Xresult')) |
| 2072 | endif |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 2073 | call delete('Xresult') |
| 2074 | endfunc |
| 2075 | |
Bram Moolenaar | e0c3c3d | 2020-06-04 22:46:04 +0200 | [diff] [blame] | 2076 | " Test error: "E135: *Filter* Autocommands must not change current buffer" |
| 2077 | func Test_cmd_bang_E135() |
| 2078 | new |
| 2079 | call setline(1, ['a', 'b', 'c', 'd']) |
| 2080 | augroup test_cmd_filter_E135 |
| 2081 | au! |
| 2082 | autocmd FilterReadPost * help |
| 2083 | augroup END |
| 2084 | call assert_fails('2,3!echo "x"', 'E135:') |
| 2085 | |
| 2086 | augroup test_cmd_filter_E135 |
| 2087 | au! |
| 2088 | augroup END |
zeertzjq | 094dd15 | 2023-06-15 22:51:57 +0100 | [diff] [blame] | 2089 | augroup! test_cmd_filter_E135 |
Bram Moolenaar | e0c3c3d | 2020-06-04 22:46:04 +0200 | [diff] [blame] | 2090 | %bwipe! |
| 2091 | endfunc |
| 2092 | |
shane.xb.qian | 4e7590e | 2022-11-08 21:40:04 +0000 | [diff] [blame] | 2093 | func Test_cmd_bang_args() |
| 2094 | new |
| 2095 | :.! |
| 2096 | call assert_equal(0, v:shell_error) |
| 2097 | |
| 2098 | " Note that below there is one space char after the '!'. This caused a |
| 2099 | " shell error in the past, see https://github.com/vim/vim/issues/11495. |
| 2100 | :.! |
| 2101 | call assert_equal(0, v:shell_error) |
| 2102 | bwipe! |
| 2103 | |
| 2104 | CheckUnix |
| 2105 | :.!pwd |
| 2106 | call assert_equal(0, v:shell_error) |
| 2107 | :.! pwd |
| 2108 | call assert_equal(0, v:shell_error) |
| 2109 | |
| 2110 | " Note there is one space after 'pwd'. |
| 2111 | :.! pwd |
| 2112 | call assert_equal(0, v:shell_error) |
| 2113 | |
| 2114 | " Note there are two spaces after 'pwd'. |
| 2115 | :.! pwd |
| 2116 | call assert_equal(0, v:shell_error) |
| 2117 | :.!ls ~ |
| 2118 | call assert_equal(0, v:shell_error) |
| 2119 | |
| 2120 | " Note there is one space char after '~'. |
| 2121 | :.!ls ~ |
| 2122 | call assert_equal(0, v:shell_error) |
| 2123 | |
| 2124 | " Note there are two spaces after '~'. |
| 2125 | :.!ls ~ |
| 2126 | call assert_equal(0, v:shell_error) |
| 2127 | |
| 2128 | :.!echo "foo" |
| 2129 | call assert_equal(getline('.'), "foo") |
| 2130 | :.!echo "foo " |
| 2131 | call assert_equal(getline('.'), "foo ") |
| 2132 | :.!echo " foo " |
| 2133 | call assert_equal(getline('.'), " foo ") |
| 2134 | :.!echo " foo " |
| 2135 | call assert_equal(getline('.'), " foo ") |
| 2136 | |
| 2137 | %bwipe! |
| 2138 | endfunc |
| 2139 | |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 2140 | " Test for using ~ for home directory in cmdline completion matches |
| 2141 | func Test_cmdline_expand_home() |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 2142 | call mkdir('Xexpdir', 'R') |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 2143 | call writefile([], 'Xexpdir/Xfile1') |
| 2144 | call writefile([], 'Xexpdir/Xfile2') |
| 2145 | cd Xexpdir |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 2146 | let save_HOME = $HOME |
| 2147 | let $HOME = getcwd() |
| 2148 | call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt') |
| 2149 | call assert_equal('"e ~/Xfile1 ~/Xfile2', @:) |
| 2150 | let $HOME = save_HOME |
| 2151 | cd .. |
Bram Moolenaar | 8d588cc | 2020-02-25 21:47:45 +0100 | [diff] [blame] | 2152 | endfunc |
| 2153 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 2154 | " Test for using CTRL-\ CTRL-G in the command line to go back to normal mode |
| 2155 | " or insert mode (when 'insertmode' is set) |
| 2156 | func Test_cmdline_ctrl_g() |
| 2157 | new |
| 2158 | call setline(1, 'abc') |
| 2159 | call cursor(1, 3) |
| 2160 | " If command line is entered from insert mode, using C-\ C-G should back to |
| 2161 | " insert mode |
| 2162 | call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt') |
| 2163 | call assert_equal('abxyc', getline(1)) |
| 2164 | call assert_equal(4, col('.')) |
| 2165 | |
| 2166 | " If command line is entered in 'insertmode', using C-\ C-G should back to |
| 2167 | " 'insertmode' |
| 2168 | call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt') |
| 2169 | call assert_equal('ab12xyc', getline(1)) |
| 2170 | close! |
| 2171 | endfunc |
| 2172 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 2173 | " Test for 'wildmode' |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 2174 | func Wildmode_tests() |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 2175 | func T(a, c, p) |
| 2176 | return "oneA\noneB\noneC" |
| 2177 | endfunc |
| 2178 | command -nargs=1 -complete=custom,T MyCmd |
| 2179 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 2180 | set nowildmenu |
| 2181 | set wildmode=full,list |
| 2182 | let g:Sline = '' |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 2183 | call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt') |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 2184 | call assert_equal('oneA oneB oneC', g:Sline) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 2185 | call assert_equal('"MyCmd oneA', @:) |
| 2186 | |
| 2187 | set wildmode=longest,full |
| 2188 | call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') |
| 2189 | call assert_equal('"MyCmd one', @:) |
| 2190 | call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt') |
| 2191 | call assert_equal('"MyCmd oneC', @:) |
| 2192 | |
| 2193 | set wildmode=longest |
| 2194 | call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt') |
| 2195 | call assert_equal('"MyCmd one', @:) |
| 2196 | |
| 2197 | set wildmode=list:longest |
| 2198 | let g:Sline = '' |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 2199 | call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt') |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 2200 | call assert_equal('oneA oneB oneC', g:Sline) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 2201 | call assert_equal('"MyCmd one', @:) |
| 2202 | |
| 2203 | set wildmode="" |
| 2204 | call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt') |
| 2205 | call assert_equal('"MyCmd oneA', @:) |
| 2206 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 2207 | " Test for wildmode=longest with 'fileignorecase' set |
| 2208 | set wildmode=longest |
| 2209 | set fileignorecase |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 2210 | argadd AAA AAAA AAAAA |
| 2211 | call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt') |
| 2212 | call assert_equal('"buffer AAA', @:) |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 2213 | set fileignorecase& |
| 2214 | |
| 2215 | " Test for listing files with wildmode=list |
| 2216 | set wildmode=list |
| 2217 | let g:Sline = '' |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 2218 | call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt') |
Bram Moolenaar | 8dfcce3 | 2020-03-18 19:32:26 +0100 | [diff] [blame] | 2219 | call assert_equal('AAA AAAA AAAAA', g:Sline) |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 2220 | call assert_equal('"b A', @:) |
| 2221 | |
Girish Palya | 2bacc3e | 2025-03-02 22:55:57 +0100 | [diff] [blame] | 2222 | " When 'wildmenu' is not set, 'noselect' completes first item |
| 2223 | set wildmode=noselect |
| 2224 | call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') |
| 2225 | call assert_equal('"MyCmd oneA', @:) |
| 2226 | |
| 2227 | " When 'noselect' is present, do not complete first <tab>. |
| 2228 | set wildmenu |
| 2229 | set wildmode=noselect |
| 2230 | call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') |
| 2231 | call assert_equal('"MyCmd o', @:) |
| 2232 | call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt') |
| 2233 | call assert_equal('"MyCmd o', @:) |
| 2234 | call feedkeys(":MyCmd o\t\t\<C-Y>\<C-B>\"\<CR>", 'xt') |
| 2235 | call assert_equal('"MyCmd o', @:) |
| 2236 | |
| 2237 | " When 'full' is present, complete after first <tab>. |
| 2238 | set wildmode=noselect,full |
| 2239 | call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') |
| 2240 | call assert_equal('"MyCmd o', @:) |
| 2241 | call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt') |
| 2242 | call assert_equal('"MyCmd oneA', @:) |
| 2243 | call feedkeys(":MyCmd o\t\t\t\<C-B>\"\<CR>", 'xt') |
| 2244 | call assert_equal('"MyCmd oneB', @:) |
| 2245 | call feedkeys(":MyCmd o\t\t\t\<C-Y>\<C-B>\"\<CR>", 'xt') |
| 2246 | call assert_equal('"MyCmd oneB', @:) |
| 2247 | |
| 2248 | " 'noselect' has no effect when 'longest' is present. |
| 2249 | set wildmode=noselect:longest |
| 2250 | call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') |
| 2251 | call assert_equal('"MyCmd one', @:) |
| 2252 | |
| 2253 | " Complete 'noselect' value in 'wildmode' option |
| 2254 | set wildmode& |
| 2255 | call feedkeys(":set wildmode=n\t\<C-B>\"\<CR>", 'xt') |
| 2256 | call assert_equal('"set wildmode=noselect', @:) |
| 2257 | call feedkeys(":set wildmode=\t\t\t\t\t\<C-B>\"\<CR>", 'xt') |
| 2258 | call assert_equal('"set wildmode=noselect', @:) |
| 2259 | |
Yegappan Lakshmanan | 4d03d87 | 2022-02-13 11:45:09 +0000 | [diff] [blame] | 2260 | " when using longest completion match, matches shorter than the argument |
| 2261 | " should be ignored (happens with :help) |
| 2262 | set wildmode=longest,full |
Yegappan Lakshmanan | 4d03d87 | 2022-02-13 11:45:09 +0000 | [diff] [blame] | 2263 | call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt') |
| 2264 | call assert_equal('"help a', @:) |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 2265 | " non existing file |
| 2266 | call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt') |
| 2267 | call assert_equal('"e a1b2y3z4', @:) |
Yegappan Lakshmanan | 4d03d87 | 2022-02-13 11:45:09 +0000 | [diff] [blame] | 2268 | |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 2269 | " Test for longest file name completion with 'fileignorecase' |
| 2270 | " On MS-Windows, file names are case insensitive. |
| 2271 | if has('unix') |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 2272 | call writefile([], 'XTESTfoo', 'D') |
| 2273 | call writefile([], 'Xtestbar', 'D') |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 2274 | set nofileignorecase |
| 2275 | call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt') |
| 2276 | call assert_equal('"e XTESTfoo', @:) |
| 2277 | call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt') |
| 2278 | call assert_equal('"e Xtestbar', @:) |
| 2279 | set fileignorecase |
| 2280 | call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt') |
| 2281 | call assert_equal('"e Xtest', @:) |
| 2282 | call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt') |
| 2283 | call assert_equal('"e Xtest', @:) |
| 2284 | set fileignorecase& |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 2285 | endif |
| 2286 | |
Girish Palya | 2bacc3e | 2025-03-02 22:55:57 +0100 | [diff] [blame] | 2287 | " If 'noselect' is present, single item menu should not insert item |
| 2288 | func! T(a, c, p) |
| 2289 | return "oneA" |
| 2290 | endfunc |
| 2291 | command! -nargs=1 -complete=custom,T MyCmd |
| 2292 | set wildmode=noselect,full |
| 2293 | call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') |
| 2294 | call assert_equal('"MyCmd o', @:) |
| 2295 | call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt') |
| 2296 | call assert_equal('"MyCmd oneA', @:) |
| 2297 | " 'nowildmenu' should make 'noselect' ineffective |
| 2298 | set nowildmenu |
| 2299 | call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt') |
| 2300 | call assert_equal('"MyCmd oneA', @:) |
| 2301 | |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 2302 | %argdelete |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 2303 | delcommand MyCmd |
| 2304 | delfunc T |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 2305 | set wildmode& |
Bram Moolenaar | 24ebd83 | 2020-03-16 21:25:24 +0100 | [diff] [blame] | 2306 | %bwipe! |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 2307 | endfunc |
| 2308 | |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 2309 | func Test_wildmode() |
| 2310 | " Test with utf-8 encoding |
| 2311 | call Wildmode_tests() |
| 2312 | |
| 2313 | " Test with latin1 encoding |
| 2314 | let save_encoding = &encoding |
| 2315 | set encoding=latin1 |
| 2316 | call Wildmode_tests() |
| 2317 | let &encoding = save_encoding |
| 2318 | endfunc |
| 2319 | |
Bram Moolenaar | da6d42c | 2022-03-17 11:46:55 +0000 | [diff] [blame] | 2320 | func Test_custom_complete_autoload() |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 2321 | call mkdir('Xcustdir/autoload', 'pR') |
Bram Moolenaar | da6d42c | 2022-03-17 11:46:55 +0000 | [diff] [blame] | 2322 | let save_rtp = &rtp |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 2323 | exe 'set rtp=' .. getcwd() .. '/Xcustdir' |
Bram Moolenaar | da6d42c | 2022-03-17 11:46:55 +0000 | [diff] [blame] | 2324 | let lines =<< trim END |
| 2325 | func vim8#Complete(a, c, p) |
| 2326 | return "oneA\noneB\noneC" |
| 2327 | endfunc |
| 2328 | END |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 2329 | call writefile(lines, 'Xcustdir/autoload/vim8.vim') |
Bram Moolenaar | da6d42c | 2022-03-17 11:46:55 +0000 | [diff] [blame] | 2330 | |
| 2331 | command -nargs=1 -complete=custom,vim8#Complete MyCmd |
| 2332 | set nowildmenu |
| 2333 | set wildmode=full,list |
| 2334 | call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt') |
| 2335 | call assert_equal('"MyCmd oneA oneB oneC', @:) |
| 2336 | |
| 2337 | let &rtp = save_rtp |
| 2338 | set wildmode& wildmenu& |
| 2339 | delcommand MyCmd |
Bram Moolenaar | da6d42c | 2022-03-17 11:46:55 +0000 | [diff] [blame] | 2340 | endfunc |
| 2341 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 2342 | " Test for interrupting the command-line completion |
| 2343 | func Test_interrupt_compl() |
| 2344 | func F(lead, cmdl, p) |
| 2345 | if a:lead =~ 'tw' |
| 2346 | call interrupt() |
| 2347 | return |
| 2348 | endif |
| 2349 | return "one\ntwo\nthree" |
| 2350 | endfunc |
| 2351 | command -nargs=1 -complete=custom,F Tcmd |
| 2352 | |
| 2353 | set nowildmenu |
| 2354 | set wildmode=full |
| 2355 | let interrupted = 0 |
| 2356 | try |
| 2357 | call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt') |
| 2358 | catch /^Vim:Interrupt$/ |
| 2359 | let interrupted = 1 |
| 2360 | endtry |
| 2361 | call assert_equal(1, interrupted) |
| 2362 | |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 2363 | let interrupted = 0 |
| 2364 | try |
| 2365 | call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt') |
| 2366 | catch /^Vim:Interrupt$/ |
| 2367 | let interrupted = 1 |
| 2368 | endtry |
| 2369 | call assert_equal(1, interrupted) |
| 2370 | |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 2371 | delcommand Tcmd |
| 2372 | delfunc F |
| 2373 | set wildmode& |
| 2374 | endfunc |
| 2375 | |
Bram Moolenaar | d30ae2f | 2020-02-29 14:23:58 +0100 | [diff] [blame] | 2376 | " Test for moving the cursor on the : command line |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 2377 | func Test_cmdline_edit() |
Bram Moolenaar | d30ae2f | 2020-02-29 14:23:58 +0100 | [diff] [blame] | 2378 | let str = ":one two\<C-U>" |
| 2379 | let str ..= "one two\<C-W>\<C-W>" |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 2380 | let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" |
Bram Moolenaar | d30ae2f | 2020-02-29 14:23:58 +0100 | [diff] [blame] | 2381 | let str ..= "\<Left>five\<Right>" |
| 2382 | let str ..= "\<Home>two " |
| 2383 | let str ..= "\<C-Left>one " |
| 2384 | let str ..= "\<C-Right> three" |
| 2385 | let str ..= "\<End>\<S-Left>four " |
| 2386 | let str ..= "\<S-Right> six" |
| 2387 | let str ..= "\<C-B>\"\<C-E> seven\<CR>" |
| 2388 | call feedkeys(str, 'xt') |
| 2389 | call assert_equal("\"one two three four five six seven", @:) |
| 2390 | endfunc |
| 2391 | |
| 2392 | " Test for moving the cursor on the / command line in 'rightleft' mode |
| 2393 | func Test_cmdline_edit_rightleft() |
| 2394 | CheckFeature rightleft |
| 2395 | set rightleft |
| 2396 | set rightleftcmd=search |
| 2397 | let str = "/one two\<C-U>" |
| 2398 | let str ..= "one two\<C-W>\<C-W>" |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 2399 | let str ..= "four\<BS>\<C-H>\<Del>\<kDel>" |
Bram Moolenaar | d30ae2f | 2020-02-29 14:23:58 +0100 | [diff] [blame] | 2400 | let str ..= "\<Right>five\<Left>" |
| 2401 | let str ..= "\<Home>two " |
| 2402 | let str ..= "\<C-Right>one " |
| 2403 | let str ..= "\<C-Left> three" |
| 2404 | let str ..= "\<End>\<S-Right>four " |
| 2405 | let str ..= "\<S-Left> six" |
| 2406 | let str ..= "\<C-B>\"\<C-E> seven\<CR>" |
| 2407 | call assert_fails("call feedkeys(str, 'xt')", 'E486:') |
| 2408 | call assert_equal("\"one two three four five six seven", @/) |
| 2409 | set rightleftcmd& |
| 2410 | set rightleft& |
| 2411 | endfunc |
| 2412 | |
| 2413 | " Test for using <C-\>e in the command line to evaluate an expression |
| 2414 | func Test_cmdline_expr() |
| 2415 | " Evaluate an expression from the beginning of a command line |
| 2416 | call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt') |
| 2417 | call assert_equal('"hello', @:) |
| 2418 | |
| 2419 | " Use an invalid expression for <C-\>e |
| 2420 | call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")') |
| 2421 | |
| 2422 | " Insert literal <CTRL-\> in the command line |
| 2423 | call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt') |
| 2424 | call assert_equal("\"e \<C-\>\<C-Y>", @:) |
Bram Moolenaar | 578fe94 | 2020-02-27 21:32:51 +0100 | [diff] [blame] | 2425 | endfunc |
| 2426 | |
Bram Moolenaar | 6046ade | 2022-06-22 13:51:54 +0100 | [diff] [blame] | 2427 | " This was making the insert position negative |
| 2428 | func Test_cmdline_expr_register() |
| 2429 | exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>" |
| 2430 | endfunc |
| 2431 | |
Bram Moolenaar | 0546d7d | 2020-03-01 16:53:09 +0100 | [diff] [blame] | 2432 | " Test for 'imcmdline' and 'imsearch' |
| 2433 | " This test doesn't actually test the input method functionality. |
| 2434 | func Test_cmdline_inputmethod() |
| 2435 | new |
| 2436 | call setline(1, ['', 'abc', '']) |
| 2437 | set imcmdline |
| 2438 | |
| 2439 | call feedkeys(":\"abc\<CR>", 'xt') |
| 2440 | call assert_equal("\"abc", @:) |
| 2441 | call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt') |
| 2442 | call assert_equal("\"abc", @:) |
| 2443 | call feedkeys("/abc\<CR>", 'xt') |
| 2444 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 2445 | call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') |
| 2446 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 2447 | |
| 2448 | set imsearch=2 |
| 2449 | call cursor(1, 1) |
| 2450 | call feedkeys("/abc\<CR>", 'xt') |
| 2451 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 2452 | call cursor(1, 1) |
| 2453 | call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') |
| 2454 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 2455 | set imdisable |
| 2456 | call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt') |
| 2457 | call assert_equal([2, 1], [line('.'), col('.')]) |
| 2458 | set imdisable& |
| 2459 | set imsearch& |
| 2460 | |
| 2461 | set imcmdline& |
| 2462 | %bwipe! |
| 2463 | endfunc |
| 2464 | |
Bram Moolenaar | 91ffc8a | 2020-03-02 20:54:22 +0100 | [diff] [blame] | 2465 | " Test for using CTRL-_ in the command line with 'allowrevins' |
| 2466 | func Test_cmdline_revins() |
| 2467 | CheckNotMSWindows |
| 2468 | CheckFeature rightleft |
| 2469 | call feedkeys(":\"abc\<c-_>\<cr>", 'xt') |
| 2470 | call assert_equal("\"abc\<c-_>", @:) |
| 2471 | set allowrevins |
| 2472 | call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt') |
| 2473 | call assert_equal('"abcñèæ', @:) |
| 2474 | set allowrevins& |
| 2475 | endfunc |
| 2476 | |
| 2477 | " Test for typing UTF-8 composing characters in the command line |
| 2478 | func Test_cmdline_composing_chars() |
| 2479 | call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt') |
| 2480 | call assert_equal('"ゔ', @:) |
| 2481 | endfunc |
| 2482 | |
Bram Moolenaar | 0e71704 | 2020-04-27 19:29:01 +0200 | [diff] [blame] | 2483 | " test that ";" works to find a match at the start of the first line |
| 2484 | func Test_zero_line_search() |
| 2485 | new |
| 2486 | call setline(1, ["1, pattern", "2, ", "3, pattern"]) |
| 2487 | call cursor(1,1) |
| 2488 | 0;/pattern/d |
| 2489 | call assert_equal(["2, ", "3, pattern"], getline(1,'$')) |
| 2490 | q! |
| 2491 | endfunc |
| 2492 | |
Bram Moolenaar | c8cb883 | 2020-06-18 21:14:30 +0200 | [diff] [blame] | 2493 | func Test_read_shellcmd() |
| 2494 | CheckUnix |
| 2495 | if executable('ls') |
| 2496 | " There should be ls in the $PATH |
| 2497 | call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx') |
| 2498 | call assert_match('^"r! .*\<ls\>', @:) |
| 2499 | endif |
| 2500 | |
| 2501 | if executable('rm') |
| 2502 | call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx') |
| 2503 | call assert_notmatch('^"r!.*\<runtest.vim\>', @:) |
| 2504 | call assert_match('^"r!.*\<rm\>', @:) |
Bram Moolenaar | 743d062 | 2020-07-03 18:15:06 +0200 | [diff] [blame] | 2505 | |
| 2506 | call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx') |
| 2507 | call assert_notmatch('^"r.*\<runtest.vim\>', @:) |
| 2508 | call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:) |
Bram Moolenaar | c8cb883 | 2020-06-18 21:14:30 +0200 | [diff] [blame] | 2509 | endif |
| 2510 | endfunc |
| 2511 | |
Bram Moolenaar | 4b2ce12 | 2020-11-21 21:41:41 +0100 | [diff] [blame] | 2512 | " Test for going up and down the directory tree using 'wildmenu' |
| 2513 | func Test_wildmenu_dirstack() |
| 2514 | CheckUnix |
| 2515 | %bw! |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 2516 | call mkdir('Xwildmenu/dir2/dir3/dir4', 'pR') |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 2517 | call writefile([], 'Xwildmenu/file1_1.txt') |
| 2518 | call writefile([], 'Xwildmenu/file1_2.txt') |
| 2519 | call writefile([], 'Xwildmenu/dir2/file2_1.txt') |
| 2520 | call writefile([], 'Xwildmenu/dir2/file2_2.txt') |
| 2521 | call writefile([], 'Xwildmenu/dir2/dir3/file3_1.txt') |
| 2522 | call writefile([], 'Xwildmenu/dir2/dir3/file3_2.txt') |
| 2523 | call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_1.txt') |
| 2524 | call writefile([], 'Xwildmenu/dir2/dir3/dir4/file4_2.txt') |
Bram Moolenaar | 4b2ce12 | 2020-11-21 21:41:41 +0100 | [diff] [blame] | 2525 | set wildmenu |
| 2526 | |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 2527 | cd Xwildmenu/dir2/dir3/dir4 |
Bram Moolenaar | 4b2ce12 | 2020-11-21 21:41:41 +0100 | [diff] [blame] | 2528 | call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt') |
Yegappan Lakshmanan | b31aec3 | 2022-02-16 12:44:29 +0000 | [diff] [blame] | 2529 | call assert_equal('"e file4_1.txt', @:) |
Bram Moolenaar | 4b2ce12 | 2020-11-21 21:41:41 +0100 | [diff] [blame] | 2530 | call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt') |
Yegappan Lakshmanan | b31aec3 | 2022-02-16 12:44:29 +0000 | [diff] [blame] | 2531 | call assert_equal('"e ../dir4/', @:) |
Bram Moolenaar | 4b2ce12 | 2020-11-21 21:41:41 +0100 | [diff] [blame] | 2532 | call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt') |
Yegappan Lakshmanan | b31aec3 | 2022-02-16 12:44:29 +0000 | [diff] [blame] | 2533 | call assert_equal('"e ../../dir3/', @:) |
| 2534 | call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt') |
| 2535 | call assert_equal('"e ../../../dir2/', @:) |
Bram Moolenaar | 4b2ce12 | 2020-11-21 21:41:41 +0100 | [diff] [blame] | 2536 | call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt') |
Yegappan Lakshmanan | b31aec3 | 2022-02-16 12:44:29 +0000 | [diff] [blame] | 2537 | call assert_equal('"e ../../dir3/dir4/', @:) |
Bram Moolenaar | 4b2ce12 | 2020-11-21 21:41:41 +0100 | [diff] [blame] | 2538 | call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt') |
Yegappan Lakshmanan | b31aec3 | 2022-02-16 12:44:29 +0000 | [diff] [blame] | 2539 | call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:) |
Bram Moolenaar | 4b2ce12 | 2020-11-21 21:41:41 +0100 | [diff] [blame] | 2540 | cd - |
Bram Moolenaar | 3b0d70f | 2022-08-29 22:31:20 +0100 | [diff] [blame] | 2541 | call feedkeys(":e Xwildmenu/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt') |
| 2542 | call assert_equal('"e Xwildmenu/dir2/dir3/dir4/file4_1.txt', @:) |
Yegappan Lakshmanan | b31aec3 | 2022-02-16 12:44:29 +0000 | [diff] [blame] | 2543 | |
Bram Moolenaar | 4b2ce12 | 2020-11-21 21:41:41 +0100 | [diff] [blame] | 2544 | set wildmenu& |
| 2545 | endfunc |
| 2546 | |
obcat | 71c6f7a | 2021-05-13 20:23:10 +0200 | [diff] [blame] | 2547 | " Test for recalling newer or older cmdline from history with <Up>, <Down>, |
Yegappan Lakshmanan | 155b088 | 2022-03-17 13:03:09 +0000 | [diff] [blame] | 2548 | " <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or |
| 2549 | " <C-n>. |
obcat | 71c6f7a | 2021-05-13 20:23:10 +0200 | [diff] [blame] | 2550 | func Test_recalling_cmdline() |
| 2551 | CheckFeature cmdline_hist |
| 2552 | |
| 2553 | let g:cmdlines = [] |
| 2554 | cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR> |
| 2555 | |
| 2556 | let histories = [ |
Yegappan Lakshmanan | 155b088 | 2022-03-17 13:03:09 +0000 | [diff] [blame] | 2557 | \ #{name: 'cmd', enter: ':', exit: "\<Esc>"}, |
| 2558 | \ #{name: 'search', enter: '/', exit: "\<Esc>"}, |
| 2559 | \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"}, |
| 2560 | \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"}, |
obcat | 71c6f7a | 2021-05-13 20:23:10 +0200 | [diff] [blame] | 2561 | "\ TODO: {'name': 'debug', ...} |
| 2562 | \] |
| 2563 | let keypairs = [ |
Yegappan Lakshmanan | 155b088 | 2022-03-17 13:03:09 +0000 | [diff] [blame] | 2564 | \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true}, |
| 2565 | \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false}, |
| 2566 | \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false}, |
| 2567 | \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false}, |
| 2568 | \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false}, |
obcat | 71c6f7a | 2021-05-13 20:23:10 +0200 | [diff] [blame] | 2569 | \] |
| 2570 | let prefix = 'vi' |
| 2571 | for h in histories |
| 2572 | call histadd(h.name, 'vim') |
| 2573 | call histadd(h.name, 'virtue') |
| 2574 | call histadd(h.name, 'Virgo') |
| 2575 | call histadd(h.name, 'vogue') |
| 2576 | call histadd(h.name, 'emacs') |
| 2577 | for k in keypairs |
| 2578 | let g:cmdlines = [] |
| 2579 | let keyseqs = h.enter |
| 2580 | \ .. prefix |
| 2581 | \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2) |
| 2582 | \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2) |
| 2583 | \ .. h.exit |
| 2584 | call feedkeys(keyseqs, 'xt') |
| 2585 | call histdel(h.name, -1) " delete the history added by feedkeys above |
| 2586 | let expect = k.prefixmatch |
| 2587 | \ ? ['virtue', 'vim', 'virtue', prefix] |
| 2588 | \ : ['emacs', 'vogue', 'emacs', prefix] |
| 2589 | call assert_equal(expect, g:cmdlines) |
| 2590 | endfor |
| 2591 | endfor |
| 2592 | |
| 2593 | unlet g:cmdlines |
| 2594 | cunmap <Plug>(save-cmdline) |
| 2595 | endfunc |
| 2596 | |
Bram Moolenaar | 847fe7d | 2021-05-15 13:19:16 +0200 | [diff] [blame] | 2597 | func Test_cmd_map_cmdlineChanged() |
| 2598 | let g:log = [] |
| 2599 | cnoremap <F1> l<Cmd><CR>s |
zeertzjq | 094dd15 | 2023-06-15 22:51:57 +0100 | [diff] [blame] | 2600 | augroup test_CmdlineChanged |
Bram Moolenaar | 847fe7d | 2021-05-15 13:19:16 +0200 | [diff] [blame] | 2601 | autocmd! |
| 2602 | autocmd CmdlineChanged : let g:log += [getcmdline()] |
| 2603 | augroup END |
| 2604 | |
| 2605 | call feedkeys(":\<F1>\<CR>", 'xt') |
| 2606 | call assert_equal(['l', 'ls'], g:log) |
| 2607 | |
Bram Moolenaar | 796139a | 2021-05-18 21:38:45 +0200 | [diff] [blame] | 2608 | let @b = 'b' |
| 2609 | cnoremap <F1> a<C-R>b |
| 2610 | let g:log = [] |
| 2611 | call feedkeys(":\<F1>\<CR>", 'xt') |
| 2612 | call assert_equal(['a', 'ab'], g:log) |
| 2613 | |
Bram Moolenaar | 847fe7d | 2021-05-15 13:19:16 +0200 | [diff] [blame] | 2614 | unlet g:log |
| 2615 | cunmap <F1> |
zeertzjq | 094dd15 | 2023-06-15 22:51:57 +0100 | [diff] [blame] | 2616 | augroup test_CmdlineChanged |
Bram Moolenaar | 847fe7d | 2021-05-15 13:19:16 +0200 | [diff] [blame] | 2617 | autocmd! |
| 2618 | augroup END |
zeertzjq | 094dd15 | 2023-06-15 22:51:57 +0100 | [diff] [blame] | 2619 | augroup! test_CmdlineChanged |
Bram Moolenaar | 847fe7d | 2021-05-15 13:19:16 +0200 | [diff] [blame] | 2620 | endfunc |
| 2621 | |
Yegappan Lakshmanan | 46aa6f9 | 2021-05-19 17:15:04 +0200 | [diff] [blame] | 2622 | " Test for the 'suffixes' option |
| 2623 | func Test_suffixes_opt() |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 2624 | call writefile([], 'Xsuffile', 'D') |
| 2625 | call writefile([], 'Xsuffile.c', 'D') |
| 2626 | call writefile([], 'Xsuffile.o', 'D') |
Yegappan Lakshmanan | 46aa6f9 | 2021-05-19 17:15:04 +0200 | [diff] [blame] | 2627 | set suffixes= |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 2628 | call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt') |
| 2629 | call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:) |
| 2630 | call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 2631 | call assert_equal('"e Xsuffile.c', @:) |
Yegappan Lakshmanan | 46aa6f9 | 2021-05-19 17:15:04 +0200 | [diff] [blame] | 2632 | set suffixes=.c |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 2633 | call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt') |
| 2634 | call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:) |
| 2635 | call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 2636 | call assert_equal('"e Xsuffile.o', @:) |
Yegappan Lakshmanan | 46aa6f9 | 2021-05-19 17:15:04 +0200 | [diff] [blame] | 2637 | set suffixes=,, |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 2638 | call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt') |
| 2639 | call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:) |
| 2640 | call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 2641 | call assert_equal('"e Xsuffile.o', @:) |
Yegappan Lakshmanan | 46aa6f9 | 2021-05-19 17:15:04 +0200 | [diff] [blame] | 2642 | set suffixes& |
Yegappan Lakshmanan | 9773db6 | 2022-02-14 11:10:59 +0000 | [diff] [blame] | 2643 | " Test for getcompletion() with different patterns |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 2644 | call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file')) |
| 2645 | call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file')) |
Yegappan Lakshmanan | 46aa6f9 | 2021-05-19 17:15:04 +0200 | [diff] [blame] | 2646 | endfunc |
Bram Moolenaar | 847fe7d | 2021-05-15 13:19:16 +0200 | [diff] [blame] | 2647 | |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2648 | " Test for using a popup menu for the command line completion matches |
| 2649 | " (wildoptions=pum) |
| 2650 | func Test_wildmenu_pum() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2651 | CheckScreendump |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2652 | CheckRunVimInTerminal |
| 2653 | |
| 2654 | let commands =<< trim [CODE] |
| 2655 | set wildmenu |
| 2656 | set wildoptions=pum |
| 2657 | set shm+=I |
| 2658 | set noruler |
| 2659 | set noshowcmd |
Yegappan Lakshmanan | 560dff4 | 2022-02-10 19:52:10 +0000 | [diff] [blame] | 2660 | |
| 2661 | func CmdCompl(a, b, c) |
| 2662 | return repeat(['aaaa'], 120) |
| 2663 | endfunc |
| 2664 | command -nargs=* -complete=customlist,CmdCompl Tcmd |
Bram Moolenaar | 481acb1 | 2022-02-11 18:51:45 +0000 | [diff] [blame] | 2665 | |
| 2666 | func MyStatusLine() abort |
| 2667 | return 'status' |
| 2668 | endfunc |
| 2669 | func SetupStatusline() |
| 2670 | set statusline=%!MyStatusLine() |
| 2671 | set laststatus=2 |
| 2672 | endfunc |
Bram Moolenaar | e4835bf | 2022-02-14 19:17:53 +0000 | [diff] [blame] | 2673 | |
| 2674 | func MyTabLine() |
| 2675 | return 'my tab line' |
| 2676 | endfunc |
| 2677 | func SetupTabline() |
| 2678 | set statusline= |
| 2679 | set tabline=%!MyTabLine() |
| 2680 | set showtabline=2 |
| 2681 | endfunc |
Bram Moolenaar | 5c52be4 | 2022-02-27 14:28:31 +0000 | [diff] [blame] | 2682 | |
| 2683 | func DoFeedKeys() |
| 2684 | let &wildcharm = char2nr("\t") |
| 2685 | call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>") |
| 2686 | endfunc |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2687 | [CODE] |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 2688 | call writefile(commands, 'Xtest', 'D') |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2689 | |
| 2690 | let buf = RunVimInTerminal('-S Xtest', #{rows: 10}) |
| 2691 | |
| 2692 | call term_sendkeys(buf, ":sign \<Tab>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2693 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {}) |
| 2694 | |
Yegappan Lakshmanan | 560dff4 | 2022-02-10 19:52:10 +0000 | [diff] [blame] | 2695 | " going down the popup menu using <Down> |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2696 | call term_sendkeys(buf, "\<Down>\<Down>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2697 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {}) |
| 2698 | |
Yegappan Lakshmanan | 560dff4 | 2022-02-10 19:52:10 +0000 | [diff] [blame] | 2699 | " going down the popup menu using <C-N> |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2700 | call term_sendkeys(buf, "\<C-N>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2701 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {}) |
| 2702 | |
Yegappan Lakshmanan | 560dff4 | 2022-02-10 19:52:10 +0000 | [diff] [blame] | 2703 | " going up the popup menu using <C-P> |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2704 | call term_sendkeys(buf, "\<C-P>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2705 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {}) |
| 2706 | |
Yegappan Lakshmanan | 560dff4 | 2022-02-10 19:52:10 +0000 | [diff] [blame] | 2707 | " going up the popup menu using <Up> |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2708 | call term_sendkeys(buf, "\<Up>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2709 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {}) |
| 2710 | |
| 2711 | " pressing <C-E> should end completion and go back to the original match |
| 2712 | call term_sendkeys(buf, "\<C-E>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2713 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {}) |
| 2714 | |
| 2715 | " pressing <C-Y> should select the current match and end completion |
| 2716 | call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2717 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {}) |
| 2718 | |
| 2719 | " With 'wildmode' set to 'longest,full', completing a match should display |
| 2720 | " the longest match, the wildmenu should not be displayed. |
| 2721 | call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>") |
| 2722 | call TermWait(buf) |
| 2723 | call term_sendkeys(buf, ":sign u\<Tab>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2724 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {}) |
| 2725 | |
| 2726 | " pressing <Tab> should display the wildmenu |
| 2727 | call term_sendkeys(buf, "\<Tab>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2728 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {}) |
| 2729 | |
| 2730 | " pressing <Tab> second time should select the next entry in the menu |
| 2731 | call term_sendkeys(buf, "\<Tab>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2732 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {}) |
| 2733 | |
| 2734 | call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>") |
Yegappan Lakshmanan | 560dff4 | 2022-02-10 19:52:10 +0000 | [diff] [blame] | 2735 | " showing popup menu in different columns in the cmdline |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2736 | call term_sendkeys(buf, ":sign define \<Tab>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2737 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {}) |
| 2738 | |
| 2739 | call term_sendkeys(buf, " \<Tab>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2740 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {}) |
| 2741 | |
| 2742 | call term_sendkeys(buf, " \<Tab>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2743 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {}) |
| 2744 | |
| 2745 | " Directory name completion |
Dominique Pelle | febe138 | 2022-09-14 12:51:49 +0100 | [diff] [blame] | 2746 | call mkdir('Xnamedir/XdirA/XdirB', 'pR') |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 2747 | call writefile([], 'Xnamedir/XfileA') |
| 2748 | call writefile([], 'Xnamedir/XdirA/XfileB') |
| 2749 | call writefile([], 'Xnamedir/XdirA/XdirB/XfileC') |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2750 | |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 2751 | call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2752 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {}) |
| 2753 | |
| 2754 | " Pressing <Right> on a directory name should go into that directory |
| 2755 | call term_sendkeys(buf, "\<Right>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2756 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {}) |
| 2757 | |
| 2758 | " Pressing <Left> on a directory name should go to the parent directory |
| 2759 | call term_sendkeys(buf, "\<Left>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2760 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {}) |
| 2761 | |
| 2762 | " 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] | 2763 | " matches but the popup menu should still remain |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2764 | call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2765 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {}) |
| 2766 | |
| 2767 | " Pressing <C-D> when the popup menu is displayed should remove the popup |
| 2768 | " menu |
| 2769 | call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2770 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {}) |
| 2771 | |
| 2772 | " Pressing <S-Tab> should open the popup menu with the last entry selected |
| 2773 | call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2774 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {}) |
| 2775 | |
| 2776 | " Pressing <Esc> should close the popup menu and cancel the cmd line |
| 2777 | call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2778 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {}) |
| 2779 | |
| 2780 | " Typing a character when the popup is open, should close the popup |
| 2781 | call term_sendkeys(buf, ":sign \<Tab>x") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2782 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {}) |
| 2783 | |
| 2784 | " When the popup is open, entering the cmdline window should close the popup |
| 2785 | call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2786 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {}) |
| 2787 | call term_sendkeys(buf, ":q\<CR>") |
| 2788 | |
| 2789 | " After the last popup menu item, <C-N> should show the original string |
| 2790 | call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2791 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {}) |
| 2792 | |
| 2793 | " Use the popup menu for the command name |
| 2794 | call term_sendkeys(buf, "\<C-U>bu\<Tab>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2795 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {}) |
| 2796 | |
| 2797 | " Pressing the left arrow should remove the popup menu |
| 2798 | call term_sendkeys(buf, "\<Left>\<Left>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2799 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {}) |
| 2800 | |
| 2801 | " Pressing <BS> should remove the popup menu and erase the last character |
| 2802 | call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2803 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {}) |
| 2804 | |
| 2805 | " Pressing <C-W> should remove the popup menu and erase the previous word |
| 2806 | call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2807 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {}) |
| 2808 | |
| 2809 | " Pressing <C-U> should remove the popup menu and erase the entire line |
| 2810 | call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2811 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {}) |
| 2812 | |
| 2813 | " Using <C-E> to cancel the popup menu and then pressing <Up> should recall |
| 2814 | " the cmdline from history |
| 2815 | call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>") |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2816 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {}) |
| 2817 | |
Bram Moolenaar | 73a16c2 | 2022-02-08 17:40:36 +0000 | [diff] [blame] | 2818 | " Check "list" still works |
| 2819 | call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>") |
| 2820 | call term_sendkeys(buf, ":cn\<Tab>") |
Bram Moolenaar | 73a16c2 | 2022-02-08 17:40:36 +0000 | [diff] [blame] | 2821 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {}) |
| 2822 | call term_sendkeys(buf, "s") |
Bram Moolenaar | 73a16c2 | 2022-02-08 17:40:36 +0000 | [diff] [blame] | 2823 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {}) |
| 2824 | |
rbtnn | 68cc2b8 | 2022-02-09 11:55:47 +0000 | [diff] [blame] | 2825 | " Tests a directory name contained full-width characters. |
Dominique Pelle | febe138 | 2022-09-14 12:51:49 +0100 | [diff] [blame] | 2826 | call mkdir('Xnamedir/あいう', 'p') |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 2827 | call writefile([], 'Xnamedir/あいう/abc') |
| 2828 | call writefile([], 'Xnamedir/あいう/xyz') |
| 2829 | call writefile([], 'Xnamedir/あいう/123') |
rbtnn | 68cc2b8 | 2022-02-09 11:55:47 +0000 | [diff] [blame] | 2830 | |
| 2831 | call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>") |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 2832 | call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>") |
rbtnn | 68cc2b8 | 2022-02-09 11:55:47 +0000 | [diff] [blame] | 2833 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {}) |
| 2834 | |
Yegappan Lakshmanan | 560dff4 | 2022-02-10 19:52:10 +0000 | [diff] [blame] | 2835 | " Pressing <C-A> when the popup menu is displayed should list all the |
| 2836 | " matches and pressing a key after that should remove the popup menu |
| 2837 | call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>") |
| 2838 | call term_sendkeys(buf, ":sign \<Tab>\<C-A>x") |
| 2839 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {}) |
| 2840 | |
| 2841 | " Pressing <C-A> when the popup menu is displayed should list all the |
| 2842 | " matches and pressing <Left> after that should move the cursor |
| 2843 | call term_sendkeys(buf, "\<C-U>abc\<Esc>") |
| 2844 | call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>") |
| 2845 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {}) |
| 2846 | |
| 2847 | " When <C-A> displays a lot of matches (screen scrolls), all the matches |
| 2848 | " should be displayed correctly on the screen. |
| 2849 | call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>") |
| 2850 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {}) |
| 2851 | |
| 2852 | " After using <C-A> to expand all the filename matches, pressing <Up> |
| 2853 | " should not open the popup menu again. |
Bram Moolenaar | 61abe7d | 2022-08-30 21:46:08 +0100 | [diff] [blame] | 2854 | call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>") |
Yegappan Lakshmanan | 560dff4 | 2022-02-10 19:52:10 +0000 | [diff] [blame] | 2855 | call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>") |
| 2856 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {}) |
| 2857 | call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>") |
| 2858 | |
| 2859 | " After using <C-A> to expand all the matches, pressing <S-Tab> used to |
| 2860 | " crash Vim |
| 2861 | call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>") |
| 2862 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {}) |
| 2863 | |
Bram Moolenaar | 414acd3 | 2022-02-10 21:09:45 +0000 | [diff] [blame] | 2864 | " After removing the pum the command line is redrawn |
| 2865 | call term_sendkeys(buf, ":edit foo\<CR>") |
| 2866 | call term_sendkeys(buf, ":edit bar\<CR>") |
| 2867 | call term_sendkeys(buf, ":ls\<CR>") |
| 2868 | call term_sendkeys(buf, ":com\<Tab> ") |
| 2869 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {}) |
Bram Moolenaar | 481acb1 | 2022-02-11 18:51:45 +0000 | [diff] [blame] | 2870 | call term_sendkeys(buf, "\<C-U>\<CR>") |
| 2871 | |
| 2872 | " Esc still works to abort the command when 'statusline' is set |
| 2873 | call term_sendkeys(buf, ":call SetupStatusline()\<CR>") |
| 2874 | call term_sendkeys(buf, ":si\<Tab>") |
| 2875 | call term_sendkeys(buf, "\<Esc>") |
| 2876 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {}) |
Bram Moolenaar | 414acd3 | 2022-02-10 21:09:45 +0000 | [diff] [blame] | 2877 | |
Bram Moolenaar | e4835bf | 2022-02-14 19:17:53 +0000 | [diff] [blame] | 2878 | " Esc still works to abort the command when 'tabline' is set |
| 2879 | call term_sendkeys(buf, ":call SetupTabline()\<CR>") |
| 2880 | call term_sendkeys(buf, ":si\<Tab>") |
| 2881 | call term_sendkeys(buf, "\<Esc>") |
| 2882 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {}) |
| 2883 | |
Bram Moolenaar | 5c52be4 | 2022-02-27 14:28:31 +0000 | [diff] [blame] | 2884 | " popup is cleared also when 'lazyredraw' is set |
| 2885 | call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>") |
| 2886 | call term_sendkeys(buf, ":call DoFeedKeys()\<CR>") |
| 2887 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {}) |
| 2888 | call term_sendkeys(buf, "\<Esc>") |
| 2889 | |
Yegappan Lakshmanan | 5cffa8d | 2022-03-16 13:33:53 +0000 | [diff] [blame] | 2890 | " Pressing <PageDown> should scroll the menu downward |
| 2891 | call term_sendkeys(buf, ":sign \<Tab>\<PageDown>") |
| 2892 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {}) |
| 2893 | call term_sendkeys(buf, "\<PageDown>") |
| 2894 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {}) |
| 2895 | call term_sendkeys(buf, "\<PageDown>") |
| 2896 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {}) |
| 2897 | call term_sendkeys(buf, "\<PageDown>") |
| 2898 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {}) |
| 2899 | call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>") |
| 2900 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {}) |
| 2901 | |
| 2902 | " Pressing <PageUp> should scroll the menu upward |
| 2903 | call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>") |
| 2904 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {}) |
| 2905 | call term_sendkeys(buf, "\<PageUp>") |
| 2906 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {}) |
| 2907 | call term_sendkeys(buf, "\<PageUp>") |
| 2908 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {}) |
| 2909 | call term_sendkeys(buf, "\<PageUp>") |
| 2910 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {}) |
| 2911 | |
Yee Cheng Chin | 209ec90 | 2023-10-17 10:56:25 +0200 | [diff] [blame] | 2912 | " pressing <C-E> to end completion should work in middle of the line too |
| 2913 | call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>") |
| 2914 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {}) |
| 2915 | call term_sendkeys(buf, "\<C-E>") |
| 2916 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {}) |
| 2917 | |
| 2918 | " pressing <C-Y> should select the current match and end completion |
| 2919 | call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>") |
| 2920 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {}) |
| 2921 | |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2922 | call term_sendkeys(buf, "\<C-U>\<CR>") |
| 2923 | call StopVimInTerminal(buf) |
Yegappan Lakshmanan | 3908ef5 | 2022-02-08 12:08:07 +0000 | [diff] [blame] | 2924 | endfunc |
| 2925 | |
Yegappan Lakshmanan | 560dff4 | 2022-02-10 19:52:10 +0000 | [diff] [blame] | 2926 | " Test for wildmenumode() with the cmdline popup menu |
| 2927 | func Test_wildmenumode_with_pum() |
| 2928 | set wildmenu |
| 2929 | set wildoptions=pum |
| 2930 | cnoremap <expr> <F2> wildmenumode() |
| 2931 | call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt') |
| 2932 | call assert_equal('"sign define10', @:) |
| 2933 | call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt') |
| 2934 | call assert_equal('"sign define jump list place undefine unplace0', @:) |
| 2935 | call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt') |
| 2936 | call assert_equal('"sign 0', @:) |
| 2937 | call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt') |
| 2938 | call assert_equal('"sign define0', @:) |
| 2939 | set nowildmenu wildoptions& |
| 2940 | cunmap <F2> |
| 2941 | endfunc |
| 2942 | |
Bram Moolenaar | 11a57df | 2022-04-11 19:38:56 +0100 | [diff] [blame] | 2943 | func Test_wildmenu_with_pum_foldexpr() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2944 | CheckScreendump |
Bram Moolenaar | 11a57df | 2022-04-11 19:38:56 +0100 | [diff] [blame] | 2945 | CheckRunVimInTerminal |
| 2946 | |
| 2947 | let lines =<< trim END |
| 2948 | call setline(1, ['folded one', 'folded two', 'some more text']) |
| 2949 | func MyFoldText() |
| 2950 | return 'foo' |
| 2951 | endfunc |
| 2952 | set foldtext=MyFoldText() wildoptions=pum |
| 2953 | normal ggzfj |
| 2954 | END |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 2955 | call writefile(lines, 'Xpumfold', 'D') |
Bram Moolenaar | 11a57df | 2022-04-11 19:38:56 +0100 | [diff] [blame] | 2956 | let buf = RunVimInTerminal('-S Xpumfold', #{rows: 10}) |
| 2957 | call term_sendkeys(buf, ":set\<Tab>") |
| 2958 | call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_1', {}) |
| 2959 | |
| 2960 | call term_sendkeys(buf, "\<Esc>") |
| 2961 | call VerifyScreenDump(buf, 'Test_wildmenu_with_pum_foldexpr_2', {}) |
| 2962 | |
| 2963 | call StopVimInTerminal(buf) |
Bram Moolenaar | 11a57df | 2022-04-11 19:38:56 +0100 | [diff] [blame] | 2964 | endfunc |
| 2965 | |
Yegappan Lakshmanan | 1104a6d | 2022-03-31 12:34:15 +0100 | [diff] [blame] | 2966 | " Test for opening the cmdline completion popup menu from the terminal window. |
| 2967 | " The popup menu should be positioned correctly over the status line of the |
| 2968 | " bottom-most window. |
| 2969 | func Test_wildmenu_pum_from_terminal() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2970 | CheckScreendump |
Yegappan Lakshmanan | 1104a6d | 2022-03-31 12:34:15 +0100 | [diff] [blame] | 2971 | CheckRunVimInTerminal |
| 2972 | let python = PythonProg() |
| 2973 | call CheckPython(python) |
| 2974 | |
| 2975 | %bw! |
| 2976 | let cmds = ['set wildmenu wildoptions=pum'] |
| 2977 | let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"' |
| 2978 | call add(cmds, "call term_start('" .. pcmd .. "')") |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 2979 | call writefile(cmds, 'Xtest', 'D') |
Yegappan Lakshmanan | 1104a6d | 2022-03-31 12:34:15 +0100 | [diff] [blame] | 2980 | let buf = RunVimInTerminal('-S Xtest', #{rows: 10}) |
| 2981 | call term_sendkeys(buf, "\r\r\r") |
| 2982 | call term_wait(buf) |
| 2983 | call term_sendkeys(buf, "\<C-W>:sign \<Tab>") |
| 2984 | call term_wait(buf) |
| 2985 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {}) |
| 2986 | call term_wait(buf) |
| 2987 | call StopVimInTerminal(buf) |
Yegappan Lakshmanan | 1104a6d | 2022-03-31 12:34:15 +0100 | [diff] [blame] | 2988 | endfunc |
| 2989 | |
Yee Cheng Chin | 8f4fb00 | 2023-10-17 10:06:56 +0200 | [diff] [blame] | 2990 | func Test_wildmenu_pum_odd_wildchar() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 2991 | CheckScreendump |
Bram Moolenaar | b9603f6 | 2022-12-08 15:44:22 +0000 | [diff] [blame] | 2992 | CheckRunVimInTerminal |
| 2993 | |
Yee Cheng Chin | 8f4fb00 | 2023-10-17 10:06:56 +0200 | [diff] [blame] | 2994 | " Test odd wildchar interactions with pum. Make sure they behave properly |
| 2995 | " 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] | 2996 | let lines =<< trim END |
| 2997 | set wildoptions=pum |
| 2998 | set wildchar=<C-E> |
| 2999 | END |
| 3000 | call writefile(lines, 'XwildmenuTest', 'D') |
| 3001 | let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10}) |
| 3002 | |
Yee Cheng Chin | 8f4fb00 | 2023-10-17 10:06:56 +0200 | [diff] [blame] | 3003 | call term_sendkeys(buf, ":\<C-E>") |
| 3004 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {}) |
Bram Moolenaar | 038e6d2 | 2022-12-08 12:00:50 +0000 | [diff] [blame] | 3005 | |
Yee Cheng Chin | 8f4fb00 | 2023-10-17 10:06:56 +0200 | [diff] [blame] | 3006 | " <C-E> being a wildchar takes priority over its original functionality |
| 3007 | call term_sendkeys(buf, "\<C-E>") |
| 3008 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {}) |
| 3009 | |
| 3010 | call term_sendkeys(buf, "\<Esc>") |
| 3011 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {}) |
| 3012 | |
| 3013 | " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape |
| 3014 | " command-line, and we need to make sure to clean up properly. |
| 3015 | call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>") |
| 3016 | call term_sendkeys(buf, ":\<Esc>") |
| 3017 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {}) |
| 3018 | |
| 3019 | call term_sendkeys(buf, "\<Esc>") |
| 3020 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {}) |
| 3021 | |
| 3022 | " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline |
| 3023 | " and we again need to make sure we clean up properly. |
| 3024 | call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>") |
| 3025 | call term_sendkeys(buf, ":\<C-\>\<C-\>") |
| 3026 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {}) |
| 3027 | |
| 3028 | call term_sendkeys(buf, "\<C-N>") |
| 3029 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {}) |
| 3030 | |
| 3031 | call StopVimInTerminal(buf) |
Bram Moolenaar | 038e6d2 | 2022-12-08 12:00:50 +0000 | [diff] [blame] | 3032 | endfunc |
| 3033 | |
zeertzjq | 883018f | 2024-06-15 15:37:11 +0200 | [diff] [blame] | 3034 | " Test that 'rightleft' should not affect cmdline completion popup menu. |
| 3035 | func Test_wildmenu_pum_rightleft() |
| 3036 | CheckFeature rightleft |
| 3037 | CheckScreendump |
| 3038 | |
| 3039 | let lines =<< trim END |
| 3040 | set wildoptions=pum |
| 3041 | set rightleft |
| 3042 | END |
| 3043 | call writefile(lines, 'Xwildmenu_pum_rl', 'D') |
| 3044 | let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50}) |
| 3045 | |
| 3046 | call term_sendkeys(buf, ":sign \<Tab>") |
| 3047 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {}) |
| 3048 | |
| 3049 | call StopVimInTerminal(buf) |
| 3050 | endfunc |
| 3051 | |
Girish Palya | 4ec46f3 | 2025-03-04 20:56:30 +0100 | [diff] [blame] | 3052 | " Test highlighting when pattern matches non-first character of item |
| 3053 | func Test_wildmenu_pum_hl_nonfirst() |
| 3054 | CheckScreendump |
| 3055 | let lines =<< trim END |
| 3056 | set wildoptions=pum wildchar=<tab> wildmode=noselect,full |
| 3057 | hi PmenuMatchSel ctermfg=6 ctermbg=7 |
| 3058 | hi PmenuMatch ctermfg=4 ctermbg=225 |
| 3059 | func T(a, c, p) |
| 3060 | return ["oneA", "o neBneB", "aoneC"] |
| 3061 | endfunc |
| 3062 | command -nargs=1 -complete=customlist,T MyCmd |
| 3063 | END |
| 3064 | |
| 3065 | call writefile(lines, 'Xwildmenu_pum_hl_nonf', 'D') |
| 3066 | let buf = RunVimInTerminal('-S Xwildmenu_pum_hl_nonf', #{rows: 10, cols: 50}) |
| 3067 | |
| 3068 | call term_sendkeys(buf, ":MyCmd ne\<tab>") |
| 3069 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_nonf', {}) |
| 3070 | call term_sendkeys(buf, "\<Esc>") |
| 3071 | call StopVimInTerminal(buf) |
| 3072 | endfunc |
| 3073 | |
zeertzjq | d8c9340 | 2024-06-17 18:25:32 +0200 | [diff] [blame] | 3074 | " Test highlighting matched text in cmdline completion popup menu. |
| 3075 | func Test_wildmenu_pum_hl_match() |
| 3076 | CheckScreendump |
| 3077 | |
| 3078 | let lines =<< trim END |
| 3079 | set wildoptions=pum,fuzzy |
| 3080 | hi PmenuMatchSel ctermfg=6 ctermbg=7 |
| 3081 | hi PmenuMatch ctermfg=4 ctermbg=225 |
| 3082 | END |
| 3083 | call writefile(lines, 'Xwildmenu_pum_hl', 'D') |
| 3084 | let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50}) |
| 3085 | |
| 3086 | call term_sendkeys(buf, ":sign plc\<Tab>") |
| 3087 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {}) |
| 3088 | call term_sendkeys(buf, "\<Tab>") |
| 3089 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {}) |
| 3090 | call term_sendkeys(buf, "\<Tab>") |
| 3091 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {}) |
| 3092 | call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>") |
| 3093 | call TermWait(buf) |
| 3094 | call term_sendkeys(buf, ":sign un\<Tab>") |
| 3095 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {}) |
| 3096 | call term_sendkeys(buf, "\<Tab>") |
| 3097 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {}) |
| 3098 | call term_sendkeys(buf, "\<Tab>") |
| 3099 | call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {}) |
| 3100 | call term_sendkeys(buf, "\<Esc>") |
| 3101 | |
| 3102 | call StopVimInTerminal(buf) |
| 3103 | endfunc |
| 3104 | |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 3105 | " Test for completion after a :substitute command followed by a pipe (|) |
| 3106 | " character |
| 3107 | func Test_cmdline_complete_substitute() |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 3108 | set wildchar=0 |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 3109 | call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt') |
| 3110 | call assert_equal("\"s | \t", @:) |
| 3111 | call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt') |
| 3112 | call assert_equal("\"s/ | \t", @:) |
| 3113 | call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt') |
| 3114 | call assert_equal("\"s/one | \t", @:) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 3115 | set wildchar& |
Yegappan Lakshmanan | e3846cf | 2022-02-15 11:35:54 +0000 | [diff] [blame] | 3116 | call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt') |
| 3117 | call assert_equal("\"s/one/ | \t", @:) |
| 3118 | call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt') |
| 3119 | call assert_equal("\"s/one/two | \t", @:) |
| 3120 | call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt') |
| 3121 | call assert_equal('"s/one/two/ | chistory', @:) |
| 3122 | call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt') |
| 3123 | call assert_equal("\"s/one/two/g \t", @:) |
| 3124 | call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt') |
| 3125 | call assert_equal("\"s/one/two/g | chistory", @:) |
| 3126 | call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt') |
| 3127 | call assert_equal("\"s/one/t\\/ | \t", @:) |
| 3128 | call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt') |
| 3129 | call assert_equal('"s/one/t"o/ | chistory', @:) |
| 3130 | call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt') |
| 3131 | call assert_equal('"s/one/t|o/ | chistory', @:) |
| 3132 | call feedkeys(":&\t\<C-B>\"\<CR>", 'xt') |
| 3133 | call assert_equal("\"&\t", @:) |
| 3134 | endfunc |
| 3135 | |
| 3136 | " Test for the :dlist command completion |
| 3137 | func Test_cmdline_complete_dlist() |
| 3138 | call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt') |
| 3139 | call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:) |
| 3140 | call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt') |
| 3141 | call assert_equal("\"dlist 10 /pat/ \t", @:) |
| 3142 | call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt') |
| 3143 | call assert_equal("\"dlist 10 /pa\\t/\t", @:) |
| 3144 | call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt') |
| 3145 | call assert_equal("\"dlist 10 /pat\\\t", @:) |
| 3146 | call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt') |
| 3147 | call assert_equal("\"dlist 10 /pat/ | chistory", @:) |
| 3148 | endfunc |
| 3149 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3150 | " argument list (only for :argdel) fuzzy completion |
| 3151 | func Test_fuzzy_completion_arglist() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3152 | argadd change.py count.py charge.py |
| 3153 | set wildoptions& |
| 3154 | call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3155 | call assert_equal('"argdel cge', @:) |
| 3156 | set wildoptions=fuzzy |
| 3157 | call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3158 | call assert_equal('"argdel change.py charge.py', @:) |
| 3159 | %argdelete |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3160 | set wildoptions& |
| 3161 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3162 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3163 | " autocmd group name fuzzy completion |
| 3164 | func Test_fuzzy_completion_autocmd() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3165 | set wildoptions& |
| 3166 | augroup MyFuzzyGroup |
| 3167 | augroup END |
| 3168 | call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3169 | call assert_equal('"augroup mfg', @:) |
| 3170 | call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3171 | call assert_equal('"augroup MyFuzzyGroup', @:) |
| 3172 | set wildoptions=fuzzy |
| 3173 | call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3174 | call assert_equal('"augroup MyFuzzyGroup', @:) |
| 3175 | call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3176 | call assert_equal('"augroup My*p', @:) |
| 3177 | augroup! MyFuzzyGroup |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3178 | set wildoptions& |
| 3179 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3180 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3181 | " buffer name fuzzy completion |
| 3182 | func Test_fuzzy_completion_bufname() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3183 | set wildoptions& |
Bram Moolenaar | 5ac4b1a | 2022-08-06 10:28:19 +0100 | [diff] [blame] | 3184 | " Use a long name to reduce the risk of matching a random directory name |
| 3185 | edit SomeRandomFileWithLetters.txt |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3186 | enew |
Bram Moolenaar | 5ac4b1a | 2022-08-06 10:28:19 +0100 | [diff] [blame] | 3187 | call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3188 | call assert_equal('"b SRFWL', @:) |
| 3189 | call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3190 | call assert_equal('"b SomeRandomFileWithLetters.txt', @:) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3191 | set wildoptions=fuzzy |
Bram Moolenaar | 5ac4b1a | 2022-08-06 10:28:19 +0100 | [diff] [blame] | 3192 | call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3193 | call assert_equal('"b SomeRandomFileWithLetters.txt', @:) |
| 3194 | call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3195 | call assert_equal('"b S*FileWithLetters.txt', @:) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3196 | %bw! |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3197 | set wildoptions& |
| 3198 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3199 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3200 | " buffer name (full path) fuzzy completion |
| 3201 | func Test_fuzzy_completion_bufname_fullpath() |
| 3202 | CheckUnix |
| 3203 | set wildoptions& |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 3204 | call mkdir('Xcmd/Xstate/Xfile.js', 'pR') |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3205 | edit Xcmd/Xstate/Xfile.js |
| 3206 | cd Xcmd/Xstate |
| 3207 | enew |
| 3208 | call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3209 | call assert_equal('"b CmdStateFile', @:) |
| 3210 | set wildoptions=fuzzy |
| 3211 | call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3212 | call assert_match('Xcmd/Xstate/Xfile.js$', @:) |
| 3213 | cd - |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 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 | " :behave suboptions fuzzy completion |
| 3218 | func Test_fuzzy_completion_behave() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3219 | set wildoptions& |
| 3220 | call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3221 | call assert_equal('"behave xm', @:) |
| 3222 | call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3223 | call assert_equal('"behave xterm', @:) |
| 3224 | set wildoptions=fuzzy |
| 3225 | call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3226 | call assert_equal('"behave xterm', @:) |
| 3227 | call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3228 | call assert_equal('"behave xt*m', @:) |
| 3229 | let g:Sline = '' |
| 3230 | call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx') |
| 3231 | call assert_equal('mswin', g:Sline) |
| 3232 | call assert_equal('"behave win', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3233 | set wildoptions& |
| 3234 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3235 | |
Christian Brabandt | a3422aa | 2025-04-23 21:04:24 +0200 | [diff] [blame] | 3236 | " :filetype suboptions completion |
| 3237 | func Test_completion_filetypecmd() |
| 3238 | set wildoptions& |
| 3239 | call feedkeys(":filetype \<C-A>\<C-B>\"\<CR>", 'tx') |
| 3240 | call assert_equal('"filetype indent off on plugin', @:) |
| 3241 | call feedkeys(":filetype plugin \<C-A>\<C-B>\"\<CR>", 'tx') |
| 3242 | call assert_equal('"filetype plugin indent off on', @:) |
| 3243 | call feedkeys(":filetype indent \<C-A>\<C-B>\"\<CR>", 'tx') |
| 3244 | call assert_equal('"filetype indent off on plugin', @:) |
| 3245 | call feedkeys(":filetype i\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3246 | call assert_equal('"filetype indent', @:) |
| 3247 | call feedkeys(":filetype p\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3248 | call assert_equal('"filetype plugin', @:) |
| 3249 | call feedkeys(":filetype o\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3250 | call assert_equal('"filetype off on', @:) |
| 3251 | call feedkeys(":filetype indent of\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3252 | call assert_equal('"filetype indent off', @:) |
| 3253 | set wildoptions& |
| 3254 | endfunc |
| 3255 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3256 | " " colorscheme name fuzzy completion - NOT supported |
| 3257 | " func Test_fuzzy_completion_colorscheme() |
| 3258 | " endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3259 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3260 | " built-in command name fuzzy completion |
| 3261 | func Test_fuzzy_completion_cmdname() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3262 | set wildoptions& |
| 3263 | call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3264 | call assert_equal('"sbwin', @:) |
| 3265 | call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3266 | call assert_equal('"sbrewind', @:) |
| 3267 | set wildoptions=fuzzy |
| 3268 | call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3269 | call assert_equal('"sbrewind', @:) |
| 3270 | call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3271 | call assert_equal('"sbr*d', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3272 | set wildoptions& |
| 3273 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3274 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3275 | " " compiler name fuzzy completion - NOT supported |
| 3276 | " func Test_fuzzy_completion_compiler() |
| 3277 | " endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3278 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3279 | " :cscope suboptions fuzzy completion |
| 3280 | func Test_fuzzy_completion_cscope() |
| 3281 | CheckFeature cscope |
| 3282 | set wildoptions& |
| 3283 | call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3284 | call assert_equal('"cscope ret', @:) |
| 3285 | call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3286 | call assert_equal('"cscope reset', @:) |
| 3287 | set wildoptions=fuzzy |
| 3288 | call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3289 | call assert_equal('"cscope reset', @:) |
| 3290 | call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3291 | call assert_equal('"cscope re*t', @:) |
| 3292 | set wildoptions& |
| 3293 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3294 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3295 | " :diffget/:diffput buffer name fuzzy completion |
| 3296 | func Test_fuzzy_completion_diff() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3297 | new SomeBuffer |
| 3298 | diffthis |
| 3299 | new OtherBuffer |
| 3300 | diffthis |
| 3301 | set wildoptions& |
| 3302 | call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3303 | call assert_equal('"diffget sbuf', @:) |
| 3304 | call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3305 | call assert_equal('"diffput sbuf', @:) |
| 3306 | set wildoptions=fuzzy |
| 3307 | call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3308 | call assert_equal('"diffget SomeBuffer', @:) |
| 3309 | call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3310 | call assert_equal('"diffput SomeBuffer', @:) |
| 3311 | %bw! |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3312 | set wildoptions& |
| 3313 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3314 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3315 | " " directory name fuzzy completion - NOT supported |
| 3316 | " func Test_fuzzy_completion_dirname() |
| 3317 | " endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3318 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3319 | " environment variable name fuzzy completion |
| 3320 | func Test_fuzzy_completion_env() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3321 | set wildoptions& |
| 3322 | call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3323 | call assert_equal('"echo $VUT', @:) |
| 3324 | set wildoptions=fuzzy |
| 3325 | call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3326 | call assert_equal('"echo $VIMRUNTIME', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3327 | set wildoptions& |
| 3328 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3329 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3330 | " autocmd event fuzzy completion |
| 3331 | func Test_fuzzy_completion_autocmd_event() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3332 | set wildoptions& |
| 3333 | call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3334 | call assert_equal('"autocmd BWout', @:) |
| 3335 | set wildoptions=fuzzy |
| 3336 | call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3337 | call assert_equal('"autocmd BufWipeout', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3338 | set wildoptions& |
| 3339 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3340 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3341 | " vim expression fuzzy completion |
| 3342 | func Test_fuzzy_completion_expr() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3343 | let g:PerPlaceCount = 10 |
| 3344 | set wildoptions& |
| 3345 | call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3346 | call assert_equal('"let c = ppc', @:) |
| 3347 | set wildoptions=fuzzy |
| 3348 | call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3349 | call assert_equal('"let c = PerPlaceCount', @:) |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3350 | set wildoptions& |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3351 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3352 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3353 | " " file name fuzzy completion - NOT supported |
| 3354 | " func Test_fuzzy_completion_filename() |
| 3355 | " endfunc |
| 3356 | |
| 3357 | " " files in path fuzzy completion - NOT supported |
| 3358 | " func Test_fuzzy_completion_filesinpath() |
| 3359 | " endfunc |
| 3360 | |
| 3361 | " " filetype name fuzzy completion - NOT supported |
| 3362 | " func Test_fuzzy_completion_filetype() |
| 3363 | " endfunc |
| 3364 | |
| 3365 | " user defined function name completion |
| 3366 | func Test_fuzzy_completion_userdefined_func() |
| 3367 | set wildoptions& |
| 3368 | call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3369 | call assert_equal('"call Test_f_u_f', @:) |
| 3370 | set wildoptions=fuzzy |
| 3371 | call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3372 | call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:) |
| 3373 | set wildoptions& |
| 3374 | endfunc |
| 3375 | |
Yegappan Lakshmanan | 5de4c43 | 2022-02-28 13:28:38 +0000 | [diff] [blame] | 3376 | " <SNR> functions should be sorted to the end |
| 3377 | func Test_fuzzy_completion_userdefined_snr_func() |
| 3378 | func s:Sendmail() |
| 3379 | endfunc |
| 3380 | func SendSomemail() |
| 3381 | endfunc |
| 3382 | func S1e2n3dmail() |
| 3383 | endfunc |
| 3384 | set wildoptions=fuzzy |
| 3385 | call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx') |
Bram Moolenaar | fe8e9f6 | 2022-03-16 13:09:15 +0000 | [diff] [blame] | 3386 | call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:) |
Yegappan Lakshmanan | 5de4c43 | 2022-02-28 13:28:38 +0000 | [diff] [blame] | 3387 | set wildoptions& |
| 3388 | delfunc s:Sendmail |
| 3389 | delfunc SendSomemail |
| 3390 | delfunc S1e2n3dmail |
| 3391 | endfunc |
| 3392 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3393 | " user defined command name completion |
| 3394 | func Test_fuzzy_completion_userdefined_cmd() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3395 | set wildoptions& |
| 3396 | call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3397 | call assert_equal('"MsFeat', @:) |
| 3398 | set wildoptions=fuzzy |
| 3399 | call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3400 | call assert_equal('"MissingFeature', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3401 | set wildoptions& |
| 3402 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3403 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3404 | " " :help tag fuzzy completion - NOT supported |
| 3405 | " func Test_fuzzy_completion_helptag() |
| 3406 | " endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3407 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3408 | " highlight group name fuzzy completion |
| 3409 | func Test_fuzzy_completion_hlgroup() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3410 | set wildoptions& |
| 3411 | call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3412 | call assert_equal('"highlight SKey', @:) |
| 3413 | call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3414 | call assert_equal('"highlight SpecialKey', @:) |
| 3415 | set wildoptions=fuzzy |
| 3416 | call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3417 | call assert_equal('"highlight SpecialKey', @:) |
| 3418 | call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3419 | call assert_equal('"highlight Sp*Key', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3420 | set wildoptions& |
| 3421 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3422 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3423 | " :history suboptions fuzzy completion |
| 3424 | func Test_fuzzy_completion_history() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3425 | set wildoptions& |
| 3426 | call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3427 | call assert_equal('"history dg', @:) |
| 3428 | call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3429 | call assert_equal('"history search', @:) |
| 3430 | set wildoptions=fuzzy |
| 3431 | call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3432 | call assert_equal('"history debug', @:) |
| 3433 | call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3434 | call assert_equal('"history se*h', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3435 | set wildoptions& |
| 3436 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3437 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3438 | " :language locale name fuzzy completion |
| 3439 | func Test_fuzzy_completion_lang() |
| 3440 | CheckUnix |
| 3441 | set wildoptions& |
| 3442 | call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3443 | call assert_equal('"lang psx', @:) |
| 3444 | set wildoptions=fuzzy |
| 3445 | call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3446 | call assert_equal('"lang POSIX', @:) |
| 3447 | set wildoptions& |
| 3448 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3449 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3450 | " :mapclear buffer argument fuzzy completion |
| 3451 | func Test_fuzzy_completion_mapclear() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3452 | set wildoptions& |
| 3453 | call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3454 | call assert_equal('"mapclear buf', @:) |
| 3455 | set wildoptions=fuzzy |
| 3456 | call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3457 | call assert_equal('"mapclear <buffer>', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3458 | set wildoptions& |
| 3459 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3460 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3461 | " map name fuzzy completion |
| 3462 | func Test_fuzzy_completion_mapname() |
Yegappan Lakshmanan | 00333cb | 2022-02-26 16:05:08 +0000 | [diff] [blame] | 3463 | " test regex completion works |
| 3464 | set wildoptions=fuzzy |
| 3465 | call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3466 | call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:) |
Yegappan Lakshmanan | 6caeda2 | 2022-02-27 12:07:30 +0000 | [diff] [blame] | 3467 | nmap <plug>MyLongMap :p<CR> |
| 3468 | call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3469 | call assert_equal("\"nmap <Plug>MyLongMap", @:) |
| 3470 | call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3471 | call assert_equal("\"nmap MLM \t", @:) |
| 3472 | call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3473 | call assert_equal("\"nmap <F2> one two \t", @:) |
| 3474 | " duplicate entries should be removed |
| 3475 | vmap <plug>MyLongMap :<C-U>#<CR> |
| 3476 | call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3477 | call assert_equal("\"nmap <Plug>MyLongMap", @:) |
| 3478 | nunmap <plug>MyLongMap |
| 3479 | vunmap <plug>MyLongMap |
| 3480 | call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3481 | call assert_equal("\"nmap ABC\t", @:) |
| 3482 | " results should be sorted by best match |
| 3483 | nmap <Plug>format : |
| 3484 | nmap <Plug>goformat : |
| 3485 | nmap <Plug>TestFOrmat : |
| 3486 | nmap <Plug>fendoff : |
| 3487 | nmap <Plug>state : |
| 3488 | nmap <Plug>FendingOff : |
| 3489 | call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3490 | call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:) |
| 3491 | nunmap <Plug>format |
| 3492 | nunmap <Plug>goformat |
| 3493 | nunmap <Plug>TestFOrmat |
| 3494 | nunmap <Plug>fendoff |
| 3495 | nunmap <Plug>state |
| 3496 | nunmap <Plug>FendingOff |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3497 | set wildoptions& |
| 3498 | endfunc |
Yegappan Lakshmanan | 6caeda2 | 2022-02-27 12:07:30 +0000 | [diff] [blame] | 3499 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3500 | " abbreviation fuzzy completion |
| 3501 | func Test_fuzzy_completion_abbr() |
Yegappan Lakshmanan | 6caeda2 | 2022-02-27 12:07:30 +0000 | [diff] [blame] | 3502 | set wildoptions=fuzzy |
| 3503 | call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3504 | call assert_equal("\"iabbr <nowait>", @:) |
| 3505 | iabbr WaitForCompletion WFC |
| 3506 | call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3507 | call assert_equal("\"iabbr WaitForCompletion", @:) |
| 3508 | call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3509 | call assert_equal("\"iabbr a1z\t", @:) |
zeertzjq | 145a6af | 2023-01-22 12:41:55 +0000 | [diff] [blame] | 3510 | |
Yegappan Lakshmanan | 6caeda2 | 2022-02-27 12:07:30 +0000 | [diff] [blame] | 3511 | iunabbrev WaitForCompletion |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3512 | set wildoptions& |
| 3513 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3514 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3515 | " menu name fuzzy completion |
| 3516 | func Test_fuzzy_completion_menu() |
zeertzjq | 145a6af | 2023-01-22 12:41:55 +0000 | [diff] [blame] | 3517 | CheckFeature menu |
| 3518 | |
| 3519 | source $VIMRUNTIME/menu.vim |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3520 | set wildoptions& |
| 3521 | call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3522 | call assert_equal('"menu pup', @:) |
| 3523 | set wildoptions=fuzzy |
| 3524 | call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3525 | call assert_equal('"menu PopUp.', @:) |
zeertzjq | 145a6af | 2023-01-22 12:41:55 +0000 | [diff] [blame] | 3526 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3527 | set wildoptions& |
zeertzjq | 145a6af | 2023-01-22 12:41:55 +0000 | [diff] [blame] | 3528 | source $VIMRUNTIME/delmenu.vim |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3529 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3530 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3531 | " :messages suboptions fuzzy completion |
| 3532 | func Test_fuzzy_completion_messages() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3533 | set wildoptions& |
| 3534 | call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3535 | call assert_equal('"messages clr', @:) |
| 3536 | set wildoptions=fuzzy |
| 3537 | call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3538 | call assert_equal('"messages clear', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3539 | set wildoptions& |
| 3540 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3541 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3542 | " :set option name fuzzy completion |
| 3543 | func Test_fuzzy_completion_option() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3544 | set wildoptions& |
| 3545 | call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3546 | call assert_equal('"set brkopt', @:) |
| 3547 | set wildoptions=fuzzy |
| 3548 | call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3549 | call assert_equal('"set breakindentopt', @:) |
| 3550 | set wildoptions& |
| 3551 | call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3552 | call assert_equal('"set fixendofline', @:) |
| 3553 | set wildoptions=fuzzy |
| 3554 | call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3555 | call assert_equal('"set fixendofline', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3556 | set wildoptions& |
| 3557 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3558 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3559 | " :set <term_option> |
| 3560 | func Test_fuzzy_completion_term_option() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3561 | set wildoptions& |
| 3562 | call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3563 | call assert_equal('"set t_EC', @:) |
| 3564 | call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3565 | call assert_equal('"set <t_EC>', @:) |
| 3566 | set wildoptions=fuzzy |
| 3567 | call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3568 | call assert_equal('"set t_EC', @:) |
| 3569 | call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3570 | call assert_equal('"set <t_EC>', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3571 | set wildoptions& |
| 3572 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3573 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3574 | " " :packadd directory name fuzzy completion - NOT supported |
| 3575 | " func Test_fuzzy_completion_packadd() |
| 3576 | " endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3577 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3578 | " " shell command name fuzzy completion - NOT supported |
| 3579 | " func Test_fuzzy_completion_shellcmd() |
| 3580 | " endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3581 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3582 | " :sign suboptions fuzzy completion |
| 3583 | func Test_fuzzy_completion_sign() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3584 | set wildoptions& |
| 3585 | call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3586 | call assert_equal('"sign ufe', @:) |
| 3587 | set wildoptions=fuzzy |
| 3588 | call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3589 | call assert_equal('"sign undefine', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3590 | set wildoptions& |
| 3591 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3592 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3593 | " :syntax suboptions fuzzy completion |
| 3594 | func Test_fuzzy_completion_syntax_cmd() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3595 | set wildoptions& |
| 3596 | call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3597 | call assert_equal('"syntax kwd', @:) |
| 3598 | set wildoptions=fuzzy |
| 3599 | call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3600 | call assert_equal('"syntax keyword', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3601 | set wildoptions& |
| 3602 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3603 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3604 | " syntax group name fuzzy completion |
| 3605 | func Test_fuzzy_completion_syntax_group() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3606 | set wildoptions& |
| 3607 | call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3608 | call assert_equal('"syntax list mpar', @:) |
| 3609 | set wildoptions=fuzzy |
| 3610 | call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3611 | call assert_equal('"syntax list MatchParen', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3612 | set wildoptions& |
| 3613 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3614 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3615 | " :syntime suboptions fuzzy completion |
| 3616 | func Test_fuzzy_completion_syntime() |
| 3617 | CheckFeature profile |
| 3618 | set wildoptions& |
| 3619 | call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3620 | call assert_equal('"syntime clr', @:) |
| 3621 | set wildoptions=fuzzy |
| 3622 | call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3623 | call assert_equal('"syntime clear', @:) |
| 3624 | set wildoptions& |
| 3625 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3626 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3627 | " " tag name fuzzy completion - NOT supported |
| 3628 | " func Test_fuzzy_completion_tagname() |
| 3629 | " endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3630 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3631 | " " tag name and file fuzzy completion - NOT supported |
| 3632 | " func Test_fuzzy_completion_tagfile() |
| 3633 | " endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3634 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3635 | " " user names fuzzy completion - how to test this functionality? |
| 3636 | " func Test_fuzzy_completion_username() |
| 3637 | " endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3638 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3639 | " user defined variable name fuzzy completion |
| 3640 | func Test_fuzzy_completion_userdefined_var() |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3641 | let g:SomeVariable=10 |
| 3642 | set wildoptions& |
| 3643 | call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3644 | call assert_equal('"let SVar', @:) |
| 3645 | set wildoptions=fuzzy |
| 3646 | call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3647 | call assert_equal('"let SomeVariable', @:) |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3648 | set wildoptions& |
| 3649 | endfunc |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3650 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3651 | " Test for sorting the results by the best match |
| 3652 | func Test_fuzzy_completion_cmd_sort_results() |
Yegappan Lakshmanan | 5ec633b | 2022-02-25 15:24:24 +0000 | [diff] [blame] | 3653 | %bw! |
| 3654 | command T123format : |
| 3655 | command T123goformat : |
| 3656 | command T123TestFOrmat : |
| 3657 | command T123fendoff : |
| 3658 | command T123state : |
| 3659 | command T123FendingOff : |
| 3660 | set wildoptions=fuzzy |
| 3661 | call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3662 | call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:) |
| 3663 | delcommand T123format |
| 3664 | delcommand T123goformat |
| 3665 | delcommand T123TestFOrmat |
| 3666 | delcommand T123fendoff |
| 3667 | delcommand T123state |
| 3668 | delcommand T123FendingOff |
| 3669 | %bw |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3670 | set wildoptions& |
| 3671 | endfunc |
Yegappan Lakshmanan | 5ec633b | 2022-02-25 15:24:24 +0000 | [diff] [blame] | 3672 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3673 | " Test for fuzzy completion of a command with lower case letters and a number |
| 3674 | func Test_fuzzy_completion_cmd_alnum() |
Yegappan Lakshmanan | 4df5b33 | 2022-02-26 11:04:42 +0000 | [diff] [blame] | 3675 | command Foo2Bar : |
| 3676 | set wildoptions=fuzzy |
| 3677 | call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3678 | call assert_equal('"Foo2Bar', @:) |
| 3679 | call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3680 | call assert_equal('"Foo2Bar', @:) |
| 3681 | call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3682 | call assert_equal('"Foo2Bar', @:) |
| 3683 | delcommand Foo2Bar |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3684 | set wildoptions& |
| 3685 | endfunc |
Yegappan Lakshmanan | 4df5b33 | 2022-02-26 11:04:42 +0000 | [diff] [blame] | 3686 | |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3687 | " Test for command completion for a command starting with 'k' |
| 3688 | func Test_fuzzy_completion_cmd_k() |
Yegappan Lakshmanan | 6caeda2 | 2022-02-27 12:07:30 +0000 | [diff] [blame] | 3689 | command KillKillKill : |
| 3690 | set wildoptions& |
| 3691 | call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3692 | call assert_equal("\"killkill\<Tab>", @:) |
| 3693 | set wildoptions=fuzzy |
| 3694 | call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3695 | call assert_equal('"KillKillKill', @:) |
| 3696 | delcom KillKillKill |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3697 | set wildoptions& |
Yegappan Lakshmanan | afd4ae3 | 2022-02-27 21:03:21 +0000 | [diff] [blame] | 3698 | endfunc |
| 3699 | |
| 3700 | " Test for fuzzy completion for user defined custom completion function |
| 3701 | func Test_fuzzy_completion_custom_func() |
| 3702 | func Tcompl(a, c, p) |
| 3703 | return "format\ngoformat\nTestFOrmat\nfendoff\nstate" |
| 3704 | endfunc |
| 3705 | command -nargs=* -complete=custom,Tcompl Fuzzy : |
| 3706 | set wildoptions& |
| 3707 | call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3708 | call assert_equal("\"Fuzzy format", @:) |
| 3709 | call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3710 | call assert_equal("\"Fuzzy xy", @:) |
| 3711 | call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3712 | call assert_equal("\"Fuzzy ttt", @:) |
| 3713 | set wildoptions=fuzzy |
| 3714 | call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx') |
| 3715 | call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:) |
| 3716 | call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3717 | call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:) |
| 3718 | call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3719 | call assert_equal("\"Fuzzy xy", @:) |
| 3720 | call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3721 | call assert_equal("\"Fuzzy TestFOrmat", @:) |
| 3722 | delcom Fuzzy |
| 3723 | set wildoptions& |
Yegappan Lakshmanan | 38b85cb | 2022-02-24 13:28:41 +0000 | [diff] [blame] | 3724 | endfunc |
| 3725 | |
Yee Cheng Chin | 209ec90 | 2023-10-17 10:56:25 +0200 | [diff] [blame] | 3726 | " Test for fuzzy completion in the middle of a cmdline instead of at the end |
| 3727 | func Test_fuzzy_completion_in_middle() |
| 3728 | set wildoptions=fuzzy |
| 3729 | call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3730 | call assert_equal("\"set wildchar wildcharm wrap", @:) |
| 3731 | |
| 3732 | call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx') |
| 3733 | call assert_equal("\"args ++encoding= zz", @:) |
| 3734 | set wildoptions& |
| 3735 | endfunc |
| 3736 | |
Bram Moolenaar | 6e2e2cc | 2022-03-14 19:24:46 +0000 | [diff] [blame] | 3737 | " Test for :breakadd argument completion |
| 3738 | func Test_cmdline_complete_breakadd() |
| 3739 | call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx') |
| 3740 | call assert_equal("\"breakadd expr file func here", @:) |
| 3741 | call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3742 | call assert_equal("\"breakadd expr", @:) |
| 3743 | call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3744 | call assert_equal("\"breakadd expr", @:) |
| 3745 | call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3746 | call assert_equal("\"breakadd here", @:) |
| 3747 | call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3748 | call assert_equal("\"breakadd here", @:) |
| 3749 | call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3750 | call assert_equal("\"breakadd abc", @:) |
| 3751 | call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint')) |
| 3752 | let l = getcompletion('not', 'breakpoint') |
| 3753 | call assert_equal([], l) |
| 3754 | |
| 3755 | " Test for :breakadd file [lnum] <file> |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 3756 | call writefile([], 'Xscript', 'D') |
Bram Moolenaar | 6e2e2cc | 2022-03-14 19:24:46 +0000 | [diff] [blame] | 3757 | call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3758 | call assert_equal("\"breakadd file Xscript", @:) |
| 3759 | call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3760 | call assert_equal("\"breakadd file Xscript", @:) |
| 3761 | call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3762 | call assert_equal("\"breakadd file 20 Xscript", @:) |
| 3763 | call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3764 | call assert_equal("\"breakadd file 20 Xscript", @:) |
| 3765 | call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3766 | call assert_equal("\"breakadd file 20x Xsc\t", @:) |
| 3767 | call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3768 | call assert_equal("\"breakadd file 20\t", @:) |
| 3769 | call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3770 | call assert_equal("\"breakadd file 20x\t", @:) |
| 3771 | call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3772 | call assert_equal("\"breakadd file Xscript ", @:) |
| 3773 | call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3774 | call assert_equal("\"breakadd file X1B2C3", @:) |
Bram Moolenaar | 6e2e2cc | 2022-03-14 19:24:46 +0000 | [diff] [blame] | 3775 | |
| 3776 | " Test for :breakadd func [lnum] <function> |
| 3777 | func Xbreak_func() |
| 3778 | endfunc |
| 3779 | call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3780 | call assert_equal("\"breakadd func Xbreak_func", @:) |
| 3781 | call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3782 | call assert_equal("\"breakadd func Xbreak_func", @:) |
| 3783 | call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3784 | call assert_equal("\"breakadd func 20 Xbreak_func", @:) |
| 3785 | call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3786 | call assert_equal("\"breakadd func 20 Xbreak_func", @:) |
| 3787 | call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3788 | call assert_equal("\"breakadd func 20x Xbr\t", @:) |
| 3789 | call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3790 | call assert_equal("\"breakadd func 20\t", @:) |
| 3791 | call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3792 | call assert_equal("\"breakadd func 20x\t", @:) |
| 3793 | call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3794 | call assert_equal("\"breakadd func Xbreak_func ", @:) |
| 3795 | call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3796 | call assert_equal("\"breakadd func X1B2C3", @:) |
| 3797 | delfunc Xbreak_func |
| 3798 | |
| 3799 | " Test for :breakadd expr <expression> |
| 3800 | let g:Xtest_var = 10 |
| 3801 | call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3802 | call assert_equal("\"breakadd expr Xtest_var", @:) |
| 3803 | call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3804 | call assert_equal("\"breakadd expr Xtest_var", @:) |
| 3805 | call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3806 | call assert_equal("\"breakadd expr Xtest_var ", @:) |
| 3807 | call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3808 | call assert_equal("\"breakadd expr X1B2C3", @:) |
| 3809 | unlet g:Xtest_var |
| 3810 | |
| 3811 | " Test for :breakadd here |
| 3812 | call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3813 | call assert_equal("\"breakadd here Xtest", @:) |
| 3814 | call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3815 | call assert_equal("\"breakadd here Xtest", @:) |
| 3816 | call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3817 | call assert_equal("\"breakadd here ", @:) |
| 3818 | endfunc |
| 3819 | |
| 3820 | " Test for :breakdel argument completion |
| 3821 | func Test_cmdline_complete_breakdel() |
| 3822 | call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx') |
| 3823 | call assert_equal("\"breakdel file func here", @:) |
| 3824 | call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3825 | call assert_equal("\"breakdel file", @:) |
| 3826 | call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3827 | call assert_equal("\"breakdel file", @:) |
| 3828 | call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3829 | call assert_equal("\"breakdel here", @:) |
| 3830 | call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3831 | call assert_equal("\"breakdel here", @:) |
| 3832 | call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3833 | call assert_equal("\"breakdel abc", @:) |
| 3834 | |
| 3835 | " Test for :breakdel file [lnum] <file> |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 3836 | call writefile([], 'Xscript', 'D') |
Bram Moolenaar | 6e2e2cc | 2022-03-14 19:24:46 +0000 | [diff] [blame] | 3837 | call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3838 | call assert_equal("\"breakdel file Xscript", @:) |
| 3839 | call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3840 | call assert_equal("\"breakdel file Xscript", @:) |
| 3841 | call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3842 | call assert_equal("\"breakdel file 20 Xscript", @:) |
| 3843 | call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3844 | call assert_equal("\"breakdel file 20 Xscript", @:) |
| 3845 | call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3846 | call assert_equal("\"breakdel file 20x Xsc\t", @:) |
| 3847 | call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3848 | call assert_equal("\"breakdel file 20\t", @:) |
| 3849 | call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3850 | call assert_equal("\"breakdel file 20x\t", @:) |
| 3851 | call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3852 | call assert_equal("\"breakdel file Xscript ", @:) |
| 3853 | call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3854 | call assert_equal("\"breakdel file X1B2C3", @:) |
Bram Moolenaar | 6e2e2cc | 2022-03-14 19:24:46 +0000 | [diff] [blame] | 3855 | |
| 3856 | " Test for :breakdel func [lnum] <function> |
| 3857 | func Xbreak_func() |
| 3858 | endfunc |
| 3859 | call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3860 | call assert_equal("\"breakdel func Xbreak_func", @:) |
| 3861 | call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3862 | call assert_equal("\"breakdel func Xbreak_func", @:) |
| 3863 | call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3864 | call assert_equal("\"breakdel func 20 Xbreak_func", @:) |
| 3865 | call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3866 | call assert_equal("\"breakdel func 20 Xbreak_func", @:) |
| 3867 | call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3868 | call assert_equal("\"breakdel func 20x Xbr\t", @:) |
| 3869 | call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3870 | call assert_equal("\"breakdel func 20\t", @:) |
| 3871 | call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3872 | call assert_equal("\"breakdel func 20x\t", @:) |
| 3873 | call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3874 | call assert_equal("\"breakdel func Xbreak_func ", @:) |
| 3875 | call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3876 | call assert_equal("\"breakdel func X1B2C3", @:) |
| 3877 | delfunc Xbreak_func |
| 3878 | |
| 3879 | " Test for :breakdel here |
| 3880 | call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3881 | call assert_equal("\"breakdel here Xtest", @:) |
| 3882 | call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3883 | call assert_equal("\"breakdel here Xtest", @:) |
| 3884 | call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3885 | call assert_equal("\"breakdel here ", @:) |
Bram Moolenaar | 6e2e2cc | 2022-03-14 19:24:46 +0000 | [diff] [blame] | 3886 | endfunc |
| 3887 | |
Yegappan Lakshmanan | 454ce67 | 2022-03-24 11:22:13 +0000 | [diff] [blame] | 3888 | " Test for :scriptnames argument completion |
| 3889 | func Test_cmdline_complete_scriptnames() |
| 3890 | set wildmenu |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 3891 | call writefile(['let a = 1'], 'Xa1b2c3.vim', 'D') |
Yegappan Lakshmanan | 454ce67 | 2022-03-24 11:22:13 +0000 | [diff] [blame] | 3892 | source Xa1b2c3.vim |
| 3893 | call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx') |
| 3894 | call assert_match("\"script .*Xa1b2c3.vim$", @:) |
| 3895 | call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx') |
| 3896 | call assert_match("\"script .*Xa1b2c3.vim$", @:) |
| 3897 | call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3898 | call assert_equal("\"script b2c3", @:) |
| 3899 | call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx') |
| 3900 | call assert_match("\"script 2\<Tab>$", @:) |
| 3901 | call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3902 | call assert_match("\"script .*Xa1b2c3.vim $", @:) |
| 3903 | call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx') |
| 3904 | call assert_equal("\"script ", @:) |
| 3905 | call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0]) |
| 3906 | call assert_equal([], getcompletion('Xa1b2', 'scriptnames')) |
| 3907 | new |
| 3908 | call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx') |
| 3909 | call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t')) |
| 3910 | bw! |
Yegappan Lakshmanan | 454ce67 | 2022-03-24 11:22:13 +0000 | [diff] [blame] | 3911 | set wildmenu& |
| 3912 | endfunc |
| 3913 | |
Bram Moolenaar | d889344 | 2022-05-06 20:38:47 +0100 | [diff] [blame] | 3914 | " this was going over the end of IObuff |
| 3915 | func Test_report_error_with_composing() |
| 3916 | let caught = 'no' |
| 3917 | try |
| 3918 | exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80" |
| 3919 | catch /E492:/ |
| 3920 | let caught = 'yes' |
| 3921 | endtry |
| 3922 | call assert_equal('yes', caught) |
| 3923 | endfunc |
| 3924 | |
Yegappan Lakshmanan | 5e877ba | 2022-03-25 21:19:26 +0000 | [diff] [blame] | 3925 | " Test for expanding 2-letter and 3-letter :substitute command arguments. |
| 3926 | " These commands don't accept an argument. |
| 3927 | func Test_cmdline_complete_substitute_short() |
| 3928 | for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl', |
| 3929 | \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr', |
| 3930 | \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir', |
| 3931 | \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr', |
| 3932 | \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr'] |
| 3933 | call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx') |
| 3934 | call assert_equal('"' .. cmd .. " \<Tab>", @:) |
| 3935 | endfor |
| 3936 | endfunc |
| 3937 | |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 3938 | " Test for shellcmdline command argument completion |
| 3939 | func Test_cmdline_complete_shellcmdline_argument() |
| 3940 | command -nargs=+ -complete=shellcmdline MyCmd |
| 3941 | |
| 3942 | set wildoptions=fuzzy |
| 3943 | |
| 3944 | call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt') |
| 3945 | call assert_equal('"MyCmd vim test_cmdline.vim', @:) |
zeertzjq | 85f36d6 | 2024-10-10 19:14:13 +0200 | [diff] [blame] | 3946 | call assert_equal(['test_cmdline.vim'], |
| 3947 | \ getcompletion('vim test_cmdline.', 'shellcmdline')) |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 3948 | |
| 3949 | call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt') |
| 3950 | call assert_equal('"MyCmd vim nonexistentfile', @:) |
zeertzjq | 85f36d6 | 2024-10-10 19:14:13 +0200 | [diff] [blame] | 3951 | call assert_equal([], |
| 3952 | \ getcompletion('vim nonexistentfile', 'shellcmdline')) |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 3953 | |
| 3954 | let compl1 = getcompletion('', 'file')[0] |
| 3955 | let compl2 = getcompletion('', 'file')[1] |
| 3956 | call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt') |
| 3957 | call assert_equal('"MyCmd vim ' .. compl1, @:) |
| 3958 | |
| 3959 | call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt') |
| 3960 | call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:) |
| 3961 | |
| 3962 | let compl = getcompletion('', 'file')[1] |
| 3963 | call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 3964 | call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:) |
| 3965 | |
| 3966 | set wildoptions& |
| 3967 | call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt') |
| 3968 | call assert_equal('"MyCmd vim test_cmdline.vim', @:) |
zeertzjq | 85f36d6 | 2024-10-10 19:14:13 +0200 | [diff] [blame] | 3969 | call assert_equal(['test_cmdline.vim'], |
| 3970 | \ getcompletion('vim test_cmdline.', 'shellcmdline')) |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 3971 | |
| 3972 | call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt') |
| 3973 | call assert_equal('"MyCmd vim nonexistentfile', @:) |
zeertzjq | 85f36d6 | 2024-10-10 19:14:13 +0200 | [diff] [blame] | 3974 | call assert_equal([], |
| 3975 | \ getcompletion('vim nonexistentfile', 'shellcmdline')) |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 3976 | |
| 3977 | let compl1 = getcompletion('', 'file')[0] |
| 3978 | let compl2 = getcompletion('', 'file')[1] |
| 3979 | call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt') |
| 3980 | call assert_equal('"MyCmd vim ' .. compl1, @:) |
| 3981 | |
| 3982 | call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt') |
| 3983 | call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:) |
| 3984 | |
| 3985 | let compl = getcompletion('', 'file')[1] |
| 3986 | call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt') |
| 3987 | call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:) |
| 3988 | |
| 3989 | delcommand MyCmd |
| 3990 | endfunc |
| 3991 | |
Yegappan Lakshmanan | 7db3a8e | 2022-07-26 22:01:36 +0100 | [diff] [blame] | 3992 | " Test for :! shell command argument completion |
| 3993 | func Test_cmdline_complete_bang_cmd_argument() |
| 3994 | set wildoptions=fuzzy |
| 3995 | call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt') |
| 3996 | call assert_equal('"!vim test_cmdline.vim', @:) |
| 3997 | set wildoptions& |
| 3998 | call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt') |
| 3999 | call assert_equal('"!vim test_cmdline.vim', @:) |
| 4000 | endfunc |
| 4001 | |
zeertzjq | 961b2e5 | 2023-04-17 15:53:24 +0100 | [diff] [blame] | 4002 | func Call_cmd_funcs() |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 4003 | return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()] |
Shougo Matsushita | 79d599b | 2022-05-07 12:48:29 +0100 | [diff] [blame] | 4004 | endfunc |
| 4005 | |
| 4006 | func Test_screenpos_and_completion() |
zeertzjq | 961b2e5 | 2023-04-17 15:53:24 +0100 | [diff] [blame] | 4007 | call assert_equal(0, getcmdpos()) |
| 4008 | call assert_equal(0, getcmdscreenpos()) |
| 4009 | call assert_equal('', getcmdcompltype()) |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 4010 | call assert_equal('', getcmdcomplpat()) |
zeertzjq | 961b2e5 | 2023-04-17 15:53:24 +0100 | [diff] [blame] | 4011 | |
zeertzjq | a821b60 | 2024-06-18 20:31:08 +0200 | [diff] [blame] | 4012 | cnoremap <expr> <F2> string(Call_cmd_funcs()) |
zeertzjq | 961b2e5 | 2023-04-17 15:53:24 +0100 | [diff] [blame] | 4013 | call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt") |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 4014 | call assert_equal("\"let a[6, 7, 'var', 'a']", @:) |
zeertzjq | 961b2e5 | 2023-04-17 15:53:24 +0100 | [diff] [blame] | 4015 | call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt") |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 4016 | call assert_equal("\"quit [6, 7, '', '']", @:) |
zeertzjq | 961b2e5 | 2023-04-17 15:53:24 +0100 | [diff] [blame] | 4017 | call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt") |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 4018 | call assert_equal("\"nosuchcommand [15, 16, '', '']", @:) |
zeertzjq | a821b60 | 2024-06-18 20:31:08 +0200 | [diff] [blame] | 4019 | |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 4020 | " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with |
| 4021 | " cmdline completion. |
zeertzjq | a821b60 | 2024-06-18 20:31:08 +0200 | [diff] [blame] | 4022 | let g:results = [] |
| 4023 | cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR> |
| 4024 | call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt") |
| 4025 | call assert_equal([ |
Ruslan Russkikh | 0407d62 | 2024-10-08 22:21:05 +0200 | [diff] [blame] | 4026 | \ ['sign undefine', 14, 15, 'sign', 'undefine'], |
| 4027 | \ ['sign unplace', 13, 14, 'sign', 'unplace'], |
| 4028 | \ ['sign un', 8, 9, 'sign', 'un']], g:results) |
zeertzjq | a821b60 | 2024-06-18 20:31:08 +0200 | [diff] [blame] | 4029 | |
| 4030 | unlet g:results |
zeertzjq | 961b2e5 | 2023-04-17 15:53:24 +0100 | [diff] [blame] | 4031 | cunmap <F2> |
Shougo Matsushita | 79d599b | 2022-05-07 12:48:29 +0100 | [diff] [blame] | 4032 | endfunc |
| 4033 | |
Bram Moolenaar | 51f0bfb | 2022-05-17 20:11:02 +0100 | [diff] [blame] | 4034 | func Test_recursive_register() |
| 4035 | let @= = '' |
| 4036 | silent! ?e/ |
| 4037 | let caught = 'no' |
| 4038 | try |
| 4039 | normal // |
| 4040 | catch /E169:/ |
| 4041 | let caught = 'yes' |
| 4042 | endtry |
| 4043 | call assert_equal('yes', caught) |
| 4044 | endfunc |
| 4045 | |
Bram Moolenaar | 44a3f33 | 2022-06-06 15:38:21 +0100 | [diff] [blame] | 4046 | func Test_long_error_message() |
| 4047 | " the error should be truncated, not overrun IObuff |
| 4048 | silent! norm Q00000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
| 4049 | endfunc |
| 4050 | |
zeertzjq | 6791adc | 2022-07-26 20:42:25 +0100 | [diff] [blame] | 4051 | func Test_cmdline_redraw_tabline() |
| 4052 | CheckRunVimInTerminal |
| 4053 | |
| 4054 | let lines =<< trim END |
| 4055 | set showtabline=2 |
| 4056 | autocmd CmdlineEnter * set tabline=foo |
| 4057 | END |
Bram Moolenaar | 45bbaef | 2022-09-08 16:39:22 +0100 | [diff] [blame] | 4058 | call writefile(lines, 'Xcmdline_redraw_tabline', 'D') |
zeertzjq | 6791adc | 2022-07-26 20:42:25 +0100 | [diff] [blame] | 4059 | let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6}) |
| 4060 | call term_sendkeys(buf, ':') |
| 4061 | call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))}) |
| 4062 | |
| 4063 | call StopVimInTerminal(buf) |
zeertzjq | 6791adc | 2022-07-26 20:42:25 +0100 | [diff] [blame] | 4064 | endfunc |
| 4065 | |
zeertzjq | b82a2ab | 2022-08-21 14:33:57 +0100 | [diff] [blame] | 4066 | func Test_wildmenu_pum_disable_while_shown() |
| 4067 | set wildoptions=pum |
| 4068 | set wildmenu |
| 4069 | cnoremap <F2> <Cmd>set nowildmenu<CR> |
| 4070 | call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx') |
| 4071 | call assert_equal(0, pumvisible()) |
| 4072 | cunmap <F2> |
| 4073 | set wildoptions& wildmenu& |
| 4074 | endfunc |
| 4075 | |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 4076 | func Test_setcmdline() |
| 4077 | func SetText(text, pos) |
zeertzjq | ac6cd31 | 2023-04-12 16:21:14 +0100 | [diff] [blame] | 4078 | call assert_equal(0, setcmdline(test_null_string())) |
| 4079 | call assert_equal('', getcmdline()) |
| 4080 | call assert_equal(1, getcmdpos()) |
| 4081 | |
| 4082 | call assert_equal(0, setcmdline(''[: -1])) |
| 4083 | call assert_equal('', getcmdline()) |
| 4084 | call assert_equal(1, getcmdpos()) |
| 4085 | |
zeertzjq | 54acb90 | 2022-08-29 16:21:25 +0100 | [diff] [blame] | 4086 | autocmd CmdlineChanged * let g:cmdtype = expand('<afile>') |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 4087 | call assert_equal(0, setcmdline(a:text)) |
| 4088 | call assert_equal(a:text, getcmdline()) |
| 4089 | call assert_equal(len(a:text) + 1, getcmdpos()) |
zeertzjq | 54acb90 | 2022-08-29 16:21:25 +0100 | [diff] [blame] | 4090 | call assert_equal(getcmdtype(), g:cmdtype) |
| 4091 | unlet g:cmdtype |
| 4092 | autocmd! CmdlineChanged |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 4093 | |
| 4094 | call assert_equal(0, setcmdline(a:text, a:pos)) |
| 4095 | call assert_equal(a:text, getcmdline()) |
| 4096 | call assert_equal(a:pos, getcmdpos()) |
| 4097 | |
| 4098 | call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:') |
Yegappan Lakshmanan | 25f1e55 | 2022-08-28 17:25:04 +0100 | [diff] [blame] | 4099 | call assert_fails('call setcmdline({}, 0)', 'E1174:') |
| 4100 | call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:') |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 4101 | |
| 4102 | return '' |
| 4103 | endfunc |
| 4104 | |
| 4105 | call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt') |
| 4106 | call assert_equal('set rtp?', @:) |
| 4107 | |
zeertzjq | 54acb90 | 2022-08-29 16:21:25 +0100 | [diff] [blame] | 4108 | call feedkeys(":let g:str = input('? ')\<CR>", 't') |
| 4109 | call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt') |
| 4110 | call assert_equal('foo', g:str) |
| 4111 | unlet g:str |
| 4112 | |
| 4113 | delfunc SetText |
| 4114 | |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 4115 | " setcmdline() returns 1 when not editing the command line. |
| 4116 | call assert_equal(1, 'foo'->setcmdline()) |
| 4117 | |
| 4118 | " Called in custom function |
| 4119 | func CustomComplete(A, L, P) |
| 4120 | call assert_equal(0, setcmdline("DoCmd ")) |
| 4121 | return "January\nFebruary\nMars\n" |
| 4122 | endfunc |
| 4123 | |
| 4124 | com! -nargs=* -complete=custom,CustomComplete DoCmd : |
| 4125 | call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx') |
| 4126 | call assert_equal('"DoCmd January February Mars', @:) |
zeertzjq | 54acb90 | 2022-08-29 16:21:25 +0100 | [diff] [blame] | 4127 | delcom DoCmd |
| 4128 | delfunc CustomComplete |
Shougo Matsushita | 07ea5f1 | 2022-08-27 12:22:25 +0100 | [diff] [blame] | 4129 | |
| 4130 | " Called in <expr> |
| 4131 | cnoremap <expr>a setcmdline('let foo=') |
| 4132 | call feedkeys(":a\<CR>", 'tx') |
| 4133 | call assert_equal('let foo=0', @:) |
| 4134 | cunmap a |
| 4135 | endfunc |
| 4136 | |
Sean Dewar | fc8a601 | 2023-04-17 16:41:20 +0100 | [diff] [blame] | 4137 | func Test_rulerformat_position() |
| 4138 | CheckScreendump |
| 4139 | |
| 4140 | let buf = RunVimInTerminal('', #{rows: 2, cols: 20}) |
| 4141 | call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>") |
| 4142 | call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>") |
| 4143 | call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p") |
| 4144 | call VerifyScreenDump(buf, 'Test_rulerformat_position', {}) |
| 4145 | |
| 4146 | " clean up |
| 4147 | call StopVimInTerminal(buf) |
| 4148 | endfunc |
| 4149 | |
Yegappan Lakshmanan | ac023e8 | 2024-11-27 20:55:45 +0100 | [diff] [blame] | 4150 | " Test for using "%!" in 'rulerformat' to use a function |
| 4151 | func Test_rulerformat_function() |
| 4152 | CheckScreendump |
| 4153 | |
| 4154 | let lines =<< trim END |
| 4155 | func TestRulerFn() |
| 4156 | return '10,20%=30%%' |
| 4157 | endfunc |
| 4158 | END |
| 4159 | call writefile(lines, 'Xrulerformat_function', 'D') |
| 4160 | |
| 4161 | let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40}) |
| 4162 | call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>") |
| 4163 | call term_sendkeys(buf, ":redraw!\<CR>") |
| 4164 | call term_wait(buf) |
| 4165 | call VerifyScreenDump(buf, 'Test_rulerformat_function', {}) |
| 4166 | |
| 4167 | " clean up |
| 4168 | call StopVimInTerminal(buf) |
| 4169 | endfunc |
| 4170 | |
zeertzjq | e4c79d3 | 2023-08-15 22:41:53 +0200 | [diff] [blame] | 4171 | func Test_getcompletion_usercmd() |
Christian Brabandt | 8ef1fbc | 2023-07-17 20:09:37 +0200 | [diff] [blame] | 4172 | command! -nargs=* -complete=command TestCompletion echo <q-args> |
Christian Brabandt | 8ef1fbc | 2023-07-17 20:09:37 +0200 | [diff] [blame] | 4173 | |
zeertzjq | e4c79d3 | 2023-08-15 22:41:53 +0200 | [diff] [blame] | 4174 | call assert_equal(getcompletion('', 'cmdline'), |
| 4175 | \ getcompletion('TestCompletion ', 'cmdline')) |
| 4176 | call assert_equal(['<buffer>'], |
| 4177 | \ getcompletion('TestCompletion map <bu', 'cmdline')) |
| 4178 | |
Christian Brabandt | 8ef1fbc | 2023-07-17 20:09:37 +0200 | [diff] [blame] | 4179 | delcom TestCompletion |
Christian Brabandt | 8ef1fbc | 2023-07-17 20:09:37 +0200 | [diff] [blame] | 4180 | endfunc |
zeertzjq | e4c79d3 | 2023-08-15 22:41:53 +0200 | [diff] [blame] | 4181 | |
Shougo Matsushita | 92997dd | 2023-08-20 20:55:55 +0200 | [diff] [blame] | 4182 | func Test_custom_completion() |
| 4183 | func CustomComplete1(lead, line, pos) |
| 4184 | return "a\nb\nc" |
| 4185 | endfunc |
| 4186 | func CustomComplete2(lead, line, pos) |
| 4187 | return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 }) |
| 4188 | endfunc |
| 4189 | func Check_custom_completion() |
| 4190 | call assert_equal('custom,CustomComplete1', getcmdcompltype()) |
| 4191 | return '' |
| 4192 | endfunc |
| 4193 | func Check_customlist_completion() |
| 4194 | call assert_equal('customlist,CustomComplete2', getcmdcompltype()) |
| 4195 | return '' |
| 4196 | endfunc |
| 4197 | |
| 4198 | command -nargs=1 -complete=custom,CustomComplete1 Test1 echo |
| 4199 | command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo |
| 4200 | |
| 4201 | call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt") |
| 4202 | call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt") |
zeertzjq | e2c0f81 | 2025-07-06 20:26:56 +0200 | [diff] [blame] | 4203 | call assert_equal('custom,CustomComplete1', getcompletiontype('Test1 ')) |
| 4204 | call assert_equal('customlist,CustomComplete2', getcompletiontype('Test2 ')) |
Shougo Matsushita | 92997dd | 2023-08-20 20:55:55 +0200 | [diff] [blame] | 4205 | |
| 4206 | call assert_fails("call getcompletion('', 'custom')", 'E475:') |
| 4207 | call assert_fails("call getcompletion('', 'customlist')", 'E475:') |
| 4208 | |
zeertzjq | 757f321 | 2024-04-15 19:01:04 +0200 | [diff] [blame] | 4209 | call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1')) |
| 4210 | call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2')) |
| 4211 | call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2')) |
Shougo Matsushita | 92997dd | 2023-08-20 20:55:55 +0200 | [diff] [blame] | 4212 | |
| 4213 | delcom Test1 |
| 4214 | delcom Test2 |
| 4215 | |
| 4216 | delfunc CustomComplete1 |
| 4217 | delfunc CustomComplete2 |
| 4218 | delfunc Check_custom_completion |
| 4219 | delfunc Check_customlist_completion |
| 4220 | endfunc |
| 4221 | |
zeertzjq | 28a2360 | 2023-09-29 19:58:35 +0200 | [diff] [blame] | 4222 | func Test_custom_completion_with_glob() |
| 4223 | func TestGlobComplete(A, L, P) |
| 4224 | return split(glob('Xglob*'), "\n") |
| 4225 | endfunc |
| 4226 | |
| 4227 | command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete : |
| 4228 | call writefile([], 'Xglob1', 'D') |
| 4229 | call writefile([], 'Xglob2', 'D') |
| 4230 | |
| 4231 | call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt') |
| 4232 | call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:) |
| 4233 | |
| 4234 | delcommand TestGlobComplete |
| 4235 | delfunc TestGlobComplete |
| 4236 | endfunc |
| 4237 | |
Christian Brabandt | 8610f74 | 2024-01-12 17:34:40 +0100 | [diff] [blame] | 4238 | func Test_window_size_stays_same_after_changing_cmdheight() |
| 4239 | set laststatus=2 |
| 4240 | let expected = winheight(0) |
| 4241 | function! Function_name() abort |
| 4242 | call feedkeys(":"..repeat('x', &columns), 'x') |
| 4243 | let &cmdheight=2 |
| 4244 | let &cmdheight=1 |
| 4245 | redraw |
| 4246 | endfunction |
| 4247 | call Function_name() |
| 4248 | call assert_equal(expected, winheight(0)) |
| 4249 | endfunc |
| 4250 | |
Christian Brabandt | 0dc0bff | 2024-02-24 14:12:13 +0100 | [diff] [blame] | 4251 | " verify that buffer-completion finds all buffer names matching a pattern |
| 4252 | func Test_buffer_completion() |
| 4253 | " should return empty list |
| 4254 | call assert_equal([], getcompletion('', 'buffer')) |
| 4255 | |
| 4256 | call mkdir('Xbuf_complete', 'R') |
| 4257 | e Xbuf_complete/Foobar.c |
| 4258 | e Xbuf_complete/MyFoobar.c |
| 4259 | e AFoobar.h |
| 4260 | let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"] |
| 4261 | |
| 4262 | call assert_equal(3, len(getcompletion('Foo', 'buffer'))) |
| 4263 | call assert_equal(expected, getcompletion('Foo', 'buffer')) |
| 4264 | call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt') |
| 4265 | call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:) |
| 4266 | endfunc |
| 4267 | |
Anton Sharonov | 49528da | 2024-04-14 20:02:24 +0200 | [diff] [blame] | 4268 | " :set t_?? |
| 4269 | func Test_term_option() |
| 4270 | set wildoptions& |
| 4271 | let _cpo = &cpo |
| 4272 | set cpo-=C |
Christian Brabandt | 0d87e3c | 2024-04-14 23:14:50 +0200 | [diff] [blame] | 4273 | " There may be more, test only until t_xo |
Anton Sharonov | 49528da | 2024-04-14 20:02:24 +0200 | [diff] [blame] | 4274 | let expected='"set t_AB t_AF t_AU t_AL t_al t_bc t_BE t_BD t_cd t_ce t_Ce t_CF t_cl t_cm' |
| 4275 | \ .. ' t_Co t_CS t_Cs t_cs t_CV t_da t_db t_DL t_dl t_ds t_Ds t_EC t_EI t_fs t_fd t_fe' |
| 4276 | \ .. ' t_GP t_IE t_IS t_ke t_ks t_le t_mb t_md t_me t_mr t_ms t_nd t_op t_RF t_RB t_RC' |
| 4277 | \ .. ' t_RI t_Ri t_RK t_RS t_RT t_RV t_Sb t_SC t_se t_Sf t_SH t_SI t_Si t_so t_SR t_sr' |
| 4278 | \ .. ' t_ST t_Te t_te t_TE t_ti t_TI t_Ts t_ts t_u7 t_ue t_us t_Us t_ut t_vb t_ve t_vi' |
Christian Brabandt | 0d87e3c | 2024-04-14 23:14:50 +0200 | [diff] [blame] | 4279 | \ .. ' t_VS t_vs t_WP t_WS t_XM t_xn t_xs t_ZH t_ZR t_8f t_8b t_8u t_xo .*' |
Anton Sharonov | 49528da | 2024-04-14 20:02:24 +0200 | [diff] [blame] | 4280 | call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx') |
Christian Brabandt | 0d87e3c | 2024-04-14 23:14:50 +0200 | [diff] [blame] | 4281 | call assert_match(expected, @:) |
Anton Sharonov | 49528da | 2024-04-14 20:02:24 +0200 | [diff] [blame] | 4282 | let &cpo = _cpo |
| 4283 | endfunc |
| 4284 | |
Christian Brabandt | 70a11a6 | 2024-07-26 19:13:55 +0200 | [diff] [blame] | 4285 | func Test_ex_command_completion() |
| 4286 | " required for :* |
| 4287 | set cpo+=* |
| 4288 | let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0') |
Hirohito Higashi | fbe4a8f | 2025-04-27 15:28:30 +0200 | [diff] [blame] | 4289 | " :++ and :-- are only valid in Vim9 script context, so they can be ignored |
Christian Brabandt | 70a11a6 | 2024-07-26 19:13:55 +0200 | [diff] [blame] | 4290 | call assert_equal(['++', '--'], sort(list)) |
Doug Kearns | ea84202 | 2024-09-29 17:17:41 +0200 | [diff] [blame] | 4291 | call assert_equal(2, exists(':k')) |
Christian Brabandt | 70a11a6 | 2024-07-26 19:13:55 +0200 | [diff] [blame] | 4292 | call assert_equal(0, exists(':ke')) |
| 4293 | call assert_equal(1, exists(':kee')) |
| 4294 | call assert_equal(1, exists(':keep')) |
| 4295 | call assert_equal(1, exists(':keepm')) |
| 4296 | call assert_equal(1, exists(':keepma')) |
| 4297 | call assert_equal(1, exists(':keepmar')) |
| 4298 | call assert_equal(1, exists(':keepmark')) |
| 4299 | call assert_equal(2, exists(':keepmarks')) |
| 4300 | call assert_equal(2, exists(':keepalt')) |
| 4301 | call assert_equal(2, exists(':keepjumps')) |
| 4302 | call assert_equal(2, exists(':keeppatterns')) |
| 4303 | set cpo-=* |
| 4304 | endfunc |
| 4305 | |
zeertzjq | 5df3cb2 | 2024-10-07 21:05:06 +0200 | [diff] [blame] | 4306 | func Test_cd_bslash_completion_windows() |
Christian Brabandt | 1a31c43 | 2024-10-06 16:34:20 +0200 | [diff] [blame] | 4307 | CheckMSWindows |
| 4308 | let save_shellslash = &shellslash |
| 4309 | set noshellslash |
| 4310 | call system('mkdir XXXa\_b') |
| 4311 | defer delete('XXXa', 'rf') |
| 4312 | call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx') |
| 4313 | call assert_equal('"cd XXXa\_b\', @:) |
| 4314 | let &shellslash = save_shellslash |
| 4315 | endfunc |
| 4316 | |
zeertzjq | ec270a5 | 2025-04-23 20:50:23 +0200 | [diff] [blame] | 4317 | " Test cmdcomplete_info() with CmdlineLeavePre autocmd |
Girish Palya | 92f68e2 | 2025-04-21 11:12:41 +0200 | [diff] [blame] | 4318 | func Test_cmdcomplete_info() |
| 4319 | augroup test_CmdlineLeavePre |
| 4320 | autocmd! |
zeertzjq | ec270a5 | 2025-04-23 20:50:23 +0200 | [diff] [blame] | 4321 | " Calling expand() should not interfere with cmdcomplete_info(). |
| 4322 | autocmd CmdlineLeavePre * call expand('test_cmdline.*') |
Girish Palya | 92f68e2 | 2025-04-21 11:12:41 +0200 | [diff] [blame] | 4323 | autocmd CmdlineLeavePre * let g:cmdcomplete_info = string(cmdcomplete_info()) |
| 4324 | augroup END |
| 4325 | new |
| 4326 | call assert_equal({}, cmdcomplete_info()) |
| 4327 | call feedkeys(":h echom\<cr>", "tx") " No expansion |
| 4328 | call assert_equal('{}', g:cmdcomplete_info) |
| 4329 | call feedkeys(":h echoms\<tab>\<cr>", "tx") |
| 4330 | call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info) |
| 4331 | call feedkeys(":h echom\<tab>\<cr>", "tx") |
| 4332 | call assert_equal( |
| 4333 | \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}', |
| 4334 | \ g:cmdcomplete_info) |
| 4335 | call feedkeys(":h echom\<tab>\<tab>\<cr>", "tx") |
| 4336 | call assert_equal( |
| 4337 | \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}', |
| 4338 | \ g:cmdcomplete_info) |
| 4339 | call feedkeys(":h echom\<tab>\<tab>\<tab>\<cr>", "tx") |
| 4340 | call assert_equal( |
| 4341 | \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}', |
| 4342 | \ g:cmdcomplete_info) |
| 4343 | |
| 4344 | set wildoptions=pum |
| 4345 | call feedkeys(":h echoms\<tab>\<cr>", "tx") |
| 4346 | call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info) |
| 4347 | call feedkeys(":h echom\<tab>\<cr>", "tx") |
| 4348 | call assert_equal( |
| 4349 | \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}', |
| 4350 | \ g:cmdcomplete_info) |
| 4351 | call feedkeys(":h echom\<tab>\<tab>\<cr>", "tx") |
| 4352 | call assert_equal( |
| 4353 | \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}', |
| 4354 | \ g:cmdcomplete_info) |
| 4355 | call feedkeys(":h echom\<tab>\<tab>\<tab>\<cr>", "tx") |
| 4356 | call assert_equal( |
| 4357 | \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}', |
| 4358 | \ g:cmdcomplete_info) |
| 4359 | bw! |
| 4360 | set wildoptions& |
| 4361 | endfunc |
| 4362 | |
Naruhiko Nishino | be5bd4d | 2025-05-14 21:20:28 +0200 | [diff] [blame] | 4363 | func Test_redrawtabpanel_error() |
| 4364 | CheckNotFeature tabpanel |
| 4365 | call assert_fails(':redrawtabpanel', 'E1547:') |
| 4366 | endfunc |
| 4367 | |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4368 | " Test wildcharm completion for '/' and '?' search |
| 4369 | func Test_search_complete() |
| 4370 | CheckOption incsearch |
| 4371 | set wildcharm=<c-z> |
| 4372 | |
| 4373 | " Disable char_avail so that expansion of commandline works |
| 4374 | call test_override("char_avail", 1) |
| 4375 | |
| 4376 | func GetComplInfo() |
| 4377 | let g:compl_info = cmdcomplete_info() |
| 4378 | return '' |
| 4379 | endfunc |
| 4380 | |
| 4381 | new |
| 4382 | cnoremap <buffer><expr> <F9> GetComplInfo() |
| 4383 | |
| 4384 | " Pressing <Tab> inserts tab character |
| 4385 | set wildchar=0 |
| 4386 | call setline(1, "x\t") |
| 4387 | call feedkeys("/x\t\r", "tx") |
| 4388 | call assert_equal("x\t", @/) |
| 4389 | set wildchar& |
| 4390 | |
| 4391 | call setline(1, ['the', 'these', 'thethe', 'thethere', 'foobar']) |
| 4392 | |
| 4393 | for trig in ["\<tab>", "\<c-z>"] |
| 4394 | " Test menu first item and order |
| 4395 | call feedkeys($"gg2j/t{trig}\<f9>", 'tx') |
| 4396 | call assert_equal(['the', 'thethere', 'there', 'these', 'thethe'], g:compl_info.matches) |
| 4397 | call feedkeys($"gg2j?t{trig}\<f9>", 'tx') |
| 4398 | call assert_equal(['these', 'the', 'there', 'thethere', 'thethe'], g:compl_info.matches) |
| 4399 | |
| 4400 | " <c-n> and <c-p> cycle through menu items |
| 4401 | call feedkeys($"gg/the{trig}\<cr>", 'tx') |
| 4402 | call assert_equal('these', getline('.')) |
| 4403 | call feedkeys($"gg/the{trig}\<c-n>\<cr>", 'tx') |
| 4404 | call assert_equal('thethe', getline('.')) |
| 4405 | call feedkeys($"gg/the{trig}".repeat("\<c-n>", 5)."\<cr>", 'tx') |
| 4406 | call assert_equal('these', getline('.')) |
| 4407 | call feedkeys($"G?the{trig}\<cr>", 'tx') |
| 4408 | call assert_equal('thethere', getline('.')) |
| 4409 | call feedkeys($"G?the{trig}".repeat("\<c-p>", 5)."\<cr>", 'tx') |
| 4410 | call assert_equal('thethere', getline('.')) |
| 4411 | |
| 4412 | " Beginning of word pattern (<) retains '<' |
| 4413 | call feedkeys($"gg2j/\\<t{trig}\<f9>", 'tx') |
| 4414 | call assert_equal(['\<thethere', '\<the', '\<these', '\<thethe'], g:compl_info.matches) |
| 4415 | call feedkeys($"gg2j?\\<t{trig}\<f9>", 'tx') |
| 4416 | call assert_equal(['\<these', '\<the', '\<thethere', '\<thethe'], g:compl_info.matches) |
| 4417 | call feedkeys($"gg2j/\\v<t{trig}\<f9>", 'tx') |
| 4418 | call assert_equal(['\v<thethere', '\v<the', '\v<these', '\v<thethe'], g:compl_info.matches) |
| 4419 | call feedkeys($"gg2j?\\v<th{trig}\<f9>", 'tx') |
| 4420 | call assert_equal(['\v<these', '\v<the', '\v<thethere', '\v<thethe'], g:compl_info.matches) |
| 4421 | endfor |
| 4422 | |
| 4423 | " Ctrl-G goes from one match to the next, after menu is opened |
| 4424 | set incsearch |
| 4425 | " first match |
| 4426 | call feedkeys("gg/the\<c-z>\<c-n>\<c-g>\<cr>", 'tx') |
| 4427 | call assert_equal('thethe', getline('.')) |
| 4428 | " second match |
| 4429 | call feedkeys("gg/the\<c-z>\<c-n>\<c-g>\<c-g>\<cr>", 'tx') |
| 4430 | call assert_equal('thethere', getline('.')) |
| 4431 | call assert_equal([0, 0, 0, 0], getpos('"')) |
| 4432 | |
| 4433 | " CTRL-T goes to the previous match |
| 4434 | " first match |
| 4435 | call feedkeys("G?the\<c-z>".repeat("\<c-n>", 2)."\<c-t>\<cr>", 'tx') |
| 4436 | call assert_equal('thethere', getline('.')) |
| 4437 | " second match |
| 4438 | call feedkeys("G?the\<c-z>".repeat("\<c-n>", 2).repeat("\<c-t>", 2)."\<cr>", 'tx') |
| 4439 | call assert_equal('thethe', getline('.')) |
| 4440 | |
| 4441 | " wild menu is cleared properly |
| 4442 | call feedkeys("/the\<c-z>\<esc>/\<f9>", 'tx') |
| 4443 | call assert_equal({}, g:compl_info) |
| 4444 | call feedkeys("/the\<c-z>\<c-e>\<f9>", 'tx') |
| 4445 | call assert_equal([], g:compl_info.matches) |
| 4446 | |
| 4447 | " Do not expand if offset is present (/pattern/offset and ?pattern?offset) |
| 4448 | for pat in ["/", "/2", "/-3", "\\/"] |
| 4449 | call feedkeys("/the" . pat . "\<c-z>\<f9>", 'tx') |
| 4450 | call assert_equal({}, g:compl_info) |
| 4451 | endfor |
| 4452 | for pat in ["?", "?2", "?-3", "\\\\?"] |
| 4453 | call feedkeys("?the" . pat . "\<c-z>\<f9>", 'tx') |
| 4454 | call assert_equal({}, g:compl_info) |
| 4455 | endfor |
| 4456 | |
| 4457 | " Last letter of match is multibyte |
| 4458 | call setline('$', ['theΩ']) |
| 4459 | call feedkeys("gg/th\<c-z>\<f9>", 'tx') |
| 4460 | call assert_equal(['these', 'thethe', 'the', 'thethere', 'there', 'theΩ'], |
| 4461 | \ g:compl_info.matches) |
| 4462 | |
| 4463 | " Identical words |
| 4464 | call setline(1, ["foo", "foo", "foo", "foobar"]) |
| 4465 | call feedkeys("gg/f\<c-z>\<f9>", 'tx') |
| 4466 | call assert_equal(['foo', 'foobar'], g:compl_info.matches) |
| 4467 | |
| 4468 | " Exact match |
| 4469 | call feedkeys("/foo\<c-z>\<f9>", 'tx') |
| 4470 | call assert_equal(['foo', 'foobar'], g:compl_info.matches) |
| 4471 | |
| 4472 | " Match case correctly |
| 4473 | %d |
| 4474 | call setline(1, ["foobar", "Foobar", "fooBAr", "FooBARR"]) |
Girish Palya | 93c2d5b | 2025-07-08 21:29:02 +0200 | [diff] [blame] | 4475 | |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4476 | call feedkeys("gg/f\<tab>\<f9>", 'tx') |
| 4477 | call assert_equal(['fooBAr', 'foobar'], g:compl_info.matches) |
| 4478 | call feedkeys("gg/Fo\<tab>\<f9>", 'tx') |
| 4479 | call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches) |
| 4480 | call feedkeys("gg/FO\<tab>\<f9>", 'tx') |
Christian Brabandt | f2ec8d4 | 2025-07-08 22:04:10 +0200 | [diff] [blame] | 4481 | call assert_equal({}, g:compl_info) |
Girish Palya | af22007 | 2025-07-07 19:42:10 +0200 | [diff] [blame] | 4482 | call feedkeys("gg/\\cFo\<tab>\<f9>", 'tx') |
| 4483 | call assert_equal(['\cFoobar', '\cFooBAr', '\cFooBARR'], g:compl_info.matches) |
Girish Palya | 93c2d5b | 2025-07-08 21:29:02 +0200 | [diff] [blame] | 4484 | |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4485 | set ignorecase |
| 4486 | call feedkeys("gg/f\<tab>\<f9>", 'tx') |
| 4487 | call assert_equal(['foobar', 'fooBAr', 'fooBARR'], g:compl_info.matches) |
| 4488 | call feedkeys("gg/Fo\<tab>\<f9>", 'tx') |
| 4489 | call assert_equal(['Foobar', 'FooBAr', 'FooBARR'], g:compl_info.matches) |
| 4490 | call feedkeys("gg/FO\<tab>\<f9>", 'tx') |
| 4491 | call assert_equal(['FOobar', 'FOoBAr', 'FOoBARR'], g:compl_info.matches) |
Girish Palya | af22007 | 2025-07-07 19:42:10 +0200 | [diff] [blame] | 4492 | call feedkeys("gg/\\Cfo\<tab>\<f9>", 'tx') |
| 4493 | call assert_equal(['\CfooBAr', '\Cfoobar'], g:compl_info.matches) |
Girish Palya | 93c2d5b | 2025-07-08 21:29:02 +0200 | [diff] [blame] | 4494 | |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4495 | set smartcase |
| 4496 | call feedkeys("gg/f\<tab>\<f9>", 'tx') |
Girish Palya | af22007 | 2025-07-07 19:42:10 +0200 | [diff] [blame] | 4497 | call assert_equal(['foobar', 'fooBAr', 'foobarr'], g:compl_info.matches) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4498 | call feedkeys("gg/Fo\<tab>\<f9>", 'tx') |
| 4499 | call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches) |
| 4500 | call feedkeys("gg/FO\<tab>\<f9>", 'tx') |
Christian Brabandt | f2ec8d4 | 2025-07-08 22:04:10 +0200 | [diff] [blame] | 4501 | call assert_equal({}, g:compl_info) |
| 4502 | |
| 4503 | " Issue #17680 (getcompletion() does not support search completion) |
| 4504 | let result = getcompletion('%s/', 'cmdline') |
| 4505 | call assert_equal([], result) |
| 4506 | |
Girish Palya | 93c2d5b | 2025-07-08 21:29:02 +0200 | [diff] [blame] | 4507 | call feedkeys("gg/foob\<tab>\<f9>", 'tx') |
| 4508 | call assert_equal(['foobar', 'foobarr'], g:compl_info.matches) |
Girish Palya | af22007 | 2025-07-07 19:42:10 +0200 | [diff] [blame] | 4509 | call feedkeys("gg/\\Cfo\<tab>\<f9>", 'tx') |
| 4510 | call assert_equal(['\CfooBAr', '\Cfoobar'], g:compl_info.matches) |
| 4511 | call feedkeys("gg/\\cFo\<tab>\<f9>", 'tx') |
| 4512 | call assert_equal(['\cFoobar', '\cFooBAr', '\cFooBARR'], g:compl_info.matches) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4513 | |
Girish Palya | 93c2d5b | 2025-07-08 21:29:02 +0200 | [diff] [blame] | 4514 | set wildoptions+=exacttext ignorecase& smartcase& |
| 4515 | call feedkeys("gg/F\<tab>\<f9>", 'tx') |
| 4516 | call assert_equal(['Foobar', 'FooBARR'], g:compl_info.matches) |
| 4517 | call feedkeys("gg/foob\<tab>\<f9>", 'tx') |
| 4518 | call assert_equal([], g:compl_info.matches) |
| 4519 | call feedkeys("gg/r\\n.\<tab>\<f9>", 'tx') |
| 4520 | call assert_equal(['r\nFoobar', 'r\nfooBAr', 'r\nFooBARR'], g:compl_info.matches) |
| 4521 | |
| 4522 | set ignorecase |
| 4523 | call feedkeys("gg/F\<tab>\<f9>", 'tx') |
| 4524 | call assert_equal(['Foobar', 'fooBAr', 'FooBARR', 'foobar'], g:compl_info.matches) |
| 4525 | call feedkeys("gg/R\\n.\<tab>\<f9>", 'tx') |
| 4526 | call assert_equal(['r\nFoobar', 'r\nfooBAr', 'r\nFooBARR'], g:compl_info.matches) |
| 4527 | |
| 4528 | set smartcase |
| 4529 | call feedkeys("gg/f\<tab>\<f9>", 'tx') |
| 4530 | call assert_equal(['Foobar', 'fooBAr', 'FooBARR', 'foobar'], g:compl_info.matches) |
| 4531 | call feedkeys("gg/foob\<tab>\<f9>", 'tx') |
| 4532 | call assert_equal(['Foobar', 'fooBAr', 'FooBARR', 'foobar'], g:compl_info.matches) |
| 4533 | call feedkeys("gg/R\\n.\<tab>\<f9>", 'tx') |
| 4534 | call assert_equal({}, g:compl_info) |
| 4535 | call feedkeys("gg/r\\n.*\\n\<tab>\<f9>", 'tx') |
| 4536 | call assert_equal(['r\nFoobar\nfooBAr', 'r\nfooBAr\nFooBARR'], g:compl_info.matches) |
| 4537 | |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4538 | bw! |
| 4539 | call test_override("char_avail", 0) |
| 4540 | delfunc GetComplInfo |
| 4541 | unlet! g:compl_info |
Girish Palya | 93c2d5b | 2025-07-08 21:29:02 +0200 | [diff] [blame] | 4542 | set wildcharm=0 incsearch& ignorecase& smartcase& wildoptions& |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4543 | endfunc |
| 4544 | |
| 4545 | func Test_search_wildmenu_screendump() |
| 4546 | CheckScreendump |
| 4547 | |
| 4548 | let lines =<< trim [SCRIPT] |
zeertzjq | 5e34eec | 2025-07-05 15:37:17 +0200 | [diff] [blame] | 4549 | call test_override('alloc_lines', 1) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4550 | set wildmenu wildcharm=<f5> |
| 4551 | call setline(1, ['the', 'these', 'the', 'foobar', 'thethe', 'thethere']) |
| 4552 | [SCRIPT] |
| 4553 | call writefile(lines, 'XTest_search_wildmenu', 'D') |
| 4554 | let buf = RunVimInTerminal('-S XTest_search_wildmenu', {'rows': 10}) |
| 4555 | |
| 4556 | " Pattern has newline at EOF |
| 4557 | call term_sendkeys(buf, "gg2j/e\\n\<f5>") |
| 4558 | call VerifyScreenDump(buf, 'Test_search_wildmenu_1', {}) |
| 4559 | |
| 4560 | " longest:full |
| 4561 | call term_sendkeys(buf, "\<esc>:set wim=longest,full\<cr>") |
| 4562 | call term_sendkeys(buf, "gg/t\<f5>") |
| 4563 | call VerifyScreenDump(buf, 'Test_search_wildmenu_2', {}) |
| 4564 | |
| 4565 | " list:full |
| 4566 | call term_sendkeys(buf, "\<esc>:set wim=list,full\<cr>") |
| 4567 | call term_sendkeys(buf, "gg/t\<f5>") |
| 4568 | call VerifyScreenDump(buf, 'Test_search_wildmenu_3', {}) |
| 4569 | |
| 4570 | " noselect:full |
| 4571 | call term_sendkeys(buf, "\<esc>:set wim=noselect,full\<cr>") |
| 4572 | call term_sendkeys(buf, "gg/t\<f5>") |
| 4573 | call VerifyScreenDump(buf, 'Test_search_wildmenu_4', {}) |
| 4574 | |
| 4575 | " Multiline |
| 4576 | call term_sendkeys(buf, "\<esc>gg/t.*\\n.*\\n.\<tab>") |
| 4577 | call VerifyScreenDump(buf, 'Test_search_wildmenu_5', {}) |
| 4578 | |
zeertzjq | 08e5b12 | 2025-07-06 11:06:44 +0200 | [diff] [blame] | 4579 | " 'incsearch' is redrawn after accepting completion |
| 4580 | call term_sendkeys(buf, "\<esc>:set wim=full\<cr>") |
| 4581 | call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") |
| 4582 | call term_sendkeys(buf, "/th") |
| 4583 | call VerifyScreenDump(buf, 'Test_search_wildmenu_6', {}) |
| 4584 | call term_sendkeys(buf, "\<f5>") |
| 4585 | call VerifyScreenDump(buf, 'Test_search_wildmenu_7', {}) |
| 4586 | call term_sendkeys(buf, "\<c-n>\<c-y>") |
| 4587 | call VerifyScreenDump(buf, 'Test_search_wildmenu_8', {}) |
| 4588 | |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4589 | call term_sendkeys(buf, "\<esc>") |
| 4590 | call StopVimInTerminal(buf) |
| 4591 | endfunc |
| 4592 | |
| 4593 | " Test wildcharm completion for :s and :g with range |
| 4594 | func Test_range_complete() |
| 4595 | set wildcharm=<c-z> |
| 4596 | |
| 4597 | " Disable char_avail so that expansion of commandline works |
| 4598 | call test_override("char_avail", 1) |
| 4599 | |
| 4600 | func GetComplInfo() |
| 4601 | let g:compl_info = cmdcomplete_info() |
| 4602 | return '' |
| 4603 | endfunc |
| 4604 | new |
| 4605 | cnoremap <buffer><expr> <F9> GetComplInfo() |
| 4606 | |
| 4607 | call setline(1, ['ab', 'ba', 'ca', 'af']) |
| 4608 | |
| 4609 | for trig in ["\<tab>", "\<c-z>"] |
| 4610 | call feedkeys($":%s/a{trig}\<f9>", 'xt') |
Christian Brabandt | f2ec8d4 | 2025-07-08 22:04:10 +0200 | [diff] [blame] | 4611 | call assert_equal(['ab', 'a', 'af'], g:compl_info.matches) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4612 | call feedkeys($":vim9cmd :%s/a{trig}\<f9>", 'xt') |
Christian Brabandt | f2ec8d4 | 2025-07-08 22:04:10 +0200 | [diff] [blame] | 4613 | call assert_equal(['ab', 'a', 'af'], g:compl_info.matches) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4614 | endfor |
| 4615 | |
| 4616 | call feedkeys(":%s/\<c-z>\<f9>", 'xt') |
Christian Brabandt | f2ec8d4 | 2025-07-08 22:04:10 +0200 | [diff] [blame] | 4617 | call assert_equal({}, g:compl_info) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4618 | |
| 4619 | for cmd in ['s', 'g'] |
Christian Brabandt | f2ec8d4 | 2025-07-08 22:04:10 +0200 | [diff] [blame] | 4620 | call feedkeys($":1,2{cmd}/a\<c-z>\<f9>", 'xt') |
| 4621 | call assert_equal(['ab', 'a'], g:compl_info.matches) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4622 | endfor |
| 4623 | |
| 4624 | 1 |
| 4625 | call feedkeys(":.,+2s/a\<c-z>\<f9>", 'xt') |
Christian Brabandt | f2ec8d4 | 2025-07-08 22:04:10 +0200 | [diff] [blame] | 4626 | call assert_equal(['ab', 'a'], g:compl_info.matches) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4627 | |
| 4628 | /f |
| 4629 | call feedkeys(":1,s/b\<c-z>\<f9>", 'xt') |
Christian Brabandt | f2ec8d4 | 2025-07-08 22:04:10 +0200 | [diff] [blame] | 4630 | call assert_equal(['b', 'ba'], g:compl_info.matches) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4631 | |
| 4632 | /c |
| 4633 | call feedkeys(":\\?,4s/a\<c-z>\<f9>", 'xt') |
Christian Brabandt | f2ec8d4 | 2025-07-08 22:04:10 +0200 | [diff] [blame] | 4634 | call assert_equal(['a', 'af'], g:compl_info.matches) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4635 | |
| 4636 | %s/c/c/ |
| 4637 | call feedkeys(":1,\\&s/a\<c-z>\<f9>", 'xt') |
Christian Brabandt | f2ec8d4 | 2025-07-08 22:04:10 +0200 | [diff] [blame] | 4638 | call assert_equal(['ab', 'a'], g:compl_info.matches) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4639 | |
| 4640 | 3 |
| 4641 | normal! ma |
| 4642 | call feedkeys(":'a,$s/a\<c-z>\<f9>", 'xt') |
Christian Brabandt | f2ec8d4 | 2025-07-08 22:04:10 +0200 | [diff] [blame] | 4643 | call assert_equal(['a', 'af'], g:compl_info.matches) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4644 | |
| 4645 | " Line number followed by a search pattern ([start]/pattern/[command]) |
| 4646 | call feedkeys("3/a\<c-z>\<f9>", 'xt') |
Christian Brabandt | f2ec8d4 | 2025-07-08 22:04:10 +0200 | [diff] [blame] | 4647 | call assert_equal(['a', 'af', 'ab'], g:compl_info.matches) |
Girish Palya | 6b49fba | 2025-06-28 19:47:34 +0200 | [diff] [blame] | 4648 | |
| 4649 | bw! |
| 4650 | call test_override("char_avail", 0) |
| 4651 | delfunc GetComplInfo |
| 4652 | unlet! g:compl_info |
| 4653 | set wildcharm=0 |
| 4654 | endfunc |
| 4655 | |
Girish Palya | 0cd7f35 | 2025-07-07 19:47:53 +0200 | [diff] [blame] | 4656 | " With 'noselect' in 'wildmode', ensure that the popup menu (pum) does not retain |
| 4657 | " its scroll position after reopening. The menu should open showing the top items, |
| 4658 | " regardless of previous scrolling. |
| 4659 | func Test_pum_scroll_noselect() |
| 4660 | CheckScreendump |
| 4661 | |
| 4662 | let lines =<< trim [SCRIPT] |
| 4663 | command! -nargs=* -complete=customlist,TestFn TestCmd echo |
| 4664 | func TestFn(a, b, c) |
| 4665 | return map(range(1, 50), 'printf("a%d", v:val)') |
| 4666 | endfunc |
| 4667 | set wildmode=noselect,full |
| 4668 | set wildoptions=pum |
| 4669 | set wildmenu |
| 4670 | set noruler |
| 4671 | [SCRIPT] |
| 4672 | call writefile(lines, 'XTest_pum_scroll', 'D') |
| 4673 | let buf = RunVimInTerminal('-S XTest_pum_scroll', {'rows': 10}) |
| 4674 | |
| 4675 | call term_sendkeys(buf, ":TestCmd \<tab>" . repeat("\<c-n>", 20)) |
| 4676 | call TermWait(buf, 50) |
| 4677 | call VerifyScreenDump(buf, 'Test_pum_scroll_noselect_1', {}) |
| 4678 | |
| 4679 | call term_sendkeys(buf, "\<esc>:TestCmd \<tab>") |
| 4680 | call TermWait(buf, 50) |
| 4681 | call VerifyScreenDump(buf, 'Test_pum_scroll_noselect_2', {}) |
| 4682 | |
| 4683 | call term_sendkeys(buf, "\<esc>") |
| 4684 | call StopVimInTerminal(buf) |
| 4685 | endfunc |
| 4686 | |
Bram Moolenaar | 309976e | 2019-12-05 18:16:33 +0100 | [diff] [blame] | 4687 | " vim: shiftwidth=2 sts=2 expandtab |