annotate src/testdir/test_ins_complete.vim @ 26518:13ba00ef7687 v8.2.3788

patch 8.2.3788: lambda for option that is a function may be freed Commit: https://github.com/vim/vim/commit/6ae8fae8696623b527c7fb22567f6a3705b2f0dd Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sun Dec 12 16:26:44 2021 +0000 patch 8.2.3788: lambda for option that is a function may be freed Problem: Lambda for option that is a function may be garbage collected. Solution: Set a reference in the funcref. (Yegappan Lakshmanan, closes #9330)
author Bram Moolenaar <Bram@vim.org>
date Sun, 12 Dec 2021 17:30:04 +0100
parents 7eaf61a67d18
children 33d680d372aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 20285
diff changeset
1 " Test for insert completion
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 20285
diff changeset
2
18892
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
3 source screendump.vim
17588
1348696d07cd patch 8.1.1791: 'completeslash' also applies to globpath()
Bram Moolenaar <Bram@vim.org>
parents: 17553
diff changeset
4 source check.vim
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
5 source vim9.vim
12686
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 " Test for insert expansion
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 func Test_ins_complete()
12692
03a6aeea2096 patch 8.0.1224: still interference between test functions
Christian Brabandt <cb@256bit.org>
parents: 12686
diff changeset
9 edit test_ins_complete.vim
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents: 12728
diff changeset
10 " The files in the current directory interferes with the files
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents: 12728
diff changeset
11 " used by this test. So use a separate directory for the test.
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents: 12728
diff changeset
12 call mkdir('Xdir')
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents: 12728
diff changeset
13 cd Xdir
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents: 12728
diff changeset
14
12686
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 set ff=unix
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 call writefile(["test11\t36Gepeto\t/Tag/",
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 \ "asd\ttest11file\t36G",
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 \ "Makefile\tto\trun"], 'Xtestfile')
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 call writefile(['', 'start of testfile',
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 \ 'ru',
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 \ 'run1',
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 \ 'run2',
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 \ 'STARTTEST',
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 \ 'ENDTEST',
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 \ 'end of testfile'], 'Xtestdata')
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 set ff&
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 enew!
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 edit Xtestdata
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 new
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 call append(0, ['#include "Xtestfile"', ''])
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 call cursor(2, 1)
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 set cot=
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 set cpt=.,w
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 " add-expands (word from next line) from other window
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 exe "normal iru\<C-N>\<C-N>\<C-X>\<C-N>\<Esc>\<C-A>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 call assert_equal('run1 run3', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 " add-expands (current buffer first)
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 exe "normal o\<C-P>\<C-X>\<C-N>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 call assert_equal('run3 run3', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 " Local expansion, ends in an empty line (unless it becomes a global
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 " expansion)
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 exe "normal o\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 call assert_equal('', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 " starts Local and switches to global add-expansion
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 exe "normal o\<C-X>\<C-P>\<C-P>\<C-X>\<C-X>\<C-N>\<C-X>\<C-N>\<C-N>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 call assert_equal('run1 run2', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 set cpt=.,w,i
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 " i-add-expands and switches to local
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 exe "normal OM\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-X>\<C-X>\<C-P>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 call assert_equal("Makefile\tto\trun3", getline('.'))
26211
485c7c4afeb7 patch 8.2.3637: typos in test files
Bram Moolenaar <Bram@vim.org>
parents: 26195
diff changeset
54 " add-expands lines (it would end in an empty line if it didn't ignore
12686
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 " itself)
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 exe "normal o\<C-X>\<C-L>\<C-X>\<C-L>\<C-P>\<C-P>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 call assert_equal("Makefile\tto\trun3", getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 call assert_equal("Makefile\tto\trun3", getline(line('.') - 1))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 set cpt=kXtestfile
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 " checks k-expansion, and file expansion (use Xtest11 instead of test11,
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 " because TEST11.OUT may match first on DOS)
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 write Xtest11.one
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 write Xtest11.two
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 exe "normal o\<C-N>\<Esc>IX\<Esc>A\<C-X>\<C-F>\<C-N>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 call assert_equal('Xtest11.two', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 " use CTRL-X CTRL-F to complete Xtest11.one, remove it and then use CTRL-X
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 " CTRL-F again to verify this doesn't cause trouble.
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 exe "normal oXt\<C-X>\<C-F>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<C-X>\<C-F>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 call assert_equal('Xtest11.one', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 normal ddk
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 set cpt=w
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 " checks make_cyclic in other window
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 exe "normal oST\<C-N>\<C-P>\<C-P>\<C-P>\<C-P>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 call assert_equal('STARTTEST', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 set cpt=u nohid
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 " checks unloaded buffer expansion
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 only
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 exe "normal oEN\<C-N>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 call assert_equal('ENDTEST', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 " checks adding mode abortion
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 exe "normal ounl\<C-N>\<C-X>\<C-X>\<C-P>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 call assert_equal('unless', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 set cpt=t,d def=^\\k* tags=Xtestfile notagbsearch
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 " tag expansion, define add-expansion interrupted
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 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>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 call assert_equal('test11file 36Gepeto /Tag/ asd', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 " t-expansion
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 exe "normal oa\<C-N>\<Esc>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 call assert_equal('asd', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 %bw!
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 call delete('Xtestfile')
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 call delete('Xtest11.one')
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 call delete('Xtest11.two')
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 call delete('Xtestdata')
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 set cpt& cot& def& tags& tagbsearch& hidden&
12788
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents: 12728
diff changeset
102 cd ..
cb9b2774f21f patch 8.0.1271: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents: 12728
diff changeset
103 call delete('Xdir', 'rf')
12686
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 endfunc
12728
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
105
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
106 func Test_omni_dash()
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
107 func Omni(findstart, base)
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
108 if a:findstart
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
109 return 5
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
110 else
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
111 echom a:base
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
112 return ['-help', '-v']
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
113 endif
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
114 endfunc
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
115 set omnifunc=Omni
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
116 new
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
117 exe "normal Gofind -\<C-x>\<C-o>"
23169
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
118 call assert_equal("find -help", getline('$'))
12728
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
119
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
120 bwipe!
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
121 delfunc Omni
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
122 set omnifunc=
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
123 endfunc
13215
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
124
25372
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
125 func Test_omni_autoload()
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
126 let save_rtp = &rtp
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
127 set rtp=Xruntime/some
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
128 let dir = 'Xruntime/some/autoload'
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
129 call mkdir(dir, 'p')
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
130
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
131 let lines =<< trim END
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
132 vim9script
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
133 def omni#func(findstart: bool, base: string): any
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
134 if findstart
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
135 return 1
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
136 else
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
137 return ['match']
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
138 endif
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
139 enddef
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
140 {
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
141 eval 1 + 2
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
142 }
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
143 END
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
144 call writefile(lines, dir .. '/omni.vim')
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
145
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
146 new
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
147 setlocal omnifunc=omni#func
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
148 call feedkeys("i\<C-X>\<C-O>\<Esc>", 'xt')
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
149
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
150 bwipe!
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
151 call delete('Xruntime', 'rf')
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
152 set omnifunc=
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
153 let &rtp = save_rtp
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
154 endfunc
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
155
14071
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
156 func Test_completefunc_args()
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
157 let s:args = []
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
158 func! CompleteFunc(findstart, base)
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
159 let s:args += [[a:findstart, empty(a:base)]]
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
160 endfunc
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
161 new
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
162
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
163 set completefunc=CompleteFunc
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
164 call feedkeys("i\<C-X>\<C-U>\<Esc>", 'x')
14075
320956bddcef patch 8.1.0055: complete test has wrong order of arguments
Christian Brabandt <cb@256bit.org>
parents: 14071
diff changeset
165 call assert_equal([1, 1], s:args[0])
320956bddcef patch 8.1.0055: complete test has wrong order of arguments
Christian Brabandt <cb@256bit.org>
parents: 14071
diff changeset
166 call assert_equal(0, s:args[1][0])
14071
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
167 set completefunc=
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
168
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
169 let s:args = []
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
170 set omnifunc=CompleteFunc
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
171 call feedkeys("i\<C-X>\<C-O>\<Esc>", 'x')
14075
320956bddcef patch 8.1.0055: complete test has wrong order of arguments
Christian Brabandt <cb@256bit.org>
parents: 14071
diff changeset
172 call assert_equal([1, 1], s:args[0])
320956bddcef patch 8.1.0055: complete test has wrong order of arguments
Christian Brabandt <cb@256bit.org>
parents: 14071
diff changeset
173 call assert_equal(0, s:args[1][0])
14071
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
174 set omnifunc=
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
175
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
176 bwipe!
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
177 unlet s:args
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
178 delfunc CompleteFunc
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
179 endfunc
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
180
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
181 func s:CompleteDone_CompleteFuncNone( findstart, base )
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
182 if a:findstart
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
183 return 0
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
184 endif
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
185
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
186 return v:none
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
187 endfunc
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
188
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
189 func s:CompleteDone_CompleteFuncDict( findstart, base )
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
190 if a:findstart
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
191 return 0
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
192 endif
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
193
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
194 return {
19047
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
195 \ 'words': [
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
196 \ {
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
197 \ 'word': 'aword',
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
198 \ 'abbr': 'wrd',
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
199 \ 'menu': 'extra text',
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
200 \ 'info': 'words are cool',
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
201 \ 'kind': 'W',
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
202 \ 'user_data': 'test'
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
203 \ }
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
204 \ ]
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
205 \ }
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
206 endfunc
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
207
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
208 func s:CompleteDone_CheckCompletedItemNone()
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
209 let s:called_completedone = 1
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
210 endfunc
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
211
19199
8cbadf7fb9d4 patch 8.2.0158: triggering CompleteDone earlier is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 19127
diff changeset
212 func s:CompleteDone_CheckCompletedItemDict(pre)
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
213 call assert_equal( 'aword', v:completed_item[ 'word' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
214 call assert_equal( 'wrd', v:completed_item[ 'abbr' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
215 call assert_equal( 'extra text', v:completed_item[ 'menu' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
216 call assert_equal( 'words are cool', v:completed_item[ 'info' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
217 call assert_equal( 'W', v:completed_item[ 'kind' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
218 call assert_equal( 'test', v:completed_item[ 'user_data' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
219
19199
8cbadf7fb9d4 patch 8.2.0158: triggering CompleteDone earlier is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 19127
diff changeset
220 if a:pre
8cbadf7fb9d4 patch 8.2.0158: triggering CompleteDone earlier is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 19127
diff changeset
221 call assert_equal('function', complete_info().mode)
8cbadf7fb9d4 patch 8.2.0158: triggering CompleteDone earlier is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 19127
diff changeset
222 endif
19127
0ee48dc3f8bc patch 8.2.0123: complete_info() does not work when CompleteDone is triggered
Bram Moolenaar <Bram@vim.org>
parents: 19055
diff changeset
223
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
224 let s:called_completedone = 1
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
225 endfunc
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
226
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
227 func Test_CompleteDoneNone()
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
228 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemNone()
16270
749a7c03de8d patch 8.1.1139: no test for what is fixed in patch 8.1.0716
Bram Moolenaar <Bram@vim.org>
parents: 15416
diff changeset
229 let oldline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '')
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
230
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
231 set completefunc=<SID>CompleteDone_CompleteFuncNone
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
232 execute "normal a\<C-X>\<C-U>\<C-Y>"
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
233 set completefunc&
16270
749a7c03de8d patch 8.1.1139: no test for what is fixed in patch 8.1.0716
Bram Moolenaar <Bram@vim.org>
parents: 15416
diff changeset
234 let newline = join(map(range(&columns), 'nr2char(screenchar(&lines-1, v:val+1))'), '')
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
235
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
236 call assert_true(s:called_completedone)
16270
749a7c03de8d patch 8.1.1139: no test for what is fixed in patch 8.1.0716
Bram Moolenaar <Bram@vim.org>
parents: 15416
diff changeset
237 call assert_equal(oldline, newline)
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
238
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
239 let s:called_completedone = 0
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
240 au! CompleteDone
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
241 endfunc
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
242
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
243 func Test_CompleteDoneDict()
19199
8cbadf7fb9d4 patch 8.2.0158: triggering CompleteDone earlier is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 19127
diff changeset
244 au CompleteDonePre * :call <SID>CompleteDone_CheckCompletedItemDict(1)
8cbadf7fb9d4 patch 8.2.0158: triggering CompleteDone earlier is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 19127
diff changeset
245 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict(0)
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
246
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
247 set completefunc=<SID>CompleteDone_CompleteFuncDict
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
248 execute "normal a\<C-X>\<C-U>\<C-Y>"
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
249 set completefunc&
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
250
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
251 call assert_equal('test', v:completed_item[ 'user_data' ])
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
252 call assert_true(s:called_completedone)
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
253
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
254 let s:called_completedone = 0
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
255 au! CompleteDone
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
256 endfunc
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
257
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
258 func s:CompleteDone_CompleteFuncDictNoUserData(findstart, base)
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
259 if a:findstart
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
260 return 0
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
261 endif
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
262
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
263 return {
19047
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
264 \ 'words': [
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
265 \ {
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
266 \ 'word': 'aword',
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
267 \ 'abbr': 'wrd',
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
268 \ 'menu': 'extra text',
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
269 \ 'info': 'words are cool',
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
270 \ 'kind': 'W',
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
271 \ 'user_data': ['one', 'two'],
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
272 \ }
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
273 \ ]
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
274 \ }
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
275 endfunc
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
276
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
277 func s:CompleteDone_CheckCompletedItemDictNoUserData()
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
278 call assert_equal( 'aword', v:completed_item[ 'word' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
279 call assert_equal( 'wrd', v:completed_item[ 'abbr' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
280 call assert_equal( 'extra text', v:completed_item[ 'menu' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
281 call assert_equal( 'words are cool', v:completed_item[ 'info' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
282 call assert_equal( 'W', v:completed_item[ 'kind' ] )
19047
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
283 call assert_equal( ['one', 'two'], v:completed_item[ 'user_data' ] )
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
284
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
285 let s:called_completedone = 1
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
286 endfunc
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
287
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
288 func Test_CompleteDoneDictNoUserData()
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
289 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDictNoUserData()
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
290
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
291 set completefunc=<SID>CompleteDone_CompleteFuncDictNoUserData
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
292 execute "normal a\<C-X>\<C-U>\<C-Y>"
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
293 set completefunc&
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
294
19047
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
295 call assert_equal(['one', 'two'], v:completed_item[ 'user_data' ])
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
296 call assert_true(s:called_completedone)
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
297
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
298 let s:called_completedone = 0
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
299 au! CompleteDone
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
300 endfunc
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
301
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
302 func s:CompleteDone_CompleteFuncList(findstart, base)
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
303 if a:findstart
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
304 return 0
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
305 endif
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
306
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
307 return [ 'aword' ]
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
308 endfunc
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
309
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
310 func s:CompleteDone_CheckCompletedItemList()
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
311 call assert_equal( 'aword', v:completed_item[ 'word' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
312 call assert_equal( '', v:completed_item[ 'abbr' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
313 call assert_equal( '', v:completed_item[ 'menu' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
314 call assert_equal( '', v:completed_item[ 'info' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
315 call assert_equal( '', v:completed_item[ 'kind' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
316 call assert_equal( '', v:completed_item[ 'user_data' ] )
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
317
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
318 let s:called_completedone = 1
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
319 endfunc
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
320
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
321 func Test_CompleteDoneList()
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
322 au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemList()
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
323
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
324 set completefunc=<SID>CompleteDone_CompleteFuncList
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
325 execute "normal a\<C-X>\<C-U>\<C-Y>"
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
326 set completefunc&
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
327
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
328 call assert_equal('', v:completed_item[ 'user_data' ])
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
329 call assert_true(s:called_completedone)
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
330
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
331 let s:called_completedone = 0
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
332 au! CompleteDone
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
333 endfunc
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
334
14489
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
335 func Test_CompleteDone_undo()
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
336 au CompleteDone * call append(0, "prepend1")
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
337 new
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
338 call setline(1, ["line1", "line2"])
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
339 call feedkeys("Go\<C-X>\<C-N>\<CR>\<ESC>", "tx")
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
340 call assert_equal(["prepend1", "line1", "line2", "line1", ""],
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
341 \ getline(1, '$'))
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
342 undo
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
343 call assert_equal(["line1", "line2"], getline(1, '$'))
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
344 bwipe!
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
345 au! CompleteDone
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
346 endfunc
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
347
22248
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
348 func CompleteTest(findstart, query)
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
349 if a:findstart
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
350 return col('.')
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
351 endif
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
352 return ['matched']
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
353 endfunc
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
354
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
355 func Test_completefunc_info()
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
356 new
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
357 set completeopt=menuone
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
358 set completefunc=CompleteTest
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
359 call feedkeys("i\<C-X>\<C-U>\<C-R>\<C-R>=string(complete_info())\<CR>\<ESC>", "tx")
22717
bd61aaf7f2a0 patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 22705
diff changeset
360 call assert_equal("matched{'pum_visible': 1, 'mode': 'function', 'selected': 0, 'items': [{'word': 'matched', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}]}", getline(1))
22248
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
361 bwipe!
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
362 set completeopt&
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
363 set completefunc&
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
364 endfunc
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
365
13215
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
366 " Check that when using feedkeys() typeahead does not interrupt searching for
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
367 " completions.
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
368 func Test_compl_feedkeys()
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
369 new
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
370 set completeopt=menuone,noselect
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
371 call feedkeys("ajump ju\<C-X>\<C-N>\<C-P>\<ESC>", "tx")
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
372 call assert_equal("jump jump", getline(1))
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
373 bwipe!
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
374 set completeopt&
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
375 endfunc
17468
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
376
26195
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
377 func s:ComplInCmdwin_GlobalCompletion(a, l, p)
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
378 return 'global'
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
379 endfunc
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
380
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
381 func s:ComplInCmdwin_LocalCompletion(a, l, p)
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
382 return 'local'
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
383 endfunc
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
384
17468
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
385 func Test_compl_in_cmdwin()
23748
93f90f2ff4e9 patch 8.2.2415: no way to check for the cmdwin feature
Bram Moolenaar <Bram@vim.org>
parents: 23169
diff changeset
386 CheckFeature cmdwin
93f90f2ff4e9 patch 8.2.2415: no way to check for the cmdwin feature
Bram Moolenaar <Bram@vim.org>
parents: 23169
diff changeset
387
17468
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
388 set wildmenu wildchar=<Tab>
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
389 com! -nargs=1 -complete=command GetInput let input = <q-args>
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
390 com! -buffer TestCommand echo 'TestCommand'
22705
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
391 let w:test_winvar = 'winvar'
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
392 let b:test_bufvar = 'bufvar'
17468
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
393
22705
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
394 " User-defined commands
17468
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
395 let input = ''
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
396 call feedkeys("q:iGetInput T\<C-x>\<C-v>\<CR>", 'tx!')
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
397 call assert_equal('TestCommand', input)
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
398
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
399 let input = ''
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
400 call feedkeys("q::GetInput T\<Tab>\<CR>:q\<CR>", 'tx!')
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
401 call assert_equal('T', input)
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
402
22705
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
403
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
404 com! -nargs=1 -complete=var GetInput let input = <q-args>
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
405 " Window-local variables
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
406 let input = ''
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
407 call feedkeys("q:iGetInput w:test_\<C-x>\<C-v>\<CR>", 'tx!')
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
408 call assert_equal('w:test_winvar', input)
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
409
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
410 let input = ''
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
411 call feedkeys("q::GetInput w:test_\<Tab>\<CR>:q\<CR>", 'tx!')
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
412 call assert_equal('w:test_', input)
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
413
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
414 " Buffer-local variables
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
415 let input = ''
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
416 call feedkeys("q:iGetInput b:test_\<C-x>\<C-v>\<CR>", 'tx!')
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
417 call assert_equal('b:test_bufvar', input)
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
418
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
419 let input = ''
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
420 call feedkeys("q::GetInput b:test_\<Tab>\<CR>:q\<CR>", 'tx!')
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
421 call assert_equal('b:test_', input)
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
422
26195
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
423
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
424 " Argument completion of buffer-local command
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
425 func s:ComplInCmdwin_GlobalCompletionList(a, l, p)
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
426 return ['global']
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
427 endfunc
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
428
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
429 func s:ComplInCmdwin_LocalCompletionList(a, l, p)
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
430 return ['local']
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
431 endfunc
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
432
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
433 func s:ComplInCmdwin_CheckCompletion(arg)
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
434 call assert_equal('local', a:arg)
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
435 endfunc
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
436
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
437 com! -nargs=1 -complete=custom,<SID>ComplInCmdwin_GlobalCompletion
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
438 \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
439 com! -buffer -nargs=1 -complete=custom,<SID>ComplInCmdwin_LocalCompletion
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
440 \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
441 call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
442
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
443 com! -nargs=1 -complete=customlist,<SID>ComplInCmdwin_GlobalCompletionList
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
444 \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
445 com! -buffer -nargs=1 -complete=customlist,<SID>ComplInCmdwin_LocalCompletionList
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
446 \ TestCommand call s:ComplInCmdwin_CheckCompletion(<q-args>)
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
447
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
448 call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
449
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
450 func! s:ComplInCmdwin_CheckCompletion(arg)
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
451 call assert_equal('global', a:arg)
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
452 endfunc
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
453 new
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
454 call feedkeys("q:iTestCommand \<Tab>\<CR>", 'tx!')
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
455 quit
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
456
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
457 delfunc s:ComplInCmdwin_GlobalCompletion
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
458 delfunc s:ComplInCmdwin_LocalCompletion
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
459 delfunc s:ComplInCmdwin_GlobalCompletionList
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
460 delfunc s:ComplInCmdwin_LocalCompletionList
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
461 delfunc s:ComplInCmdwin_CheckCompletion
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
462
41b3718d84c3 patch 8.2.3629: command completion in cmdline window uses global commands
Bram Moolenaar <Bram@vim.org>
parents: 25707
diff changeset
463 delcom -buffer TestCommand
17468
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
464 delcom TestCommand
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
465 delcom GetInput
22705
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
466 unlet w:test_winvar
ba3f547dc490 patch 8.2.1901: variable completion does not work in command line window
Bram Moolenaar <Bram@vim.org>
parents: 22427
diff changeset
467 unlet b:test_bufvar
17468
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
468 set wildmenu& wildchar&
fa6c9047ec70 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents: 16270
diff changeset
469 endfunc
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
470
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
471 " Test for insert path completion with completeslash option
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
472 func Test_ins_completeslash()
17588
1348696d07cd patch 8.1.1791: 'completeslash' also applies to globpath()
Bram Moolenaar <Bram@vim.org>
parents: 17553
diff changeset
473 CheckMSWindows
22397
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
474
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
475 call mkdir('Xdir')
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
476 let orig_shellslash = &shellslash
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
477 set cpt&
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
478 new
22397
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
479
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
480 set noshellslash
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
481
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
482 set completeslash=
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
483 exe "normal oXd\<C-X>\<C-F>"
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
484 call assert_equal('Xdir\', getline('.'))
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
485
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
486 set completeslash=backslash
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
487 exe "normal oXd\<C-X>\<C-F>"
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
488 call assert_equal('Xdir\', getline('.'))
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
489
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
490 set completeslash=slash
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
491 exe "normal oXd\<C-X>\<C-F>"
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
492 call assert_equal('Xdir/', getline('.'))
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
493
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
494 set shellslash
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
495
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
496 set completeslash=
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
497 exe "normal oXd\<C-X>\<C-F>"
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
498 call assert_equal('Xdir/', getline('.'))
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
499
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
500 set completeslash=backslash
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
501 exe "normal oXd\<C-X>\<C-F>"
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
502 call assert_equal('Xdir\', getline('.'))
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
503
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
504 set completeslash=slash
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
505 exe "normal oXd\<C-X>\<C-F>"
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
506 call assert_equal('Xdir/', getline('.'))
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
507 %bw!
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
508 call delete('Xdir', 'rf')
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
509
17588
1348696d07cd patch 8.1.1791: 'completeslash' also applies to globpath()
Bram Moolenaar <Bram@vim.org>
parents: 17553
diff changeset
510 set noshellslash
1348696d07cd patch 8.1.1791: 'completeslash' also applies to globpath()
Bram Moolenaar <Bram@vim.org>
parents: 17553
diff changeset
511 set completeslash=slash
1348696d07cd patch 8.1.1791: 'completeslash' also applies to globpath()
Bram Moolenaar <Bram@vim.org>
parents: 17553
diff changeset
512 call assert_true(stridx(globpath(&rtp, 'syntax/*.vim', 1, 1)[0], '\') != -1)
1348696d07cd patch 8.1.1791: 'completeslash' also applies to globpath()
Bram Moolenaar <Bram@vim.org>
parents: 17553
diff changeset
513
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
514 let &shellslash = orig_shellslash
17588
1348696d07cd patch 8.1.1791: 'completeslash' also applies to globpath()
Bram Moolenaar <Bram@vim.org>
parents: 17553
diff changeset
515 set completeslash=
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
516 endfunc
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
517
22427
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
518 func Test_pum_stopped_by_timer()
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
519 CheckScreendump
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
520
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
521 let lines =<< trim END
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
522 call setline(1, ['hello', 'hullo', 'heeee', ''])
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
523 func StartCompl()
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
524 call timer_start(100, { -> execute('stopinsert') })
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
525 call feedkeys("Gah\<C-N>")
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
526 endfunc
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
527 END
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
528
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
529 call writefile(lines, 'Xpumscript')
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
530 let buf = RunVimInTerminal('-S Xpumscript', #{rows: 12})
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
531 call term_sendkeys(buf, ":call StartCompl()\<CR>")
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
532 call TermWait(buf, 200)
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
533 call term_sendkeys(buf, "k")
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
534 call VerifyScreenDump(buf, 'Test_pum_stopped_by_timer', {})
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
535
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
536 call StopVimInTerminal(buf)
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
537 call delete('Xpumscript')
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
538 endfunc
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
539
18892
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
540 func Test_pum_with_folds_two_tabs()
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
541 CheckScreendump
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
542
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
543 let lines =<< trim END
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
544 set fdm=marker
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
545 call setline(1, ['" x {{{1', '" a some text'])
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
546 call setline(3, range(&lines)->map({_, val -> '" a' .. val}))
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
547 norm! zm
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
548 tab sp
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
549 call feedkeys('2Gzv', 'xt')
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
550 call feedkeys("0fa", 'xt')
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
551 END
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
552
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
553 call writefile(lines, 'Xpumscript')
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
554 let buf = RunVimInTerminal('-S Xpumscript', #{rows: 10})
19954
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
555 call TermWait(buf, 50)
18892
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
556 call term_sendkeys(buf, "a\<C-N>")
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
557 call VerifyScreenDump(buf, 'Test_pum_with_folds_two_tabs', {})
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
558
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
559 call term_sendkeys(buf, "\<Esc>")
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
560 call StopVimInTerminal(buf)
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
561 call delete('Xpumscript')
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
562 endfunc
18900
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
563
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
564 func Test_pum_with_preview_win()
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
565 CheckScreendump
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
566
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
567 let lines =<< trim END
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
568 funct Omni_test(findstart, base)
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
569 if a:findstart
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
570 return col(".") - 1
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
571 endif
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
572 return [#{word: "one", info: "1info"}, #{word: "two", info: "2info"}, #{word: "three", info: "3info"}]
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
573 endfunc
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
574 set omnifunc=Omni_test
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
575 set completeopt+=longest
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
576 END
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
577
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
578 call writefile(lines, 'Xpreviewscript')
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
579 let buf = RunVimInTerminal('-S Xpreviewscript', #{rows: 12})
19954
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
580 call TermWait(buf, 50)
18900
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
581 call term_sendkeys(buf, "Gi\<C-X>\<C-O>")
19954
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19932
diff changeset
582 call TermWait(buf, 100)
18900
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
583 call term_sendkeys(buf, "\<C-N>")
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
584 call VerifyScreenDump(buf, 'Test_pum_with_preview_win', {})
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
585
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
586 call term_sendkeys(buf, "\<Esc>")
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
587 call StopVimInTerminal(buf)
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
588 call delete('Xpreviewscript')
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
589 endfunc
19055
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
590
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
591 " Test for inserting the tag search pattern in insert mode
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
592 func Test_ins_compl_tag_sft()
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
593 call writefile([
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
594 \ "!_TAG_FILE_ENCODING\tutf-8\t//",
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
595 \ "first\tXfoo\t/^int first() {}$/",
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
596 \ "second\tXfoo\t/^int second() {}$/",
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
597 \ "third\tXfoo\t/^int third() {}$/"],
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
598 \ 'Xtags')
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
599 set tags=Xtags
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
600 let code =<< trim [CODE]
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
601 int first() {}
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
602 int second() {}
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
603 int third() {}
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
604 [CODE]
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
605 call writefile(code, 'Xfoo')
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
606
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
607 enew
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
608 set showfulltag
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
609 exe "normal isec\<C-X>\<C-]>\<C-N>\<CR>"
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
610 call assert_equal('int second() {}', getline(1))
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
611 set noshowfulltag
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
612
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
613 call delete('Xtags')
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
614 call delete('Xfoo')
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
615 set tags&
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
616 %bwipe!
8645b73b3645 patch 8.2.0088: insufficient tests for tags; bug in using extra tag field
Bram Moolenaar <Bram@vim.org>
parents: 19047
diff changeset
617 endfunc
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
618
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
619 " Test for 'completefunc' deleting text
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
620 func Test_completefunc_error()
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
621 new
20120
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
622 " delete text when called for the first time
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
623 func CompleteFunc(findstart, base)
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
624 if a:findstart == 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
625 normal dd
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
626 return col('.') - 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
627 endif
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
628 return ['a', 'b']
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
629 endfunc
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
630 set completefunc=CompleteFunc
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
631 call setline(1, ['', 'abcd', ''])
23772
f5225486d3de patch 8.2.2427: can still switch windows for 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 23770
diff changeset
632 call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:')
20120
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
633
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
634 " delete text when called for the second time
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
635 func CompleteFunc2(findstart, base)
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
636 if a:findstart == 1
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
637 return col('.') - 1
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
638 endif
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
639 normal dd
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
640 return ['a', 'b']
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
641 endfunc
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
642 set completefunc=CompleteFunc2
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
643 call setline(1, ['', 'abcd', ''])
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 20199
diff changeset
644 call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:')
20120
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
645
23766
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
646 " Jump to a different window from the complete function
23770
385d33dfb7df patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents: 23766
diff changeset
647 func CompleteFunc3(findstart, base)
23766
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
648 if a:findstart == 1
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
649 return col('.') - 1
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
650 endif
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
651 wincmd p
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
652 return ['a', 'b']
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
653 endfunc
23770
385d33dfb7df patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents: 23766
diff changeset
654 set completefunc=CompleteFunc3
23766
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
655 new
23770
385d33dfb7df patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents: 23766
diff changeset
656 call assert_fails('exe "normal a\<C-X>\<C-U>"', 'E565:')
23766
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
657 close!
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
658
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
659 set completefunc&
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
660 delfunc CompleteFunc
23770
385d33dfb7df patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents: 23766
diff changeset
661 delfunc CompleteFunc2
385d33dfb7df patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents: 23766
diff changeset
662 delfunc CompleteFunc3
385d33dfb7df patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents: 23766
diff changeset
663 close!
23766
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
664 endfunc
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
665
20285
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
666 " Test for returning non-string values from 'completefunc'
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
667 func Test_completefunc_invalid_data()
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
668 new
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
669 func! CompleteFunc(findstart, base)
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
670 if a:findstart == 1
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
671 return col('.') - 1
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
672 endif
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
673 return [{}, '', 'moon']
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
674 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
675 set completefunc=CompleteFunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
676 exe "normal i\<C-X>\<C-U>"
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
677 call assert_equal('moon', getline(1))
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
678 set completefunc&
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
679 close!
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
680 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
681
20120
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
682 " Test for errors in using complete() function
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
683 func Test_complete_func_error()
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
684 call assert_fails('call complete(1, ["a"])', 'E785:')
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
685 func ListColors()
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
686 call complete(col('.'), "blue")
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
687 endfunc
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
688 call assert_fails('exe "normal i\<C-R>=ListColors()\<CR>"', 'E474:')
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
689 func ListMonths()
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
690 call complete(col('.'), test_null_list())
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
691 endfunc
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
692 call assert_fails('exe "normal i\<C-R>=ListMonths()\<CR>"', 'E474:')
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
693 delfunc ListColors
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
694 delfunc ListMonths
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
695 call assert_fails('call complete_info({})', 'E714:')
20285
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
696 call assert_equal([], complete_info(['items']).items)
20120
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
697 endfunc
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
698
20199
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
699 " Test for completing words following a completed word in a line
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
700 func Test_complete_wrapscan()
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
701 " complete words from another buffer
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
702 new
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
703 call setline(1, ['one two', 'three four'])
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
704 new
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
705 setlocal complete=w
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
706 call feedkeys("itw\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>", 'xt')
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
707 call assert_equal('two three four', getline(1))
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
708 close!
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
709 " complete words from the current buffer
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
710 setlocal complete=.
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
711 %d
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
712 call setline(1, ['one two', ''])
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
713 call cursor(2, 1)
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
714 call feedkeys("ion\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>", 'xt')
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
715 call assert_equal('one two one two', getline(2))
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
716 close!
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
717 endfunc
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
718
20285
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
719 " Test for completing special characters
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
720 func Test_complete_special_chars()
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
721 new
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
722 call setline(1, 'int .*[-\^$ func float')
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
723 call feedkeys("oin\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>", 'xt')
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
724 call assert_equal('int .*[-\^$ func float', getline(2))
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
725 close!
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
726 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
727
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
728 " Test for completion when text is wrapped across lines.
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
729 func Test_complete_across_line()
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
730 new
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
731 call setline(1, ['red green blue', 'one two three'])
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
732 setlocal textwidth=20
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
733 exe "normal 2G$a re\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>"
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
734 call assert_equal(['one two three red', 'green blue one'], getline(2, '$'))
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
735 close!
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
736 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
737
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
738 " Test for using CTRL-L to add one character when completing matching
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
739 func Test_complete_add_onechar()
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
740 new
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
741 call setline(1, ['wool', 'woodwork'])
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
742 call feedkeys("Gowoo\<C-P>\<C-P>\<C-P>\<C-L>f", 'xt')
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
743 call assert_equal('woof', getline(3))
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
744
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
745 " use 'ignorecase' and backspace to erase characters from the prefix string
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
746 " and then add letters using CTRL-L
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
747 %d
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
748 set ignorecase backspace=2
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
749 setlocal complete=.
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
750 call setline(1, ['workhorse', 'workload'])
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
751 normal Go
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
752 exe "normal aWOR\<C-P>\<bs>\<bs>\<bs>\<bs>\<bs>\<bs>\<C-L>r\<C-L>\<C-L>"
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
753 call assert_equal('workh', getline(3))
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
754 set ignorecase& backspace&
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
755 close!
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
756 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
757
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
758 " Test insert completion with 'cindent' (adjust the indent)
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
759 func Test_complete_with_cindent()
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
760 new
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
761 setlocal cindent
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
762 call setline(1, ['if (i == 1)', " j = 2;"])
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
763 exe "normal Go{\<CR>i\<C-X>\<C-L>\<C-X>\<C-L>\<CR>}"
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
764 call assert_equal(['{', "\tif (i == 1)", "\t\tj = 2;", '}'], getline(3, '$'))
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
765
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
766 %d
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
767 call setline(1, ['when while', '{', ''])
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
768 setlocal cinkeys+==while
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
769 exe "normal Giwh\<C-P> "
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
770 call assert_equal("\twhile ", getline('$'))
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
771 close!
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
772 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
773
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
774 " Test for <CTRL-X> <CTRL-V> completion. Complete commands and functions
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
775 func Test_complete_cmdline()
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
776 new
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
777 exe "normal icaddb\<C-X>\<C-V>"
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
778 call assert_equal('caddbuffer', getline(1))
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
779 exe "normal ocall getqf\<C-X>\<C-V>"
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
780 call assert_equal('call getqflist(', getline(2))
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
781 exe "normal oabcxyz(\<C-X>\<C-V>"
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
782 call assert_equal('abcxyz(', getline(3))
25707
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
783 com! -buffer TestCommand1 echo 'TestCommand1'
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
784 com! -buffer TestCommand2 echo 'TestCommand2'
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
785 write TestCommand1Test
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
786 write TestCommand2Test
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
787 " Test repeating <CTRL-X> <CTRL-V> and switching to another CTRL-X mode
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
788 exe "normal oT\<C-X>\<C-V>\<C-X>\<C-V>\<C-X>\<C-F>\<Esc>"
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
789 call assert_equal('TestCommand2Test', getline(4))
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
790 call delete('TestCommand1Test')
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
791 call delete('TestCommand2Test')
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
792 delcom TestCommand1
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
793 delcom TestCommand2
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
794 close!
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
795 endfunc
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
796
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
797 " Test for <CTRL-X> <CTRL-Z> stopping completion without changing the match
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
798 func Test_complete_stop()
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
799 new
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
800 func Save_mode1()
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
801 let g:mode1 = mode(1)
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
802 return ''
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
803 endfunc
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
804 func Save_mode2()
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
805 let g:mode2 = mode(1)
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
806 return ''
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
807 endfunc
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
808 inoremap <F1> <C-R>=Save_mode1()<CR>
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
809 inoremap <F2> <C-R>=Save_mode2()<CR>
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
810 call setline(1, ['aaa bbb ccc '])
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
811 exe "normal A\<C-N>\<C-P>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>"
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
812 call assert_equal('ic', g:mode1)
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
813 call assert_equal('i', g:mode2)
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
814 call assert_equal('aaa bbb ccc ', getline(1))
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
815 exe "normal A\<C-N>\<Down>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>"
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
816 call assert_equal('ic', g:mode1)
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
817 call assert_equal('i', g:mode2)
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
818 call assert_equal('aaa bbb ccc aaa', getline(1))
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
819 set completeopt+=noselect
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
820 exe "normal A \<C-N>\<Down>\<Down>\<C-L>\<C-L>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>"
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
821 call assert_equal('ic', g:mode1)
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
822 call assert_equal('i', g:mode2)
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
823 call assert_equal('aaa bbb ccc aaa bb', getline(1))
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
824 set completeopt&
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
825 exe "normal A d\<C-N>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>"
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
826 call assert_equal('ic', g:mode1)
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
827 call assert_equal('i', g:mode2)
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
828 call assert_equal('aaa bbb ccc aaa bb d', getline(1))
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
829 com! -buffer TestCommand1 echo 'TestCommand1'
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
830 com! -buffer TestCommand2 echo 'TestCommand2'
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
831 exe "normal oT\<C-X>\<C-V>\<C-X>\<C-V>\<F1>\<C-X>\<C-Z>\<F2>\<Esc>"
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
832 call assert_equal('ic', g:mode1)
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
833 call assert_equal('i', g:mode2)
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
834 call assert_equal('TestCommand2', getline(2))
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
835 delcom TestCommand1
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
836 delcom TestCommand2
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
837 unlet g:mode1
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
838 unlet g:mode2
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
839 iunmap <F1>
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
840 iunmap <F2>
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
841 delfunc Save_mode1
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
842 delfunc Save_mode2
20285
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
843 close!
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
844 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
845
22397
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
846 func Test_issue_7021()
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
847 CheckMSWindows
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
848
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
849 let orig_shellslash = &shellslash
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
850 set noshellslash
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
851
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
852 set completeslash=slash
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
853 call assert_false(expand('~') =~ '/')
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
854
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
855 let &shellslash = orig_shellslash
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
856 set completeslash=
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
857 endfunc
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
858
23169
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
859 " Test to ensure 'Scanning...' messages are not recorded in messages history
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
860 func Test_z1_complete_no_history()
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
861 new
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
862 messages clear
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
863 let currmess = execute('messages')
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
864 setlocal dictionary=README.txt
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
865 exe "normal owh\<C-X>\<C-K>"
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
866 exe "normal owh\<C-N>"
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
867 call assert_equal(currmess, execute('messages'))
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
868 close!
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
869 endfunc
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
870
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
871 " Test for different ways of setting the 'completefunc' option
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
872 func Test_completefunc_callback()
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
873 func MycompleteFunc1(val, findstart, base)
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
874 call add(g:MycompleteFunc1_args, [a:val, a:findstart, a:base])
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
875 return a:findstart ? 0 : []
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
876 endfunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
877
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
878 let lines =<< trim END
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
879 #" Test for using a function()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
880 set completefunc=function('g:MycompleteFunc1',\ [10])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
881 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
882 call setline(1, 'one')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
883 LET g:MycompleteFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
884 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
885 call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MycompleteFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
886 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
887
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
888 #" Using a funcref variable to set 'completefunc'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
889 VAR Fn = function('g:MycompleteFunc1', [11])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
890 LET &completefunc = Fn
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
891 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
892 call setline(1, 'two')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
893 LET g:MycompleteFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
894 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
895 call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MycompleteFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
896 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
897
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
898 #" Using string(funcref_variable) to set 'completefunc'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
899 LET Fn = function('g:MycompleteFunc1', [12])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
900 LET &completefunc = string(Fn)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
901 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
902 call setline(1, 'two')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
903 LET g:MycompleteFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
904 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
905 call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MycompleteFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
906 bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
907
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
908 #" Test for using a funcref()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
909 set completefunc=funcref('g:MycompleteFunc1',\ [13])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
910 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
911 call setline(1, 'three')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
912 LET g:MycompleteFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
913 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
914 call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MycompleteFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
915 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
916
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
917 #" Using a funcref variable to set 'completefunc'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
918 LET Fn = funcref('g:MycompleteFunc1', [14])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
919 LET &completefunc = Fn
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
920 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
921 call setline(1, 'four')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
922 LET g:MycompleteFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
923 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
924 call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MycompleteFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
925 bw!
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26408
diff changeset
926
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
927 #" Using a string(funcref_variable) to set 'completefunc'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
928 LET Fn = funcref('g:MycompleteFunc1', [15])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
929 LET &completefunc = string(Fn)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
930 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
931 call setline(1, 'four')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
932 LET g:MycompleteFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
933 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
934 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MycompleteFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
935 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
936
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
937 #" Test for using a lambda function with set
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
938 VAR optval = "LSTART a, b LMIDDLE MycompleteFunc1(16, a, b) LEND"
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
939 LET optval = substitute(optval, ' ', '\\ ', 'g')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
940 exe "set completefunc=" .. optval
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
941 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
942 call setline(1, 'five')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
943 LET g:MycompleteFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
944 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
945 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MycompleteFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
946 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
947
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
948 #" Set 'completefunc' to a lambda expression
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
949 LET &completefunc = LSTART a, b LMIDDLE MycompleteFunc1(17, a, b) LEND
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
950 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
951 call setline(1, 'six')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
952 LET g:MycompleteFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
953 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
954 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MycompleteFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
955 bw!
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26408
diff changeset
956
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
957 #" Set 'completefunc' to string(lambda_expression)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
958 LET &completefunc = 'LSTART a, b LMIDDLE MycompleteFunc1(18, a, b) LEND'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
959 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
960 call setline(1, 'six')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
961 LET g:MycompleteFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
962 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
963 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MycompleteFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
964 bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
965
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
966 #" Set 'completefunc' to a variable with a lambda expression
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
967 VAR Lambda = LSTART a, b LMIDDLE MycompleteFunc1(19, a, b) LEND
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
968 LET &completefunc = Lambda
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
969 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
970 call setline(1, 'seven')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
971 LET g:MycompleteFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
972 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
973 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MycompleteFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
974 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
975
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
976 #" Set 'completefunc' to a string(variable with a lambda expression)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
977 LET Lambda = LSTART a, b LMIDDLE MycompleteFunc1(20, a, b) LEND
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
978 LET &completefunc = string(Lambda)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
979 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
980 call setline(1, 'seven')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
981 LET g:MycompleteFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
982 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
983 call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MycompleteFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
984 bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
985
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
986 #" Test for using a lambda function with incorrect return value
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
987 LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
988 LET &completefunc = Lambda
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
989 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
990 call setline(1, 'eight')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
991 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
992 bw!
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26408
diff changeset
993
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
994 #" Test for clearing the 'completefunc' option
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
995 set completefunc=''
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
996 set completefunc&
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
997 call assert_fails("set completefunc=function('abc')", "E700:")
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
998 call assert_fails("set completefunc=funcref('abc')", "E700:")
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
999
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1000 #" set 'completefunc' to a non-existing function
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1001 func MycompleteFunc2(findstart, base)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1002 call add(g:MycompleteFunc2_args, [a:findstart, a:base])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1003 return a:findstart ? 0 : []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1004 endfunc
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1005 set completefunc=MycompleteFunc2
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1006 call setline(1, 'five')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1007 call assert_fails("set completefunc=function('NonExistingFunc')", 'E700:')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1008 call assert_fails("LET &completefunc = function('NonExistingFunc')", 'E700:')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1009 LET g:MycompleteFunc2_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1010 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1011 call assert_equal([[1, ''], [0, 'five']], g:MycompleteFunc2_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1012 bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1013 END
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1014 call CheckLegacyAndVim9Success(lines)
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1015
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26408
diff changeset
1016 let &completefunc = {a -> 'abc'}
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1017 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1018
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1019 " Using Vim9 lambda expression in legacy context should fail
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1020 set completefunc=(a,\ b)\ =>\ MycompleteFunc1(21,\ a,\ b)
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1021 new | only
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1022 let g:MycompleteFunc1_args = []
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1023 call assert_fails('call feedkeys("A\<C-X>\<C-U>\<Esc>", "x")', 'E117:')
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1024 call assert_equal([], g:MycompleteFunc1_args)
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1025
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1026 " set 'completefunc' to a partial with dict. This used to cause a crash.
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1027 func SetCompleteFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1028 let params = {'complete': function('g:DictCompleteFunc')}
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1029 let &completefunc = params.complete
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1030 endfunc
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1031 func g:DictCompleteFunc(_) dict
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1032 endfunc
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1033 call SetCompleteFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1034 new
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1035 call SetCompleteFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1036 bw
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1037 call test_garbagecollect_now()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1038 new
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1039 set completefunc=
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1040 wincmd w
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1041 set completefunc=
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1042 %bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1043 delfunc g:DictCompleteFunc
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1044 delfunc SetCompleteFunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1045
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1046 " Vim9 tests
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1047 let lines =<< trim END
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1048 vim9script
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1049
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1050 # Test for using a def function with completefunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1051 def Vim9CompleteFunc(val: number, findstart: number, base: string): any
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1052 add(g:Vim9completeFuncArgs, [val, findstart, base])
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1053 return findstart ? 0 : []
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1054 enddef
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1055 set completefunc=function('Vim9CompleteFunc',\ [60])
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1056 new | only
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1057 setline(1, 'one')
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1058 g:Vim9completeFuncArgs = []
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1059 feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1060 assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9completeFuncArgs)
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1061 bw!
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1062 END
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1063 call CheckScriptSuccess(lines)
26452
65b4109a4297 patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
1064
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1065 " cleanup
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1066 delfunc MycompleteFunc1
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1067 delfunc MycompleteFunc2
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1068 set completefunc&
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1069 %bw!
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1070 endfunc
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1071
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1072 " Test for different ways of setting the 'omnifunc' option
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1073 func Test_omnifunc_callback()
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1074 func MyomniFunc1(val, findstart, base)
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1075 call add(g:MyomniFunc1_args, [a:val, a:findstart, a:base])
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1076 return a:findstart ? 0 : []
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1077 endfunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1078
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1079 let lines =<< trim END
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1080 #" Test for using a function()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1081 set omnifunc=function('g:MyomniFunc1',\ [10])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1082 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1083 call setline(1, 'one')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1084 LET g:MyomniFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1085 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1086 call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MyomniFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1087 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1088
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1089 #" Using a funcref variable to set 'omnifunc'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1090 VAR Fn = function('g:MyomniFunc1', [11])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1091 LET &omnifunc = Fn
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1092 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1093 call setline(1, 'two')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1094 LET g:MyomniFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1095 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1096 call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MyomniFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1097 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1098
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1099 #" Using a string(funcref_variable) to set 'omnifunc'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1100 LET Fn = function('g:MyomniFunc1', [12])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1101 LET &omnifunc = string(Fn)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1102 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1103 call setline(1, 'two')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1104 LET g:MyomniFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1105 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1106 call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MyomniFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1107 bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1108
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1109 #" Test for using a funcref()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1110 set omnifunc=funcref('g:MyomniFunc1',\ [13])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1111 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1112 call setline(1, 'three')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1113 LET g:MyomniFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1114 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1115 call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MyomniFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1116 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1117
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1118 #" Use let to set 'omnifunc' to a funcref
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1119 LET Fn = funcref('g:MyomniFunc1', [14])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1120 LET &omnifunc = Fn
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1121 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1122 call setline(1, 'four')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1123 LET g:MyomniFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1124 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1125 call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MyomniFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1126 bw!
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26408
diff changeset
1127
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1128 #" Using a string(funcref) to set 'omnifunc'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1129 LET Fn = funcref("g:MyomniFunc1", [15])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1130 LET &omnifunc = string(Fn)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1131 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1132 call setline(1, 'four')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1133 LET g:MyomniFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1134 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1135 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MyomniFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1136 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1137
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1138 #" Test for using a lambda function with set
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1139 VAR optval = "LSTART a, b LMIDDLE MyomniFunc1(16, a, b) LEND"
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1140 LET optval = substitute(optval, ' ', '\\ ', 'g')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1141 exe "set omnifunc=" .. optval
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1142 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1143 call setline(1, 'five')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1144 LET g:MyomniFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1145 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1146 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MyomniFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1147 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1148
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1149 #" Set 'omnifunc' to a lambda expression
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1150 LET &omnifunc = LSTART a, b LMIDDLE MyomniFunc1(17, a, b) LEND
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1151 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1152 call setline(1, 'six')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1153 LET g:MyomniFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1154 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1155 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MyomniFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1156 bw!
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26408
diff changeset
1157
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1158 #" Set 'omnifunc' to a string(lambda_expression)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1159 LET &omnifunc = 'LSTART a, b LMIDDLE MyomniFunc1(18, a, b) LEND'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1160 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1161 call setline(1, 'six')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1162 LET g:MyomniFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1163 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1164 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MyomniFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1165 bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1166
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1167 #" Set 'omnifunc' to a variable with a lambda expression
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1168 VAR Lambda = LSTART a, b LMIDDLE MyomniFunc1(19, a, b) LEND
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1169 LET &omnifunc = Lambda
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1170 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1171 call setline(1, 'seven')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1172 LET g:MyomniFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1173 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1174 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MyomniFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1175 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1176
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1177 #" Set 'omnifunc' to a string(variable with a lambda expression)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1178 LET Lambda = LSTART a, b LMIDDLE MyomniFunc1(20, a, b) LEND
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1179 LET &omnifunc = string(Lambda)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1180 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1181 call setline(1, 'seven')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1182 LET g:MyomniFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1183 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1184 call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MyomniFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1185 bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1186
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1187 #" Test for using a lambda function with incorrect return value
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1188 LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1189 LET &omnifunc = Lambda
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1190 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1191 call setline(1, 'eight')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1192 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1193 bw!
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26408
diff changeset
1194
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1195 #" Test for clearing the 'omnifunc' option
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1196 set omnifunc=''
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1197 set omnifunc&
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1198 call assert_fails("set omnifunc=function('abc')", "E700:")
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1199 call assert_fails("set omnifunc=funcref('abc')", "E700:")
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1200
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1201 #" set 'omnifunc' to a non-existing function
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1202 func MyomniFunc2(findstart, base)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1203 call add(g:MyomniFunc2_args, [a:findstart, a:base])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1204 return a:findstart ? 0 : []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1205 endfunc
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1206 set omnifunc=MyomniFunc2
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1207 call setline(1, 'nine')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1208 call assert_fails("set omnifunc=function('NonExistingFunc')", 'E700:')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1209 call assert_fails("LET &omnifunc = function('NonExistingFunc')", 'E700:')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1210 LET g:MyomniFunc2_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1211 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1212 call assert_equal([[1, ''], [0, 'nine']], g:MyomniFunc2_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1213 bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1214 END
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1215 call CheckLegacyAndVim9Success(lines)
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1216
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26408
diff changeset
1217 let &omnifunc = {a -> 'abc'}
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1218 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1219
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1220 " Using Vim9 lambda expression in legacy context should fail
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1221 set omnifunc=(a,\ b)\ =>\ MyomniFunc1(21,\ a,\ b)
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1222 new | only
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1223 let g:MyomniFunc1_args = []
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1224 call assert_fails('call feedkeys("A\<C-X>\<C-O>\<Esc>", "x")', 'E117:')
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1225 call assert_equal([], g:MyomniFunc1_args)
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1226
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1227 " set 'omnifunc' to a partial with dict. This used to cause a crash.
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1228 func SetOmniFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1229 let params = {'omni': function('g:DictOmniFunc')}
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1230 let &omnifunc = params.omni
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1231 endfunc
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1232 func g:DictOmniFunc(_) dict
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1233 endfunc
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1234 call SetOmniFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1235 new
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1236 call SetOmniFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1237 bw
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1238 call test_garbagecollect_now()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1239 new
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1240 set omnifunc=
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1241 wincmd w
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1242 set omnifunc=
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1243 %bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1244 delfunc g:DictOmniFunc
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1245 delfunc SetOmniFunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1246
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1247 " Vim9 tests
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1248 let lines =<< trim END
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1249 vim9script
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1250
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1251 # Test for using a def function with omnifunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1252 def Vim9omniFunc(val: number, findstart: number, base: string): any
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1253 add(g:Vim9omniFunc_Args, [val, findstart, base])
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1254 return findstart ? 0 : []
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1255 enddef
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1256 set omnifunc=function('Vim9omniFunc',\ [60])
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1257 new | only
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1258 setline(1, 'one')
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1259 g:Vim9omniFunc_Args = []
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1260 feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1261 assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9omniFunc_Args)
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1262 bw!
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1263 END
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1264 call CheckScriptSuccess(lines)
26452
65b4109a4297 patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
1265
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1266 " cleanup
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1267 delfunc MyomniFunc1
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1268 delfunc MyomniFunc2
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1269 set omnifunc&
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1270 %bw!
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1271 endfunc
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1272
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1273 " Test for different ways of setting the 'thesaurusfunc' option
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1274 func Test_thesaurusfunc_callback()
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1275 func MytsrFunc1(val, findstart, base)
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1276 call add(g:MytsrFunc1_args, [a:val, a:findstart, a:base])
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1277 return a:findstart ? 0 : []
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1278 endfunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1279
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1280 let lines =<< trim END
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1281 #" Test for using a function()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1282 set thesaurusfunc=function('g:MytsrFunc1',\ [10])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1283 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1284 call setline(1, 'one')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1285 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1286 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1287 call assert_equal([[10, 1, ''], [10, 0, 'one']], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1288 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1289
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1290 #" Using a funcref variable to set 'thesaurusfunc'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1291 VAR Fn = function('g:MytsrFunc1', [11])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1292 LET &thesaurusfunc = Fn
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1293 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1294 call setline(1, 'two')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1295 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1296 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1297 call assert_equal([[11, 1, ''], [11, 0, 'two']], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1298 bw!
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26408
diff changeset
1299
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1300 #" Using a string(funcref_variable) to set 'thesaurusfunc'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1301 LET Fn = function('g:MytsrFunc1', [12])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1302 LET &thesaurusfunc = string(Fn)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1303 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1304 call setline(1, 'two')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1305 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1306 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1307 call assert_equal([[12, 1, ''], [12, 0, 'two']], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1308 bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1309
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1310 #" Test for using a funcref()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1311 set thesaurusfunc=funcref('g:MytsrFunc1',\ [13])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1312 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1313 call setline(1, 'three')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1314 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1315 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1316 call assert_equal([[13, 1, ''], [13, 0, 'three']], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1317 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1318
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1319 #" Using a funcref variable to set 'thesaurusfunc'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1320 LET Fn = funcref('g:MytsrFunc1', [14])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1321 LET &thesaurusfunc = Fn
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1322 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1323 call setline(1, 'four')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1324 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1325 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1326 call assert_equal([[14, 1, ''], [14, 0, 'four']], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1327 bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1328
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1329 #" Using a string(funcref_variable) to set 'thesaurusfunc'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1330 LET Fn = funcref('g:MytsrFunc1', [15])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1331 LET &thesaurusfunc = string(Fn)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1332 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1333 call setline(1, 'four')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1334 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1335 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1336 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1337 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1338
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1339 #" Test for using a lambda function
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1340 VAR optval = "LSTART a, b LMIDDLE MytsrFunc1(16, a, b) LEND"
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1341 LET optval = substitute(optval, ' ', '\\ ', 'g')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1342 exe "set thesaurusfunc=" .. optval
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1343 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1344 call setline(1, 'five')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1345 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1346 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1347 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1348 bw!
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26408
diff changeset
1349
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1350 #" Test for using a lambda function with set
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1351 LET &thesaurusfunc = LSTART a, b LMIDDLE MytsrFunc1(17, a, b) LEND
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1352 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1353 call setline(1, 'six')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1354 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1355 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1356 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1357 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1358
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1359 #" Set 'thesaurusfunc' to a string(lambda expression)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1360 LET &thesaurusfunc = 'LSTART a, b LMIDDLE MytsrFunc1(18, a, b) LEND'
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1361 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1362 call setline(1, 'six')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1363 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1364 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1365 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1366 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1367
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1368 #" Set 'thesaurusfunc' to a variable with a lambda expression
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1369 VAR Lambda = LSTART a, b LMIDDLE MytsrFunc1(19, a, b) LEND
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1370 LET &thesaurusfunc = Lambda
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1371 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1372 call setline(1, 'seven')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1373 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1374 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1375 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1376 bw!
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26408
diff changeset
1377
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1378 #" Set 'thesaurusfunc' to a string(variable with a lambda expression)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1379 LET Lambda = LSTART a, b LMIDDLE MytsrFunc1(20, a, b) LEND
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1380 LET &thesaurusfunc = string(Lambda)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1381 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1382 call setline(1, 'seven')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1383 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1384 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1385 call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1386 bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1387
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1388 #" Test for using a lambda function with incorrect return value
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1389 LET Lambda = LSTART a, b LMIDDLE strlen(a) LEND
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1390 LET &thesaurusfunc = Lambda
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1391 new | only
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1392 call setline(1, 'eight')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1393 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1394 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1395
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1396 #" Test for clearing the 'thesaurusfunc' option
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1397 set thesaurusfunc=''
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1398 set thesaurusfunc&
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1399 call assert_fails("set thesaurusfunc=function('abc')", "E700:")
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1400 call assert_fails("set thesaurusfunc=funcref('abc')", "E700:")
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1401
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1402 #" set 'thesaurusfunc' to a non-existing function
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1403 func MytsrFunc2(findstart, base)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1404 call add(g:MytsrFunc2_args, [a:findstart, a:base])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1405 return a:findstart ? 0 : ['sunday']
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1406 endfunc
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1407 set thesaurusfunc=MytsrFunc2
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1408 call setline(1, 'ten')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1409 call assert_fails("set thesaurusfunc=function('NonExistingFunc')", 'E700:')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1410 call assert_fails("LET &thesaurusfunc = function('NonExistingFunc')", 'E700:')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1411 LET g:MytsrFunc2_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1412 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1413 call assert_equal([[1, ''], [0, 'ten']], g:MytsrFunc2_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1414 bw!
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26408
diff changeset
1415
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1416 #" Use a buffer-local value and a global value
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1417 set thesaurusfunc&
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1418 setlocal thesaurusfunc=function('g:MytsrFunc1',\ [22])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1419 call setline(1, 'sun')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1420 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1421 call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1422 call assert_equal('sun', getline(1))
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1423 call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1424 new
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1425 call setline(1, 'sun')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1426 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1427 call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1428 call assert_equal('sun', getline(1))
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1429 call assert_equal([], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1430 set thesaurusfunc=function('g:MytsrFunc1',\ [23])
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1431 wincmd w
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1432 call setline(1, 'sun')
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1433 LET g:MytsrFunc1_args = []
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1434 call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1435 call assert_equal('sun', getline(1))
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1436 call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:MytsrFunc1_args)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1437 :%bw!
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1438 END
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1439 call CheckLegacyAndVim9Success(lines)
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1440
26441
65ab0b035dd8 patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents: 26408
diff changeset
1441 let &thesaurusfunc = {a -> 'abc'}
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1442 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1443
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1444 " Using Vim9 lambda expression in legacy context should fail
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1445 set thesaurusfunc=(a,\ b)\ =>\ MytsrFunc1(21,\ a,\ b)
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1446 new | only
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1447 let g:MytsrFunc1_args = []
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1448 call assert_fails('call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")', 'E117:')
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1449 call assert_equal([], g:MytsrFunc1_args)
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1450 bw!
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1451
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1452 " set 'thesaurusfunc' to a partial with dict. This used to cause a crash.
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1453 func SetTsrFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1454 let params = {'thesaurus': function('g:DictTsrFunc')}
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1455 let &thesaurusfunc = params.thesaurus
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1456 endfunc
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1457 func g:DictTsrFunc(_) dict
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1458 endfunc
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1459 call SetTsrFunc()
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1460 new
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1461 call SetTsrFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1462 bw
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1463 call test_garbagecollect_now()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1464 new
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1465 set thesaurusfunc=
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1466 wincmd w
26452
65b4109a4297 patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
1467 %bw!
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1468 delfunc SetTsrFunc
26452
65b4109a4297 patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
1469
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1470 " set buffer-local 'thesaurusfunc' to a partial with dict. This used to
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1471 " cause a crash.
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1472 func SetLocalTsrFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1473 let params = {'thesaurus': function('g:DictTsrFunc')}
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1474 let &l:thesaurusfunc = params.thesaurus
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1475 endfunc
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1476 call SetLocalTsrFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1477 call test_garbagecollect_now()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1478 call SetLocalTsrFunc()
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1479 set thesaurusfunc=
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1480 bw!
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1481 delfunc g:DictTsrFunc
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1482 delfunc SetLocalTsrFunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1483
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1484 " Vim9 tests
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1485 let lines =<< trim END
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1486 vim9script
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1487
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1488 # Test for using a def function with thesaurusfunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1489 def Vim9tsrFunc(val: number, findstart: number, base: string): any
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1490 add(g:Vim9tsrFunc_Args, [val, findstart, base])
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1491 return findstart ? 0 : []
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1492 enddef
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1493 set thesaurusfunc=function('Vim9tsrFunc',\ [60])
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1494 new | only
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1495 setline(1, 'one')
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1496 g:Vim9tsrFunc_Args = []
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1497 feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1498 assert_equal([[60, 1, ''], [60, 0, 'one']], g:Vim9tsrFunc_Args)
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1499 bw!
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1500 END
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1501 call CheckScriptSuccess(lines)
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1502
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1503 " cleanup
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1504 set thesaurusfunc&
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1505 delfunc MytsrFunc1
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1506 delfunc MytsrFunc2
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1507 %bw!
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1508 endfunc
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1509
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
1510 " vim: shiftwidth=2 sts=2 expandtab