comparison src/testdir/test_iminsert.vim @ 27457:4c16acb2525f v8.2.4257

patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent Commit: https://github.com/vim/vim/commit/62aec93bfdb9e1b40d03a6d2e8e9511f8b1bdb2d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 29 21:45:34 2022 +0000 patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent Problem: Vim9: finding global function without g: prefix but not finding global variable is inconsistent. Solution: Require using g: for a global function. Change the vim9.vim script into a Vim9 script with exports. Fix that import in legacy script does not work.
author Bram Moolenaar <Bram@vim.org>
date Sat, 29 Jan 2022 23:00:05 +0100
parents 33d680d372aa
children 54247d52bee9
comparison
equal deleted inserted replaced
27456:a8e2d91995ce 27457:4c16acb2525f
1 " Test for 'iminsert' 1 " Test for 'iminsert'
2 2
3 source view_util.vim 3 source view_util.vim
4 source check.vim 4 source check.vim
5 source vim9.vim 5 import './vim9.vim' as v9
6 6
7 let s:imactivatefunc_called = 0 7 let s:imactivatefunc_called = 0
8 let s:imstatusfunc_called = 0 8 let s:imstatusfunc_called = 0
9 let s:imstatus_active = 0 9 let s:imstatus_active = 0
10 10
163 LET &imactivatefunc = string(Fn1) 163 LET &imactivatefunc = string(Fn1)
164 LET &imstatusfunc = string(Fn2) 164 LET &imstatusfunc = string(Fn2)
165 normal! i 165 normal! i
166 166
167 #" Test for using a lambda function 167 #" Test for using a lambda function
168 VAR optval = "LSTART a LMIDDLE IMactivatefunc1(a) LEND" 168 VAR optval = "LSTART a LMIDDLE g:IMactivatefunc1(a) LEND"
169 LET optval = substitute(optval, ' ', '\\ ', 'g') 169 LET optval = substitute(optval, ' ', '\\ ', 'g')
170 exe "set imactivatefunc=" .. optval 170 exe "set imactivatefunc=" .. optval
171 LET optval = "LSTART LMIDDLE IMstatusfunc1() LEND" 171 LET optval = "LSTART LMIDDLE g:IMstatusfunc1() LEND"
172 LET optval = substitute(optval, ' ', '\\ ', 'g') 172 LET optval = substitute(optval, ' ', '\\ ', 'g')
173 exe "set imstatusfunc=" .. optval 173 exe "set imstatusfunc=" .. optval
174 normal! i 174 normal! i
175 175
176 #" Set 'imactivatefunc' and 'imstatusfunc' to a lambda expression 176 #" Set 'imactivatefunc' and 'imstatusfunc' to a lambda expression
177 LET &imactivatefunc = LSTART a LMIDDLE IMactivatefunc1(a) LEND 177 LET &imactivatefunc = LSTART a LMIDDLE g:IMactivatefunc1(a) LEND
178 LET &imstatusfunc = LSTART LMIDDLE IMstatusfunc1() LEND 178 LET &imstatusfunc = LSTART LMIDDLE g:IMstatusfunc1() LEND
179 normal! i 179 normal! i
180 180
181 #" Set 'imactivatefunc' and 'imstatusfunc' to a string(lambda expression) 181 #" Set 'imactivatefunc' and 'imstatusfunc' to a string(lambda expression)
182 LET &imactivatefunc = 'LSTART a LMIDDLE IMactivatefunc1(a) LEND' 182 LET &imactivatefunc = 'LSTART a LMIDDLE g:IMactivatefunc1(a) LEND'
183 LET &imstatusfunc = 'LSTART LMIDDLE IMstatusfunc1() LEND' 183 LET &imstatusfunc = 'LSTART LMIDDLE g:IMstatusfunc1() LEND'
184 normal! i 184 normal! i
185 185
186 #" Set 'imactivatefunc' 'imstatusfunc' to a variable with a lambda 186 #" Set 'imactivatefunc' 'imstatusfunc' to a variable with a lambda
187 #" expression 187 #" expression
188 VAR Lambda1 = LSTART a LMIDDLE IMactivatefunc1(a) LEND 188 VAR Lambda1 = LSTART a LMIDDLE g:IMactivatefunc1(a) LEND
189 VAR Lambda2 = LSTART LMIDDLE IMstatusfunc1() LEND 189 VAR Lambda2 = LSTART LMIDDLE g:IMstatusfunc1() LEND
190 LET &imactivatefunc = Lambda1 190 LET &imactivatefunc = Lambda1
191 LET &imstatusfunc = Lambda2 191 LET &imstatusfunc = Lambda2
192 normal! i 192 normal! i
193 193
194 #" Set 'imactivatefunc' 'imstatusfunc' to a string(variable with a lambda 194 #" Set 'imactivatefunc' 'imstatusfunc' to a string(variable with a lambda
221 normal! i 221 normal! i
222 222
223 call assert_equal(14, g:IMactivatefunc_called) 223 call assert_equal(14, g:IMactivatefunc_called)
224 call assert_equal(28, g:IMstatusfunc_called) 224 call assert_equal(28, g:IMstatusfunc_called)
225 END 225 END
226 call CheckLegacyAndVim9Success(lines) 226 call v9.CheckLegacyAndVim9Success(lines)
227 227
228 " Using Vim9 lambda expression in legacy context should fail 228 " Using Vim9 lambda expression in legacy context should fail
229 set imactivatefunc=(a)\ =>\ IMactivatefunc1(a) 229 set imactivatefunc=(a)\ =>\ IMactivatefunc1(a)
230 set imstatusfunc=IMstatusfunc1 230 set imstatusfunc=IMstatusfunc1
231 call assert_fails('normal! i', 'E117:') 231 call assert_fails('normal! i', 'E117:')
283 283
284 set iminsert=0 284 set iminsert=0
285 set imactivatefunc= 285 set imactivatefunc=
286 set imstatusfunc= 286 set imstatusfunc=
287 END 287 END
288 call CheckScriptSuccess(lines) 288 call v9.CheckScriptSuccess(lines)
289 289
290 " cleanup 290 " cleanup
291 set iminsert=0 291 set iminsert=0
292 set imactivatefunc& 292 set imactivatefunc&
293 set imstatusfunc& 293 set imstatusfunc&