Bram Moolenaar | 00672e1 | 2016-06-26 18:38:13 +0200 | [diff] [blame] | 1 | " Test for completion menu |
| 2 | |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 3 | source shared.vim |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 4 | source screendump.vim |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 5 | source check.vim |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 6 | |
Bram Moolenaar | 00672e1 | 2016-06-26 18:38:13 +0200 | [diff] [blame] | 7 | let g:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] |
| 8 | let g:setting = '' |
| 9 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 10 | func ListMonths() |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 11 | if g:setting != '' |
| 12 | exe ":set" g:setting |
| 13 | endif |
Bram Moolenaar | aed6d0b | 2017-01-27 21:48:54 +0100 | [diff] [blame] | 14 | let mth = copy(g:months) |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 15 | let entered = strcharpart(getline('.'),0,col('.')) |
| 16 | if !empty(entered) |
Bram Moolenaar | aed6d0b | 2017-01-27 21:48:54 +0100 | [diff] [blame] | 17 | let mth = filter(mth, 'v:val=~"^".entered') |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 18 | endif |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 19 | call complete(1, mth) |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 20 | return '' |
Bram Moolenaar | 00672e1 | 2016-06-26 18:38:13 +0200 | [diff] [blame] | 21 | endfunc |
| 22 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 23 | func Test_popup_complete2() |
Bram Moolenaar | 9e02cfa | 2016-09-22 21:27:11 +0200 | [diff] [blame] | 24 | " Although the popupmenu is not visible, this does not mean completion mode |
| 25 | " has ended. After pressing <f5> to complete the currently typed char, Vim |
| 26 | " still stays in the first state of the completion (:h ins-completion-menu), |
| 27 | " although the popupmenu wasn't shown <c-e> will remove the inserted |
| 28 | " completed text (:h complete_CTRL-E), while the following <c-e> will behave |
| 29 | " like expected (:h i_CTRL-E) |
Bram Moolenaar | dac1947 | 2016-09-03 22:35:40 +0200 | [diff] [blame] | 30 | new |
| 31 | inoremap <f5> <c-r>=ListMonths()<cr> |
| 32 | call append(1, ["December2015"]) |
| 33 | :1 |
| 34 | call feedkeys("aD\<f5>\<C-E>\<C-E>\<C-E>\<C-E>\<enter>\<esc>", 'tx') |
Bram Moolenaar | 9e02cfa | 2016-09-22 21:27:11 +0200 | [diff] [blame] | 35 | call assert_equal(["Dece", "", "December2015"], getline(1,3)) |
Bram Moolenaar | dac1947 | 2016-09-03 22:35:40 +0200 | [diff] [blame] | 36 | %d |
| 37 | bw! |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 38 | endfunc |
Bram Moolenaar | dac1947 | 2016-09-03 22:35:40 +0200 | [diff] [blame] | 39 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 40 | func Test_popup_complete() |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 41 | new |
| 42 | inoremap <f5> <c-r>=ListMonths()<cr> |
| 43 | |
| 44 | " <C-E> - select original typed text before the completion started |
| 45 | call feedkeys("aJu\<f5>\<down>\<c-e>\<esc>", 'tx') |
| 46 | call assert_equal(["Ju"], getline(1,2)) |
| 47 | %d |
| 48 | |
| 49 | " <C-Y> - accept current match |
| 50 | call feedkeys("a\<f5>". repeat("\<down>",7). "\<c-y>\<esc>", 'tx') |
| 51 | call assert_equal(["August"], getline(1,2)) |
| 52 | %d |
| 53 | |
| 54 | " <BS> - Delete one character from the inserted text (state: 1) |
| 55 | " TODO: This should not end the completion, but it does. |
| 56 | " This should according to the documentation: |
| 57 | " January |
| 58 | " but instead, this does |
| 59 | " Januar |
| 60 | " (idea is, C-L inserts the match from the popup menu |
| 61 | " but if the menu is closed, it will insert the character <c-l> |
| 62 | call feedkeys("aJ\<f5>\<bs>\<c-l>\<esc>", 'tx') |
| 63 | call assert_equal(["Januar"], getline(1,2)) |
| 64 | %d |
| 65 | |
| 66 | " any-non special character: Stop completion without changing the match |
| 67 | " and insert the typed character |
| 68 | call feedkeys("a\<f5>20", 'tx') |
| 69 | call assert_equal(["January20"], getline(1,2)) |
| 70 | %d |
| 71 | |
| 72 | " any-non printable, non-white character: Add this character and |
| 73 | " reduce number of matches |
| 74 | call feedkeys("aJu\<f5>\<c-p>l\<c-y>", 'tx') |
| 75 | call assert_equal(["Jul"], getline(1,2)) |
| 76 | %d |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 77 | |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 78 | " any-non printable, non-white character: Add this character and |
| 79 | " reduce number of matches |
| 80 | call feedkeys("aJu\<f5>\<c-p>l\<c-n>\<c-y>", 'tx') |
| 81 | call assert_equal(["July"], getline(1,2)) |
| 82 | %d |
| 83 | |
| 84 | " any-non printable, non-white character: Add this character and |
| 85 | " reduce number of matches |
| 86 | call feedkeys("aJu\<f5>\<c-p>l\<c-e>", 'tx') |
| 87 | call assert_equal(["Jul"], getline(1,2)) |
| 88 | %d |
| 89 | |
| 90 | " <BS> - Delete one character from the inserted text (state: 2) |
| 91 | call feedkeys("a\<f5>\<c-n>\<bs>", 'tx') |
| 92 | call assert_equal(["Februar"], getline(1,2)) |
| 93 | %d |
| 94 | |
| 95 | " <c-l> - Insert one character from the current match |
| 96 | call feedkeys("aJ\<f5>".repeat("\<c-n>",3)."\<c-l>\<esc>", 'tx') |
| 97 | call assert_equal(["J"], getline(1,2)) |
| 98 | %d |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 99 | |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 100 | " <c-l> - Insert one character from the current match |
| 101 | call feedkeys("aJ\<f5>".repeat("\<c-n>",4)."\<c-l>\<esc>", 'tx') |
| 102 | call assert_equal(["January"], getline(1,2)) |
| 103 | %d |
| 104 | |
| 105 | " <c-y> - Accept current selected match |
| 106 | call feedkeys("aJ\<f5>\<c-y>\<esc>", 'tx') |
| 107 | call assert_equal(["January"], getline(1,2)) |
| 108 | %d |
| 109 | |
| 110 | " <c-e> - End completion, go back to what was there before selecting a match |
| 111 | call feedkeys("aJu\<f5>\<c-e>\<esc>", 'tx') |
| 112 | call assert_equal(["Ju"], getline(1,2)) |
| 113 | %d |
| 114 | |
| 115 | " <PageUp> - Select a match several entries back |
| 116 | call feedkeys("a\<f5>\<PageUp>\<c-y>\<esc>", 'tx') |
| 117 | call assert_equal([""], getline(1,2)) |
| 118 | %d |
| 119 | |
| 120 | " <PageUp><PageUp> - Select a match several entries back |
| 121 | call feedkeys("a\<f5>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx') |
| 122 | call assert_equal(["December"], getline(1,2)) |
| 123 | %d |
| 124 | |
| 125 | " <PageUp><PageUp><PageUp> - Select a match several entries back |
| 126 | call feedkeys("a\<f5>\<PageUp>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx') |
| 127 | call assert_equal(["February"], getline(1,2)) |
| 128 | %d |
| 129 | |
| 130 | " <PageDown> - Select a match several entries further |
| 131 | call feedkeys("a\<f5>\<PageDown>\<c-y>\<esc>", 'tx') |
| 132 | call assert_equal(["November"], getline(1,2)) |
| 133 | %d |
| 134 | |
| 135 | " <PageDown><PageDown> - Select a match several entries further |
| 136 | call feedkeys("a\<f5>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx') |
| 137 | call assert_equal(["December"], getline(1,2)) |
| 138 | %d |
| 139 | |
| 140 | " <PageDown><PageDown><PageDown> - Select a match several entries further |
| 141 | call feedkeys("a\<f5>\<PageDown>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx') |
| 142 | call assert_equal([""], getline(1,2)) |
| 143 | %d |
| 144 | |
| 145 | " <PageDown><PageDown><PageDown><PageDown> - Select a match several entries further |
| 146 | call feedkeys("a\<f5>".repeat("\<PageDown>",4)."\<c-y>\<esc>", 'tx') |
| 147 | call assert_equal(["October"], getline(1,2)) |
| 148 | %d |
| 149 | |
| 150 | " <Up> - Select a match don't insert yet |
| 151 | call feedkeys("a\<f5>\<Up>\<c-y>\<esc>", 'tx') |
| 152 | call assert_equal([""], getline(1,2)) |
| 153 | %d |
| 154 | |
| 155 | " <Up><Up> - Select a match don't insert yet |
| 156 | call feedkeys("a\<f5>\<Up>\<Up>\<c-y>\<esc>", 'tx') |
| 157 | call assert_equal(["December"], getline(1,2)) |
| 158 | %d |
| 159 | |
| 160 | " <Up><Up><Up> - Select a match don't insert yet |
| 161 | call feedkeys("a\<f5>\<Up>\<Up>\<Up>\<c-y>\<esc>", 'tx') |
| 162 | call assert_equal(["November"], getline(1,2)) |
| 163 | %d |
| 164 | |
| 165 | " <Tab> - Stop completion and insert the match |
| 166 | call feedkeys("a\<f5>\<Tab>\<c-y>\<esc>", 'tx') |
| 167 | call assert_equal(["January "], getline(1,2)) |
| 168 | %d |
| 169 | |
| 170 | " <Space> - Stop completion and insert the match |
| 171 | call feedkeys("a\<f5>".repeat("\<c-p>",5)." \<esc>", 'tx') |
| 172 | call assert_equal(["September "], getline(1,2)) |
| 173 | %d |
| 174 | |
| 175 | " <Enter> - Use the text and insert line break (state: 1) |
| 176 | call feedkeys("a\<f5>\<enter>\<esc>", 'tx') |
| 177 | call assert_equal(["January", ''], getline(1,2)) |
| 178 | %d |
| 179 | |
| 180 | " <Enter> - Insert the current selected text (state: 2) |
| 181 | call feedkeys("a\<f5>".repeat("\<Up>",5)."\<enter>\<esc>", 'tx') |
| 182 | call assert_equal(["September"], getline(1,2)) |
| 183 | %d |
| 184 | |
| 185 | " Insert match immediately, if there is only one match |
| 186 | " <c-y> selects a character from the line above |
| 187 | call append(0, ["December2015"]) |
| 188 | call feedkeys("aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>", 'tx') |
| 189 | call assert_equal(["December2015", "December2015", ""], getline(1,3)) |
| 190 | %d |
| 191 | |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 192 | " use menuone for 'completeopt' |
| 193 | " Since for the first <c-y> the menu is still shown, will only select |
| 194 | " three letters from the line above |
| 195 | set completeopt&vim |
| 196 | set completeopt+=menuone |
| 197 | call append(0, ["December2015"]) |
| 198 | call feedkeys("aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>", 'tx') |
| 199 | call assert_equal(["December2015", "December201", ""], getline(1,3)) |
| 200 | %d |
| 201 | |
| 202 | " use longest for 'completeopt' |
| 203 | set completeopt&vim |
| 204 | call feedkeys("aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>", 'tx') |
| 205 | set completeopt+=longest |
| 206 | call feedkeys("aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>", 'tx') |
| 207 | call assert_equal(["M", "Ma", ""], getline(1,3)) |
| 208 | %d |
| 209 | |
| 210 | " use noselect/noinsert for 'completeopt' |
| 211 | set completeopt&vim |
| 212 | call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') |
| 213 | set completeopt+=noselect |
| 214 | call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') |
| 215 | set completeopt-=noselect completeopt+=noinsert |
| 216 | call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') |
| 217 | call assert_equal(["March", "M", "March"], getline(1,4)) |
| 218 | %d |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 219 | endfunc |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 220 | |
| 221 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 222 | func Test_popup_completion_insertmode() |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 223 | new |
| 224 | inoremap <F5> <C-R>=ListMonths()<CR> |
| 225 | |
| 226 | call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx') |
| 227 | call assert_equal('February', getline(1)) |
| 228 | %d |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 229 | " Set noinsertmode |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 230 | let g:setting = 'noinsertmode' |
| 231 | call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx') |
| 232 | call assert_equal('February', getline(1)) |
| 233 | call assert_false(pumvisible()) |
| 234 | %d |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 235 | " Go through all matches, until none is selected |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 236 | let g:setting = '' |
| 237 | call feedkeys("a\<f5>". repeat("\<c-n>",12)."\<enter>\<esc>", 'tx') |
| 238 | call assert_equal('', getline(1)) |
| 239 | %d |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 240 | " select previous entry |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 241 | call feedkeys("a\<f5>\<c-p>\<enter>\<esc>", 'tx') |
| 242 | call assert_equal('', getline(1)) |
| 243 | %d |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 244 | " select last entry |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 245 | call feedkeys("a\<f5>\<c-p>\<c-p>\<enter>\<esc>", 'tx') |
| 246 | call assert_equal('December', getline(1)) |
| 247 | |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 248 | iunmap <F5> |
| 249 | endfunc |
| 250 | |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 251 | func Test_noinsert_complete() |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 252 | func! s:complTest1() abort |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 253 | eval ['source', 'soundfold']->complete(1) |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 254 | return '' |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 255 | endfunc |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 256 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 257 | func! s:complTest2() abort |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 258 | call complete(1, ['source', 'soundfold']) |
| 259 | return '' |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 260 | endfunc |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 261 | |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 262 | new |
| 263 | set completeopt+=noinsert |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 264 | inoremap <F5> <C-R>=s:complTest1()<CR> |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 265 | call feedkeys("i\<F5>soun\<CR>\<CR>\<ESC>.", 'tx') |
| 266 | call assert_equal('soundfold', getline(1)) |
| 267 | call assert_equal('soundfold', getline(2)) |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 268 | bwipe! |
Bram Moolenaar | 32b808a | 2016-07-09 21:57:20 +0200 | [diff] [blame] | 269 | |
| 270 | new |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 271 | inoremap <F5> <C-R>=s:complTest2()<CR> |
Bram Moolenaar | 32b808a | 2016-07-09 21:57:20 +0200 | [diff] [blame] | 272 | call feedkeys("i\<F5>\<CR>\<ESC>", 'tx') |
| 273 | call assert_equal('source', getline(1)) |
| 274 | bwipe! |
| 275 | |
Bram Moolenaar | 67081e5 | 2016-07-09 21:49:03 +0200 | [diff] [blame] | 276 | set completeopt-=noinsert |
| 277 | iunmap <F5> |
Bram Moolenaar | 00672e1 | 2016-06-26 18:38:13 +0200 | [diff] [blame] | 278 | endfunc |
Bram Moolenaar | 32b808a | 2016-07-09 21:57:20 +0200 | [diff] [blame] | 279 | |
Bram Moolenaar | 73655cf | 2019-04-06 13:45:55 +0200 | [diff] [blame] | 280 | func Test_complete_no_filter() |
| 281 | func! s:complTest1() abort |
| 282 | call complete(1, [{'word': 'foobar'}]) |
| 283 | return '' |
| 284 | endfunc |
| 285 | func! s:complTest2() abort |
| 286 | call complete(1, [{'word': 'foobar', 'equal': 1}]) |
| 287 | return '' |
| 288 | endfunc |
| 289 | |
| 290 | let completeopt = &completeopt |
| 291 | |
| 292 | " without equal=1 |
| 293 | new |
| 294 | set completeopt=menuone,noinsert,menu |
| 295 | inoremap <F5> <C-R>=s:complTest1()<CR> |
| 296 | call feedkeys("i\<F5>z\<CR>\<CR>\<ESC>.", 'tx') |
| 297 | call assert_equal('z', getline(1)) |
| 298 | bwipe! |
| 299 | |
| 300 | " with equal=1 |
| 301 | new |
| 302 | set completeopt=menuone,noinsert,menu |
| 303 | inoremap <F5> <C-R>=s:complTest2()<CR> |
| 304 | call feedkeys("i\<F5>z\<CR>\<CR>\<ESC>.", 'tx') |
| 305 | call assert_equal('foobar', getline(1)) |
| 306 | bwipe! |
| 307 | |
| 308 | let &completeopt = completeopt |
| 309 | iunmap <F5> |
| 310 | endfunc |
| 311 | |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 312 | func Test_compl_vim_cmds_after_register_expr() |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 313 | func! s:test_func() |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 314 | return 'autocmd ' |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 315 | endfunc |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 316 | augroup AAAAA_Group |
| 317 | au! |
| 318 | augroup END |
Bram Moolenaar | 32b808a | 2016-07-09 21:57:20 +0200 | [diff] [blame] | 319 | |
Bram Moolenaar | 33a80ee | 2016-09-05 21:51:14 +0200 | [diff] [blame] | 320 | new |
| 321 | call feedkeys("i\<c-r>=s:test_func()\<CR>\<C-x>\<C-v>\<Esc>", 'tx') |
| 322 | call assert_equal('autocmd AAAAA_Group', getline(1)) |
| 323 | autocmd! AAAAA_Group |
| 324 | augroup! AAAAA_Group |
| 325 | bwipe! |
| 326 | endfunc |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 327 | |
zeertzjq | ee44603 | 2022-04-30 15:02:22 +0100 | [diff] [blame] | 328 | func Test_compl_ignore_mappings() |
| 329 | call setline(1, ['foo', 'bar', 'baz', 'foobar']) |
| 330 | inoremap <C-P> (C-P) |
| 331 | inoremap <C-N> (C-N) |
| 332 | normal! G |
| 333 | call feedkeys("o\<C-X>\<C-N>\<C-N>\<C-N>\<C-P>\<C-N>\<C-Y>", 'tx') |
| 334 | call assert_equal('baz', getline('.')) |
| 335 | " Also test with unsimplified keys |
| 336 | call feedkeys("o\<C-X>\<*C-N>\<*C-N>\<*C-N>\<*C-P>\<*C-N>\<C-Y>", 'tx') |
| 337 | call assert_equal('baz', getline('.')) |
| 338 | iunmap <C-P> |
| 339 | iunmap <C-N> |
| 340 | bwipe! |
| 341 | endfunc |
| 342 | |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 343 | func DummyCompleteOne(findstart, base) |
| 344 | if a:findstart |
| 345 | return 0 |
| 346 | else |
| 347 | wincmd n |
| 348 | return ['onedef', 'oneDEF'] |
| 349 | endif |
| 350 | endfunc |
| 351 | |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 352 | " Test that nothing happens if the 'completefunc' tries to open |
| 353 | " a new window (fails to open window, continues) |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 354 | func Test_completefunc_opens_new_window_one() |
| 355 | new |
| 356 | let winid = win_getid() |
| 357 | setlocal completefunc=DummyCompleteOne |
| 358 | call setline(1, 'one') |
| 359 | /^one |
Bram Moolenaar | 28976e2 | 2021-01-29 21:07:07 +0100 | [diff] [blame] | 360 | call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E565:') |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 361 | call assert_equal(winid, win_getid()) |
Bram Moolenaar | 28ee892 | 2020-10-28 20:20:00 +0100 | [diff] [blame] | 362 | call assert_equal('onedef', getline(1)) |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 363 | q! |
| 364 | endfunc |
| 365 | |
| 366 | " Test that nothing happens if the 'completefunc' opens |
| 367 | " a new window (no completion, no crash) |
| 368 | func DummyCompleteTwo(findstart, base) |
| 369 | if a:findstart |
| 370 | wincmd n |
| 371 | return 0 |
| 372 | else |
| 373 | return ['twodef', 'twoDEF'] |
| 374 | endif |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 375 | endfunc |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 376 | |
| 377 | " Test that nothing happens if the 'completefunc' opens |
| 378 | " a new window (no completion, no crash) |
| 379 | func Test_completefunc_opens_new_window_two() |
| 380 | new |
| 381 | let winid = win_getid() |
| 382 | setlocal completefunc=DummyCompleteTwo |
| 383 | call setline(1, 'two') |
| 384 | /^two |
Bram Moolenaar | 3eb6bd9 | 2021-01-29 21:47:24 +0100 | [diff] [blame] | 385 | call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E565:') |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 386 | call assert_equal(winid, win_getid()) |
Bram Moolenaar | 3eb6bd9 | 2021-01-29 21:47:24 +0100 | [diff] [blame] | 387 | call assert_equal('twodef', getline(1)) |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 388 | q! |
| 389 | endfunc |
| 390 | |
| 391 | func DummyCompleteThree(findstart, base) |
| 392 | if a:findstart |
| 393 | return 0 |
| 394 | else |
| 395 | return ['threedef', 'threeDEF'] |
| 396 | endif |
| 397 | endfunc |
| 398 | |
| 399 | :"Test that 'completefunc' works when it's OK. |
| 400 | func Test_completefunc_works() |
| 401 | new |
| 402 | let winid = win_getid() |
| 403 | setlocal completefunc=DummyCompleteThree |
| 404 | call setline(1, 'three') |
| 405 | /^three |
| 406 | call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x") |
| 407 | call assert_equal(winid, win_getid()) |
| 408 | call assert_equal('threeDEF', getline(1)) |
| 409 | q! |
| 410 | endfunc |
| 411 | |
| 412 | func DummyCompleteFour(findstart, base) |
| 413 | if a:findstart |
| 414 | return 0 |
| 415 | else |
| 416 | call complete_add('four1') |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 417 | eval 'four2'->complete_add() |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 418 | call complete_check() |
| 419 | call complete_add('four3') |
| 420 | call complete_add('four4') |
| 421 | call complete_check() |
| 422 | call complete_add('four5') |
| 423 | call complete_add('four6') |
| 424 | return [] |
| 425 | endif |
| 426 | endfunc |
| 427 | |
Bram Moolenaar | 60ef3e8 | 2016-10-29 14:37:56 +0200 | [diff] [blame] | 428 | " Test that 'omnifunc' works when it's OK. |
Bram Moolenaar | 472e859 | 2016-10-15 17:06:47 +0200 | [diff] [blame] | 429 | func Test_omnifunc_with_check() |
| 430 | new |
| 431 | setlocal omnifunc=DummyCompleteFour |
| 432 | call setline(1, 'four') |
| 433 | /^four |
| 434 | call feedkeys("A\<C-X>\<C-O>\<C-N>\<Esc>", "x") |
| 435 | call assert_equal('four2', getline(1)) |
| 436 | |
| 437 | call setline(1, 'four') |
| 438 | /^four |
| 439 | call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<Esc>", "x") |
| 440 | call assert_equal('four3', getline(1)) |
| 441 | |
| 442 | call setline(1, 'four') |
| 443 | /^four |
| 444 | call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<C-N>\<Esc>", "x") |
| 445 | call assert_equal('four5', getline(1)) |
| 446 | |
| 447 | q! |
| 448 | endfunc |
| 449 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 450 | func UndoComplete() |
Bram Moolenaar | 869e352 | 2016-10-16 15:35:47 +0200 | [diff] [blame] | 451 | call complete(1, ['January', 'February', 'March', |
| 452 | \ 'April', 'May', 'June', 'July', 'August', 'September', |
| 453 | \ 'October', 'November', 'December']) |
| 454 | return '' |
| 455 | endfunc |
| 456 | |
| 457 | " Test that no undo item is created when no completion is inserted |
| 458 | func Test_complete_no_undo() |
| 459 | set completeopt=menu,preview,noinsert,noselect |
| 460 | inoremap <Right> <C-R>=UndoComplete()<CR> |
| 461 | new |
| 462 | call feedkeys("ixxx\<CR>\<CR>yyy\<Esc>k", 'xt') |
| 463 | call feedkeys("iaaa\<Esc>0", 'xt') |
| 464 | call assert_equal('aaa', getline(2)) |
| 465 | call feedkeys("i\<Right>\<Esc>", 'xt') |
| 466 | call assert_equal('aaa', getline(2)) |
| 467 | call feedkeys("u", 'xt') |
| 468 | call assert_equal('', getline(2)) |
| 469 | |
Bram Moolenaar | cbd3bd6 | 2016-10-17 20:47:02 +0200 | [diff] [blame] | 470 | call feedkeys("ibbb\<Esc>0", 'xt') |
| 471 | call assert_equal('bbb', getline(2)) |
| 472 | call feedkeys("A\<Right>\<Down>\<CR>\<Esc>", 'xt') |
| 473 | call assert_equal('January', getline(2)) |
| 474 | call feedkeys("u", 'xt') |
| 475 | call assert_equal('bbb', getline(2)) |
| 476 | |
Bram Moolenaar | 9ec7fa8 | 2016-10-18 13:06:41 +0200 | [diff] [blame] | 477 | call feedkeys("A\<Right>\<C-N>\<Esc>", 'xt') |
| 478 | call assert_equal('January', getline(2)) |
| 479 | call feedkeys("u", 'xt') |
| 480 | call assert_equal('bbb', getline(2)) |
| 481 | |
Bram Moolenaar | 869e352 | 2016-10-16 15:35:47 +0200 | [diff] [blame] | 482 | iunmap <Right> |
| 483 | set completeopt& |
| 484 | q! |
| 485 | endfunc |
| 486 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 487 | func DummyCompleteFive(findstart, base) |
Bram Moolenaar | 60ef3e8 | 2016-10-29 14:37:56 +0200 | [diff] [blame] | 488 | if a:findstart |
| 489 | return 0 |
| 490 | else |
| 491 | return [ |
| 492 | \ { 'word': 'January', 'info': "info1-1\n1-2\n1-3" }, |
| 493 | \ { 'word': 'February', 'info': "info2-1\n2-2\n2-3" }, |
| 494 | \ { 'word': 'March', 'info': "info3-1\n3-2\n3-3" }, |
| 495 | \ { 'word': 'April', 'info': "info4-1\n4-2\n4-3" }, |
| 496 | \ { 'word': 'May', 'info': "info5-1\n5-2\n5-3" }, |
| 497 | \ ] |
| 498 | endif |
| 499 | endfunc |
| 500 | |
| 501 | " Test that 'completefunc' on Scratch buffer with preview window works when |
| 502 | " it's OK. |
| 503 | func Test_completefunc_with_scratch_buffer() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 504 | CheckFeature quickfix |
| 505 | |
Bram Moolenaar | 60ef3e8 | 2016-10-29 14:37:56 +0200 | [diff] [blame] | 506 | new +setlocal\ buftype=nofile\ bufhidden=wipe\ noswapfile |
| 507 | set completeopt+=preview |
| 508 | setlocal completefunc=DummyCompleteFive |
| 509 | call feedkeys("A\<C-X>\<C-U>\<C-N>\<C-N>\<C-N>\<Esc>", "x") |
| 510 | call assert_equal(['April'], getline(1, '$')) |
| 511 | pclose |
| 512 | q! |
| 513 | set completeopt& |
| 514 | endfunc |
Bram Moolenaar | 869e352 | 2016-10-16 15:35:47 +0200 | [diff] [blame] | 515 | |
Bram Moolenaar | 73fd498 | 2016-12-09 19:36:56 +0100 | [diff] [blame] | 516 | " <C-E> - select original typed text before the completion started without |
| 517 | " auto-wrap text. |
| 518 | func Test_completion_ctrl_e_without_autowrap() |
| 519 | new |
Bram Moolenaar | aed6d0b | 2017-01-27 21:48:54 +0100 | [diff] [blame] | 520 | let tw_save = &tw |
Bram Moolenaar | 73fd498 | 2016-12-09 19:36:56 +0100 | [diff] [blame] | 521 | set tw=78 |
| 522 | let li = [ |
| 523 | \ '" zzz', |
| 524 | \ '" zzzyyyyyyyyyyyyyyyyyyy'] |
| 525 | call setline(1, li) |
| 526 | 0 |
| 527 | call feedkeys("A\<C-X>\<C-N>\<C-E>\<Esc>", "tx") |
| 528 | call assert_equal(li, getline(1, '$')) |
| 529 | |
Bram Moolenaar | aed6d0b | 2017-01-27 21:48:54 +0100 | [diff] [blame] | 530 | let &tw = tw_save |
Bram Moolenaar | 73fd498 | 2016-12-09 19:36:56 +0100 | [diff] [blame] | 531 | q! |
| 532 | endfunc |
| 533 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 534 | func DummyCompleteSix() |
Bram Moolenaar | aed6d0b | 2017-01-27 21:48:54 +0100 | [diff] [blame] | 535 | call complete(1, ['Hello', 'World']) |
| 536 | return '' |
| 537 | endfunction |
| 538 | |
| 539 | " complete() correctly clears the list of autocomplete candidates |
| 540 | " See #1411 |
| 541 | func Test_completion_clear_candidate_list() |
| 542 | new |
| 543 | %d |
| 544 | " select first entry from the completion popup |
| 545 | call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>", "tx") |
| 546 | call assert_equal('Hello', getline(1)) |
| 547 | %d |
| 548 | " select second entry from the completion popup |
| 549 | call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>", "tx") |
| 550 | call assert_equal('World', getline(1)) |
| 551 | %d |
| 552 | " select original text |
| 553 | call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>", "tx") |
| 554 | call assert_equal(' xxx', getline(1)) |
| 555 | %d |
| 556 | " back at first entry from completion list |
| 557 | call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>\<C-N>", "tx") |
| 558 | call assert_equal('Hello', getline(1)) |
| 559 | |
| 560 | bw! |
| 561 | endfunc |
| 562 | |
Bram Moolenaar | 190b04c | 2017-02-09 17:37:03 +0100 | [diff] [blame] | 563 | func Test_completion_respect_bs_option() |
| 564 | new |
| 565 | let li = ["aaa", "aaa12345", "aaaabcdef", "aaaABC"] |
| 566 | |
| 567 | set bs=indent,eol |
| 568 | call setline(1, li) |
| 569 | 1 |
| 570 | call feedkeys("A\<C-X>\<C-N>\<C-P>\<BS>\<BS>\<BS>\<Esc>", "tx") |
| 571 | call assert_equal('aaa', getline(1)) |
| 572 | |
| 573 | %d |
| 574 | set bs=indent,eol,start |
| 575 | call setline(1, li) |
| 576 | 1 |
| 577 | call feedkeys("A\<C-X>\<C-N>\<C-P>\<BS>\<BS>\<BS>\<Esc>", "tx") |
| 578 | call assert_equal('', getline(1)) |
| 579 | |
| 580 | bw! |
| 581 | endfunc |
| 582 | |
Bram Moolenaar | d56a79d | 2017-02-19 15:26:18 +0100 | [diff] [blame] | 583 | func CompleteUndo() abort |
| 584 | call complete(1, g:months) |
| 585 | return '' |
| 586 | endfunc |
| 587 | |
| 588 | func Test_completion_can_undo() |
| 589 | inoremap <Right> <c-r>=CompleteUndo()<cr> |
| 590 | set completeopt+=noinsert,noselect |
| 591 | |
| 592 | new |
| 593 | call feedkeys("a\<Right>a\<Esc>", 'xt') |
| 594 | call assert_equal('a', getline(1)) |
| 595 | undo |
| 596 | call assert_equal('', getline(1)) |
| 597 | |
| 598 | bwipe! |
| 599 | set completeopt& |
| 600 | iunmap <Right> |
| 601 | endfunc |
| 602 | |
Bram Moolenaar | d099e03 | 2017-02-21 23:00:36 +0100 | [diff] [blame] | 603 | func Test_completion_comment_formatting() |
| 604 | new |
| 605 | setl formatoptions=tcqro |
| 606 | call feedkeys("o/*\<cr>\<cr>/\<esc>", 'tx') |
| 607 | call assert_equal(['', '/*', ' *', ' */'], getline(1,4)) |
| 608 | %d |
| 609 | call feedkeys("o/*\<cr>foobar\<cr>/\<esc>", 'tx') |
| 610 | call assert_equal(['', '/*', ' * foobar', ' */'], getline(1,4)) |
| 611 | %d |
| 612 | try |
| 613 | call feedkeys("o/*\<cr>\<cr>\<c-x>\<c-u>/\<esc>", 'tx') |
Bram Moolenaar | 3717540 | 2017-03-18 20:18:45 +0100 | [diff] [blame] | 614 | call assert_report('completefunc not set, should have failed') |
Bram Moolenaar | d099e03 | 2017-02-21 23:00:36 +0100 | [diff] [blame] | 615 | catch |
| 616 | call assert_exception('E764:') |
| 617 | endtry |
| 618 | call assert_equal(['', '/*', ' *', ' */'], getline(1,4)) |
| 619 | bwipe! |
| 620 | endfunc |
| 621 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 622 | func MessCompleteMonths() |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 623 | for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep") |
| 624 | call complete_add(m) |
| 625 | if complete_check() |
| 626 | break |
| 627 | endif |
| 628 | endfor |
| 629 | return [] |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 630 | endfunc |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 631 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 632 | func MessCompleteMore() |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 633 | call complete(1, split("Oct Nov Dec")) |
| 634 | return [] |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 635 | endfunc |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 636 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 637 | func MessComplete(findstart, base) |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 638 | if a:findstart |
| 639 | let line = getline('.') |
| 640 | let start = col('.') - 1 |
| 641 | while start > 0 && line[start - 1] =~ '\a' |
| 642 | let start -= 1 |
| 643 | endwhile |
| 644 | return start |
| 645 | else |
| 646 | call MessCompleteMonths() |
| 647 | call MessCompleteMore() |
| 648 | return [] |
| 649 | endif |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 650 | endfunc |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 651 | |
| 652 | func Test_complete_func_mess() |
| 653 | " Calling complete() after complete_add() in 'completefunc' is wrong, but it |
| 654 | " should not crash. |
| 655 | set completefunc=MessComplete |
| 656 | new |
| 657 | call setline(1, 'Ju') |
zeertzjq | cfe4565 | 2022-05-27 17:26:55 +0100 | [diff] [blame] | 658 | call assert_fails('call feedkeys("A\<c-x>\<c-u>/\<esc>", "tx")', 'E565:') |
Bram Moolenaar | 28976e2 | 2021-01-29 21:07:07 +0100 | [diff] [blame] | 659 | call assert_equal('Jan/', getline(1)) |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 660 | bwipe! |
| 661 | set completefunc= |
| 662 | endfunc |
| 663 | |
Bram Moolenaar | 24a9e34 | 2017-06-24 15:39:07 +0200 | [diff] [blame] | 664 | func Test_complete_CTRLN_startofbuffer() |
| 665 | new |
| 666 | call setline(1, [ 'organize(cupboard, 3, 2);', |
| 667 | \ 'prioritize(bureau, 8, 7);', |
| 668 | \ 'realize(bannister, 4, 4);', |
| 669 | \ 'moralize(railing, 3,9);']) |
| 670 | let expected=['cupboard.organize(3, 2);', |
| 671 | \ 'bureau.prioritize(8, 7);', |
| 672 | \ 'bannister.realize(4, 4);', |
| 673 | \ 'railing.moralize(3,9);'] |
| 674 | call feedkeys("qai\<c-n>\<c-n>.\<esc>3wdW\<cr>q3@a", 'tx') |
| 675 | call assert_equal(expected, getline(1,'$')) |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 676 | bwipe! |
| 677 | endfunc |
| 678 | |
| 679 | func Test_popup_and_window_resize() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 680 | CheckFeature terminal |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 681 | CheckFeature quickfix |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 682 | CheckNotGui |
Bram Moolenaar | f08b0eb | 2021-10-16 13:00:14 +0100 | [diff] [blame] | 683 | let g:test_is_flaky = 1 |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 684 | |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 685 | let h = winheight(0) |
| 686 | if h < 15 |
| 687 | return |
| 688 | endif |
Bram Moolenaar | b315876 | 2017-11-02 17:50:14 +0100 | [diff] [blame] | 689 | let rows = h / 3 |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 690 | let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': rows}) |
| 691 | call term_sendkeys(buf, (h / 3 - 1) . "o\<esc>") |
Bram Moolenaar | b315876 | 2017-11-02 17:50:14 +0100 | [diff] [blame] | 692 | " Wait for the nested Vim to exit insert mode, where it will show the ruler. |
| 693 | " Need to trigger a redraw. |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 694 | call WaitFor({-> execute("redraw") == "" && term_getline(buf, rows) =~ '\<' . rows . ',.*Bot'}) |
Bram Moolenaar | b315876 | 2017-11-02 17:50:14 +0100 | [diff] [blame] | 695 | |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 696 | call term_sendkeys(buf, "Gi\<c-x>") |
| 697 | call term_sendkeys(buf, "\<c-v>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 698 | call TermWait(buf, 50) |
Bram Moolenaar | f52c383 | 2017-09-30 16:49:19 +0200 | [diff] [blame] | 699 | " popup first entry "!" must be at the top |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 700 | call WaitForAssert({-> assert_match('^!\s*$', term_getline(buf, 1))}) |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 701 | exe 'resize +' . (h - 1) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 702 | call TermWait(buf, 50) |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 703 | redraw! |
Bram Moolenaar | f52c383 | 2017-09-30 16:49:19 +0200 | [diff] [blame] | 704 | " popup shifted down, first line is now empty |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 705 | call WaitForAssert({-> assert_equal('', term_getline(buf, 1))}) |
Bram Moolenaar | a5e6621 | 2017-09-29 22:42:33 +0200 | [diff] [blame] | 706 | sleep 100m |
Bram Moolenaar | f52c383 | 2017-09-30 16:49:19 +0200 | [diff] [blame] | 707 | " popup is below cursor line and shows first match "!" |
Bram Moolenaar | 0e9d1ae | 2018-04-30 14:28:24 +0200 | [diff] [blame] | 708 | call WaitForAssert({-> assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0] + 1))}) |
Bram Moolenaar | f52c383 | 2017-09-30 16:49:19 +0200 | [diff] [blame] | 709 | " cursor line also shows ! |
Bram Moolenaar | ab8b1c1 | 2017-11-04 19:24:31 +0100 | [diff] [blame] | 710 | call assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0])) |
Bram Moolenaar | 24a9e34 | 2017-06-24 15:39:07 +0200 | [diff] [blame] | 711 | bwipe! |
| 712 | endfunc |
Bram Moolenaar | 4475b62 | 2017-05-01 20:46:52 +0200 | [diff] [blame] | 713 | |
Bram Moolenaar | 9ad89c6 | 2017-10-26 22:04:04 +0200 | [diff] [blame] | 714 | func Test_popup_and_preview_autocommand() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 715 | CheckFeature python |
| 716 | CheckFeature quickfix |
| 717 | if winheight(0) < 15 |
| 718 | throw 'Skipped: window height insufficient' |
| 719 | endif |
| 720 | |
Bram Moolenaar | 9ad89c6 | 2017-10-26 22:04:04 +0200 | [diff] [blame] | 721 | " This used to crash Vim |
Bram Moolenaar | 9ad89c6 | 2017-10-26 22:04:04 +0200 | [diff] [blame] | 722 | new |
| 723 | augroup MyBufAdd |
| 724 | au! |
| 725 | au BufAdd * nested tab sball |
| 726 | augroup END |
| 727 | set omnifunc=pythoncomplete#Complete |
| 728 | call setline(1, 'import os') |
| 729 | " make the line long |
| 730 | call setline(2, ' os.') |
| 731 | $ |
| 732 | call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<enter>\<esc>", 'tx') |
Bram Moolenaar | 2a45d64 | 2017-10-27 01:35:00 +0200 | [diff] [blame] | 733 | call assert_equal("import os", getline(1)) |
| 734 | call assert_match(' os.\(EX_IOERR\|O_CREAT\)$', getline(2)) |
Bram Moolenaar | 9ad89c6 | 2017-10-26 22:04:04 +0200 | [diff] [blame] | 735 | call assert_equal(1, winnr('$')) |
| 736 | " previewwindow option is not set |
| 737 | call assert_equal(0, &previewwindow) |
| 738 | norm! gt |
| 739 | call assert_equal(0, &previewwindow) |
| 740 | norm! gT |
Bram Moolenaar | 02ae9b4 | 2018-02-09 15:06:02 +0100 | [diff] [blame] | 741 | call assert_equal(10, tabpagenr('$')) |
Bram Moolenaar | 9ad89c6 | 2017-10-26 22:04:04 +0200 | [diff] [blame] | 742 | tabonly |
| 743 | pclose |
| 744 | augroup MyBufAdd |
| 745 | au! |
| 746 | augroup END |
| 747 | augroup! MyBufAdd |
| 748 | bw! |
| 749 | endfunc |
| 750 | |
Bram Moolenaar | 614ab8a | 2018-12-01 11:59:00 +0100 | [diff] [blame] | 751 | func Test_popup_and_previewwindow_dump() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 752 | CheckScreendump |
| 753 | CheckFeature quickfix |
| 754 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 755 | let lines =<< trim END |
| 756 | set previewheight=9 |
| 757 | silent! pedit |
Bram Moolenaar | 37bb030 | 2020-03-27 20:24:14 +0100 | [diff] [blame] | 758 | call setline(1, map(repeat(["ab"], 10), "v:val .. v:key")) |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 759 | exec "norm! G\<C-E>\<C-E>" |
| 760 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 761 | call writefile(lines, 'Xscript', 'D') |
Bram Moolenaar | 614ab8a | 2018-12-01 11:59:00 +0100 | [diff] [blame] | 762 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 763 | |
Bram Moolenaar | 37bb030 | 2020-03-27 20:24:14 +0100 | [diff] [blame] | 764 | " wait for the script to finish |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 765 | call TermWait(buf) |
Bram Moolenaar | 37bb030 | 2020-03-27 20:24:14 +0100 | [diff] [blame] | 766 | |
Bram Moolenaar | 614ab8a | 2018-12-01 11:59:00 +0100 | [diff] [blame] | 767 | " Test that popup and previewwindow do not overlap. |
Bram Moolenaar | 37bb030 | 2020-03-27 20:24:14 +0100 | [diff] [blame] | 768 | call term_sendkeys(buf, "o") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 769 | call TermWait(buf, 50) |
Bram Moolenaar | 37bb030 | 2020-03-27 20:24:14 +0100 | [diff] [blame] | 770 | call term_sendkeys(buf, "\<C-X>\<C-N>") |
Bram Moolenaar | 614ab8a | 2018-12-01 11:59:00 +0100 | [diff] [blame] | 771 | call VerifyScreenDump(buf, 'Test_popup_and_previewwindow_01', {}) |
| 772 | |
| 773 | call term_sendkeys(buf, "\<Esc>u") |
| 774 | call StopVimInTerminal(buf) |
Bram Moolenaar | 614ab8a | 2018-12-01 11:59:00 +0100 | [diff] [blame] | 775 | endfunc |
| 776 | |
Bram Moolenaar | 246fe03 | 2017-11-19 19:56:27 +0100 | [diff] [blame] | 777 | func Test_balloon_split() |
Bram Moolenaar | 073e4b9 | 2019-08-18 23:01:56 +0200 | [diff] [blame] | 778 | CheckFunction balloon_split |
| 779 | |
Bram Moolenaar | 246fe03 | 2017-11-19 19:56:27 +0100 | [diff] [blame] | 780 | call assert_equal([ |
Bram Moolenaar | a3571eb | 2017-11-26 16:53:16 +0100 | [diff] [blame] | 781 | \ 'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"', |
| 782 | \ ], balloon_split( |
| 783 | \ 'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"')) |
| 784 | call assert_equal([ |
Bram Moolenaar | 246fe03 | 2017-11-19 19:56:27 +0100 | [diff] [blame] | 785 | \ 'one two three four one two three four one two thre', |
| 786 | \ 'e four', |
| 787 | \ ], balloon_split( |
| 788 | \ 'one two three four one two three four one two three four')) |
| 789 | |
Bram Moolenaar | 073e4b9 | 2019-08-18 23:01:56 +0200 | [diff] [blame] | 790 | eval 'struct = {one = 1, two = 2, three = 3}' |
| 791 | \ ->balloon_split() |
| 792 | \ ->assert_equal([ |
| 793 | \ 'struct = {', |
| 794 | \ ' one = 1,', |
| 795 | \ ' two = 2,', |
| 796 | \ ' three = 3}', |
| 797 | \ ]) |
Bram Moolenaar | 246fe03 | 2017-11-19 19:56:27 +0100 | [diff] [blame] | 798 | |
| 799 | call assert_equal([ |
| 800 | \ 'struct = {', |
| 801 | \ ' one = 1,', |
| 802 | \ ' nested = {', |
| 803 | \ ' n1 = "yes",', |
| 804 | \ ' n2 = "no"}', |
| 805 | \ ' two = 2}', |
| 806 | \ ], balloon_split( |
| 807 | \ 'struct = {one = 1, nested = {n1 = "yes", n2 = "no"} two = 2}')) |
| 808 | call assert_equal([ |
| 809 | \ 'struct = 0x234 {', |
| 810 | \ ' long = 2343 "\\"some long string that will be wr', |
| 811 | \ 'apped in two\\"",', |
| 812 | \ ' next = 123}', |
| 813 | \ ], balloon_split( |
| 814 | \ 'struct = 0x234 {long = 2343 "\\"some long string that will be wrapped in two\\"", next = 123}')) |
Bram Moolenaar | 9ae862e | 2019-11-21 13:27:06 +0100 | [diff] [blame] | 815 | call assert_equal([ |
| 816 | \ 'Some comment', |
| 817 | \ '', |
| 818 | \ 'typedef this that;', |
| 819 | \ ], balloon_split( |
| 820 | \ "Some comment\n\ntypedef this that;")) |
Bram Moolenaar | 246fe03 | 2017-11-19 19:56:27 +0100 | [diff] [blame] | 821 | endfunc |
| 822 | |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 823 | func Test_popup_position() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 824 | CheckScreendump |
| 825 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 826 | let lines =<< trim END |
| 827 | 123456789_123456789_123456789_a |
| 828 | 123456789_123456789_123456789_b |
| 829 | 123 |
| 830 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 831 | call writefile(lines, 'Xtest', 'D') |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 832 | let buf = RunVimInTerminal('Xtest', {}) |
| 833 | call term_sendkeys(buf, ":vsplit\<CR>") |
| 834 | |
| 835 | " default pumwidth in left window: overlap in right window |
| 836 | call term_sendkeys(buf, "GA\<C-N>") |
| 837 | call VerifyScreenDump(buf, 'Test_popup_position_01', {'rows': 8}) |
| 838 | call term_sendkeys(buf, "\<Esc>u") |
| 839 | |
| 840 | " default pumwidth: fill until right of window |
| 841 | call term_sendkeys(buf, "\<C-W>l") |
| 842 | call term_sendkeys(buf, "GA\<C-N>") |
| 843 | call VerifyScreenDump(buf, 'Test_popup_position_02', {'rows': 8}) |
| 844 | |
| 845 | " larger pumwidth: used as minimum width |
| 846 | call term_sendkeys(buf, "\<Esc>u") |
| 847 | call term_sendkeys(buf, ":set pumwidth=30\<CR>") |
| 848 | call term_sendkeys(buf, "GA\<C-N>") |
| 849 | call VerifyScreenDump(buf, 'Test_popup_position_03', {'rows': 8}) |
| 850 | |
Bram Moolenaar | 2b10bcb | 2018-02-24 21:25:44 +0100 | [diff] [blame] | 851 | " completed text wider than the window and 'pumwidth' smaller than available |
| 852 | " space |
| 853 | call term_sendkeys(buf, "\<Esc>u") |
| 854 | call term_sendkeys(buf, ":set pumwidth=20\<CR>") |
| 855 | call term_sendkeys(buf, "ggI123456789_\<Esc>") |
| 856 | call term_sendkeys(buf, "jI123456789_\<Esc>") |
| 857 | call term_sendkeys(buf, "GA\<C-N>") |
| 858 | call VerifyScreenDump(buf, 'Test_popup_position_04', {'rows': 10}) |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 859 | |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 860 | call term_sendkeys(buf, "\<Esc>u") |
| 861 | call StopVimInTerminal(buf) |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 862 | endfunc |
| 863 | |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 864 | func Test_popup_command() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 865 | CheckFeature menu |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 866 | |
Bram Moolenaar | 0eabd4d | 2020-03-15 16:13:53 +0100 | [diff] [blame] | 867 | menu Test.Foo Foo |
| 868 | call assert_fails('popup Test.Foo', 'E336:') |
| 869 | call assert_fails('popup Test.Foo.X', 'E327:') |
| 870 | call assert_fails('popup Foo', 'E337:') |
| 871 | unmenu Test.Foo |
zeertzjq | f7570f2 | 2022-11-12 17:30:25 +0000 | [diff] [blame] | 872 | endfunc |
| 873 | |
| 874 | func Test_popup_command_dump() |
| 875 | CheckFeature menu |
| 876 | CheckScreendump |
Bram Moolenaar | 0eabd4d | 2020-03-15 16:13:53 +0100 | [diff] [blame] | 877 | |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 878 | let script =<< trim END |
| 879 | func StartTimer() |
| 880 | call timer_start(100, {-> ChangeMenu()}) |
| 881 | endfunc |
| 882 | func ChangeMenu() |
zeertzjq | f7570f2 | 2022-11-12 17:30:25 +0000 | [diff] [blame] | 883 | aunmenu PopUp.&Paste |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 884 | nnoremenu 1.40 PopUp.&Paste :echomsg "pasted"<CR> |
| 885 | echomsg 'changed' |
| 886 | endfunc |
| 887 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 888 | call writefile(script, 'XtimerScript', 'D') |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 889 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 890 | let lines =<< trim END |
| 891 | one two three four five |
| 892 | and one two Xthree four five |
| 893 | one more two three four five |
| 894 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 895 | call writefile(lines, 'Xtest', 'D') |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 896 | let buf = RunVimInTerminal('-S XtimerScript Xtest', {}) |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 897 | call term_sendkeys(buf, ":source $VIMRUNTIME/menu.vim\<CR>") |
| 898 | call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>") |
| 899 | call VerifyScreenDump(buf, 'Test_popup_command_01', {}) |
| 900 | |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 901 | " go to the Paste entry in the menu |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 902 | call term_sendkeys(buf, "jj") |
| 903 | call VerifyScreenDump(buf, 'Test_popup_command_02', {}) |
| 904 | |
| 905 | " Select a word |
| 906 | call term_sendkeys(buf, "j\<CR>") |
| 907 | call VerifyScreenDump(buf, 'Test_popup_command_03', {}) |
| 908 | |
| 909 | call term_sendkeys(buf, "\<Esc>") |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 910 | |
| 911 | " Set a timer to change a menu entry while it's displayed. The text should |
| 912 | " not change but the command does. Making the screendump also verifies that |
zeertzjq | 4e1ca0d | 2023-04-27 19:36:55 +0100 | [diff] [blame] | 913 | " "changed" shows up, which means the timer triggered. |
Bram Moolenaar | 38455a9 | 2020-12-24 18:39:02 +0100 | [diff] [blame] | 914 | call term_sendkeys(buf, "/X\<CR>:call StartTimer() | popup PopUp\<CR>") |
| 915 | call VerifyScreenDump(buf, 'Test_popup_command_04', {}) |
| 916 | |
| 917 | " Select the Paste entry, executes the changed menu item. |
| 918 | call term_sendkeys(buf, "jj\<CR>") |
| 919 | call VerifyScreenDump(buf, 'Test_popup_command_05', {}) |
| 920 | |
zeertzjq | 4e1ca0d | 2023-04-27 19:36:55 +0100 | [diff] [blame] | 921 | call term_sendkeys(buf, "\<Esc>") |
| 922 | |
| 923 | " Add a window toolbar to the window and check the :popup menu position. |
| 924 | call term_sendkeys(buf, ":nnoremenu WinBar.TEST :\<CR>") |
| 925 | call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>") |
| 926 | call VerifyScreenDump(buf, 'Test_popup_command_06', {}) |
| 927 | |
| 928 | call term_sendkeys(buf, "\<Esc>") |
| 929 | |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 930 | call StopVimInTerminal(buf) |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 931 | endfunc |
| 932 | |
Bram Moolenaar | e87edf3 | 2018-04-17 22:14:32 +0200 | [diff] [blame] | 933 | func Test_popup_complete_backwards() |
| 934 | new |
| 935 | call setline(1, ['Post', 'Port', 'Po']) |
| 936 | let expected=['Post', 'Port', 'Port'] |
| 937 | call cursor(3,2) |
| 938 | call feedkeys("A\<C-X>". repeat("\<C-P>", 3). "rt\<cr>", 'tx') |
| 939 | call assert_equal(expected, getline(1,'$')) |
| 940 | bwipe! |
| 941 | endfunc |
Bram Moolenaar | 69f5a30 | 2018-03-06 13:23:08 +0100 | [diff] [blame] | 942 | |
Bram Moolenaar | bad0ce7 | 2018-04-17 23:31:05 +0200 | [diff] [blame] | 943 | func Test_popup_complete_backwards_ctrl_p() |
| 944 | new |
| 945 | call setline(1, ['Post', 'Port', 'Po']) |
| 946 | let expected=['Post', 'Port', 'Port'] |
| 947 | call cursor(3,2) |
| 948 | call feedkeys("A\<C-P>\<C-N>rt\<cr>", 'tx') |
| 949 | call assert_equal(expected, getline(1,'$')) |
| 950 | bwipe! |
| 951 | endfunc |
| 952 | |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 953 | func Test_complete_o_tab() |
Bram Moolenaar | 39de952 | 2018-05-08 22:48:00 +0200 | [diff] [blame] | 954 | let s:o_char_pressed = 0 |
| 955 | |
| 956 | fun! s:act_on_text_changed() |
| 957 | if s:o_char_pressed |
| 958 | let s:o_char_pressed = 0 |
| 959 | call feedkeys("\<c-x>\<c-n>", 'i') |
| 960 | endif |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 961 | endfunc |
Bram Moolenaar | 39de952 | 2018-05-08 22:48:00 +0200 | [diff] [blame] | 962 | |
| 963 | set completeopt=menu,noselect |
| 964 | new |
| 965 | imap <expr> <buffer> <tab> pumvisible() ? "\<c-p>" : "X" |
| 966 | autocmd! InsertCharPre <buffer> let s:o_char_pressed = (v:char ==# 'o') |
| 967 | autocmd! TextChangedI <buffer> call <sid>act_on_text_changed() |
| 968 | call setline(1, ['hoard', 'hoax', 'hoarse', '']) |
| 969 | let l:expected = ['hoard', 'hoax', 'hoarse', 'hoax', 'hoax'] |
| 970 | call cursor(4,1) |
| 971 | call test_override("char_avail", 1) |
| 972 | call feedkeys("Ahoa\<tab>\<tab>\<c-y>\<esc>", 'tx') |
| 973 | call feedkeys("oho\<tab>\<tab>\<c-y>\<esc>", 'tx') |
| 974 | call assert_equal(l:expected, getline(1,'$')) |
| 975 | |
| 976 | call test_override("char_avail", 0) |
| 977 | bwipe! |
| 978 | set completeopt& |
| 979 | delfunc s:act_on_text_changed |
Bram Moolenaar | ae0f30b | 2018-06-12 15:22:43 +0200 | [diff] [blame] | 980 | endfunc |
Bram Moolenaar | 39de952 | 2018-05-08 22:48:00 +0200 | [diff] [blame] | 981 | |
Bram Moolenaar | f42b45d | 2019-01-06 13:11:05 +0100 | [diff] [blame] | 982 | func Test_menu_only_exists_in_terminal() |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 983 | CheckCommand tlmenu |
| 984 | CheckNotGui |
| 985 | |
Bram Moolenaar | f42b45d | 2019-01-06 13:11:05 +0100 | [diff] [blame] | 986 | tlnoremenu &Edit.&Paste<Tab>"+gP <C-W>"+ |
| 987 | aunmenu * |
| 988 | try |
| 989 | popup Edit |
| 990 | call assert_false(1, 'command should have failed') |
| 991 | catch |
| 992 | call assert_exception('E328:') |
| 993 | endtry |
| 994 | endfunc |
Bram Moolenaar | 39de952 | 2018-05-08 22:48:00 +0200 | [diff] [blame] | 995 | |
zeertzjq | 92a1678 | 2022-07-26 12:24:41 +0100 | [diff] [blame] | 996 | " This used to crash before patch 8.1.1424 |
| 997 | func Test_popup_delete_when_shown() |
| 998 | CheckFeature menu |
| 999 | CheckNotGui |
| 1000 | |
| 1001 | func Func() |
| 1002 | popup Foo |
| 1003 | return "\<Ignore>" |
| 1004 | endfunc |
| 1005 | |
| 1006 | nmenu Foo.Bar : |
| 1007 | nnoremap <expr> <F2> Func() |
| 1008 | call feedkeys("\<F2>\<F2>\<Esc>", 'xt') |
| 1009 | |
| 1010 | delfunc Func |
| 1011 | nunmenu Foo.Bar |
| 1012 | nunmap <F2> |
| 1013 | endfunc |
| 1014 | |
Bram Moolenaar | fd13332 | 2019-03-29 12:20:27 +0100 | [diff] [blame] | 1015 | func Test_popup_complete_info_01() |
| 1016 | new |
| 1017 | inoremap <buffer><F5> <C-R>=complete_info().mode<CR> |
| 1018 | func s:complTestEval() abort |
| 1019 | call complete(1, ['aa', 'ab']) |
| 1020 | return '' |
| 1021 | endfunc |
| 1022 | inoremap <buffer><F6> <C-R>=s:complTestEval()<CR> |
| 1023 | call writefile([ |
| 1024 | \ 'dummy dummy.txt 1', |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 1025 | \], 'Xdummy.txt', 'D') |
Bram Moolenaar | fd13332 | 2019-03-29 12:20:27 +0100 | [diff] [blame] | 1026 | setlocal tags=Xdummy.txt |
| 1027 | setlocal dictionary=Xdummy.txt |
| 1028 | setlocal thesaurus=Xdummy.txt |
| 1029 | setlocal omnifunc=syntaxcomplete#Complete |
| 1030 | setlocal completefunc=syntaxcomplete#Complete |
| 1031 | setlocal spell |
| 1032 | for [keys, mode_name] in [ |
| 1033 | \ ["", ''], |
| 1034 | \ ["\<C-X>", 'ctrl_x'], |
| 1035 | \ ["\<C-X>\<C-N>", 'keyword'], |
| 1036 | \ ["\<C-X>\<C-P>", 'keyword'], |
zeertzjq | 27fef59 | 2021-10-03 12:01:27 +0100 | [diff] [blame] | 1037 | \ ["\<C-X>\<C-E>", 'scroll'], |
| 1038 | \ ["\<C-X>\<C-Y>", 'scroll'], |
| 1039 | \ ["\<C-X>\<C-E>\<C-E>\<C-Y>", 'scroll'], |
| 1040 | \ ["\<C-X>\<C-Y>\<C-E>\<C-Y>", 'scroll'], |
Bram Moolenaar | fd13332 | 2019-03-29 12:20:27 +0100 | [diff] [blame] | 1041 | \ ["\<C-X>\<C-L>", 'whole_line'], |
| 1042 | \ ["\<C-X>\<C-F>", 'files'], |
| 1043 | \ ["\<C-X>\<C-]>", 'tags'], |
| 1044 | \ ["\<C-X>\<C-D>", 'path_defines'], |
| 1045 | \ ["\<C-X>\<C-I>", 'path_patterns'], |
| 1046 | \ ["\<C-X>\<C-K>", 'dictionary'], |
| 1047 | \ ["\<C-X>\<C-T>", 'thesaurus'], |
| 1048 | \ ["\<C-X>\<C-V>", 'cmdline'], |
| 1049 | \ ["\<C-X>\<C-U>", 'function'], |
| 1050 | \ ["\<C-X>\<C-O>", 'omni'], |
| 1051 | \ ["\<C-X>s", 'spell'], |
| 1052 | \ ["\<F6>", 'eval'], |
| 1053 | \] |
| 1054 | call feedkeys("i" . keys . "\<F5>\<Esc>", 'tx') |
| 1055 | call assert_equal(mode_name, getline('.')) |
| 1056 | %d |
| 1057 | endfor |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 1058 | |
Bram Moolenaar | fd13332 | 2019-03-29 12:20:27 +0100 | [diff] [blame] | 1059 | bwipe! |
| 1060 | endfunc |
| 1061 | |
| 1062 | func UserDefinedComplete(findstart, base) |
| 1063 | if a:findstart |
| 1064 | return 0 |
| 1065 | else |
| 1066 | return [ |
| 1067 | \ { 'word': 'Jan', 'menu': 'January' }, |
| 1068 | \ { 'word': 'Feb', 'menu': 'February' }, |
| 1069 | \ { 'word': 'Mar', 'menu': 'March' }, |
| 1070 | \ { 'word': 'Apr', 'menu': 'April' }, |
| 1071 | \ { 'word': 'May', 'menu': 'May' }, |
| 1072 | \ ] |
| 1073 | endif |
| 1074 | endfunc |
| 1075 | |
| 1076 | func GetCompleteInfo() |
| 1077 | if empty(g:compl_what) |
| 1078 | let g:compl_info = complete_info() |
| 1079 | else |
Bram Moolenaar | 1a3a891 | 2019-08-23 22:31:37 +0200 | [diff] [blame] | 1080 | let g:compl_info = g:compl_what->complete_info() |
Bram Moolenaar | fd13332 | 2019-03-29 12:20:27 +0100 | [diff] [blame] | 1081 | endif |
| 1082 | return '' |
| 1083 | endfunc |
| 1084 | |
| 1085 | func Test_popup_complete_info_02() |
| 1086 | new |
| 1087 | inoremap <buffer><F5> <C-R>=GetCompleteInfo()<CR> |
| 1088 | setlocal completefunc=UserDefinedComplete |
| 1089 | |
| 1090 | let d = { |
| 1091 | \ 'mode': 'function', |
| 1092 | \ 'pum_visible': 1, |
| 1093 | \ 'items': [ |
| 1094 | \ {'word': 'Jan', 'menu': 'January', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, |
| 1095 | \ {'word': 'Feb', 'menu': 'February', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, |
| 1096 | \ {'word': 'Mar', 'menu': 'March', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, |
| 1097 | \ {'word': 'Apr', 'menu': 'April', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}, |
| 1098 | \ {'word': 'May', 'menu': 'May', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''} |
| 1099 | \ ], |
| 1100 | \ 'selected': 0, |
| 1101 | \ } |
| 1102 | |
| 1103 | let g:compl_what = [] |
| 1104 | call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx') |
| 1105 | call assert_equal(d, g:compl_info) |
| 1106 | |
| 1107 | let g:compl_what = ['mode', 'pum_visible', 'selected'] |
| 1108 | call remove(d, 'items') |
| 1109 | call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx') |
| 1110 | call assert_equal(d, g:compl_info) |
| 1111 | |
| 1112 | let g:compl_what = ['mode'] |
| 1113 | call remove(d, 'selected') |
| 1114 | call remove(d, 'pum_visible') |
| 1115 | call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx') |
| 1116 | call assert_equal(d, g:compl_info) |
| 1117 | bwipe! |
| 1118 | endfunc |
| 1119 | |
Bram Moolenaar | e9bd572 | 2019-08-17 19:36:06 +0200 | [diff] [blame] | 1120 | func Test_popup_complete_info_no_pum() |
| 1121 | new |
| 1122 | call assert_false( pumvisible() ) |
| 1123 | let no_pum_info = complete_info() |
| 1124 | let d = { |
| 1125 | \ 'mode': '', |
| 1126 | \ 'pum_visible': 0, |
| 1127 | \ 'items': [], |
| 1128 | \ 'selected': -1, |
| 1129 | \ } |
| 1130 | call assert_equal( d, complete_info() ) |
| 1131 | bwipe! |
| 1132 | endfunc |
| 1133 | |
Bram Moolenaar | d7f246c | 2019-04-08 18:15:41 +0200 | [diff] [blame] | 1134 | func Test_CompleteChanged() |
| 1135 | new |
| 1136 | call setline(1, ['foo', 'bar', 'foobar', '']) |
| 1137 | set complete=. completeopt=noinsert,noselect,menuone |
| 1138 | function! OnPumChange() |
| 1139 | let g:event = copy(v:event) |
| 1140 | let g:item = get(v:event, 'completed_item', {}) |
| 1141 | let g:word = get(g:item, 'word', v:null) |
| 1142 | endfunction |
| 1143 | augroup AAAAA_Group |
| 1144 | au! |
| 1145 | autocmd CompleteChanged * :call OnPumChange() |
| 1146 | augroup END |
| 1147 | call cursor(4, 1) |
| 1148 | |
| 1149 | call feedkeys("Sf\<C-N>", 'tx') |
| 1150 | call assert_equal({'completed_item': {}, 'width': 15, |
| 1151 | \ 'height': 2, 'size': 2, |
| 1152 | \ 'col': 0, 'row': 4, 'scrollbar': v:false}, g:event) |
| 1153 | call feedkeys("a\<C-N>\<C-N>\<C-E>", 'tx') |
| 1154 | call assert_equal('foo', g:word) |
| 1155 | call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-E>", 'tx') |
| 1156 | call assert_equal('foobar', g:word) |
| 1157 | call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-N>\<C-E>", 'tx') |
| 1158 | call assert_equal(v:null, g:word) |
| 1159 | call feedkeys("a\<C-N>\<C-N>\<C-N>\<C-N>\<C-P>", 'tx') |
| 1160 | call assert_equal('foobar', g:word) |
| 1161 | |
| 1162 | autocmd! AAAAA_Group |
| 1163 | set complete& completeopt& |
Bram Moolenaar | e9bd572 | 2019-08-17 19:36:06 +0200 | [diff] [blame] | 1164 | delfunc! OnPumChange |
Bram Moolenaar | d7f246c | 2019-04-08 18:15:41 +0200 | [diff] [blame] | 1165 | bw! |
| 1166 | endfunc |
| 1167 | |
Bram Moolenaar | 97f0eb1 | 2022-10-06 19:49:13 +0100 | [diff] [blame] | 1168 | func GetPumPosition() |
Bram Moolenaar | e9bd572 | 2019-08-17 19:36:06 +0200 | [diff] [blame] | 1169 | call assert_true( pumvisible() ) |
| 1170 | let g:pum_pos = pum_getpos() |
| 1171 | return '' |
Bram Moolenaar | 97f0eb1 | 2022-10-06 19:49:13 +0100 | [diff] [blame] | 1172 | endfunc |
Bram Moolenaar | e9bd572 | 2019-08-17 19:36:06 +0200 | [diff] [blame] | 1173 | |
| 1174 | func Test_pum_getpos() |
| 1175 | new |
| 1176 | inoremap <buffer><F5> <C-R>=GetPumPosition()<CR> |
| 1177 | setlocal completefunc=UserDefinedComplete |
| 1178 | |
| 1179 | let d = { |
| 1180 | \ 'height': 5, |
| 1181 | \ 'width': 15, |
| 1182 | \ 'row': 1, |
| 1183 | \ 'col': 0, |
| 1184 | \ 'size': 5, |
| 1185 | \ 'scrollbar': v:false, |
| 1186 | \ } |
| 1187 | call feedkeys("i\<C-X>\<C-U>\<F5>", 'tx') |
| 1188 | call assert_equal(d, g:pum_pos) |
| 1189 | |
| 1190 | call assert_false( pumvisible() ) |
| 1191 | call assert_equal( {}, pum_getpos() ) |
| 1192 | bw! |
| 1193 | unlet g:pum_pos |
| 1194 | endfunc |
| 1195 | |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1196 | " Test for the popup menu with the 'rightleft' option set |
| 1197 | func Test_pum_rightleft() |
Dominique Pelle | 56cddb3 | 2021-06-04 21:09:55 +0200 | [diff] [blame] | 1198 | CheckFeature rightleft |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1199 | CheckScreendump |
Dominique Pelle | 56cddb3 | 2021-06-04 21:09:55 +0200 | [diff] [blame] | 1200 | |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1201 | let lines =<< trim END |
| 1202 | abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz |
| 1203 | vim |
| 1204 | victory |
| 1205 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 1206 | call writefile(lines, 'Xtest1', 'D') |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1207 | let buf = RunVimInTerminal('--cmd "set rightleft" Xtest1', {}) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1208 | call term_sendkeys(buf, "Go\<C-P>") |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1209 | call VerifyScreenDump(buf, 'Test_pum_rightleft_01', {'rows': 8}) |
| 1210 | call term_sendkeys(buf, "\<C-P>\<C-Y>") |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1211 | call TermWait(buf, 30) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1212 | redraw! |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1213 | call WaitForAssert({-> assert_match('\s*miv', Screenline(5))}) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1214 | |
| 1215 | " Test for expanding tabs to spaces in the popup menu |
| 1216 | let lines =<< trim END |
| 1217 | one two |
| 1218 | one three |
| 1219 | four |
| 1220 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 1221 | call writefile(lines, 'Xtest2', 'D') |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1222 | call term_sendkeys(buf, "\<Esc>:e! Xtest2\<CR>") |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1223 | call TermWait(buf, 30) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1224 | call term_sendkeys(buf, "Goone\<C-X>\<C-L>") |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1225 | call TermWait(buf, 30) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1226 | redraw! |
| 1227 | call VerifyScreenDump(buf, 'Test_pum_rightleft_02', {'rows': 7}) |
| 1228 | call term_sendkeys(buf, "\<C-Y>") |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1229 | call TermWait(buf, 30) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1230 | redraw! |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1231 | call WaitForAssert({-> assert_match('\s*eerht eno', Screenline(4))}) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1232 | |
| 1233 | call StopVimInTerminal(buf) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1234 | endfunc |
| 1235 | |
| 1236 | " Test for a popup menu with a scrollbar |
| 1237 | func Test_pum_scrollbar() |
| 1238 | CheckScreendump |
| 1239 | let lines =<< trim END |
| 1240 | one |
| 1241 | two |
| 1242 | three |
| 1243 | END |
Bram Moolenaar | 7dd5a78 | 2022-09-29 21:01:57 +0100 | [diff] [blame] | 1244 | call writefile(lines, 'Xtest1', 'D') |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1245 | let buf = RunVimInTerminal('--cmd "set pumheight=2" Xtest1', {}) |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1246 | call TermWait(buf) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1247 | call term_sendkeys(buf, "Go\<C-P>\<C-P>\<C-P>") |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1248 | call VerifyScreenDump(buf, 'Test_pum_scrollbar_01', {'rows': 7}) |
| 1249 | call term_sendkeys(buf, "\<C-E>\<Esc>dd") |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1250 | call TermWait(buf) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1251 | |
Dominique Pelle | 56cddb3 | 2021-06-04 21:09:55 +0200 | [diff] [blame] | 1252 | if has('rightleft') |
| 1253 | call term_sendkeys(buf, ":set rightleft\<CR>") |
Bram Moolenaar | 37bb3b1 | 2022-06-21 17:40:47 +0100 | [diff] [blame] | 1254 | call TermWait(buf) |
Dominique Pelle | 56cddb3 | 2021-06-04 21:09:55 +0200 | [diff] [blame] | 1255 | call term_sendkeys(buf, "Go\<C-P>\<C-P>\<C-P>") |
Dominique Pelle | 56cddb3 | 2021-06-04 21:09:55 +0200 | [diff] [blame] | 1256 | call VerifyScreenDump(buf, 'Test_pum_scrollbar_02', {'rows': 7}) |
| 1257 | endif |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1258 | |
| 1259 | call StopVimInTerminal(buf) |
Yegappan Lakshmanan | 1e61566 | 2021-05-22 17:12:46 +0200 | [diff] [blame] | 1260 | endfunc |
| 1261 | |
Gianmaria Bajo | 6a7c774 | 2023-03-10 16:35:53 +0000 | [diff] [blame] | 1262 | " Test default highlight groups for popup menu |
| 1263 | func Test_pum_highlights_default() |
| 1264 | CheckScreendump |
| 1265 | let lines =<< trim END |
| 1266 | func CompleteFunc( findstart, base ) |
| 1267 | if a:findstart |
| 1268 | return 0 |
| 1269 | endif |
| 1270 | return { |
| 1271 | \ 'words': [ |
| 1272 | \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', }, |
| 1273 | \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', }, |
| 1274 | \ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', }, |
| 1275 | \]} |
| 1276 | endfunc |
| 1277 | set completeopt=menu |
| 1278 | set completefunc=CompleteFunc |
| 1279 | END |
| 1280 | call writefile(lines, 'Xscript', 'D') |
| 1281 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1282 | call TermWait(buf) |
| 1283 | call term_sendkeys(buf, "iaw\<C-X>\<C-u>") |
| 1284 | call TermWait(buf, 50) |
| 1285 | call VerifyScreenDump(buf, 'Test_pum_highlights_01', {}) |
| 1286 | call term_sendkeys(buf, "\<C-E>\<Esc>u") |
| 1287 | call TermWait(buf) |
| 1288 | call StopVimInTerminal(buf) |
| 1289 | endfunc |
| 1290 | |
| 1291 | " Test custom highlight groups for popup menu |
| 1292 | func Test_pum_highlights_custom() |
| 1293 | CheckScreendump |
| 1294 | let lines =<< trim END |
| 1295 | func CompleteFunc( findstart, base ) |
| 1296 | if a:findstart |
| 1297 | return 0 |
| 1298 | endif |
| 1299 | return { |
| 1300 | \ 'words': [ |
| 1301 | \ { 'word': 'aword1', 'menu': 'extra text 1', 'kind': 'W', }, |
| 1302 | \ { 'word': 'aword2', 'menu': 'extra text 2', 'kind': 'W', }, |
| 1303 | \ { 'word': 'aword3', 'menu': 'extra text 3', 'kind': 'W', }, |
| 1304 | \]} |
| 1305 | endfunc |
| 1306 | set completeopt=menu |
| 1307 | set completefunc=CompleteFunc |
| 1308 | hi PmenuKind ctermfg=1 ctermbg=225 |
| 1309 | hi PmenuKindSel ctermfg=1 ctermbg=7 |
| 1310 | hi PmenuExtra ctermfg=243 ctermbg=225 |
| 1311 | hi PmenuExtraSel ctermfg=0 ctermbg=7 |
| 1312 | END |
| 1313 | call writefile(lines, 'Xscript', 'D') |
| 1314 | let buf = RunVimInTerminal('-S Xscript', {}) |
| 1315 | call TermWait(buf) |
| 1316 | call term_sendkeys(buf, "iaw\<C-X>\<C-u>") |
| 1317 | call TermWait(buf, 50) |
| 1318 | call VerifyScreenDump(buf, 'Test_pum_highlights_02', {}) |
| 1319 | call term_sendkeys(buf, "\<C-E>\<Esc>u") |
| 1320 | call TermWait(buf) |
| 1321 | call StopVimInTerminal(buf) |
| 1322 | endfunc |
| 1323 | |
Bram Moolenaar | 4724728 | 2016-08-02 22:36:02 +0200 | [diff] [blame] | 1324 | " vim: shiftwidth=2 sts=2 expandtab |