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