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