annotate src/testdir/test_ins_complete.vim @ 30473:1928947b8e1a v9.0.0572

patch 9.0.0572: insert complete tests leave a mapping behind Commit: https://github.com/vim/vim/commit/75f4bafabdcc6bce5cf3e09fee29c634bf102c17 Author: zeertzjq <zeertzjq@outlook.com> Date: Sat Sep 24 14:08:23 2022 +0100 patch 9.0.0572: insert complete tests leave a mapping behind Problem: Insert complete tests leave a mapping behind. Solution: Use a buffer-local mapping. (closes https://github.com/vim/vim/issues/11211)
author Bram Moolenaar <Bram@vim.org>
date Sat, 24 Sep 2022 15:15:03 +0200
parents faecc8c6916f
children 79e2d9b7780c
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
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
5 import './vim9.vim' as v9
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.
29970
d891115c0aea patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 29554
diff changeset
12 call mkdir('Xcpldir')
d891115c0aea patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 29554
diff changeset
13 cd Xcpldir
12788
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
26817
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
50 set cpt=.,\ ,w,i
12686
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
27016
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
74 " Test for expanding a non-existing filename
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
75 exe "normal oa1b2X3Y4\<C-X>\<C-F>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
76 call assert_equal('a1b2X3Y4', getline('.'))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
77 normal ddk
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
78
12686
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 set cpt=w
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 " 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
81 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
82 call assert_equal('STARTTEST', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 set cpt=u nohid
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 " checks unloaded buffer expansion
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 only
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 exe "normal oEN\<C-N>"
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 call assert_equal('ENDTEST', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 " checks adding mode abortion
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 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
91 call assert_equal('unless', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 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
94 " 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
95 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
96 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
97 " t-expansion
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 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
99 call assert_equal('asd', getline('.'))
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 %bw!
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 call delete('Xtestfile')
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 call delete('Xtest11.one')
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 call delete('Xtest11.two')
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 call delete('Xtestdata')
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 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
107 cd ..
29970
d891115c0aea patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 29554
diff changeset
108 call delete('Xcpldir', 'rf')
12686
aa658b33f25a patch 8.0.1221: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 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
110
26773
80e134cbee4b patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
111 func Test_ins_complete_invalid_byte()
80e134cbee4b patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
112 if has('unix') && executable('base64')
80e134cbee4b patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
113 " this weird command was causing an illegal memory access
80e134cbee4b patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
114 call writefile(['bm9ybTlvMDCAMM4Dbw4OGA4ODg=='], 'Xinvalid64')
80e134cbee4b patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
115 call system('base64 -d Xinvalid64 > Xinvalid')
80e134cbee4b patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
116 call writefile(['qa!'], 'Xexit')
80e134cbee4b patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
117 call RunVim([], [], " -i NONE -n -X -Z -e -m -s -S Xinvalid -S Xexit")
80e134cbee4b patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
118 call delete('Xinvalid64')
80e134cbee4b patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
119 call delete('Xinvalid')
80e134cbee4b patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
120 call delete('Xexit')
80e134cbee4b patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
121 endif
80e134cbee4b patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
122 endfunc
80e134cbee4b patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents: 26618
diff changeset
123
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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 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
136 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
137
9c1659761fc3 patch 8.0.1242: function argument with only dash is seen as number zero
Christian Brabandt <cb@256bit.org>
parents: 12692
diff changeset
138 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
139 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
140 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
141 endfunc
13215
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
142
29000
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
143 func Test_omni_throw()
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
144 let g:CallCount = 0
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
145 func Omni(findstart, base)
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
146 let g:CallCount += 1
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
147 if a:findstart
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
148 throw "he he he"
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
149 endif
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
150 endfunc
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
151 set omnifunc=Omni
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
152 new
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
153 try
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
154 exe "normal ifoo\<C-x>\<C-o>"
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
155 call assert_false(v:true, 'command should have failed')
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
156 catch
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
157 call assert_exception('he he he')
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
158 call assert_equal(1, g:CallCount)
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
159 endtry
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
160
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
161 bwipe!
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
162 delfunc Omni
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
163 unlet g:CallCount
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
164 set omnifunc=
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
165 endfunc
7d28903e80df patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents: 28682
diff changeset
166
25372
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
167 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
168 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
169 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
170 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
171 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
172
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
173 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
174 vim9script
27474
307341b9c227 patch 8.2.4265: autoload tests fails
Bram Moolenaar <Bram@vim.org>
parents: 27464
diff changeset
175 export def Func(findstart: bool, base: string): any
25372
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
176 if findstart
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
177 return 1
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
178 else
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
179 return ['match']
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
180 endif
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
181 enddef
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
182 {
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
183 eval 1 + 2
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
184 }
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
185 END
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
186 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
187
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
188 new
27474
307341b9c227 patch 8.2.4265: autoload tests fails
Bram Moolenaar <Bram@vim.org>
parents: 27464
diff changeset
189 setlocal omnifunc=omni#Func
25372
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
190 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
191
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
192 bwipe!
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
193 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
194 set omnifunc=
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
195 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
196 endfunc
c63a2d24b7e2 patch 8.2.3223: Vim: using {} block in autoloade omnifunc fails
Bram Moolenaar <Bram@vim.org>
parents: 23772
diff changeset
197
14071
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
198 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
199 let s:args = []
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
200 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
201 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
202 endfunc
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
203 new
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
204
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
205 set completefunc=CompleteFunc
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
206 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
207 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
208 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
209 set completefunc=
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
210
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
211 let s:args = []
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
212 set omnifunc=CompleteFunc
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
213 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
214 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
215 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
216 set omnifunc=
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
217
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
218 bwipe!
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
219 unlet s:args
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
220 delfunc CompleteFunc
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
221 endfunc
c1fcfafa8d1a patch 8.1.0053: first argument of 'completefunc' has inconsistent type
Christian Brabandt <cb@256bit.org>
parents: 13238
diff changeset
222
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
223 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
224 if a:findstart
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
225 return 0
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
226 endif
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
227
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
228 return v:none
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
229 endfunc
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
230
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
231 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
232 if a:findstart
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
233 return 0
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
234 endif
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
235
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
236 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
237 \ 'words': [
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
238 \ {
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
239 \ '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
240 \ '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
241 \ '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
242 \ '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
243 \ '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
244 \ '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
245 \ }
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
246 \ ]
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
247 \ }
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
248 endfunc
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
249
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
250 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
251 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
252 endfunc
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
253
19199
8cbadf7fb9d4 patch 8.2.0158: triggering CompleteDone earlier is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 19127
diff changeset
254 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
255 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
256 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
257 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
258 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
259 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
260 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
261
19199
8cbadf7fb9d4 patch 8.2.0158: triggering CompleteDone earlier is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 19127
diff changeset
262 if a:pre
8cbadf7fb9d4 patch 8.2.0158: triggering CompleteDone earlier is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 19127
diff changeset
263 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
264 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
265
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
266 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
267 endfunc
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
268
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
269 func Test_CompleteDoneNone()
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
270 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
271 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
272
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
273 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
274 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
275 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
276 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
277
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
278 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
279 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
280
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
281 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
282 au! CompleteDone
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
283 endfunc
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
284
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
285 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
286 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
287 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
288
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
289 set completefunc=<SID>CompleteDone_CompleteFuncDict
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
290 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
291 set completefunc&
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
292
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
293 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
294 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
295
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
296 let s:called_completedone = 0
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
297 au! CompleteDone
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
298 endfunc
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
299
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
300 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
301 if a:findstart
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
302 return 0
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
303 endif
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
304
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
305 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
306 \ 'words': [
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
307 \ {
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
308 \ '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
309 \ '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
310 \ '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
311 \ '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
312 \ '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
313 \ '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
314 \ }
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
315 \ ]
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
316 \ }
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
317 endfunc
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
318
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
319 func s:CompleteDone_CheckCompletedItemDictNoUserData()
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
320 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
321 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
322 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
323 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
324 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
325 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
326
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
327 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
328 endfunc
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
329
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
330 func Test_CompleteDoneDictNoUserData()
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
331 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
332
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
333 set completefunc=<SID>CompleteDone_CompleteFuncDictNoUserData
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
334 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
335 set completefunc&
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
336
19047
a3fce2763e83 patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents: 18900
diff changeset
337 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
338 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
339
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
340 let s:called_completedone = 0
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
341 au! CompleteDone
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
342 endfunc
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
343
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
344 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
345 if a:findstart
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
346 return 0
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
347 endif
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
348
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
349 return [ 'aword' ]
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
350 endfunc
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
351
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14489
diff changeset
352 func s:CompleteDone_CheckCompletedItemList()
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
353 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
354 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
355 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
356 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
357 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
358 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
359
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
360 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
361 endfunc
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
362
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
363 func Test_CompleteDoneList()
13238
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
364 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
365
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
366 set completefunc=<SID>CompleteDone_CompleteFuncList
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
367 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
368 set completefunc&
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
369
15416
5f8ddd2a7b92 patch 8.1.0716: get warning message when 'completefunc' returns nothing
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
370 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
371 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
372
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
373 let s:called_completedone = 0
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
374 au! CompleteDone
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
375 endfunc
e0dcfd3dbb52 patch 8.0.1493: completion items cannot be annotated
Christian Brabandt <cb@256bit.org>
parents: 13215
diff changeset
376
14489
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
377 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
378 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
379 new
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
380 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
381 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
382 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
383 \ getline(1, '$'))
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
384 undo
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
385 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
386 bwipe!
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
387 au! CompleteDone
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
388 endfunc
cda216729f9b patch 8.1.0258: not enough testing for the CompleteDone event
Christian Brabandt <cb@256bit.org>
parents: 14075
diff changeset
389
29501
69d24e60f4f8 patch 9.0.0092: plugins cannot change v:completed_item
Bram Moolenaar <Bram@vim.org>
parents: 29436
diff changeset
390 func Test_CompleteDone_modify()
69d24e60f4f8 patch 9.0.0092: plugins cannot change v:completed_item
Bram Moolenaar <Bram@vim.org>
parents: 29436
diff changeset
391 let value = {
69d24e60f4f8 patch 9.0.0092: plugins cannot change v:completed_item
Bram Moolenaar <Bram@vim.org>
parents: 29436
diff changeset
392 \ 'word': '',
69d24e60f4f8 patch 9.0.0092: plugins cannot change v:completed_item
Bram Moolenaar <Bram@vim.org>
parents: 29436
diff changeset
393 \ 'abbr': '',
69d24e60f4f8 patch 9.0.0092: plugins cannot change v:completed_item
Bram Moolenaar <Bram@vim.org>
parents: 29436
diff changeset
394 \ 'menu': '',
69d24e60f4f8 patch 9.0.0092: plugins cannot change v:completed_item
Bram Moolenaar <Bram@vim.org>
parents: 29436
diff changeset
395 \ 'info': '',
69d24e60f4f8 patch 9.0.0092: plugins cannot change v:completed_item
Bram Moolenaar <Bram@vim.org>
parents: 29436
diff changeset
396 \ 'kind': '',
69d24e60f4f8 patch 9.0.0092: plugins cannot change v:completed_item
Bram Moolenaar <Bram@vim.org>
parents: 29436
diff changeset
397 \ 'user_data': '',
69d24e60f4f8 patch 9.0.0092: plugins cannot change v:completed_item
Bram Moolenaar <Bram@vim.org>
parents: 29436
diff changeset
398 \ }
69d24e60f4f8 patch 9.0.0092: plugins cannot change v:completed_item
Bram Moolenaar <Bram@vim.org>
parents: 29436
diff changeset
399 let v:completed_item = value
29554
d413dccd4f8a patch 9.0.0118: no test for what patch 9.0.0155 fixes
Bram Moolenaar <Bram@vim.org>
parents: 29521
diff changeset
400 call assert_equal(value, v:completed_item)
29501
69d24e60f4f8 patch 9.0.0092: plugins cannot change v:completed_item
Bram Moolenaar <Bram@vim.org>
parents: 29436
diff changeset
401 endfunc
69d24e60f4f8 patch 9.0.0092: plugins cannot change v:completed_item
Bram Moolenaar <Bram@vim.org>
parents: 29436
diff changeset
402
22248
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
403 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
404 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
405 return col('.')
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
406 endif
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
407 return ['matched']
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
408 endfunc
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
409
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
410 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
411 new
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
412 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
413 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
414 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
415 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
416 bwipe!
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
417 set completeopt&
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
418 set completefunc&
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
419 endfunc
80a000b09cb0 patch 8.2.1673: complete_info() selected index has an invalid value
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
420
13215
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
421 " 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
422 " completions.
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
423 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
424 new
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
425 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
426 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
427 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
428 bwipe!
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
429 set completeopt&
ae5f855a64be patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents: 12788
diff changeset
430 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
431
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
432 " 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
433 func Test_ins_completeslash()
17588
1348696d07cd patch 8.1.1791: 'completeslash' also applies to globpath()
Bram Moolenaar <Bram@vim.org>
parents: 17553
diff changeset
434 CheckMSWindows
22397
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
435
29970
d891115c0aea patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 29554
diff changeset
436 call mkdir('Xcpldir')
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
437 let orig_shellslash = &shellslash
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
438 set cpt&
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
439 new
22397
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
440
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
441 set noshellslash
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
442
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
443 set completeslash=
29974
aafac1ae89c7 patch 9.0.0325: MS-Windows: completion test fails
Bram Moolenaar <Bram@vim.org>
parents: 29970
diff changeset
444 exe "normal oXcp\<C-X>\<C-F>"
29970
d891115c0aea patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 29554
diff changeset
445 call assert_equal('Xcpldir\', getline('.'))
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
446
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
447 set completeslash=backslash
29974
aafac1ae89c7 patch 9.0.0325: MS-Windows: completion test fails
Bram Moolenaar <Bram@vim.org>
parents: 29970
diff changeset
448 exe "normal oXcp\<C-X>\<C-F>"
29970
d891115c0aea patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 29554
diff changeset
449 call assert_equal('Xcpldir\', getline('.'))
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
450
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
451 set completeslash=slash
29974
aafac1ae89c7 patch 9.0.0325: MS-Windows: completion test fails
Bram Moolenaar <Bram@vim.org>
parents: 29970
diff changeset
452 exe "normal oXcp\<C-X>\<C-F>"
29970
d891115c0aea patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 29554
diff changeset
453 call assert_equal('Xcpldir/', getline('.'))
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
454
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
455 set shellslash
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
456
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
457 set completeslash=
29974
aafac1ae89c7 patch 9.0.0325: MS-Windows: completion test fails
Bram Moolenaar <Bram@vim.org>
parents: 29970
diff changeset
458 exe "normal oXcp\<C-X>\<C-F>"
29970
d891115c0aea patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 29554
diff changeset
459 call assert_equal('Xcpldir/', getline('.'))
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
460
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
461 set completeslash=backslash
29974
aafac1ae89c7 patch 9.0.0325: MS-Windows: completion test fails
Bram Moolenaar <Bram@vim.org>
parents: 29970
diff changeset
462 exe "normal oXcp\<C-X>\<C-F>"
29970
d891115c0aea patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 29554
diff changeset
463 call assert_equal('Xcpldir\', getline('.'))
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
464
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
465 set completeslash=slash
29974
aafac1ae89c7 patch 9.0.0325: MS-Windows: completion test fails
Bram Moolenaar <Bram@vim.org>
parents: 29970
diff changeset
466 exe "normal oXcp\<C-X>\<C-F>"
29970
d891115c0aea patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 29554
diff changeset
467 call assert_equal('Xcpldir/', getline('.'))
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
468 %bw!
29970
d891115c0aea patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 29554
diff changeset
469 call delete('Xcpldir', 'rf')
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
470
17588
1348696d07cd patch 8.1.1791: 'completeslash' also applies to globpath()
Bram Moolenaar <Bram@vim.org>
parents: 17553
diff changeset
471 set noshellslash
1348696d07cd patch 8.1.1791: 'completeslash' also applies to globpath()
Bram Moolenaar <Bram@vim.org>
parents: 17553
diff changeset
472 set completeslash=slash
1348696d07cd patch 8.1.1791: 'completeslash' also applies to globpath()
Bram Moolenaar <Bram@vim.org>
parents: 17553
diff changeset
473 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
474
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
475 let &shellslash = orig_shellslash
17588
1348696d07cd patch 8.1.1791: 'completeslash' also applies to globpath()
Bram Moolenaar <Bram@vim.org>
parents: 17553
diff changeset
476 set completeslash=
17543
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
477 endfunc
77c3f6428b6c patch 8.1.1769: 'shellslash' is also used for completion
Bram Moolenaar <Bram@vim.org>
parents: 17468
diff changeset
478
22427
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
479 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
480 CheckScreendump
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
481
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
482 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
483 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
484 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
485 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
486 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
487 endfunc
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
488 END
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
489
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
490 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
491 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
492 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
493 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
494 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
495 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
496
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
497 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
498 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
499 endfunc
58cdc5d7f143 patch 8.2.1762: when a timer uses :stopinsert completion isn't stopped
Bram Moolenaar <Bram@vim.org>
parents: 22397
diff changeset
500
28682
c1591fa6f81a patch 8.2.4865: :startinsert right after :stopinsert may not work
Bram Moolenaar <Bram@vim.org>
parents: 28369
diff changeset
501 func Test_complete_stopinsert_startinsert()
c1591fa6f81a patch 8.2.4865: :startinsert right after :stopinsert may not work
Bram Moolenaar <Bram@vim.org>
parents: 28369
diff changeset
502 nnoremap <F2> <Cmd>startinsert<CR>
c1591fa6f81a patch 8.2.4865: :startinsert right after :stopinsert may not work
Bram Moolenaar <Bram@vim.org>
parents: 28369
diff changeset
503 inoremap <F2> <Cmd>stopinsert<CR>
c1591fa6f81a patch 8.2.4865: :startinsert right after :stopinsert may not work
Bram Moolenaar <Bram@vim.org>
parents: 28369
diff changeset
504 " This just checks if this causes an error
c1591fa6f81a patch 8.2.4865: :startinsert right after :stopinsert may not work
Bram Moolenaar <Bram@vim.org>
parents: 28369
diff changeset
505 call feedkeys("i\<C-X>\<C-N>\<F2>\<F2>", 'x')
c1591fa6f81a patch 8.2.4865: :startinsert right after :stopinsert may not work
Bram Moolenaar <Bram@vim.org>
parents: 28369
diff changeset
506 nunmap <F2>
c1591fa6f81a patch 8.2.4865: :startinsert right after :stopinsert may not work
Bram Moolenaar <Bram@vim.org>
parents: 28369
diff changeset
507 iunmap <F2>
c1591fa6f81a patch 8.2.4865: :startinsert right after :stopinsert may not work
Bram Moolenaar <Bram@vim.org>
parents: 28369
diff changeset
508 endfunc
c1591fa6f81a patch 8.2.4865: :startinsert right after :stopinsert may not work
Bram Moolenaar <Bram@vim.org>
parents: 28369
diff changeset
509
18892
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
510 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
511 CheckScreendump
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
512
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
513 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
514 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
515 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
516 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
517 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
518 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
519 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
520 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
521 END
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
522
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
523 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
524 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
525 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
526 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
527 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
528
fb2d26bc8ca1 patch 8.2.0007: popup menu positioned wrong with folding in two tabs
Bram Moolenaar <Bram@vim.org>
parents: 17588
diff changeset
529 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
530 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
531 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
532 endfunc
18900
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
533
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
534 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
535 CheckScreendump
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
536
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
537 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
538 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
539 if a:findstart
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
540 return col(".") - 1
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
541 endif
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
542 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
543 endfunc
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
544 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
545 set completeopt+=longest
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
546 END
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
547
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
548 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
549 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
550 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
551 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
552 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
553 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
554 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
555
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
556 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
557 call StopVimInTerminal(buf)
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
558 call delete('Xpreviewscript')
a9c47c623f4a patch 8.2.0011: screen updating wrong when opeing preview window
Bram Moolenaar <Bram@vim.org>
parents: 18892
diff changeset
559 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
560
27944
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
561 func Test_scrollbar_on_wide_char()
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
562 CheckScreendump
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
563
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
564 let lines =<< trim END
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
565 call setline(1, ['a', ' 啊啊啊',
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
566 \ ' 哦哦哦',
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
567 \ ' 呃呃呃'])
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
568 call setline(5, range(10)->map({i, v -> 'aa' .. v .. 'bb'}))
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
569 END
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
570 call writefile(lines, 'Xwidescript')
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
571 let buf = RunVimInTerminal('-S Xwidescript', #{rows: 10})
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
572 call term_sendkeys(buf, "A\<C-N>")
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
573 call VerifyScreenDump(buf, 'Test_scrollbar_on_wide_char', {})
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
574
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
575 call StopVimInTerminal(buf)
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
576 call delete('Xwidescript')
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
577 endfunc
05fa2837e8a1 patch 8.2.4497: wrong color for half of wide character next to pum scrollbar
Bram Moolenaar <Bram@vim.org>
parents: 27780
diff changeset
578
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
579 " 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
580 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
581 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
582 \ "!_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
583 \ "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
584 \ "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
585 \ "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
586 \ '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
587 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
588 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
589 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
590 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
591 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
592 [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
593 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
594
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 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
596 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
597 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
598 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
599 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
600
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 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
602 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
603 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
604 %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
605 endfunc
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
606
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
607 " 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
608 func Test_completefunc_error()
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
609 new
20120
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
610 " 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
611 func CompleteFunc(findstart, base)
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
612 if a:findstart == 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
613 normal dd
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
614 return col('.') - 1
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
615 endif
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
616 return ['a', 'b']
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
617 endfunc
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
618 set completefunc=CompleteFunc
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
619 call setline(1, ['', 'abcd', ''])
29014
45c182c4f7e9 patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents: 29000
diff changeset
620 call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E565:')
20120
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
621
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 second time
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
623 func CompleteFunc2(findstart, base)
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
624 if a:findstart == 1
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
625 return col('.') - 1
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
626 endif
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
627 normal dd
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
628 return ['a', 'b']
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
629 endfunc
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
630 set completefunc=CompleteFunc2
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
631 call setline(1, ['', 'abcd', ''])
29014
45c182c4f7e9 patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents: 29000
diff changeset
632 call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E565:')
20120
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
633
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
634 " 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
635 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
636 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
637 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
638 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
639 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
640 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
641 endfunc
23770
385d33dfb7df patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents: 23766
diff changeset
642 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
643 new
23770
385d33dfb7df patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents: 23766
diff changeset
644 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
645 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
646
704fdd4d0949 patch 8.2.2424: some tests are known to cause an error with ASAN
Bram Moolenaar <Bram@vim.org>
parents: 23748
diff changeset
647 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
648 delfunc CompleteFunc
23770
385d33dfb7df patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents: 23766
diff changeset
649 delfunc CompleteFunc2
385d33dfb7df patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents: 23766
diff changeset
650 delfunc CompleteFunc3
385d33dfb7df patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents: 23766
diff changeset
651 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
652 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
653
20285
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
654 " 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
655 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
656 new
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
657 func! CompleteFunc(findstart, base)
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
658 if a:findstart == 1
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
659 return col('.') - 1
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
660 endif
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
661 return [{}, '', 'moon']
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
662 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
663 set completefunc=CompleteFunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
664 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
665 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
666 set completefunc&
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
667 close!
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
668 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
669
20120
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
670 " 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
671 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
672 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
673 func ListColors()
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
674 call complete(col('.'), "blue")
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
675 endfunc
30015
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29974
diff changeset
676 call assert_fails('exe "normal i\<C-R>=ListColors()\<CR>"', 'E1211:')
20120
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
677 func ListMonths()
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
678 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
679 endfunc
30015
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29974
diff changeset
680 call assert_fails('exe "normal i\<C-R>=ListMonths()\<CR>"', 'E1298:')
20120
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
681 delfunc ListColors
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
682 delfunc ListMonths
30015
adb0de8be4ce patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents: 29974
diff changeset
683 call assert_fails('call complete_info({})', 'E1211:')
20285
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
684 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
685 endfunc
16460964c304 patch 8.2.0615: regexp benchmark stest is old style
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
686
26921
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
687 " Test for recursively starting completion mode using complete()
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
688 func Test_recursive_complete_func()
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
689 func ListColors()
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
690 call complete(5, ["red", "blue"])
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
691 return ''
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
692 endfunc
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
693 new
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
694 call setline(1, ['a1', 'a2'])
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
695 set complete=.
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
696 exe "normal Goa\<C-X>\<C-L>\<C-R>=ListColors()\<CR>\<C-N>"
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
697 call assert_equal('a2blue', getline(3))
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
698 delfunc ListColors
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
699 bw!
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
700 endfunc
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
701
30463
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
702 " Test for using complete() with completeopt+=longest
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
703 func Test_complete_with_longest()
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
704 new
30473
1928947b8e1a patch 9.0.0572: insert complete tests leave a mapping behind
Bram Moolenaar <Bram@vim.org>
parents: 30463
diff changeset
705 inoremap <buffer> <f3> <cmd>call complete(1, ["iaax", "iaay", "iaaz"])<cr>
30463
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
706
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
707 " default: insert first match
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
708 set completeopt&
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
709 call setline(1, ['i'])
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
710 exe "normal Aa\<f3>\<esc>"
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
711 call assert_equal('iaax', getline(1))
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
712
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
713 " with longest: insert longest prefix
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
714 set completeopt+=longest
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
715 call setline(1, ['i'])
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
716 exe "normal Aa\<f3>\<esc>"
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
717 call assert_equal('iaa', getline(1))
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
718 set completeopt&
30473
1928947b8e1a patch 9.0.0572: insert complete tests leave a mapping behind
Bram Moolenaar <Bram@vim.org>
parents: 30463
diff changeset
719 bwipe!
30463
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
720 endfunc
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
721
faecc8c6916f patch 9.0.0567: 'completeopt' "longest" is not used for complete()
Bram Moolenaar <Bram@vim.org>
parents: 30051
diff changeset
722
20199
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
723 " 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
724 func Test_complete_wrapscan()
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
725 " complete words from another buffer
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
726 new
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
727 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
728 new
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
729 setlocal complete=w
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
730 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
731 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
732 close!
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
733 " 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
734 setlocal complete=.
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
735 %d
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
736 call setline(1, ['one two', ''])
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
737 call cursor(2, 1)
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
738 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
739 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
740 close!
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
741 endfunc
a4bd28e2cf1d patch 8.2.0655: search code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 20120
diff changeset
742
20285
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
743 " 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
744 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
745 new
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
746 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
747 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
748 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
749 close!
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
750 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
751
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
752 " 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
753 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
754 new
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
755 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
756 setlocal textwidth=20
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
757 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
758 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
759 close!
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
760 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
761
26817
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
762 " Test for completing words with a '.' at the end of a word.
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
763 func Test_complete_joinspaces()
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
764 new
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
765 call setline(1, ['one two.', 'three. four'])
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
766 set joinspaces
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
767 exe "normal Goon\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>"
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
768 call assert_equal("one two. three. four", getline(3))
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
769 set joinspaces&
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
770 bw!
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
771 endfunc
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
772
20285
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
773 " 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
774 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
775 new
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
776 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
777 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
778 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
779
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
780 " 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
781 " 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
782 %d
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
783 set ignorecase backspace=2
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
784 setlocal complete=.
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
785 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
786 normal Go
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
787 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
788 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
789 set ignorecase& backspace&
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
790 close!
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
791 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
792
26817
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
793 " Test for using CTRL-X CTRL-L to complete whole lines lines
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
794 func Test_complete_wholeline()
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
795 new
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
796 " complete one-line
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
797 call setline(1, ['a1', 'a2'])
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
798 exe "normal ggoa\<C-X>\<C-L>"
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
799 call assert_equal(['a1', 'a1', 'a2'], getline(1, '$'))
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
800 " go to the next match (wrapping around the buffer)
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
801 exe "normal 2GCa\<C-X>\<C-L>\<C-N>"
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
802 call assert_equal(['a1', 'a', 'a2'], getline(1, '$'))
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
803 " go to the next match
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
804 exe "normal 2GCa\<C-X>\<C-L>\<C-N>\<C-N>"
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
805 call assert_equal(['a1', 'a2', 'a2'], getline(1, '$'))
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
806 exe "normal 2GCa\<C-X>\<C-L>\<C-N>\<C-N>\<C-N>"
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
807 call assert_equal(['a1', 'a1', 'a2'], getline(1, '$'))
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
808 " repeat the test using CTRL-L
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
809 " go to the next match (wrapping around the buffer)
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
810 exe "normal 2GCa\<C-X>\<C-L>\<C-L>"
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
811 call assert_equal(['a1', 'a2', 'a2'], getline(1, '$'))
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
812 " go to the next match
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
813 exe "normal 2GCa\<C-X>\<C-L>\<C-L>\<C-L>"
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
814 call assert_equal(['a1', 'a', 'a2'], getline(1, '$'))
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
815 exe "normal 2GCa\<C-X>\<C-L>\<C-L>\<C-L>\<C-L>"
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
816 call assert_equal(['a1', 'a1', 'a2'], getline(1, '$'))
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
817 %d
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
818 " use CTRL-X CTRL-L to add one more line
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
819 call setline(1, ['a1', 'b1'])
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
820 setlocal complete=.
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
821 exe "normal ggOa\<C-X>\<C-L>\<C-X>\<C-L>\<C-X>\<C-L>"
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
822 call assert_equal(['a1', 'b1', '', 'a1', 'b1'], getline(1, '$'))
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
823 bw!
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
824 endfunc
a8ded20a59e6 patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents: 26773
diff changeset
825
20285
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
826 " 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
827 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
828 new
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
829 setlocal cindent
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
830 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
831 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
832 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
833
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
834 %d
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
835 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
836 setlocal cinkeys+==while
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
837 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
838 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
839 close!
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
840 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
841
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
842 " 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
843 func Test_complete_cmdline()
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
844 new
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
845 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
846 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
847 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
848 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
849 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
850 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
851 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
852 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
853 write TestCommand1Test
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
854 write TestCommand2Test
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
855 " 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
856 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
857 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
858 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
859 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
860 delcom TestCommand1
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
861 delcom TestCommand2
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
862 close!
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
863 endfunc
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
864
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
865 " 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
866 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
867 new
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
868 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
869 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
870 return ''
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
871 endfunc
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
872 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
873 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
874 return ''
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
875 endfunc
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
876 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
877 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
878 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
879 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
880 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
881 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
882 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
883 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
884 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
885 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
886 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
887 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
888 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
889 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
890 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
891 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
892 set completeopt&
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
893 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
894 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
895 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
896 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
897 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
898 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
899 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
900 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
901 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
902 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
903 delcom TestCommand1
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
904 delcom TestCommand2
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
905 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
906 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
907 iunmap <F1>
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
908 iunmap <F2>
31db9c6df4e3 patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents: 25372
diff changeset
909 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
910 delfunc Save_mode2
20285
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
911 close!
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
912 endfunc
bce10d039e06 patch 8.2.0698: insert mode completion not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
913
26831
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
914 " Test for typing CTRL-R in insert completion mode to insert a register
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
915 " content.
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
916 func Test_complete_reginsert()
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
917 new
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
918 call setline(1, ['a1', 'a12', 'a123', 'a1234'])
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
919
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
920 " if a valid CTRL-X mode key is returned from <C-R>=, then it should be
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
921 " processed. Otherwise, CTRL-X mode should be stopped and the key should be
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
922 " inserted.
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
923 exe "normal Goa\<C-P>\<C-R>=\"\\<C-P>\"\<CR>"
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
924 call assert_equal('a123', getline(5))
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
925 let @r = "\<C-P>\<C-P>"
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
926 exe "normal GCa\<C-P>\<C-R>r"
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
927 call assert_equal('a12', getline(5))
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
928 exe "normal GCa\<C-P>\<C-R>=\"x\"\<CR>"
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
929 call assert_equal('a1234x', getline(5))
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
930 bw!
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
931 endfunc
537fdb6653a9 patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents: 26817
diff changeset
932
22397
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
933 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
934 CheckMSWindows
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
935
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
936 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
937 set noshellslash
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
938
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
939 set completeslash=slash
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
940 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
941
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
942 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
943 set completeslash=
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
944 endfunc
0a5770061295 patch 8.2.1747: result of expand() unexpectedly depends on 'completeslash'
Bram Moolenaar <Bram@vim.org>
parents: 22248
diff changeset
945
26921
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
946 " Test for 'longest' setting in 'completeopt' with latin1 and utf-8 encodings
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
947 func Test_complete_longest_match()
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
948 for e in ['latin1', 'utf-8']
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
949 exe 'set encoding=' .. e
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
950 new
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
951 set complete=.
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
952 set completeopt=menu,longest
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
953 call setline(1, ['pfx_a1', 'pfx_a12', 'pfx_a123', 'pfx_b1'])
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
954 exe "normal Gopfx\<C-P>"
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
955 call assert_equal('pfx_', getline(5))
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
956 bw!
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
957 endfor
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
958
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
959 " Test for completing additional words with longest match set
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
960 new
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
961 call setline(1, ['abc1', 'abd2'])
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
962 exe "normal Goab\<C-P>\<C-X>\<C-P>"
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
963 call assert_equal('ab', getline(3))
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
964 bw!
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
965 set complete& completeopt&
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
966 endfunc
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
967
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
968 " Test for removing the first displayed completion match and selecting the
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
969 " match just before that.
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
970 func Test_complete_erase_firstmatch()
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
971 new
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
972 call setline(1, ['a12', 'a34', 'a56'])
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
973 set complete=.
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
974 exe "normal Goa\<C-P>\<BS>\<BS>3\<CR>"
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
975 call assert_equal('a34', getline('$'))
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
976 set complete&
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
977 bw!
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
978 endfunc
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
979
27016
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
980 " Test for completing words from unloaded buffers
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
981 func Test_complete_from_unloadedbuf()
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
982 call writefile(['abc'], "Xfile1")
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
983 call writefile(['def'], "Xfile2")
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
984 edit Xfile1
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
985 edit Xfile2
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
986 new | close
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
987 enew
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
988 bunload Xfile1 Xfile2
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
989 set complete=u
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
990 " complete from an unloaded buffer
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
991 exe "normal! ia\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
992 call assert_equal('abc', getline(1))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
993 exe "normal! od\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
994 call assert_equal('def', getline(2))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
995 set complete&
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
996 %bw!
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
997 call delete("Xfile1")
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
998 call delete("Xfile2")
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
999 endfunc
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1000
26921
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1001 " Test for completing whole lines from unloaded buffers
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1002 func Test_complete_wholeline_unloadedbuf()
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1003 call writefile(['a line1', 'a line2', 'a line3'], "Xfile1")
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1004 edit Xfile1
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1005 enew
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1006 set complete=u
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1007 exe "normal! ia\<C-X>\<C-L>\<C-P>"
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1008 call assert_equal('a line2', getline(1))
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1009 %d
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1010 " completing from an unlisted buffer should fail
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1011 bdel Xfile1
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1012 exe "normal! ia\<C-X>\<C-L>\<C-P>"
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1013 call assert_equal('a', getline(1))
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1014 set complete&
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1015 %bw!
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1016 call delete("Xfile1")
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1017 endfunc
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1018
27016
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1019 " Test for completing words from unlisted buffers
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1020 func Test_complete_from_unlistedbuf()
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1021 call writefile(['abc'], "Xfile1")
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1022 call writefile(['def'], "Xfile2")
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1023 edit Xfile1
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1024 edit Xfile2
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1025 new | close
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1026 bdel Xfile1 Xfile2
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1027 set complete=U
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1028 " complete from an unlisted buffer
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1029 exe "normal! ia\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1030 call assert_equal('abc', getline(1))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1031 exe "normal! od\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1032 call assert_equal('def', getline(2))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1033 set complete&
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1034 %bw!
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1035 call delete("Xfile1")
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1036 call delete("Xfile2")
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1037 endfunc
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1038
26921
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1039 " Test for completing whole lines from unlisted buffers
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1040 func Test_complete_wholeline_unlistedbuf()
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1041 call writefile(['a line1', 'a line2', 'a line3'], "Xfile1")
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1042 edit Xfile1
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1043 enew
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1044 set complete=U
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1045 " completing from a unloaded buffer should fail
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1046 exe "normal! ia\<C-X>\<C-L>\<C-P>"
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1047 call assert_equal('a', getline(1))
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1048 %d
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1049 bdel Xfile1
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1050 exe "normal! ia\<C-X>\<C-L>\<C-P>"
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1051 call assert_equal('a line2', getline(1))
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1052 set complete&
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1053 %bw!
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1054 call delete("Xfile1")
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1055 endfunc
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1056
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1057 " Test for adding a multibyte character using CTRL-L in completion mode
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1058 func Test_complete_mbyte_char_add()
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1059 new
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1060 set complete=.
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1061 call setline(1, 'abė')
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1062 exe "normal! oa\<C-P>\<BS>\<BS>\<C-L>\<C-L>"
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1063 call assert_equal('abė', getline(2))
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1064 " Test for a leader with multibyte character
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1065 %d
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1066 call setline(1, 'abėĕ')
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1067 exe "normal! oabė\<C-P>"
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1068 call assert_equal('abėĕ', getline(2))
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1069 bw!
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1070 endfunc
b975b7c16ba1 patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents: 26831
diff changeset
1071
27016
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1072 " Test for using <C-X><C-P> for local expansion even if 'complete' is set to
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1073 " not to complete matches from the local buffer. Also test using multiple
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1074 " <C-X> to cancel the current completion mode.
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1075 func Test_complete_local_expansion()
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1076 new
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1077 set complete=t
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1078 call setline(1, ['abc', 'def'])
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1079 exe "normal! Go\<C-X>\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1080 call assert_equal("def", getline(3))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1081 exe "normal! Go\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1082 call assert_equal("", getline(4))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1083 exe "normal! Go\<C-X>\<C-N>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1084 call assert_equal("abc", getline(5))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1085 exe "normal! Go\<C-N>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1086 call assert_equal("", getline(6))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1087
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1088 " use multiple <C-X> to cancel the previous completion mode
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1089 exe "normal! Go\<C-P>\<C-X>\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1090 call assert_equal("", getline(7))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1091 exe "normal! Go\<C-P>\<C-X>\<C-X>\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1092 call assert_equal("", getline(8))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1093 exe "normal! Go\<C-P>\<C-X>\<C-X>\<C-X>\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1094 call assert_equal("abc", getline(9))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1095
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1096 " interrupt the current completion mode
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1097 set completeopt=menu,noinsert
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1098 exe "normal! Go\<C-X>\<C-F>\<C-X>\<C-X>\<C-P>\<C-Y>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1099 call assert_equal("abc", getline(10))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1100
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1101 " when only one <C-X> is used to interrupt, do normal expansion
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1102 exe "normal! Go\<C-X>\<C-F>\<C-X>\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1103 call assert_equal("", getline(11))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1104 set completeopt&
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1105
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1106 " using two <C-X> in non-completion mode and restarting the same mode
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1107 exe "normal! God\<C-X>\<C-X>\<C-P>\<C-X>\<C-X>\<C-P>\<C-Y>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1108 call assert_equal("def", getline(12))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1109
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1110 " test for adding a match from the original empty text
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1111 %d
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1112 call setline(1, 'abc def g')
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1113 exe "normal! o\<C-X>\<C-P>\<C-N>\<C-X>\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1114 call assert_equal('def', getline(2))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1115 exe "normal! 0C\<C-X>\<C-N>\<C-P>\<C-X>\<C-N>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1116 call assert_equal('abc', getline(2))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1117
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1118 bw!
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1119 endfunc
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1120
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1121 " Test for undoing changes after a insert-mode completion
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1122 func Test_complete_undo()
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1123 new
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1124 set complete=.
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1125 " undo with 'ignorecase'
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1126 call setline(1, ['ABOVE', 'BELOW'])
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1127 set ignorecase
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1128 exe "normal! Goab\<C-G>u\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1129 call assert_equal("ABOVE", getline(3))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1130 undo
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1131 call assert_equal("ab", getline(3))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1132 set ignorecase&
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1133 %d
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1134 " undo with longest match
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1135 set completeopt=menu,longest
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1136 call setline(1, ['above', 'about'])
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1137 exe "normal! Goa\<C-G>u\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1138 call assert_equal("abo", getline(3))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1139 undo
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1140 call assert_equal("a", getline(3))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1141 set completeopt&
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1142 %d
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1143 " undo for line completion
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1144 call setline(1, ['above that change', 'below that change'])
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1145 exe "normal! Goabove\<C-G>u\<C-X>\<C-L>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1146 call assert_equal("above that change", getline(3))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1147 undo
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1148 call assert_equal("above", getline(3))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1149
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1150 bw!
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1151 endfunc
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1152
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1153 " Test for completing a very long word
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1154 func Test_complete_long_word()
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1155 set complete&
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1156 new
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1157 call setline(1, repeat('x', 950) .. ' one two three')
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1158 exe "normal! Gox\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1159 call assert_equal(repeat('x', 950) .. ' one two three', getline(2))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1160 %d
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1161 " should fail when more than 950 characters are in a word
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1162 call setline(1, repeat('x', 951) .. ' one two three')
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1163 exe "normal! Gox\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>\<C-X>\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1164 call assert_equal(repeat('x', 951), getline(2))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1165
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1166 " Test for adding a very long word to an existing completion
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1167 %d
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1168 call setline(1, ['abc', repeat('x', 1016) .. '012345'])
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1169 exe "normal! Goab\<C-P>\<C-X>\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1170 call assert_equal('abc ' .. repeat('x', 1016) .. '0123', getline(3))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1171 bw!
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1172 endfunc
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1173
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1174 " Test for some fields in the complete items used by complete()
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1175 func Test_complete_items()
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1176 func CompleteItems(idx)
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1177 let items = [[#{word: "one", dup: 1, user_data: 'u1'}, #{word: "one", dup: 1, user_data: 'u2'}],
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1178 \ [#{word: "one", dup: 0, user_data: 'u3'}, #{word: "one", dup: 0, user_data: 'u4'}],
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1179 \ [#{word: "one", icase: 1, user_data: 'u7'}, #{word: "oNE", icase: 1, user_data: 'u8'}],
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1180 \ [#{user_data: 'u9'}],
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1181 \ [#{word: "", user_data: 'u10'}],
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1182 \ [#{word: "", empty: 1, user_data: 'u11'}]]
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1183 call complete(col('.'), items[a:idx])
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1184 return ''
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1185 endfunc
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1186 new
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1187 exe "normal! i\<C-R>=CompleteItems(0)\<CR>\<C-N>\<C-Y>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1188 call assert_equal('u2', v:completed_item.user_data)
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1189 call assert_equal('one', getline(1))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1190 exe "normal! o\<C-R>=CompleteItems(1)\<CR>\<C-Y>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1191 call assert_equal('u3', v:completed_item.user_data)
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1192 call assert_equal('one', getline(2))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1193 exe "normal! o\<C-R>=CompleteItems(1)\<CR>\<C-N>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1194 call assert_equal('', getline(3))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1195 set completeopt=menu,noinsert
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1196 exe "normal! o\<C-R>=CompleteItems(2)\<CR>one\<C-N>\<C-Y>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1197 call assert_equal('oNE', getline(4))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1198 call assert_equal('u8', v:completed_item.user_data)
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1199 set completeopt&
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1200 exe "normal! o\<C-R>=CompleteItems(3)\<CR>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1201 call assert_equal('', getline(5))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1202 exe "normal! o\<C-R>=CompleteItems(4)\<CR>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1203 call assert_equal('', getline(6))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1204 exe "normal! o\<C-R>=CompleteItems(5)\<CR>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1205 call assert_equal('', getline(7))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1206 call assert_equal('u11', v:completed_item.user_data)
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1207 " pass invalid argument to complete()
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1208 let cmd = "normal! o\<C-R>=complete(1, [[]])\<CR>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1209 call assert_fails('exe cmd', 'E730:')
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1210 bw!
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1211 delfunc CompleteItems
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1212 endfunc
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1213
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1214 " Test for the "refresh" item in the dict returned by an insert completion
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1215 " function
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1216 func Test_complete_item_refresh_always()
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1217 let g:CallCount = 0
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1218 func! Tcomplete(findstart, base)
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1219 if a:findstart
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1220 " locate the start of the word
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1221 let line = getline('.')
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1222 let start = col('.') - 1
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1223 while start > 0 && line[start - 1] =~ '\a'
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1224 let start -= 1
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1225 endwhile
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1226 return start
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1227 else
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1228 let g:CallCount += 1
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1229 let res = ["update1", "update12", "update123"]
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1230 return #{words: res, refresh: 'always'}
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1231 endif
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1232 endfunc
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1233 new
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1234 set completeopt=menu,longest
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1235 set completefunc=Tcomplete
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1236 exe "normal! iup\<C-X>\<C-U>\<BS>\<BS>\<BS>\<BS>\<BS>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1237 call assert_equal('up', getline(1))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1238 call assert_equal(2, g:CallCount)
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1239 set completeopt&
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1240 set completefunc&
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1241 bw!
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1242 delfunc Tcomplete
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1243 endfunc
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1244
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1245 " Test for completing from a thesaurus file without read permission
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1246 func Test_complete_unreadable_thesaurus_file()
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1247 CheckUnix
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1248 CheckNotRoot
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1249
30051
13b02c1ea0f7 patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
1250 call writefile(['about', 'above'], 'Xunrfile')
13b02c1ea0f7 patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
1251 call setfperm('Xunrfile', '---r--r--')
27016
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1252 new
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1253 set complete=sXfile
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1254 exe "normal! ia\<C-P>"
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1255 call assert_equal('a', getline(1))
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1256 bw!
30051
13b02c1ea0f7 patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents: 30015
diff changeset
1257 call delete('Xunrfile')
27016
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1258 set complete&
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1259 endfunc
1d9a7aa42744 patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26921
diff changeset
1260
23169
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
1261 " 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
1262 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
1263 new
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
1264 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
1265 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
1266 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
1267 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
1268 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
1269 call assert_equal(currmess, execute('messages'))
27954
3de9be15de51 patch 8.2.4502: in the GUI a modifier is not recognized after CTRL-X
Bram Moolenaar <Bram@vim.org>
parents: 27944
diff changeset
1270 bwipe!
3de9be15de51 patch 8.2.4502: in the GUI a modifier is not recognized after CTRL-X
Bram Moolenaar <Bram@vim.org>
parents: 27944
diff changeset
1271 endfunc
3de9be15de51 patch 8.2.4502: in the GUI a modifier is not recognized after CTRL-X
Bram Moolenaar <Bram@vim.org>
parents: 27944
diff changeset
1272
3de9be15de51 patch 8.2.4502: in the GUI a modifier is not recognized after CTRL-X
Bram Moolenaar <Bram@vim.org>
parents: 27944
diff changeset
1273 " A mapping is not used for the key after CTRL-X.
3de9be15de51 patch 8.2.4502: in the GUI a modifier is not recognized after CTRL-X
Bram Moolenaar <Bram@vim.org>
parents: 27944
diff changeset
1274 func Test_no_mapping_for_ctrl_x_key()
3de9be15de51 patch 8.2.4502: in the GUI a modifier is not recognized after CTRL-X
Bram Moolenaar <Bram@vim.org>
parents: 27944
diff changeset
1275 new
30473
1928947b8e1a patch 9.0.0572: insert complete tests leave a mapping behind
Bram Moolenaar <Bram@vim.org>
parents: 30463
diff changeset
1276 inoremap <buffer> <C-K> <Cmd>let was_mapped = 'yes'<CR>
27954
3de9be15de51 patch 8.2.4502: in the GUI a modifier is not recognized after CTRL-X
Bram Moolenaar <Bram@vim.org>
parents: 27944
diff changeset
1277 setlocal dictionary=README.txt
3de9be15de51 patch 8.2.4502: in the GUI a modifier is not recognized after CTRL-X
Bram Moolenaar <Bram@vim.org>
parents: 27944
diff changeset
1278 call feedkeys("aexam\<C-X>\<C-K> ", 'xt')
3de9be15de51 patch 8.2.4502: in the GUI a modifier is not recognized after CTRL-X
Bram Moolenaar <Bram@vim.org>
parents: 27944
diff changeset
1279 call assert_equal('example ', getline(1))
3de9be15de51 patch 8.2.4502: in the GUI a modifier is not recognized after CTRL-X
Bram Moolenaar <Bram@vim.org>
parents: 27944
diff changeset
1280 call assert_false(exists('was_mapped'))
3de9be15de51 patch 8.2.4502: in the GUI a modifier is not recognized after CTRL-X
Bram Moolenaar <Bram@vim.org>
parents: 27944
diff changeset
1281 bwipe!
23169
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
1282 endfunc
5e6855ebc4ea patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents: 22717
diff changeset
1283
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1284 " 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
1285 func Test_completefunc_callback()
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1286 func CompleteFunc1(callnr, findstart, base)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1287 call add(g:CompleteFunc1Args, [a:callnr, a:findstart, a:base])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1288 return a:findstart ? 0 : []
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1289 endfunc
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1290 func CompleteFunc2(findstart, base)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1291 call add(g:CompleteFunc2Args, [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
1292 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
1293 endfunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1294
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
1295 let lines =<< trim END
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1296 #" Test for using a global function name
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1297 LET &completefunc = 'g:CompleteFunc2'
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1298 new
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1299 call setline(1, 'global')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1300 LET g:CompleteFunc2Args = []
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1301 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1302 call assert_equal([[1, ''], [0, 'global']], g:CompleteFunc2Args)
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1303 bw!
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1304
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
1305 #" Test for using a function()
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1306 set completefunc=function('g:CompleteFunc1',\ [10])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1307 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
1308 call setline(1, 'one')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1309 LET g:CompleteFunc1Args = []
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
1310 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1311 call assert_equal([[10, 1, ''], [10, 0, 'one']], g:CompleteFunc1Args)
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
1312 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1313
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
1314 #" Using a funcref variable to set 'completefunc'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1315 VAR Fn = function('g:CompleteFunc1', [11])
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
1316 LET &completefunc = Fn
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1317 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
1318 call setline(1, 'two')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1319 LET g:CompleteFunc1Args = []
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
1320 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1321 call assert_equal([[11, 1, ''], [11, 0, 'two']], g:CompleteFunc1Args)
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
1322 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1323
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
1324 #" Using string(funcref_variable) to set 'completefunc'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1325 LET Fn = function('g:CompleteFunc1', [12])
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
1326 LET &completefunc = string(Fn)
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1327 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
1328 call setline(1, 'two')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1329 LET g:CompleteFunc1Args = []
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
1330 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1331 call assert_equal([[12, 1, ''], [12, 0, 'two']], g:CompleteFunc1Args)
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
1332 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
1333
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 #" Test for using a funcref()
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1335 set completefunc=funcref('g:CompleteFunc1',\ [13])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1336 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
1337 call setline(1, 'three')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1338 LET g:CompleteFunc1Args = []
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 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1340 call assert_equal([[13, 1, ''], [13, 0, 'three']], g:CompleteFunc1Args)
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
1341 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1342
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
1343 #" Using a funcref variable to set 'completefunc'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1344 LET Fn = funcref('g:CompleteFunc1', [14])
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
1345 LET &completefunc = Fn
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1346 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
1347 call setline(1, 'four')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1348 LET g:CompleteFunc1Args = []
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
1349 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1350 call assert_equal([[14, 1, ''], [14, 0, 'four']], g:CompleteFunc1Args)
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
1351 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
1352
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
1353 #" Using a string(funcref_variable) to set 'completefunc'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1354 LET Fn = funcref('g:CompleteFunc1', [15])
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
1355 LET &completefunc = string(Fn)
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1356 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
1357 call setline(1, 'four')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1358 LET g:CompleteFunc1Args = []
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 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1360 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:CompleteFunc1Args)
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
1361 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1362
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
1363 #" Test for using a lambda function with set
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1364 VAR optval = "LSTART a, b LMIDDLE g:CompleteFunc1(16, a, b) LEND"
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
1365 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
1366 exe "set completefunc=" .. optval
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1367 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
1368 call setline(1, 'five')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1369 LET g:CompleteFunc1Args = []
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
1370 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1371 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:CompleteFunc1Args)
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
1372 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1373
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
1374 #" Set 'completefunc' to a lambda expression
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1375 LET &completefunc = LSTART a, b LMIDDLE g:CompleteFunc1(17, a, b) LEND
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1376 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
1377 call setline(1, 'six')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1378 LET g:CompleteFunc1Args = []
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
1379 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1380 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:CompleteFunc1Args)
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
1381 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
1382
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
1383 #" Set 'completefunc' to string(lambda_expression)
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1384 LET &completefunc = 'LSTART a, b LMIDDLE g:CompleteFunc1(18, a, b) LEND'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1385 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
1386 call setline(1, 'six')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1387 LET g:CompleteFunc1Args = []
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
1388 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1389 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:CompleteFunc1Args)
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
1390 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
1391
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 #" Set 'completefunc' to a variable with a lambda expression
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1393 VAR Lambda = LSTART a, b LMIDDLE g:CompleteFunc1(19, a, b) LEND
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
1394 LET &completefunc = Lambda
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1395 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
1396 call setline(1, 'seven')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1397 LET g:CompleteFunc1Args = []
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
1398 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1399 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:CompleteFunc1Args)
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
1400 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1401
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
1402 #" Set 'completefunc' to a string(variable with a lambda expression)
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1403 LET Lambda = LSTART a, b LMIDDLE g:CompleteFunc1(20, a, b) LEND
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
1404 LET &completefunc = string(Lambda)
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1405 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
1406 call setline(1, 'seven')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1407 LET g:CompleteFunc1Args = []
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
1408 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1409 call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:CompleteFunc1Args)
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
1410 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
1411
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 #" 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
1413 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
1414 LET &completefunc = Lambda
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1415 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
1416 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
1417 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
1418 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
1419
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
1420 #" 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
1421 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
1422 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
1423 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
1424 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
1425
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
1426 #" set 'completefunc' to a non-existing function
27464
a14c4d3e3260 patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 27457
diff changeset
1427 set completefunc=g:CompleteFunc2
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
1428 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
1429 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
1430 call assert_fails("LET &completefunc = function('NonExistingFunc')", 'E700:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1431 LET g:CompleteFunc2Args = []
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
1432 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1433 call assert_equal([[1, ''], [0, 'five']], g:CompleteFunc2Args)
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
1434 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
1435 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1436 call v9.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
1437
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1438 " Test for using a script-local function name
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1439 func s:CompleteFunc3(findstart, base)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1440 call add(g:CompleteFunc3Args, [a:findstart, a:base])
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1441 return a:findstart ? 0 : []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1442 endfunc
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1443 set completefunc=s:CompleteFunc3
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1444 new
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1445 call setline(1, 'script1')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1446 let g:CompleteFunc3Args = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1447 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1448 call assert_equal([[1, ''], [0, 'script1']], g:CompleteFunc3Args)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1449 bw!
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1450
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1451 let &completefunc = 's:CompleteFunc3'
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1452 new
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1453 call setline(1, 'script2')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1454 let g:CompleteFunc3Args = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1455 call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1456 call assert_equal([[1, ''], [0, 'script2']], g:CompleteFunc3Args)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1457 bw!
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1458 delfunc s:CompleteFunc3
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1459
27780
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1460 " In Vim9 script s: can be omitted
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1461 let lines =<< trim END
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1462 vim9script
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1463 var CompleteFunc4Args = []
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1464 def CompleteFunc4(findstart: bool, base: string): any
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1465 add(CompleteFunc4Args, [findstart, base])
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1466 return findstart ? 0 : []
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1467 enddef
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1468 set completefunc=CompleteFunc4
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1469 new
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1470 setline(1, 'script1')
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1471 feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1472 assert_equal([[1, ''], [0, 'script1']], CompleteFunc4Args)
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1473 bw!
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1474 END
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1475 call v9.CheckScriptSuccess(lines)
f1d5822ca0d7 patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
1476
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1477 " invalid return value
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
1478 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
1479 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
1480
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1481 " Using Vim9 lambda expression in legacy context should fail
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1482 set completefunc=(a,\ b)\ =>\ g:CompleteFunc1(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
1483 new | only
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1484 let g:CompleteFunc1Args = []
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1485 call assert_fails('call feedkeys("A\<C-X>\<C-U>\<Esc>", "x")', 'E117:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1486 call assert_equal([], g:CompleteFunc1Args)
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
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 " 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
1489 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
1490 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
1491 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
1492 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
1493 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
1494 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
1495 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
1496 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
1497 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
1498 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
1499 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
1500 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
1501 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
1502 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
1503 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
1504 %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
1505 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
1506 delfunc SetCompleteFunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1507
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1508 " Vim9 tests
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1509 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
1510 vim9script
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1511
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1512 def Vim9CompleteFunc(callnr: number, findstart: number, base: string): any
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1513 add(g:Vim9completeFuncArgs, [callnr, findstart, base])
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1514 return findstart ? 0 : []
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1515 enddef
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1516
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1517 # 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
1518 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
1519 new | only
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1520 setline(1, 'one')
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1521 g:Vim9completeFuncArgs = []
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1522 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
1523 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
1524 bw!
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1525
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1526 # Test for using a global function name
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1527 &completefunc = g:CompleteFunc2
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1528 new | only
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1529 setline(1, 'two')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1530 g:CompleteFunc2Args = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1531 feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1532 assert_equal([[1, ''], [0, 'two']], g:CompleteFunc2Args)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1533 bw!
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1534
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1535 # Test for using a script-local function name
27671
19367412787c patch 8.2.4361: Vim9: some tests fail
Bram Moolenaar <Bram@vim.org>
parents: 27474
diff changeset
1536 def LocalCompleteFunc(findstart: number, base: string): any
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1537 add(g:LocalCompleteFuncArgs, [findstart, base])
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1538 return findstart ? 0 : []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1539 enddef
27671
19367412787c patch 8.2.4361: Vim9: some tests fail
Bram Moolenaar <Bram@vim.org>
parents: 27474
diff changeset
1540 &completefunc = LocalCompleteFunc
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1541 new | only
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1542 setline(1, 'three')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1543 g:LocalCompleteFuncArgs = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1544 feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1545 assert_equal([[1, ''], [0, 'three']], g:LocalCompleteFuncArgs)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1546 bw!
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1547 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1548 call v9.CheckScriptSuccess(lines)
26452
65b4109a4297 patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
1549
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1550 " cleanup
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1551 set completefunc&
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1552 delfunc CompleteFunc1
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1553 delfunc CompleteFunc2
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1554 unlet g:CompleteFunc1Args g:CompleteFunc2Args
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1555 %bw!
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1556 endfunc
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1557
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1558 " 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
1559 func Test_omnifunc_callback()
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1560 func OmniFunc1(callnr, findstart, base)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1561 call add(g:OmniFunc1Args, [a:callnr, a:findstart, a:base])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1562 return a:findstart ? 0 : []
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1563 endfunc
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1564 func OmniFunc2(findstart, base)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1565 call add(g:OmniFunc2Args, [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
1566 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
1567 endfunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1568
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
1569 let lines =<< trim END
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1570 #" Test for using a function name
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1571 LET &omnifunc = 'g:OmniFunc2'
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1572 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1573 call setline(1, 'zero')
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1574 LET g:OmniFunc2Args = []
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1575 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1576 call assert_equal([[1, ''], [0, 'zero']], g:OmniFunc2Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1577 bw!
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1578
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
1579 #" Test for using a function()
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1580 set omnifunc=function('g:OmniFunc1',\ [10])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1581 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
1582 call setline(1, 'one')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1583 LET g:OmniFunc1Args = []
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
1584 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1585 call assert_equal([[10, 1, ''], [10, 0, 'one']], g:OmniFunc1Args)
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
1586 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1587
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
1588 #" Using a funcref variable to set 'omnifunc'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1589 VAR Fn = function('g:OmniFunc1', [11])
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
1590 LET &omnifunc = Fn
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1591 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
1592 call setline(1, 'two')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1593 LET g:OmniFunc1Args = []
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
1594 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1595 call assert_equal([[11, 1, ''], [11, 0, 'two']], g:OmniFunc1Args)
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
1596 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1597
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
1598 #" Using a string(funcref_variable) to set 'omnifunc'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1599 LET Fn = function('g:OmniFunc1', [12])
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
1600 LET &omnifunc = string(Fn)
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1601 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
1602 call setline(1, 'two')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1603 LET g:OmniFunc1Args = []
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
1604 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1605 call assert_equal([[12, 1, ''], [12, 0, 'two']], g:OmniFunc1Args)
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
1606 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
1607
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1608 #" Test for using a funcref()
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1609 set omnifunc=funcref('g:OmniFunc1',\ [13])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1610 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
1611 call setline(1, 'three')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1612 LET g:OmniFunc1Args = []
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
1613 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1614 call assert_equal([[13, 1, ''], [13, 0, 'three']], g:OmniFunc1Args)
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
1615 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1616
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
1617 #" Use let to set 'omnifunc' to a funcref
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1618 LET Fn = funcref('g:OmniFunc1', [14])
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
1619 LET &omnifunc = Fn
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1620 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
1621 call setline(1, 'four')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1622 LET g:OmniFunc1Args = []
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
1623 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1624 call assert_equal([[14, 1, ''], [14, 0, 'four']], g:OmniFunc1Args)
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
1625 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
1626
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
1627 #" Using a string(funcref) to set 'omnifunc'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1628 LET Fn = funcref("g:OmniFunc1", [15])
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
1629 LET &omnifunc = string(Fn)
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1630 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
1631 call setline(1, 'four')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1632 LET g:OmniFunc1Args = []
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
1633 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1634 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:OmniFunc1Args)
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
1635 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1636
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
1637 #" Test for using a lambda function with set
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1638 VAR optval = "LSTART a, b LMIDDLE g:OmniFunc1(16, a, b) LEND"
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
1639 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
1640 exe "set omnifunc=" .. optval
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1641 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
1642 call setline(1, 'five')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1643 LET g:OmniFunc1Args = []
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
1644 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1645 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:OmniFunc1Args)
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
1646 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1647
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
1648 #" Set 'omnifunc' to a lambda expression
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1649 LET &omnifunc = LSTART a, b LMIDDLE g:OmniFunc1(17, a, b) LEND
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1650 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
1651 call setline(1, 'six')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1652 LET g:OmniFunc1Args = []
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
1653 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1654 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:OmniFunc1Args)
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
1655 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
1656
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
1657 #" Set 'omnifunc' to a string(lambda_expression)
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1658 LET &omnifunc = 'LSTART a, b LMIDDLE g:OmniFunc1(18, a, b) LEND'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1659 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
1660 call setline(1, 'six')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1661 LET g:OmniFunc1Args = []
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
1662 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1663 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:OmniFunc1Args)
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
1664 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
1665
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1666 #" Set 'omnifunc' to a variable with a lambda expression
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1667 VAR Lambda = LSTART a, b LMIDDLE g:OmniFunc1(19, a, b) LEND
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
1668 LET &omnifunc = Lambda
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1669 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
1670 call setline(1, 'seven')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1671 LET g:OmniFunc1Args = []
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
1672 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1673 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:OmniFunc1Args)
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
1674 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1675
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
1676 #" Set 'omnifunc' to a string(variable with a lambda expression)
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1677 LET Lambda = LSTART a, b LMIDDLE g:OmniFunc1(20, a, b) LEND
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
1678 LET &omnifunc = string(Lambda)
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1679 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
1680 call setline(1, 'seven')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1681 LET g:OmniFunc1Args = []
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
1682 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1683 call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:OmniFunc1Args)
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
1684 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
1685
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1686 #" 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
1687 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
1688 LET &omnifunc = Lambda
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1689 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
1690 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
1691 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
1692 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
1693
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
1694 #" 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
1695 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
1696 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
1697 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
1698 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
1699
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
1700 #" set 'omnifunc' to a non-existing function
27464
a14c4d3e3260 patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 27457
diff changeset
1701 set omnifunc=g:OmniFunc2
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
1702 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
1703 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
1704 call assert_fails("LET &omnifunc = function('NonExistingFunc')", 'E700:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1705 LET g:OmniFunc2Args = []
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
1706 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1707 call assert_equal([[1, ''], [0, 'nine']], g:OmniFunc2Args)
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
1708 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
1709 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1710 call v9.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
1711
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1712 " Test for using a script-local function name
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1713 func s:OmniFunc3(findstart, base)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1714 call add(g:OmniFunc3Args, [a:findstart, a:base])
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1715 return a:findstart ? 0 : []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1716 endfunc
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1717 set omnifunc=s:OmniFunc3
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1718 new
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1719 call setline(1, 'script1')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1720 let g:OmniFunc3Args = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1721 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1722 call assert_equal([[1, ''], [0, 'script1']], g:OmniFunc3Args)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1723 bw!
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1724
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1725 let &omnifunc = 's:OmniFunc3'
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1726 new
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1727 call setline(1, 'script2')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1728 let g:OmniFunc3Args = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1729 call feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1730 call assert_equal([[1, ''], [0, 'script2']], g:OmniFunc3Args)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1731 bw!
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1732 delfunc s:OmniFunc3
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1733
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1734 " invalid return value
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
1735 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
1736 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
1737
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1738 " Using Vim9 lambda expression in legacy context should fail
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1739 set omnifunc=(a,\ b)\ =>\ OmniFunc1(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
1740 new | only
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1741 let g:OmniFunc1Args = []
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1742 call assert_fails('call feedkeys("A\<C-X>\<C-O>\<Esc>", "x")', 'E117:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1743 call assert_equal([], g:OmniFunc1Args)
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1744
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
1745 " 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
1746 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
1747 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
1748 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
1749 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
1750 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
1751 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
1752 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
1753 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
1754 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
1755 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
1756 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
1757 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
1758 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
1759 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
1760 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
1761 %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
1762 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
1763 delfunc SetOmniFunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1764
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1765 " Vim9 tests
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1766 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
1767 vim9script
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1768
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1769 def Vim9omniFunc(callnr: number, findstart: number, base: string): any
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1770 add(g:Vim9omniFunc_Args, [callnr, findstart, base])
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1771 return findstart ? 0 : []
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1772 enddef
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1773
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1774 # 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
1775 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
1776 new | only
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1777 setline(1, 'one')
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1778 g:Vim9omniFunc_Args = []
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1779 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
1780 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
1781 bw!
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1782
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1783 # Test for using a global function name
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1784 &omnifunc = g:OmniFunc2
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1785 new | only
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1786 setline(1, 'two')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1787 g:OmniFunc2Args = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1788 feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1789 assert_equal([[1, ''], [0, 'two']], g:OmniFunc2Args)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1790 bw!
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1791
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1792 # Test for using a script-local function name
27671
19367412787c patch 8.2.4361: Vim9: some tests fail
Bram Moolenaar <Bram@vim.org>
parents: 27474
diff changeset
1793 def LocalOmniFunc(findstart: number, base: string): any
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1794 add(g:LocalOmniFuncArgs, [findstart, base])
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1795 return findstart ? 0 : []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1796 enddef
27671
19367412787c patch 8.2.4361: Vim9: some tests fail
Bram Moolenaar <Bram@vim.org>
parents: 27474
diff changeset
1797 &omnifunc = LocalOmniFunc
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1798 new | only
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1799 setline(1, 'three')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1800 g:LocalOmniFuncArgs = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1801 feedkeys("A\<C-X>\<C-O>\<Esc>", 'x')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1802 assert_equal([[1, ''], [0, 'three']], g:LocalOmniFuncArgs)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1803 bw!
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1804 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1805 call v9.CheckScriptSuccess(lines)
26452
65b4109a4297 patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
1806
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1807 " cleanup
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1808 set omnifunc&
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1809 delfunc OmniFunc1
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1810 delfunc OmniFunc2
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1811 unlet g:OmniFunc1Args g:OmniFunc2Args
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1812 %bw!
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1813 endfunc
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1814
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1815 " 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
1816 func Test_thesaurusfunc_callback()
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1817 func TsrFunc1(callnr, findstart, base)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1818 call add(g:TsrFunc1Args, [a:callnr, 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
1819 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
1820 endfunc
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1821 func TsrFunc2(findstart, base)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1822 call add(g:TsrFunc2Args, [a:findstart, a:base])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1823 return a:findstart ? 0 : ['sunday']
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1824 endfunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
1825
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
1826 let lines =<< trim END
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1827 #" Test for using a function name
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1828 LET &thesaurusfunc = 'g:TsrFunc2'
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1829 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1830 call setline(1, 'zero')
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1831 LET g:TsrFunc2Args = []
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1832 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1833 call assert_equal([[1, ''], [0, 'zero']], g:TsrFunc2Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1834 bw!
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1835
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
1836 #" Test for using a function()
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1837 set thesaurusfunc=function('g:TsrFunc1',\ [10])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1838 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
1839 call setline(1, 'one')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1840 LET g:TsrFunc1Args = []
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
1841 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1842 call assert_equal([[10, 1, ''], [10, 0, 'one']], g:TsrFunc1Args)
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
1843 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1844
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
1845 #" Using a funcref variable to set 'thesaurusfunc'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1846 VAR Fn = function('g:TsrFunc1', [11])
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
1847 LET &thesaurusfunc = Fn
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1848 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
1849 call setline(1, 'two')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1850 LET g:TsrFunc1Args = []
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
1851 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1852 call assert_equal([[11, 1, ''], [11, 0, 'two']], g:TsrFunc1Args)
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
1853 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
1854
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1855 #" Using a string(funcref_variable) to set 'thesaurusfunc'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1856 LET Fn = function('g:TsrFunc1', [12])
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
1857 LET &thesaurusfunc = string(Fn)
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1858 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1859 call setline(1, 'two')
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1860 LET g:TsrFunc1Args = []
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1861 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1862 call assert_equal([[12, 1, ''], [12, 0, 'two']], g:TsrFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1863 bw!
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1864
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1865 #" Test for using a funcref()
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1866 set thesaurusfunc=funcref('g:TsrFunc1',\ [13])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1867 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1868 call setline(1, 'three')
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1869 LET g:TsrFunc1Args = []
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1870 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1871 call assert_equal([[13, 1, ''], [13, 0, 'three']], g:TsrFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1872 bw!
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1873
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1874 #" Using a funcref variable to set 'thesaurusfunc'
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1875 LET Fn = funcref('g:TsrFunc1', [14])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1876 LET &thesaurusfunc = Fn
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1877 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
1878 call setline(1, 'four')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1879 LET g:TsrFunc1Args = []
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
1880 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1881 call assert_equal([[14, 1, ''], [14, 0, 'four']], g:TsrFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1882 bw!
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1883
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1884 #" Using a string(funcref_variable) to set 'thesaurusfunc'
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1885 LET Fn = funcref('g:TsrFunc1', [15])
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1886 LET &thesaurusfunc = string(Fn)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1887 new
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1888 call setline(1, 'four')
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1889 LET g:TsrFunc1Args = []
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1890 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1891 call assert_equal([[15, 1, ''], [15, 0, 'four']], g:TsrFunc1Args)
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
1892 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1893
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
1894 #" Test for using a lambda function
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1895 VAR optval = "LSTART a, b LMIDDLE g:TsrFunc1(16, a, b) LEND"
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
1896 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
1897 exe "set thesaurusfunc=" .. optval
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1898 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
1899 call setline(1, 'five')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1900 LET g:TsrFunc1Args = []
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
1901 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1902 call assert_equal([[16, 1, ''], [16, 0, 'five']], g:TsrFunc1Args)
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
1903 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
1904
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
1905 #" Test for using a lambda function with set
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1906 LET &thesaurusfunc = LSTART a, b LMIDDLE g:TsrFunc1(17, a, b) LEND
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1907 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
1908 call setline(1, 'six')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1909 LET g:TsrFunc1Args = []
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
1910 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1911 call assert_equal([[17, 1, ''], [17, 0, 'six']], g:TsrFunc1Args)
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
1912 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1913
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
1914 #" Set 'thesaurusfunc' to a string(lambda expression)
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1915 LET &thesaurusfunc = 'LSTART a, b LMIDDLE g:TsrFunc1(18, a, b) LEND'
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1916 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
1917 call setline(1, 'six')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1918 LET g:TsrFunc1Args = []
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
1919 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1920 call assert_equal([[18, 1, ''], [18, 0, 'six']], g:TsrFunc1Args)
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
1921 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1922
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
1923 #" Set 'thesaurusfunc' to a variable with a lambda expression
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1924 VAR Lambda = LSTART a, b LMIDDLE g:TsrFunc1(19, a, b) LEND
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
1925 LET &thesaurusfunc = Lambda
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1926 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
1927 call setline(1, 'seven')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1928 LET g:TsrFunc1Args = []
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
1929 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1930 call assert_equal([[19, 1, ''], [19, 0, 'seven']], g:TsrFunc1Args)
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
1931 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
1932
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
1933 #" Set 'thesaurusfunc' to a string(variable with a lambda expression)
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1934 LET Lambda = LSTART a, b LMIDDLE g:TsrFunc1(20, a, b) LEND
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
1935 LET &thesaurusfunc = string(Lambda)
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1936 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
1937 call setline(1, 'seven')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1938 LET g:TsrFunc1Args = []
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
1939 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1940 call assert_equal([[20, 1, ''], [20, 0, 'seven']], g:TsrFunc1Args)
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
1941 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
1942
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1943 #" 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
1944 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
1945 LET &thesaurusfunc = Lambda
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1946 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
1947 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
1948 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
1949 bw!
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
1950
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
1951 #" 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
1952 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
1953 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
1954 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
1955 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
1956
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26456
diff changeset
1957 #" set 'thesaurusfunc' to a non-existing function
27464
a14c4d3e3260 patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents: 27457
diff changeset
1958 set thesaurusfunc=g:TsrFunc2
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
1959 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
1960 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
1961 call assert_fails("LET &thesaurusfunc = function('NonExistingFunc')", 'E700:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1962 LET g:TsrFunc2Args = []
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
1963 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1964 call assert_equal([[1, ''], [0, 'ten']], g:TsrFunc2Args)
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
1965 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
1966
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
1967 #" 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
1968 set thesaurusfunc&
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1969 setlocal thesaurusfunc=function('g:TsrFunc1',\ [22])
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
1970 call setline(1, 'sun')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1971 LET g:TsrFunc1Args = []
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
1972 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
1973 call assert_equal('sun', getline(1))
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1974 call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args)
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
1975 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
1976 call setline(1, 'sun')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1977 LET g:TsrFunc1Args = []
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
1978 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
1979 call assert_equal('sun', getline(1))
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1980 call assert_equal([], g:TsrFunc1Args)
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1981 set thesaurusfunc=function('g:TsrFunc1',\ [23])
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
1982 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
1983 call setline(1, 'sun')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1984 LET g:TsrFunc1Args = []
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
1985 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
1986 call assert_equal('sun', getline(1))
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1987 call assert_equal([[22, 1, ''], [22, 0, 'sun']], g:TsrFunc1Args)
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
1988 :%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
1989 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
1990 call v9.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
1991
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1992 " Test for using a script-local function name
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1993 func s:TsrFunc3(findstart, base)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1994 call add(g:TsrFunc3Args, [a:findstart, a:base])
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1995 return a:findstart ? 0 : []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1996 endfunc
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1997 set tsrfu=s:TsrFunc3
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1998 new
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
1999 call setline(1, 'script1')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2000 let g:TsrFunc3Args = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2001 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2002 call assert_equal([[1, ''], [0, 'script1']], g:TsrFunc3Args)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2003 bw!
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2004
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2005 let &tsrfu = 's:TsrFunc3'
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2006 new
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2007 call setline(1, 'script2')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2008 let g:TsrFunc3Args = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2009 call feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2010 call assert_equal([[1, ''], [0, 'script2']], g:TsrFunc3Args)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2011 bw!
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2012 delfunc s:TsrFunc3
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2013
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2014 " invalid return value
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
2015 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
2016 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
2017
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
2018 " Using Vim9 lambda expression in legacy context should fail
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
2019 set thesaurusfunc=(a,\ b)\ =>\ TsrFunc1(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
2020 new | only
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
2021 let g:TsrFunc1Args = []
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
2022 call assert_fails('call feedkeys("A\<C-X>\<C-T>\<Esc>", "x")', 'E117:')
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
2023 call assert_equal([], g:TsrFunc1Args)
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
2024 bw!
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
2025
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
2026 " 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
2027 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
2028 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
2029 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
2030 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
2031 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
2032 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
2033 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
2034 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
2035 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
2036 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
2037 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
2038 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
2039 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
2040 wincmd w
26452
65b4109a4297 patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
2041 %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
2042 delfunc SetTsrFunc
26452
65b4109a4297 patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents: 26441
diff changeset
2043
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
2044 " 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
2045 " 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
2046 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
2047 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
2048 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
2049 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
2050 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
2051 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
2052 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
2053 set thesaurusfunc=
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
2054 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
2055 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
2056 delfunc SetLocalTsrFunc
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
2057
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
2058 " Vim9 tests
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
2059 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
2060 vim9script
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
2061
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2062 def Vim9tsrFunc(callnr: number, findstart: number, base: string): any
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2063 add(g:Vim9tsrFunc_Args, [callnr, findstart, base])
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
2064 return findstart ? 0 : []
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
2065 enddef
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2066
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2067 # 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
2068 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
2069 new | only
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
2070 setline(1, 'one')
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
2071 g:Vim9tsrFunc_Args = []
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
2072 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
2073 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
2074 bw!
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2075
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2076 # Test for using a global function name
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2077 &thesaurusfunc = g:TsrFunc2
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2078 new | only
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2079 setline(1, 'two')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2080 g:TsrFunc2Args = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2081 feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2082 assert_equal([[1, ''], [0, 'two']], g:TsrFunc2Args)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2083 bw!
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2084
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2085 # Test for using a script-local function name
27671
19367412787c patch 8.2.4361: Vim9: some tests fail
Bram Moolenaar <Bram@vim.org>
parents: 27474
diff changeset
2086 def LocalTsrFunc(findstart: number, base: string): any
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2087 add(g:LocalTsrFuncArgs, [findstart, base])
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2088 return findstart ? 0 : []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2089 enddef
27671
19367412787c patch 8.2.4361: Vim9: some tests fail
Bram Moolenaar <Bram@vim.org>
parents: 27474
diff changeset
2090 &thesaurusfunc = LocalTsrFunc
26618
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2091 new | only
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2092 setline(1, 'three')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2093 g:LocalTsrFuncArgs = []
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2094 feedkeys("A\<C-X>\<C-T>\<Esc>", 'x')
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2095 assert_equal([[1, ''], [0, 'three']], g:LocalTsrFuncArgs)
b531c26f728b patch 8.2.3838: cannot use script-local function for setting *func options
Bram Moolenaar <Bram@vim.org>
parents: 26526
diff changeset
2096 bw!
26456
7eaf61a67d18 patch 8.2.3758: options that take a function insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26452
diff changeset
2097 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27016
diff changeset
2098 call v9.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
2099
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
2100 " cleanup
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
2101 set thesaurusfunc&
26526
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
2102 delfunc TsrFunc1
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
2103 delfunc TsrFunc2
33d680d372aa patch 8.2.3792: setting *func options insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
2104 unlet g:TsrFunc1Args g:TsrFunc2Args
26388
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
2105 %bw!
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
2106 endfunc
8aba638e91eb patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
2107
28369
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2108 func FooBarComplete(findstart, base)
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2109 if a:findstart
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2110 return col('.') - 1
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2111 else
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2112 return ["Foo", "Bar", "}"]
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2113 endif
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2114 endfunc
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2115
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2116 func Test_complete_smartindent()
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2117 new
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2118 setlocal smartindent completefunc=FooBarComplete
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2119
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2120 exe "norm! o{\<cr>\<c-x>\<c-u>\<c-p>}\<cr>\<esc>"
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2121 let result = getline(1,'$')
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2122 call assert_equal(['', '{','}',''], result)
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2123 bw!
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2124 delfunction! FooBarComplete
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2125 endfunc
38332c6da029 patch 8.2.4710: smart indenting does not work after completion
Bram Moolenaar <Bram@vim.org>
parents: 27954
diff changeset
2126
29355
796198629190 patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents: 29014
diff changeset
2127 func Test_complete_overrun()
796198629190 patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents: 29014
diff changeset
2128 " this was going past the end of the copied text
796198629190 patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents: 29014
diff changeset
2129 new
796198629190 patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents: 29014
diff changeset
2130 sil norm si”0s0 
796198629190 patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents: 29014
diff changeset
2131 bwipe!
796198629190 patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents: 29014
diff changeset
2132 endfunc
796198629190 patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents: 29014
diff changeset
2133
29406
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2134 func Test_infercase_very_long_line()
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2135 " this was truncating the line when inferring case
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2136 new
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2137 let longLine = "blah "->repeat(300)
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2138 let verylongLine = "blah "->repeat(400)
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2139 call setline(1, verylongLine)
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2140 call setline(2, longLine)
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2141 set ic infercase
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2142 exe "normal 2Go\<C-X>\<C-L>\<Esc>"
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2143 call assert_equal(longLine, getline(3))
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2144
29436
6888567953ca patch 9.0.0060: accessing uninitialized memory when completing long line
Bram Moolenaar <Bram@vim.org>
parents: 29408
diff changeset
2145 " check that the too long text is NUL terminated
6888567953ca patch 9.0.0060: accessing uninitialized memory when completing long line
Bram Moolenaar <Bram@vim.org>
parents: 29408
diff changeset
2146 %del
6888567953ca patch 9.0.0060: accessing uninitialized memory when completing long line
Bram Moolenaar <Bram@vim.org>
parents: 29408
diff changeset
2147 norm o
6888567953ca patch 9.0.0060: accessing uninitialized memory when completing long line
Bram Moolenaar <Bram@vim.org>
parents: 29408
diff changeset
2148 norm 1987ax
6888567953ca patch 9.0.0060: accessing uninitialized memory when completing long line
Bram Moolenaar <Bram@vim.org>
parents: 29408
diff changeset
2149 exec "norm ox\<C-X>\<C-L>"
6888567953ca patch 9.0.0060: accessing uninitialized memory when completing long line
Bram Moolenaar <Bram@vim.org>
parents: 29408
diff changeset
2150 call assert_equal(repeat('x', 1987), getline(3))
6888567953ca patch 9.0.0060: accessing uninitialized memory when completing long line
Bram Moolenaar <Bram@vim.org>
parents: 29408
diff changeset
2151
29406
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2152 bwipe!
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2153 set noic noinfercase
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2154 endfunc
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2155
29408
c12fb2c5b1b3 patch 9.0.0046: reading past end of completion with duplicate match
Bram Moolenaar <Bram@vim.org>
parents: 29406
diff changeset
2156 func Test_ins_complete_add()
c12fb2c5b1b3 patch 9.0.0046: reading past end of completion with duplicate match
Bram Moolenaar <Bram@vim.org>
parents: 29406
diff changeset
2157 " this was reading past the end of allocated memory
c12fb2c5b1b3 patch 9.0.0046: reading past end of completion with duplicate match
Bram Moolenaar <Bram@vim.org>
parents: 29406
diff changeset
2158 new
c12fb2c5b1b3 patch 9.0.0046: reading past end of completion with duplicate match
Bram Moolenaar <Bram@vim.org>
parents: 29406
diff changeset
2159 norm o
c12fb2c5b1b3 patch 9.0.0046: reading past end of completion with duplicate match
Bram Moolenaar <Bram@vim.org>
parents: 29406
diff changeset
2160 norm 7o€€
c12fb2c5b1b3 patch 9.0.0046: reading past end of completion with duplicate match
Bram Moolenaar <Bram@vim.org>
parents: 29406
diff changeset
2161 sil! norm o
c12fb2c5b1b3 patch 9.0.0046: reading past end of completion with duplicate match
Bram Moolenaar <Bram@vim.org>
parents: 29406
diff changeset
2162
c12fb2c5b1b3 patch 9.0.0046: reading past end of completion with duplicate match
Bram Moolenaar <Bram@vim.org>
parents: 29406
diff changeset
2163 bwipe!
c12fb2c5b1b3 patch 9.0.0046: reading past end of completion with duplicate match
Bram Moolenaar <Bram@vim.org>
parents: 29406
diff changeset
2164 endfunc
c12fb2c5b1b3 patch 9.0.0046: reading past end of completion with duplicate match
Bram Moolenaar <Bram@vim.org>
parents: 29406
diff changeset
2165
29521
f538704ca03b patch 9.0.0102: reading past end of line with insert mode completion
Bram Moolenaar <Bram@vim.org>
parents: 29501
diff changeset
2166 func Test_ins_complete_end_of_line()
f538704ca03b patch 9.0.0102: reading past end of line with insert mode completion
Bram Moolenaar <Bram@vim.org>
parents: 29501
diff changeset
2167 " this was reading past the end of the line
f538704ca03b patch 9.0.0102: reading past end of line with insert mode completion
Bram Moolenaar <Bram@vim.org>
parents: 29501
diff changeset
2168 new
f538704ca03b patch 9.0.0102: reading past end of line with insert mode completion
Bram Moolenaar <Bram@vim.org>
parents: 29501
diff changeset
2169 norm 8o€ý 
f538704ca03b patch 9.0.0102: reading past end of line with insert mode completion
Bram Moolenaar <Bram@vim.org>
parents: 29501
diff changeset
2170 sil! norm o
f538704ca03b patch 9.0.0102: reading past end of line with insert mode completion
Bram Moolenaar <Bram@vim.org>
parents: 29501
diff changeset
2171
f538704ca03b patch 9.0.0102: reading past end of line with insert mode completion
Bram Moolenaar <Bram@vim.org>
parents: 29501
diff changeset
2172 bwipe!
f538704ca03b patch 9.0.0102: reading past end of line with insert mode completion
Bram Moolenaar <Bram@vim.org>
parents: 29501
diff changeset
2173 endfunc
29406
979ce206409a patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents: 29369
diff changeset
2174
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19651
diff changeset
2175 " vim: shiftwidth=2 sts=2 expandtab