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 120function! s:CompleteDone_CompleteFuncDict( findstart, base ) 121 if a:findstart 122 return 0 123 endif 124 125 return { 126 \ 'words': [ 127 \ { 128 \ 'word': 'aword', 129 \ 'abbr': 'wrd', 130 \ 'menu': 'extra text', 131 \ 'info': 'words are cool', 132 \ 'kind': 'W', 133 \ 'user_data': 'test' 134 \ } 135 \ ] 136 \ } 137endfunction 138 139function! s:CompleteDone_CheckCompletedItemDict() 140 call assert_equal( 'aword', v:completed_item[ 'word' ] ) 141 call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) 142 call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) 143 call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) 144 call assert_equal( 'W', v:completed_item[ 'kind' ] ) 145 call assert_equal( 'test', v:completed_item[ 'user_data' ] ) 146 147 let s:called_completedone = 1 148endfunction 149 150function Test_CompleteDoneDict() 151 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict() 152 153 set completefunc=<SID>CompleteDone_CompleteFuncDict 154 execute "normal a\<C-X>\<C-U>\<C-Y>" 155 set completefunc& 156 157 call assert_equal( 'test', v:completed_item[ 'user_data' ] ) 158 call assert_true( s:called_completedone ) 159 160 let s:called_completedone = 0 161 au! CompleteDone 162endfunc 163 164function! s:CompleteDone_CompleteFuncDictNoUserData( findstart, base ) 165 if a:findstart 166 return 0 167 endif 168 169 return { 170 \ 'words': [ 171 \ { 172 \ 'word': 'aword', 173 \ 'abbr': 'wrd', 174 \ 'menu': 'extra text', 175 \ 'info': 'words are cool', 176 \ 'kind': 'W' 177 \ } 178 \ ] 179 \ } 180endfunction 181 182function! s:CompleteDone_CheckCompletedItemDictNoUserData() 183 call assert_equal( 'aword', v:completed_item[ 'word' ] ) 184 call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) 185 call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) 186 call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) 187 call assert_equal( 'W', v:completed_item[ 'kind' ] ) 188 call assert_equal( '', v:completed_item[ 'user_data' ] ) 189 190 let s:called_completedone = 1 191endfunction 192 193function Test_CompleteDoneDictNoUserData() 194 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDictNoUserData() 195 196 set completefunc=<SID>CompleteDone_CompleteFuncDictNoUserData 197 execute "normal a\<C-X>\<C-U>\<C-Y>" 198 set completefunc& 199 200 call assert_equal( '', v:completed_item[ 'user_data' ] ) 201 call assert_true( s:called_completedone ) 202 203 let s:called_completedone = 0 204 au! CompleteDone 205endfunc 206 207function! s:CompleteDone_CompleteFuncList( findstart, base ) 208 if a:findstart 209 return 0 210 endif 211 212 return [ 'aword' ] 213endfunction 214 215function! s:CompleteDone_CheckCompletedItemList() 216 call assert_equal( 'aword', v:completed_item[ 'word' ] ) 217 call assert_equal( '', v:completed_item[ 'abbr' ] ) 218 call assert_equal( '', v:completed_item[ 'menu' ] ) 219 call assert_equal( '', v:completed_item[ 'info' ] ) 220 call assert_equal( '', v:completed_item[ 'kind' ] ) 221 call assert_equal( '', v:completed_item[ 'user_data' ] ) 222 223 let s:called_completedone = 1 224endfunction 225 226function Test_CompleteDoneList() 227 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemList() 228 229 set completefunc=<SID>CompleteDone_CompleteFuncList 230 execute "normal a\<C-X>\<C-U>\<C-Y>" 231 set completefunc& 232 233 call assert_equal( '', v:completed_item[ 'user_data' ] ) 234 call assert_true( s:called_completedone ) 235 236 let s:called_completedone = 0 237 au! CompleteDone 238endfunc 239 240" Check that when using feedkeys() typeahead does not interrupt searching for 241" completions. 242func Test_compl_feedkeys() 243 new 244 set completeopt=menuone,noselect 245 call feedkeys("ajump ju\<C-X>\<C-N>\<C-P>\<ESC>", "tx") 246 call assert_equal("jump jump", getline(1)) 247 bwipe! 248 set completeopt& 249endfunc 250