1 2" Test for insert expansion 3func Test_ins_complete() 4 edit test_ins_complete.vim 5 " The files in the current directory interferes with the files 6 " used by this test. So use a separate directory for the test. 7 call mkdir('Xdir') 8 cd Xdir 9 10 set ff=unix 11 call writefile(["test11\t36Gepeto\t/Tag/", 12 \ "asd\ttest11file\t36G", 13 \ "Makefile\tto\trun"], 'Xtestfile') 14 call writefile(['', 'start of testfile', 15 \ 'ru', 16 \ 'run1', 17 \ 'run2', 18 \ 'STARTTEST', 19 \ 'ENDTEST', 20 \ 'end of testfile'], 'Xtestdata') 21 set ff& 22 23 enew! 24 edit Xtestdata 25 new 26 call append(0, ['#include "Xtestfile"', '']) 27 call cursor(2, 1) 28 29 set cot= 30 set cpt=.,w 31 " add-expands (word from next line) from other window 32 exe "normal iru\<C-N>\<C-N>\<C-X>\<C-N>\<Esc>\<C-A>" 33 call assert_equal('run1 run3', getline('.')) 34 " add-expands (current buffer first) 35 exe "normal o\<C-P>\<C-X>\<C-N>" 36 call assert_equal('run3 run3', getline('.')) 37 " Local expansion, ends in an empty line (unless it becomes a global 38 " expansion) 39 exe "normal o\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>" 40 call assert_equal('', getline('.')) 41 " starts Local and switches to global add-expansion 42 exe "normal o\<C-X>\<C-P>\<C-P>\<C-X>\<C-X>\<C-N>\<C-X>\<C-N>\<C-N>" 43 call assert_equal('run1 run2', getline('.')) 44 45 set cpt=.,w,i 46 " i-add-expands and switches to local 47 exe "normal OM\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-X>\<C-X>\<C-P>" 48 call assert_equal("Makefile\tto\trun3", getline('.')) 49 " add-expands lines (it would end in an empty line if it didn't ignored 50 " itself) 51 exe "normal o\<C-X>\<C-L>\<C-X>\<C-L>\<C-P>\<C-P>" 52 call assert_equal("Makefile\tto\trun3", getline('.')) 53 call assert_equal("Makefile\tto\trun3", getline(line('.') - 1)) 54 55 set cpt=kXtestfile 56 " checks k-expansion, and file expansion (use Xtest11 instead of test11, 57 " because TEST11.OUT may match first on DOS) 58 write Xtest11.one 59 write Xtest11.two 60 exe "normal o\<C-N>\<Esc>IX\<Esc>A\<C-X>\<C-F>\<C-N>" 61 call assert_equal('Xtest11.two', getline('.')) 62 63 " use CTRL-X CTRL-F to complete Xtest11.one, remove it and then use CTRL-X 64 " CTRL-F again to verify this doesn't cause trouble. 65 exe "normal oXt\<C-X>\<C-F>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<C-X>\<C-F>" 66 call assert_equal('Xtest11.one', getline('.')) 67 normal ddk 68 69 set cpt=w 70 " checks make_cyclic in other window 71 exe "normal oST\<C-N>\<C-P>\<C-P>\<C-P>\<C-P>" 72 call assert_equal('STARTTEST', getline('.')) 73 74 set cpt=u nohid 75 " checks unloaded buffer expansion 76 only 77 exe "normal oEN\<C-N>" 78 call assert_equal('ENDTEST', getline('.')) 79 " checks adding mode abortion 80 exe "normal ounl\<C-N>\<C-X>\<C-X>\<C-P>" 81 call assert_equal('unless', getline('.')) 82 83 set cpt=t,d def=^\\k* tags=Xtestfile notagbsearch 84 " tag expansion, define add-expansion interrupted 85 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>" 86 call assert_equal('test11file 36Gepeto /Tag/ asd', getline('.')) 87 " t-expansion 88 exe "normal oa\<C-N>\<Esc>" 89 call assert_equal('asd', getline('.')) 90 91 %bw! 92 call delete('Xtestfile') 93 call delete('Xtest11.one') 94 call delete('Xtest11.two') 95 call delete('Xtestdata') 96 set cpt& cot& def& tags& tagbsearch& hidden& 97 cd .. 98 call delete('Xdir', 'rf') 99endfunc 100 101func Test_omni_dash() 102 func Omni(findstart, base) 103 if a:findstart 104 return 5 105 else 106 echom a:base 107 return ['-help', '-v'] 108 endif 109 endfunc 110 set omnifunc=Omni 111 new 112 exe "normal Gofind -\<C-x>\<C-o>" 113 call assert_equal("\n-\nmatch 1 of 2", execute(':2mess')) 114 115 bwipe! 116 delfunc Omni 117 set omnifunc= 118endfunc 119 120func Test_completefunc_args() 121 let s:args = [] 122 func! CompleteFunc(findstart, base) 123 let s:args += [[a:findstart, empty(a:base)]] 124 endfunc 125 new 126 127 set completefunc=CompleteFunc 128 call feedkeys("i\<C-X>\<C-U>\<Esc>", 'x') 129 call assert_equal([1, 1], s:args[0]) 130 call assert_equal(0, s:args[1][0]) 131 set completefunc= 132 133 let s:args = [] 134 set omnifunc=CompleteFunc 135 call feedkeys("i\<C-X>\<C-O>\<Esc>", 'x') 136 call assert_equal([1, 1], s:args[0]) 137 call assert_equal(0, s:args[1][0]) 138 set omnifunc= 139 140 bwipe! 141 unlet s:args 142 delfunc CompleteFunc 143endfunc 144 145func s:CompleteDone_CompleteFuncNone( findstart, base ) 146 if a:findstart 147 return 0 148 endif 149 150 return v:none 151endfunc 152 153func s:CompleteDone_CompleteFuncDict( findstart, base ) 154 if a:findstart 155 return 0 156 endif 157 158 return { 159 \ 'words': [ 160 \ { 161 \ 'word': 'aword', 162 \ 'abbr': 'wrd', 163 \ 'menu': 'extra text', 164 \ 'info': 'words are cool', 165 \ 'kind': 'W', 166 \ 'user_data': 'test' 167 \ } 168 \ ] 169 \ } 170endfunc 171 172func s:CompleteDone_CheckCompletedItemNone() 173 let s:called_completedone = 1 174endfunc 175 176func s:CompleteDone_CheckCompletedItemDict() 177 call assert_equal( 'aword', v:completed_item[ 'word' ] ) 178 call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) 179 call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) 180 call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) 181 call assert_equal( 'W', v:completed_item[ 'kind' ] ) 182 call assert_equal( 'test', v:completed_item[ 'user_data' ] ) 183 184 let s:called_completedone = 1 185endfunc 186 187func Test_CompleteDoneNone() 188 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemNone() 189 190 set completefunc=<SID>CompleteDone_CompleteFuncNone 191 execute "normal a\<C-X>\<C-U>\<C-Y>" 192 set completefunc& 193 194 call assert_true(s:called_completedone) 195 196 let s:called_completedone = 0 197 au! CompleteDone 198endfunc 199 200func Test_CompleteDoneDict() 201 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict() 202 203 set completefunc=<SID>CompleteDone_CompleteFuncDict 204 execute "normal a\<C-X>\<C-U>\<C-Y>" 205 set completefunc& 206 207 call assert_equal('test', v:completed_item[ 'user_data' ]) 208 call assert_true(s:called_completedone) 209 210 let s:called_completedone = 0 211 au! CompleteDone 212endfunc 213 214func s:CompleteDone_CompleteFuncDictNoUserData(findstart, base) 215 if a:findstart 216 return 0 217 endif 218 219 return { 220 \ 'words': [ 221 \ { 222 \ 'word': 'aword', 223 \ 'abbr': 'wrd', 224 \ 'menu': 'extra text', 225 \ 'info': 'words are cool', 226 \ 'kind': 'W' 227 \ } 228 \ ] 229 \ } 230endfunc 231 232func s:CompleteDone_CheckCompletedItemDictNoUserData() 233 call assert_equal( 'aword', v:completed_item[ 'word' ] ) 234 call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) 235 call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) 236 call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) 237 call assert_equal( 'W', v:completed_item[ 'kind' ] ) 238 call assert_equal( '', v:completed_item[ 'user_data' ] ) 239 240 let s:called_completedone = 1 241endfunc 242 243func Test_CompleteDoneDictNoUserData() 244 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDictNoUserData() 245 246 set completefunc=<SID>CompleteDone_CompleteFuncDictNoUserData 247 execute "normal a\<C-X>\<C-U>\<C-Y>" 248 set completefunc& 249 250 call assert_equal('', v:completed_item[ 'user_data' ]) 251 call assert_true(s:called_completedone) 252 253 let s:called_completedone = 0 254 au! CompleteDone 255endfunc 256 257func s:CompleteDone_CompleteFuncList(findstart, base) 258 if a:findstart 259 return 0 260 endif 261 262 return [ 'aword' ] 263endfunc 264 265func s:CompleteDone_CheckCompletedItemList() 266 call assert_equal( 'aword', v:completed_item[ 'word' ] ) 267 call assert_equal( '', v:completed_item[ 'abbr' ] ) 268 call assert_equal( '', v:completed_item[ 'menu' ] ) 269 call assert_equal( '', v:completed_item[ 'info' ] ) 270 call assert_equal( '', v:completed_item[ 'kind' ] ) 271 call assert_equal( '', v:completed_item[ 'user_data' ] ) 272 273 let s:called_completedone = 1 274endfunc 275 276func Test_CompleteDoneList() 277 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemList() 278 279 set completefunc=<SID>CompleteDone_CompleteFuncList 280 execute "normal a\<C-X>\<C-U>\<C-Y>" 281 set completefunc& 282 283 call assert_equal('', v:completed_item[ 'user_data' ]) 284 call assert_true(s:called_completedone) 285 286 let s:called_completedone = 0 287 au! CompleteDone 288endfunc 289 290func Test_CompleteDone_undo() 291 au CompleteDone * call append(0, "prepend1") 292 new 293 call setline(1, ["line1", "line2"]) 294 call feedkeys("Go\<C-X>\<C-N>\<CR>\<ESC>", "tx") 295 call assert_equal(["prepend1", "line1", "line2", "line1", ""], 296 \ getline(1, '$')) 297 undo 298 call assert_equal(["line1", "line2"], getline(1, '$')) 299 bwipe! 300 au! CompleteDone 301endfunc 302 303" Check that when using feedkeys() typeahead does not interrupt searching for 304" completions. 305func Test_compl_feedkeys() 306 new 307 set completeopt=menuone,noselect 308 call feedkeys("ajump ju\<C-X>\<C-N>\<C-P>\<ESC>", "tx") 309 call assert_equal("jump jump", getline(1)) 310 bwipe! 311 set completeopt& 312endfunc 313