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