Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1 | " Test for insert completion |
| 2 | |
Bram Moolenaar | 09dd2bb | 2019-12-14 18:42:15 +0100 | [diff] [blame] | 3 | source screendump.vim |
Bram Moolenaar | 50f91d2 | 2019-08-02 19:52:15 +0200 | [diff] [blame] | 4 | source check.vim |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 5 | |
| 6 | " Test for insert expansion |
| 7 | func Test_ins_complete() |
Bram Moolenaar | cf1ba35 | 2017-10-27 00:55:04 +0200 | [diff] [blame] | 8 | edit test_ins_complete.vim |
Bram Moolenaar | fb094e1 | 2017-11-05 20:59:28 +0100 | [diff] [blame] | 9 | " The files in the current directory interferes with the files |
| 10 | " used by this test. So use a separate directory for the test. |
| 11 | call mkdir('Xdir') |
| 12 | cd Xdir |
| 13 | |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 14 | set ff=unix |
| 15 | call writefile(["test11\t36Gepeto\t/Tag/", |
| 16 | \ "asd\ttest11file\t36G", |
| 17 | \ "Makefile\tto\trun"], 'Xtestfile') |
| 18 | call writefile(['', 'start of testfile', |
| 19 | \ 'ru', |
| 20 | \ 'run1', |
| 21 | \ 'run2', |
| 22 | \ 'STARTTEST', |
| 23 | \ 'ENDTEST', |
| 24 | \ 'end of testfile'], 'Xtestdata') |
| 25 | set ff& |
| 26 | |
| 27 | enew! |
| 28 | edit Xtestdata |
| 29 | new |
| 30 | call append(0, ['#include "Xtestfile"', '']) |
| 31 | call cursor(2, 1) |
| 32 | |
| 33 | set cot= |
| 34 | set cpt=.,w |
| 35 | " add-expands (word from next line) from other window |
| 36 | exe "normal iru\<C-N>\<C-N>\<C-X>\<C-N>\<Esc>\<C-A>" |
| 37 | call assert_equal('run1 run3', getline('.')) |
| 38 | " add-expands (current buffer first) |
| 39 | exe "normal o\<C-P>\<C-X>\<C-N>" |
| 40 | call assert_equal('run3 run3', getline('.')) |
| 41 | " Local expansion, ends in an empty line (unless it becomes a global |
| 42 | " expansion) |
| 43 | exe "normal o\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>" |
| 44 | call assert_equal('', getline('.')) |
| 45 | " starts Local and switches to global add-expansion |
| 46 | exe "normal o\<C-X>\<C-P>\<C-P>\<C-X>\<C-X>\<C-N>\<C-X>\<C-N>\<C-N>" |
| 47 | call assert_equal('run1 run2', getline('.')) |
| 48 | |
| 49 | set cpt=.,w,i |
| 50 | " i-add-expands and switches to local |
| 51 | exe "normal OM\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-X>\<C-X>\<C-P>" |
| 52 | call assert_equal("Makefile\tto\trun3", getline('.')) |
| 53 | " add-expands lines (it would end in an empty line if it didn't ignored |
| 54 | " itself) |
| 55 | exe "normal o\<C-X>\<C-L>\<C-X>\<C-L>\<C-P>\<C-P>" |
| 56 | call assert_equal("Makefile\tto\trun3", getline('.')) |
| 57 | call assert_equal("Makefile\tto\trun3", getline(line('.') - 1)) |
| 58 | |
| 59 | set cpt=kXtestfile |
| 60 | " checks k-expansion, and file expansion (use Xtest11 instead of test11, |
| 61 | " because TEST11.OUT may match first on DOS) |
| 62 | write Xtest11.one |
| 63 | write Xtest11.two |
| 64 | exe "normal o\<C-N>\<Esc>IX\<Esc>A\<C-X>\<C-F>\<C-N>" |
| 65 | call assert_equal('Xtest11.two', getline('.')) |
| 66 | |
| 67 | " use CTRL-X CTRL-F to complete Xtest11.one, remove it and then use CTRL-X |
| 68 | " CTRL-F again to verify this doesn't cause trouble. |
| 69 | exe "normal oXt\<C-X>\<C-F>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<C-X>\<C-F>" |
| 70 | call assert_equal('Xtest11.one', getline('.')) |
| 71 | normal ddk |
| 72 | |
| 73 | set cpt=w |
| 74 | " checks make_cyclic in other window |
| 75 | exe "normal oST\<C-N>\<C-P>\<C-P>\<C-P>\<C-P>" |
| 76 | call assert_equal('STARTTEST', getline('.')) |
| 77 | |
| 78 | set cpt=u nohid |
| 79 | " checks unloaded buffer expansion |
| 80 | only |
| 81 | exe "normal oEN\<C-N>" |
| 82 | call assert_equal('ENDTEST', getline('.')) |
| 83 | " checks adding mode abortion |
| 84 | exe "normal ounl\<C-N>\<C-X>\<C-X>\<C-P>" |
| 85 | call assert_equal('unless', getline('.')) |
| 86 | |
| 87 | set cpt=t,d def=^\\k* tags=Xtestfile notagbsearch |
| 88 | " tag expansion, define add-expansion interrupted |
| 89 | exe "normal o\<C-X>\<C-]>\<C-X>\<C-D>\<C-X>\<C-D>\<C-X>\<C-X>\<C-D>\<C-X>\<C-D>\<C-X>\<C-D>\<C-X>\<C-D>" |
| 90 | call assert_equal('test11file 36Gepeto /Tag/ asd', getline('.')) |
| 91 | " t-expansion |
| 92 | exe "normal oa\<C-N>\<Esc>" |
| 93 | call assert_equal('asd', getline('.')) |
| 94 | |
| 95 | %bw! |
| 96 | call delete('Xtestfile') |
| 97 | call delete('Xtest11.one') |
| 98 | call delete('Xtest11.two') |
| 99 | call delete('Xtestdata') |
| 100 | set cpt& cot& def& tags& tagbsearch& hidden& |
Bram Moolenaar | fb094e1 | 2017-11-05 20:59:28 +0100 | [diff] [blame] | 101 | cd .. |
| 102 | call delete('Xdir', 'rf') |
Bram Moolenaar | 15993ce | 2017-10-26 20:21:44 +0200 | [diff] [blame] | 103 | endfunc |
Bram Moolenaar | ffd99f7 | 2017-11-02 15:44:14 +0100 | [diff] [blame] | 104 | |
| 105 | func Test_omni_dash() |
| 106 | func Omni(findstart, base) |
| 107 | if a:findstart |
| 108 | return 5 |
| 109 | else |
| 110 | echom a:base |
| 111 | return ['-help', '-v'] |
| 112 | endif |
| 113 | endfunc |
| 114 | set omnifunc=Omni |
| 115 | new |
| 116 | exe "normal Gofind -\<C-x>\<C-o>" |
Bram Moolenaar | cc23358 | 2020-12-12 13:32:07 +0100 | [diff] [blame] | 117 | call assert_equal("find -help", getline('$')) |
Bram Moolenaar | ffd99f7 | 2017-11-02 15:44:14 +0100 | [diff] [blame] | 118 | |
| 119 | bwipe! |
| 120 | delfunc Omni |
| 121 | set omnifunc= |
| 122 | endfunc |
Bram Moolenaar | 02ae9b4 | 2018-02-09 15:06:02 +0100 | [diff] [blame] | 123 | |
Bram Moolenaar | ff34bee | 2021-07-25 20:27:06 +0200 | [diff] [blame] | 124 | func Test_omni_autoload() |
| 125 | let save_rtp = &rtp |
| 126 | set rtp=Xruntime/some |
| 127 | let dir = 'Xruntime/some/autoload' |
| 128 | call mkdir(dir, 'p') |
| 129 | |
| 130 | let lines =<< trim END |
| 131 | vim9script |
| 132 | def omni#func(findstart: bool, base: string): any |
| 133 | if findstart |
| 134 | return 1 |
| 135 | else |
| 136 | return ['match'] |
| 137 | endif |
| 138 | enddef |
| 139 | { |
| 140 | eval 1 + 2 |
| 141 | } |
| 142 | END |
| 143 | call writefile(lines, dir .. '/omni.vim') |
| 144 | |
| 145 | new |
| 146 | setlocal omnifunc=omni#func |
| 147 | call feedkeys("i\<C-X>\<C-O>\<Esc>", 'xt') |
| 148 | |
| 149 | bwipe! |
| 150 | call delete('Xruntime', 'rf') |
| 151 | set omnifunc= |
| 152 | let &rtp = save_rtp |
| 153 | endfunc |
| 154 | |
Bram Moolenaar | ffa9684 | 2018-06-12 22:05:14 +0200 | [diff] [blame] | 155 | func Test_completefunc_args() |
| 156 | let s:args = [] |
| 157 | func! CompleteFunc(findstart, base) |
| 158 | let s:args += [[a:findstart, empty(a:base)]] |
| 159 | endfunc |
| 160 | new |
| 161 | |
| 162 | set completefunc=CompleteFunc |
| 163 | call feedkeys("i\<C-X>\<C-U>\<Esc>", 'x') |
Bram Moolenaar | 52d3aae | 2018-06-13 21:27:24 +0200 | [diff] [blame] | 164 | call assert_equal([1, 1], s:args[0]) |
| 165 | call assert_equal(0, s:args[1][0]) |
Bram Moolenaar | ffa9684 | 2018-06-12 22:05:14 +0200 | [diff] [blame] | 166 | set completefunc= |
| 167 | |
| 168 | let s:args = [] |
| 169 | set omnifunc=CompleteFunc |
| 170 | call feedkeys("i\<C-X>\<C-O>\<Esc>", 'x') |
Bram Moolenaar | 52d3aae | 2018-06-13 21:27:24 +0200 | [diff] [blame] | 171 | call assert_equal([1, 1], s:args[0]) |
| 172 | call assert_equal(0, s:args[1][0]) |
Bram Moolenaar | ffa9684 | 2018-06-12 22:05:14 +0200 | [diff] [blame] | 173 | set omnifunc= |
| 174 | |
| 175 | bwipe! |
| 176 | unlet s:args |
| 177 | delfunc CompleteFunc |
| 178 | endfunc |
| 179 | |
Bram Moolenaar | cee9bc2 | 2019-01-11 13:02:23 +0100 | [diff] [blame] | 180 | func s:CompleteDone_CompleteFuncNone( findstart, base ) |
| 181 | if a:findstart |
| 182 | return 0 |
| 183 | endif |
| 184 | |
| 185 | return v:none |
| 186 | endfunc |
| 187 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 188 | func s:CompleteDone_CompleteFuncDict( findstart, base ) |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 189 | if a:findstart |
| 190 | return 0 |
| 191 | endif |
| 192 | |
| 193 | return { |
Bram Moolenaar | 0892832 | 2020-01-04 14:32:48 +0100 | [diff] [blame] | 194 | \ 'words': [ |
| 195 | \ { |
| 196 | \ 'word': 'aword', |
| 197 | \ 'abbr': 'wrd', |
| 198 | \ 'menu': 'extra text', |
| 199 | \ 'info': 'words are cool', |
| 200 | \ 'kind': 'W', |
| 201 | \ 'user_data': 'test' |
| 202 | \ } |
| 203 | \ ] |
| 204 | \ } |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 205 | endfunc |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 206 | |
Bram Moolenaar | cee9bc2 | 2019-01-11 13:02:23 +0100 | [diff] [blame] | 207 | func s:CompleteDone_CheckCompletedItemNone() |
| 208 | let s:called_completedone = 1 |
| 209 | endfunc |
| 210 | |
Bram Moolenaar | 3f169ce | 2020-01-26 22:43:31 +0100 | [diff] [blame] | 211 | func s:CompleteDone_CheckCompletedItemDict(pre) |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 212 | call assert_equal( 'aword', v:completed_item[ 'word' ] ) |
| 213 | call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) |
| 214 | call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) |
| 215 | call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) |
| 216 | call assert_equal( 'W', v:completed_item[ 'kind' ] ) |
| 217 | call assert_equal( 'test', v:completed_item[ 'user_data' ] ) |
| 218 | |
Bram Moolenaar | 3f169ce | 2020-01-26 22:43:31 +0100 | [diff] [blame] | 219 | if a:pre |
| 220 | call assert_equal('function', complete_info().mode) |
| 221 | endif |
Bram Moolenaar | 17e0478 | 2020-01-17 18:58:59 +0100 | [diff] [blame] | 222 | |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 223 | let s:called_completedone = 1 |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 224 | endfunc |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 225 | |
Bram Moolenaar | cee9bc2 | 2019-01-11 13:02:23 +0100 | [diff] [blame] | 226 | func Test_CompleteDoneNone() |
| 227 | au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemNone() |
Bram Moolenaar | 9845f36 | 2019-04-08 18:59:54 +0200 | [diff] [blame] | 228 | let oldline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '') |
Bram Moolenaar | cee9bc2 | 2019-01-11 13:02:23 +0100 | [diff] [blame] | 229 | |
| 230 | set completefunc=<SID>CompleteDone_CompleteFuncNone |
| 231 | execute "normal a\<C-X>\<C-U>\<C-Y>" |
| 232 | set completefunc& |
Bram Moolenaar | 9845f36 | 2019-04-08 18:59:54 +0200 | [diff] [blame] | 233 | let newline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '') |
Bram Moolenaar | cee9bc2 | 2019-01-11 13:02:23 +0100 | [diff] [blame] | 234 | |
| 235 | call assert_true(s:called_completedone) |
Bram Moolenaar | 9845f36 | 2019-04-08 18:59:54 +0200 | [diff] [blame] | 236 | call assert_equal(oldline, newline) |
Bram Moolenaar | cee9bc2 | 2019-01-11 13:02:23 +0100 | [diff] [blame] | 237 | |
| 238 | let s:called_completedone = 0 |
| 239 | au! CompleteDone |
| 240 | endfunc |
| 241 | |
| 242 | func Test_CompleteDoneDict() |
Bram Moolenaar | 3f169ce | 2020-01-26 22:43:31 +0100 | [diff] [blame] | 243 | au CompleteDonePre * :call <SID>CompleteDone_CheckCompletedItemDict(1) |
| 244 | au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict(0) |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 245 | |
| 246 | set completefunc=<SID>CompleteDone_CompleteFuncDict |
| 247 | execute "normal a\<C-X>\<C-U>\<C-Y>" |
| 248 | set completefunc& |
| 249 | |
Bram Moolenaar | cee9bc2 | 2019-01-11 13:02:23 +0100 | [diff] [blame] | 250 | call assert_equal('test', v:completed_item[ 'user_data' ]) |
| 251 | call assert_true(s:called_completedone) |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 252 | |
| 253 | let s:called_completedone = 0 |
| 254 | au! CompleteDone |
| 255 | endfunc |
| 256 | |
Bram Moolenaar | cee9bc2 | 2019-01-11 13:02:23 +0100 | [diff] [blame] | 257 | func s:CompleteDone_CompleteFuncDictNoUserData(findstart, base) |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 258 | if a:findstart |
| 259 | return 0 |
| 260 | endif |
| 261 | |
| 262 | return { |
Bram Moolenaar | 0892832 | 2020-01-04 14:32:48 +0100 | [diff] [blame] | 263 | \ 'words': [ |
| 264 | \ { |
| 265 | \ 'word': 'aword', |
| 266 | \ 'abbr': 'wrd', |
| 267 | \ 'menu': 'extra text', |
| 268 | \ 'info': 'words are cool', |
| 269 | \ 'kind': 'W', |
| 270 | \ 'user_data': ['one', 'two'], |
| 271 | \ } |
| 272 | \ ] |
| 273 | \ } |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 274 | endfunc |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 275 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 276 | func s:CompleteDone_CheckCompletedItemDictNoUserData() |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 277 | call assert_equal( 'aword', v:completed_item[ 'word' ] ) |
| 278 | call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) |
| 279 | call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) |
| 280 | call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) |
| 281 | call assert_equal( 'W', v:completed_item[ 'kind' ] ) |
Bram Moolenaar | 0892832 | 2020-01-04 14:32:48 +0100 | [diff] [blame] | 282 | call assert_equal( ['one', 'two'], v:completed_item[ 'user_data' ] ) |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 283 | |
| 284 | let s:called_completedone = 1 |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 285 | endfunc |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 286 | |
Bram Moolenaar | cee9bc2 | 2019-01-11 13:02:23 +0100 | [diff] [blame] | 287 | func Test_CompleteDoneDictNoUserData() |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 288 | au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDictNoUserData() |
| 289 | |
| 290 | set completefunc=<SID>CompleteDone_CompleteFuncDictNoUserData |
| 291 | execute "normal a\<C-X>\<C-U>\<C-Y>" |
| 292 | set completefunc& |
| 293 | |
Bram Moolenaar | 0892832 | 2020-01-04 14:32:48 +0100 | [diff] [blame] | 294 | call assert_equal(['one', 'two'], v:completed_item[ 'user_data' ]) |
Bram Moolenaar | cee9bc2 | 2019-01-11 13:02:23 +0100 | [diff] [blame] | 295 | call assert_true(s:called_completedone) |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 296 | |
| 297 | let s:called_completedone = 0 |
| 298 | au! CompleteDone |
| 299 | endfunc |
| 300 | |
Bram Moolenaar | cee9bc2 | 2019-01-11 13:02:23 +0100 | [diff] [blame] | 301 | func s:CompleteDone_CompleteFuncList(findstart, base) |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 302 | if a:findstart |
| 303 | return 0 |
| 304 | endif |
| 305 | |
| 306 | return [ 'aword' ] |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 307 | endfunc |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 308 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 309 | func s:CompleteDone_CheckCompletedItemList() |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 310 | call assert_equal( 'aword', v:completed_item[ 'word' ] ) |
| 311 | call assert_equal( '', v:completed_item[ 'abbr' ] ) |
| 312 | call assert_equal( '', v:completed_item[ 'menu' ] ) |
| 313 | call assert_equal( '', v:completed_item[ 'info' ] ) |
| 314 | call assert_equal( '', v:completed_item[ 'kind' ] ) |
| 315 | call assert_equal( '', v:completed_item[ 'user_data' ] ) |
| 316 | |
| 317 | let s:called_completedone = 1 |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 318 | endfunc |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 319 | |
Bram Moolenaar | cee9bc2 | 2019-01-11 13:02:23 +0100 | [diff] [blame] | 320 | func Test_CompleteDoneList() |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 321 | au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemList() |
| 322 | |
| 323 | set completefunc=<SID>CompleteDone_CompleteFuncList |
| 324 | execute "normal a\<C-X>\<C-U>\<C-Y>" |
| 325 | set completefunc& |
| 326 | |
Bram Moolenaar | cee9bc2 | 2019-01-11 13:02:23 +0100 | [diff] [blame] | 327 | call assert_equal('', v:completed_item[ 'user_data' ]) |
| 328 | call assert_true(s:called_completedone) |
Bram Moolenaar | 9b56a57 | 2018-02-10 16:19:32 +0100 | [diff] [blame] | 329 | |
| 330 | let s:called_completedone = 0 |
| 331 | au! CompleteDone |
| 332 | endfunc |
| 333 | |
Bram Moolenaar | af559d2 | 2018-08-08 22:55:41 +0200 | [diff] [blame] | 334 | func Test_CompleteDone_undo() |
| 335 | au CompleteDone * call append(0, "prepend1") |
| 336 | new |
| 337 | call setline(1, ["line1", "line2"]) |
| 338 | call feedkeys("Go\<C-X>\<C-N>\<CR>\<ESC>", "tx") |
| 339 | call assert_equal(["prepend1", "line1", "line2", "line1", ""], |
| 340 | \ getline(1, '$')) |
| 341 | undo |
| 342 | call assert_equal(["line1", "line2"], getline(1, '$')) |
| 343 | bwipe! |
| 344 | au! CompleteDone |
| 345 | endfunc |
| 346 | |
Bram Moolenaar | b806aa5 | 2020-09-12 22:52:57 +0200 | [diff] [blame] | 347 | func CompleteTest(findstart, query) |
| 348 | if a:findstart |
| 349 | return col('.') |
| 350 | endif |
| 351 | return ['matched'] |
| 352 | endfunc |
| 353 | |
| 354 | func Test_completefunc_info() |
| 355 | new |
| 356 | set completeopt=menuone |
| 357 | set completefunc=CompleteTest |
| 358 | call feedkeys("i\<C-X>\<C-U>\<C-R>\<C-R>=string(complete_info())\<CR>\<ESC>", "tx") |
Bram Moolenaar | f9d5135 | 2020-10-26 19:22:42 +0100 | [diff] [blame] | 359 | call assert_equal("matched{'pum_visible': 1, 'mode': 'function', 'selected': 0, 'items': [{'word': 'matched', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}]}", getline(1)) |
Bram Moolenaar | b806aa5 | 2020-09-12 22:52:57 +0200 | [diff] [blame] | 360 | bwipe! |
| 361 | set completeopt& |
| 362 | set completefunc& |
| 363 | endfunc |
| 364 | |
Bram Moolenaar | 02ae9b4 | 2018-02-09 15:06:02 +0100 | [diff] [blame] | 365 | " Check that when using feedkeys() typeahead does not interrupt searching for |
| 366 | " completions. |
| 367 | func Test_compl_feedkeys() |
| 368 | new |
| 369 | set completeopt=menuone,noselect |
| 370 | call feedkeys("ajump ju\<C-X>\<C-N>\<C-P>\<ESC>", "tx") |
| 371 | call assert_equal("jump jump", getline(1)) |
| 372 | bwipe! |
| 373 | set completeopt& |
| 374 | endfunc |
Bram Moolenaar | f03e328 | 2019-07-22 21:55:18 +0200 | [diff] [blame] | 375 | |
mityu | a119812 | 2021-11-20 19:13:39 +0000 | [diff] [blame] | 376 | func s:ComplInCmdwin_GlobalCompletion(a, l, p) |
| 377 | return 'global' |
| 378 | endfunc |
| 379 | |
| 380 | func s:ComplInCmdwin_LocalCompletion(a, l, p) |
| 381 | return 'local' |
| 382 | endfunc |
| 383 | |
Bram Moolenaar | f03e328 | 2019-07-22 21:55:18 +0200 | [diff] [blame] | 384 | func Test_compl_in_cmdwin() |
Bram Moolenaar | 21829c5 | 2021-01-26 22:42:21 +0100 | [diff] [blame] | 385 | CheckFeature cmdwin |
| 386 | |
Bram Moolenaar | f03e328 | 2019-07-22 21:55:18 +0200 | [diff] [blame] | 387 | set wildmenu wildchar=<Tab> |
| 388 | com! -nargs=1 -complete=command GetInput let input = <q-args> |
| 389 | com! -buffer TestCommand echo 'TestCommand' |
Bram Moolenaar | 4ff2f2f | 2020-10-25 13:22:42 +0100 | [diff] [blame] | 390 | let w:test_winvar = 'winvar' |
| 391 | let b:test_bufvar = 'bufvar' |
Bram Moolenaar | f03e328 | 2019-07-22 21:55:18 +0200 | [diff] [blame] | 392 | |
Bram Moolenaar | 4ff2f2f | 2020-10-25 13:22:42 +0100 | [diff] [blame] | 393 | " User-defined commands |
Bram Moolenaar | f03e328 | 2019-07-22 21:55:18 +0200 | [diff] [blame] | 394 | let input = '' |
| 395 | call feedkeys("q:iGetInput T\<C-x>\<C-v>\<CR>", 'tx!') |
| 396 | call assert_equal('TestCommand', input) |
| 397 | |
| 398 | let input = '' |
| 399 | call feedkeys("q::GetInput T\<Tab>\<CR>:q\<CR>", 'tx!') |
| 400 | call assert_equal('T', input) |
| 401 | |
Bram Moolenaar | 4ff2f2f | 2020-10-25 13:22:42 +0100 | [diff] [blame] | 402 | |
| 403 | com! -nargs=1 -complete=var GetInput let input = <q-args> |
| 404 | " Window-local variables |
| 405 | let input = '' |
| 406 | call feedkeys("q:iGetInput w:test_\<C-x>\<C-v>\<CR>", 'tx!') |
| 407 | call assert_equal('w:test_winvar', input) |
| 408 | |
| 409 | let input = '' |
| 410 | call feedkeys("q::GetInput w:test_\<Tab>\<CR>:q\<CR>", 'tx!') |
| 411 | call assert_equal('w:test_', input) |
| 412 | |
| 413 | " Buffer-local variables |
| 414 | let input = '' |
| 415 | call feedkeys("q:iGetInput b:test_\<C-x>\<C-v>\<CR>", 'tx!') |
| 416 | call assert_equal('b:test_bufvar', input) |
| 417 | |
| 418 | let input = '' |
| 419 | call feedkeys("q::GetInput b:test_\<Tab>\<CR>:q\<CR>", 'tx!') |
| 420 | call assert_equal('b:test_', input) |
| 421 | |
mityu | a119812 | 2021-11-20 19:13:39 +0000 | [diff] [blame] | 422 | |
| 423 | " Argument completion of buffer-local command |
| 424 | func s:ComplInCmdwin_GlobalCompletionList(a, l, p) |
| 425 | return ['global'] |
| 426 | endfunc |
| 427 | |
| 428 | func s:ComplInCmdwin_LocalCompletionList(a, l, p) |
| 429 | return ['local'] |
| 430 | endfunc |
| 431 | |
| 432 | func s:ComplInCmdwin_CheckCompletion(arg) |
| 433 | call assert_equal('local', a:arg) |
| 434 | endfunc |
| 435 | |
| 436 | com! -nargs=1 -complete=custom,<SID>ComplInCmdwin_GlobalCompletion |
| 437 | \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>) |
| 438 | com! -buffer -nargs=1 -complete=custom,<SID>ComplInCmdwin_LocalCompletion |
| 439 | \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>) |
| 440 | call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!') |
| 441 | |
| 442 | com! -nargs=1 -complete=customlist,<SID>ComplInCmdwin_GlobalCompletionList |
| 443 | \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>) |
| 444 | com! -buffer -nargs=1 -complete=customlist,<SID>ComplInCmdwin_LocalCompletionList |
| 445 | \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>) |
| 446 | |
| 447 | call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!') |
| 448 | |
| 449 | func! s:ComplInCmdwin_CheckCompletion(arg) |
| 450 | call assert_equal('global', a:arg) |
| 451 | endfunc |
| 452 | new |
| 453 | call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!') |
| 454 | quit |
| 455 | |
| 456 | delfunc s:ComplInCmdwin_GlobalCompletion |
| 457 | delfunc s:ComplInCmdwin_LocalCompletion |
| 458 | delfunc s:ComplInCmdwin_GlobalCompletionList |
| 459 | delfunc s:ComplInCmdwin_LocalCompletionList |
| 460 | delfunc s:ComplInCmdwin_CheckCompletion |
| 461 | |
| 462 | delcom -buffer TestCommand |
Bram Moolenaar | f03e328 | 2019-07-22 21:55:18 +0200 | [diff] [blame] | 463 | delcom TestCommand |
| 464 | delcom GetInput |
Bram Moolenaar | 4ff2f2f | 2020-10-25 13:22:42 +0100 | [diff] [blame] | 465 | unlet w:test_winvar |
| 466 | unlet b:test_bufvar |
Bram Moolenaar | f03e328 | 2019-07-22 21:55:18 +0200 | [diff] [blame] | 467 | set wildmenu& wildchar& |
| 468 | endfunc |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 469 | |
| 470 | " Test for insert path completion with completeslash option |
| 471 | func Test_ins_completeslash() |
Bram Moolenaar | 50f91d2 | 2019-08-02 19:52:15 +0200 | [diff] [blame] | 472 | CheckMSWindows |
Bram Moolenaar | 8f187fc | 2020-09-26 18:47:11 +0200 | [diff] [blame] | 473 | |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 474 | call mkdir('Xdir') |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 475 | let orig_shellslash = &shellslash |
| 476 | set cpt& |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 477 | new |
Bram Moolenaar | 8f187fc | 2020-09-26 18:47:11 +0200 | [diff] [blame] | 478 | |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 479 | set noshellslash |
| 480 | |
| 481 | set completeslash= |
| 482 | exe "normal oXd\<C-X>\<C-F>" |
| 483 | call assert_equal('Xdir\', getline('.')) |
| 484 | |
| 485 | set completeslash=backslash |
| 486 | exe "normal oXd\<C-X>\<C-F>" |
| 487 | call assert_equal('Xdir\', getline('.')) |
| 488 | |
| 489 | set completeslash=slash |
| 490 | exe "normal oXd\<C-X>\<C-F>" |
| 491 | call assert_equal('Xdir/', getline('.')) |
| 492 | |
| 493 | set shellslash |
| 494 | |
| 495 | set completeslash= |
| 496 | exe "normal oXd\<C-X>\<C-F>" |
| 497 | call assert_equal('Xdir/', getline('.')) |
| 498 | |
| 499 | set completeslash=backslash |
| 500 | exe "normal oXd\<C-X>\<C-F>" |
| 501 | call assert_equal('Xdir\', getline('.')) |
| 502 | |
| 503 | set completeslash=slash |
| 504 | exe "normal oXd\<C-X>\<C-F>" |
| 505 | call assert_equal('Xdir/', getline('.')) |
| 506 | %bw! |
| 507 | call delete('Xdir', 'rf') |
| 508 | |
Bram Moolenaar | 50f91d2 | 2019-08-02 19:52:15 +0200 | [diff] [blame] | 509 | set noshellslash |
| 510 | set completeslash=slash |
| 511 | call assert_true(stridx(globpath(&rtp, 'syntax/*.vim', 1, 1)[0], '\') != -1) |
| 512 | |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 513 | let &shellslash = orig_shellslash |
Bram Moolenaar | 50f91d2 | 2019-08-02 19:52:15 +0200 | [diff] [blame] | 514 | set completeslash= |
Bram Moolenaar | ac3150d | 2019-07-28 16:36:39 +0200 | [diff] [blame] | 515 | endfunc |
| 516 | |
Bram Moolenaar | d0e1b71 | 2020-09-27 20:13:03 +0200 | [diff] [blame] | 517 | func Test_pum_stopped_by_timer() |
| 518 | CheckScreendump |
| 519 | |
| 520 | let lines =<< trim END |
| 521 | call setline(1, ['hello', 'hullo', 'heeee', '']) |
| 522 | func StartCompl() |
| 523 | call timer_start(100, { -> execute('stopinsert') }) |
| 524 | call feedkeys("Gah\<C-N>") |
| 525 | endfunc |
| 526 | END |
| 527 | |
| 528 | call writefile(lines, 'Xpumscript') |
| 529 | let buf = RunVimInTerminal('-S Xpumscript', #{rows: 12}) |
| 530 | call term_sendkeys(buf, ":call StartCompl()\<CR>") |
| 531 | call TermWait(buf, 200) |
| 532 | call term_sendkeys(buf, "k") |
| 533 | call VerifyScreenDump(buf, 'Test_pum_stopped_by_timer', {}) |
| 534 | |
| 535 | call StopVimInTerminal(buf) |
| 536 | call delete('Xpumscript') |
| 537 | endfunc |
| 538 | |
Bram Moolenaar | 09dd2bb | 2019-12-14 18:42:15 +0100 | [diff] [blame] | 539 | func Test_pum_with_folds_two_tabs() |
| 540 | CheckScreendump |
| 541 | |
| 542 | let lines =<< trim END |
| 543 | set fdm=marker |
| 544 | call setline(1, ['" x {{{1', '" a some text']) |
| 545 | call setline(3, range(&lines)->map({_, val -> '" a' .. val})) |
| 546 | norm! zm |
| 547 | tab sp |
| 548 | call feedkeys('2Gzv', 'xt') |
| 549 | call feedkeys("0fa", 'xt') |
| 550 | END |
| 551 | |
| 552 | call writefile(lines, 'Xpumscript') |
| 553 | let buf = RunVimInTerminal('-S Xpumscript', #{rows: 10}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 554 | call TermWait(buf, 50) |
Bram Moolenaar | 09dd2bb | 2019-12-14 18:42:15 +0100 | [diff] [blame] | 555 | call term_sendkeys(buf, "a\<C-N>") |
| 556 | call VerifyScreenDump(buf, 'Test_pum_with_folds_two_tabs', {}) |
| 557 | |
| 558 | call term_sendkeys(buf, "\<Esc>") |
| 559 | call StopVimInTerminal(buf) |
| 560 | call delete('Xpumscript') |
| 561 | endfunc |
Bram Moolenaar | 5e5a98d | 2019-12-15 14:55:33 +0100 | [diff] [blame] | 562 | |
| 563 | func Test_pum_with_preview_win() |
| 564 | CheckScreendump |
| 565 | |
| 566 | let lines =<< trim END |
| 567 | funct Omni_test(findstart, base) |
| 568 | if a:findstart |
| 569 | return col(".") - 1 |
| 570 | endif |
| 571 | return [#{word: "one", info: "1info"}, #{word: "two", info: "2info"}, #{word: "three", info: "3info"}] |
| 572 | endfunc |
| 573 | set omnifunc=Omni_test |
| 574 | set completeopt+=longest |
| 575 | END |
| 576 | |
| 577 | call writefile(lines, 'Xpreviewscript') |
| 578 | let buf = RunVimInTerminal('-S Xpreviewscript', #{rows: 12}) |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 579 | call TermWait(buf, 50) |
Bram Moolenaar | 5e5a98d | 2019-12-15 14:55:33 +0100 | [diff] [blame] | 580 | call term_sendkeys(buf, "Gi\<C-X>\<C-O>") |
Bram Moolenaar | 6a2c5a7 | 2020-04-08 21:50:25 +0200 | [diff] [blame] | 581 | call TermWait(buf, 100) |
Bram Moolenaar | 5e5a98d | 2019-12-15 14:55:33 +0100 | [diff] [blame] | 582 | call term_sendkeys(buf, "\<C-N>") |
| 583 | call VerifyScreenDump(buf, 'Test_pum_with_preview_win', {}) |
| 584 | |
| 585 | call term_sendkeys(buf, "\<Esc>") |
| 586 | call StopVimInTerminal(buf) |
| 587 | call delete('Xpreviewscript') |
| 588 | endfunc |
Bram Moolenaar | 830c1af | 2020-01-05 20:35:44 +0100 | [diff] [blame] | 589 | |
| 590 | " Test for inserting the tag search pattern in insert mode |
| 591 | func Test_ins_compl_tag_sft() |
| 592 | call writefile([ |
| 593 | \ "!_TAG_FILE_ENCODING\tutf-8\t//", |
| 594 | \ "first\tXfoo\t/^int first() {}$/", |
| 595 | \ "second\tXfoo\t/^int second() {}$/", |
| 596 | \ "third\tXfoo\t/^int third() {}$/"], |
| 597 | \ 'Xtags') |
| 598 | set tags=Xtags |
| 599 | let code =<< trim [CODE] |
| 600 | int first() {} |
| 601 | int second() {} |
| 602 | int third() {} |
| 603 | [CODE] |
| 604 | call writefile(code, 'Xfoo') |
| 605 | |
| 606 | enew |
| 607 | set showfulltag |
| 608 | exe "normal isec\<C-X>\<C-]>\<C-N>\<CR>" |
| 609 | call assert_equal('int second() {}', getline(1)) |
| 610 | set noshowfulltag |
| 611 | |
| 612 | call delete('Xtags') |
| 613 | call delete('Xfoo') |
| 614 | set tags& |
| 615 | %bwipe! |
| 616 | endfunc |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 617 | |
| 618 | " Test for 'completefunc' deleting text |
| 619 | func Test_completefunc_error() |
| 620 | new |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 621 | " delete text when called for the first time |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 622 | func CompleteFunc(findstart, base) |
| 623 | if a:findstart == 1 |
| 624 | normal dd |
| 625 | return col('.') - 1 |
| 626 | endif |
| 627 | return ['a', 'b'] |
| 628 | endfunc |
| 629 | set completefunc=CompleteFunc |
| 630 | call setline(1, ['', 'abcd', '']) |
Bram Moolenaar | 3eb6bd9 | 2021-01-29 21:47:24 +0100 | [diff] [blame] | 631 | call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:') |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 632 | |
| 633 | " delete text when called for the second time |
| 634 | func CompleteFunc2(findstart, base) |
| 635 | if a:findstart == 1 |
| 636 | return col('.') - 1 |
| 637 | endif |
| 638 | normal dd |
| 639 | return ['a', 'b'] |
| 640 | endfunc |
| 641 | set completefunc=CompleteFunc2 |
| 642 | call setline(1, ['', 'abcd', '']) |
Bram Moolenaar | 6adb9ea | 2020-04-30 22:31:18 +0200 | [diff] [blame] | 643 | call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:') |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 644 | |
Bram Moolenaar | 97202d9 | 2021-01-28 18:34:35 +0100 | [diff] [blame] | 645 | " Jump to a different window from the complete function |
Bram Moolenaar | 28976e2 | 2021-01-29 21:07:07 +0100 | [diff] [blame] | 646 | func CompleteFunc3(findstart, base) |
Bram Moolenaar | 97202d9 | 2021-01-28 18:34:35 +0100 | [diff] [blame] | 647 | if a:findstart == 1 |
| 648 | return col('.') - 1 |
| 649 | endif |
| 650 | wincmd p |
| 651 | return ['a', 'b'] |
| 652 | endfunc |
Bram Moolenaar | 28976e2 | 2021-01-29 21:07:07 +0100 | [diff] [blame] | 653 | set completefunc=CompleteFunc3 |
Bram Moolenaar | 97202d9 | 2021-01-28 18:34:35 +0100 | [diff] [blame] | 654 | new |
Bram Moolenaar | 28976e2 | 2021-01-29 21:07:07 +0100 | [diff] [blame] | 655 | call assert_fails('exe "normal a\<C-X>\<C-U>"', 'E565:') |
Bram Moolenaar | 97202d9 | 2021-01-28 18:34:35 +0100 | [diff] [blame] | 656 | close! |
| 657 | |
| 658 | set completefunc& |
| 659 | delfunc CompleteFunc |
Bram Moolenaar | 28976e2 | 2021-01-29 21:07:07 +0100 | [diff] [blame] | 660 | delfunc CompleteFunc2 |
| 661 | delfunc CompleteFunc3 |
| 662 | close! |
Bram Moolenaar | 97202d9 | 2021-01-28 18:34:35 +0100 | [diff] [blame] | 663 | endfunc |
| 664 | |
Bram Moolenaar | f9ab52e | 2020-05-05 19:57:18 +0200 | [diff] [blame] | 665 | " Test for returning non-string values from 'completefunc' |
| 666 | func Test_completefunc_invalid_data() |
| 667 | new |
| 668 | func! CompleteFunc(findstart, base) |
| 669 | if a:findstart == 1 |
| 670 | return col('.') - 1 |
| 671 | endif |
| 672 | return [{}, '', 'moon'] |
| 673 | endfunc |
| 674 | set completefunc=CompleteFunc |
| 675 | exe "normal i\<C-X>\<C-U>" |
| 676 | call assert_equal('moon', getline(1)) |
| 677 | set completefunc& |
| 678 | close! |
| 679 | endfunc |
| 680 | |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 681 | " Test for errors in using complete() function |
| 682 | func Test_complete_func_error() |
| 683 | call assert_fails('call complete(1, ["a"])', 'E785:') |
| 684 | func ListColors() |
| 685 | call complete(col('.'), "blue") |
| 686 | endfunc |
| 687 | call assert_fails('exe "normal i\<C-R>=ListColors()\<CR>"', 'E474:') |
| 688 | func ListMonths() |
| 689 | call complete(col('.'), test_null_list()) |
| 690 | endfunc |
| 691 | call assert_fails('exe "normal i\<C-R>=ListMonths()\<CR>"', 'E474:') |
| 692 | delfunc ListColors |
| 693 | delfunc ListMonths |
| 694 | call assert_fails('call complete_info({})', 'E714:') |
Bram Moolenaar | f9ab52e | 2020-05-05 19:57:18 +0200 | [diff] [blame] | 695 | call assert_equal([], complete_info(['items']).items) |
Bram Moolenaar | ad48e6c | 2020-04-21 22:19:45 +0200 | [diff] [blame] | 696 | endfunc |
| 697 | |
Bram Moolenaar | 224a5f1 | 2020-04-28 20:29:07 +0200 | [diff] [blame] | 698 | " Test for completing words following a completed word in a line |
| 699 | func Test_complete_wrapscan() |
| 700 | " complete words from another buffer |
| 701 | new |
| 702 | call setline(1, ['one two', 'three four']) |
| 703 | new |
| 704 | setlocal complete=w |
| 705 | call feedkeys("itw\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>", 'xt') |
| 706 | call assert_equal('two three four', getline(1)) |
| 707 | close! |
| 708 | " complete words from the current buffer |
| 709 | setlocal complete=. |
| 710 | %d |
| 711 | call setline(1, ['one two', '']) |
| 712 | call cursor(2, 1) |
| 713 | call feedkeys("ion\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>", 'xt') |
| 714 | call assert_equal('one two one two', getline(2)) |
| 715 | close! |
| 716 | endfunc |
| 717 | |
Bram Moolenaar | f9ab52e | 2020-05-05 19:57:18 +0200 | [diff] [blame] | 718 | " Test for completing special characters |
| 719 | func Test_complete_special_chars() |
| 720 | new |
| 721 | call setline(1, 'int .*[-\^$ func float') |
| 722 | call feedkeys("oin\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>", 'xt') |
| 723 | call assert_equal('int .*[-\^$ func float', getline(2)) |
| 724 | close! |
| 725 | endfunc |
| 726 | |
| 727 | " Test for completion when text is wrapped across lines. |
| 728 | func Test_complete_across_line() |
| 729 | new |
| 730 | call setline(1, ['red green blue', 'one two three']) |
| 731 | setlocal textwidth=20 |
| 732 | exe "normal 2G$a re\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>" |
| 733 | call assert_equal(['one two three red', 'green blue one'], getline(2, '$')) |
| 734 | close! |
| 735 | endfunc |
| 736 | |
| 737 | " Test for using CTRL-L to add one character when completing matching |
| 738 | func Test_complete_add_onechar() |
| 739 | new |
| 740 | call setline(1, ['wool', 'woodwork']) |
| 741 | call feedkeys("Gowoo\<C-P>\<C-P>\<C-P>\<C-L>f", 'xt') |
| 742 | call assert_equal('woof', getline(3)) |
| 743 | |
| 744 | " use 'ignorecase' and backspace to erase characters from the prefix string |
| 745 | " and then add letters using CTRL-L |
| 746 | %d |
| 747 | set ignorecase backspace=2 |
| 748 | setlocal complete=. |
| 749 | call setline(1, ['workhorse', 'workload']) |
| 750 | normal Go |
| 751 | exe "normal aWOR\<C-P>\<bs>\<bs>\<bs>\<bs>\<bs>\<bs>\<C-L>r\<C-L>\<C-L>" |
| 752 | call assert_equal('workh', getline(3)) |
| 753 | set ignorecase& backspace& |
| 754 | close! |
| 755 | endfunc |
| 756 | |
| 757 | " Test insert completion with 'cindent' (adjust the indent) |
| 758 | func Test_complete_with_cindent() |
| 759 | new |
| 760 | setlocal cindent |
| 761 | call setline(1, ['if (i == 1)', " j = 2;"]) |
| 762 | exe "normal Go{\<CR>i\<C-X>\<C-L>\<C-X>\<C-L>\<CR>}" |
| 763 | call assert_equal(['{', "\tif (i == 1)", "\t\tj = 2;", '}'], getline(3, '$')) |
| 764 | |
| 765 | %d |
| 766 | call setline(1, ['when while', '{', '']) |
| 767 | setlocal cinkeys+==while |
| 768 | exe "normal Giwh\<C-P> " |
| 769 | call assert_equal("\twhile ", getline('$')) |
| 770 | close! |
| 771 | endfunc |
| 772 | |
| 773 | " Test for <CTRL-X> <CTRL-V> completion. Complete commands and functions |
| 774 | func Test_complete_cmdline() |
| 775 | new |
| 776 | exe "normal icaddb\<C-X>\<C-V>" |
| 777 | call assert_equal('caddbuffer', getline(1)) |
| 778 | exe "normal ocall getqf\<C-X>\<C-V>" |
| 779 | call assert_equal('call getqflist(', getline(2)) |
| 780 | exe "normal oabcxyz(\<C-X>\<C-V>" |
| 781 | call assert_equal('abcxyz(', getline(3)) |
zeertzjq | dca29d9 | 2021-08-31 19:12:51 +0200 | [diff] [blame] | 782 | com! -buffer TestCommand1 echo 'TestCommand1' |
| 783 | com! -buffer TestCommand2 echo 'TestCommand2' |
| 784 | write TestCommand1Test |
| 785 | write TestCommand2Test |
| 786 | " Test repeating <CTRL-X> <CTRL-V> and switching to another CTRL-X mode |
| 787 | exe "normal oT\<C-X>\<C-V>\<C-X>\<C-V>\<C-X>\<C-F>\<Esc>" |
| 788 | call assert_equal('TestCommand2Test', getline(4)) |
| 789 | call delete('TestCommand1Test') |
| 790 | call delete('TestCommand2Test') |
| 791 | delcom TestCommand1 |
| 792 | delcom TestCommand2 |
| 793 | close! |
| 794 | endfunc |
| 795 | |
| 796 | " Test for <CTRL-X> <CTRL-Z> stopping completion without changing the match |
| 797 | func Test_complete_stop() |
| 798 | new |
| 799 | func Save_mode1() |
| 800 | let g:mode1 = mode(1) |
| 801 | return '' |
| 802 | endfunc |
| 803 | func Save_mode2() |
| 804 | let g:mode2 = mode(1) |
| 805 | return '' |
| 806 | endfunc |
| 807 | inoremap <F1> <C-R>=Save_mode1()<CR> |
| 808 | inoremap <F2> <C-R>=Save_mode2()<CR> |
| 809 | call setline(1, ['aaa bbb ccc ']) |
| 810 | exe "normal A\<C-N>\<C-P>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>" |
| 811 | call assert_equal('ic', g:mode1) |
| 812 | call assert_equal('i', g:mode2) |
| 813 | call assert_equal('aaa bbb ccc ', getline(1)) |
| 814 | exe "normal A\<C-N>\<Down>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>" |
| 815 | call assert_equal('ic', g:mode1) |
| 816 | call assert_equal('i', g:mode2) |
| 817 | call assert_equal('aaa bbb ccc aaa', getline(1)) |
| 818 | set completeopt+=noselect |
| 819 | exe "normal A \<C-N>\<Down>\<Down>\<C-L>\<C-L>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>" |
| 820 | call assert_equal('ic', g:mode1) |
| 821 | call assert_equal('i', g:mode2) |
| 822 | call assert_equal('aaa bbb ccc aaa bb', getline(1)) |
| 823 | set completeopt& |
| 824 | exe "normal A d\<C-N>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>" |
| 825 | call assert_equal('ic', g:mode1) |
| 826 | call assert_equal('i', g:mode2) |
| 827 | call assert_equal('aaa bbb ccc aaa bb d', getline(1)) |
| 828 | com! -buffer TestCommand1 echo 'TestCommand1' |
| 829 | com! -buffer TestCommand2 echo 'TestCommand2' |
| 830 | exe "normal oT\<C-X>\<C-V>\<C-X>\<C-V>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>" |
| 831 | call assert_equal('ic', g:mode1) |
| 832 | call assert_equal('i', g:mode2) |
| 833 | call assert_equal('TestCommand2', getline(2)) |
| 834 | delcom TestCommand1 |
| 835 | delcom TestCommand2 |
| 836 | unlet g:mode1 |
| 837 | unlet g:mode2 |
| 838 | iunmap <F1> |
| 839 | iunmap <F2> |
| 840 | delfunc Save_mode1 |
| 841 | delfunc Save_mode2 |
Bram Moolenaar | f9ab52e | 2020-05-05 19:57:18 +0200 | [diff] [blame] | 842 | close! |
| 843 | endfunc |
| 844 | |
Bram Moolenaar | 8f187fc | 2020-09-26 18:47:11 +0200 | [diff] [blame] | 845 | func Test_issue_7021() |
| 846 | CheckMSWindows |
| 847 | |
| 848 | let orig_shellslash = &shellslash |
| 849 | set noshellslash |
| 850 | |
| 851 | set completeslash=slash |
| 852 | call assert_false(expand('~') =~ '/') |
| 853 | |
| 854 | let &shellslash = orig_shellslash |
| 855 | set completeslash= |
| 856 | endfunc |
| 857 | |
Bram Moolenaar | cc23358 | 2020-12-12 13:32:07 +0100 | [diff] [blame] | 858 | " Test to ensure 'Scanning...' messages are not recorded in messages history |
| 859 | func Test_z1_complete_no_history() |
| 860 | new |
| 861 | messages clear |
| 862 | let currmess = execute('messages') |
| 863 | setlocal dictionary=README.txt |
| 864 | exe "normal owh\<C-X>\<C-K>" |
| 865 | exe "normal owh\<C-N>" |
| 866 | call assert_equal(currmess, execute('messages')) |
| 867 | close! |
| 868 | endfunc |
| 869 | |
Bram Moolenaar | ee4e0c1 | 2020-04-06 21:35:05 +0200 | [diff] [blame] | 870 | " vim: shiftwidth=2 sts=2 expandtab |