7
|
1 " Vim script language tests
|
|
2 " Author: Servatius Brandt <Servatius.Brandt@fujitsu-siemens.com>
|
95
|
3 " Last Change: 2005 Jan 11
|
7
|
4
|
|
5 "-------------------------------------------------------------------------------
|
|
6 " Test environment {{{1
|
|
7 "-------------------------------------------------------------------------------
|
|
8
|
|
9
|
|
10 " Adding new tests easily. {{{2
|
|
11 "
|
|
12 " Writing new tests is eased considerably with the following functions and
|
|
13 " abbreviations (see "Commands for recording the execution path", "Automatic
|
|
14 " argument generation").
|
|
15 "
|
|
16 " To get the abbreviations, execute the command
|
|
17 "
|
|
18 " :let test49_set_env = 1 | source test49.vim
|
|
19 "
|
|
20 " To get them always (from src/testdir), put a line
|
|
21 "
|
|
22 " au! BufRead test49.vim let test49_set_env = 1 | source test49.vim
|
|
23 "
|
|
24 " into the local .vimrc file in the src/testdir directory.
|
|
25 "
|
|
26 if exists("test49_set_env") && test49_set_env
|
|
27
|
|
28 " Automatic argument generation for the test environment commands.
|
|
29
|
|
30 function! Xsum()
|
|
31 let addend = substitute(getline("."), '^.*"\s*X:\s*\|^.*', '', "")
|
|
32 " Evaluate arithmetic expression.
|
|
33 if addend != ""
|
|
34 exec "let g:Xsum = g:Xsum + " . addend
|
|
35 endif
|
|
36 endfunction
|
|
37
|
|
38 function! Xcheck()
|
|
39 let g:Xsum=0
|
|
40 ?XpathINIT?,.call Xsum()
|
|
41 exec "norm A "
|
|
42 return g:Xsum
|
|
43 endfunction
|
|
44
|
|
45 iab Xcheck Xcheck<Space><C-R>=Xcheck()<CR><C-O>x
|
|
46
|
|
47 function! Xcomment(num)
|
|
48 let str = ""
|
|
49 let tabwidth = &sts ? &sts : &ts
|
|
50 let tabs = (48+tabwidth - a:num - virtcol(".")) / tabwidth
|
|
51 while tabs > 0
|
|
52 let str = str . "\t"
|
|
53 let tabs = tabs - 1
|
|
54 endwhile
|
|
55 let str = str . '" X:'
|
|
56 return str
|
|
57 endfunction
|
|
58
|
|
59 function! Xloop()
|
|
60 let back = line(".") . "|norm" . virtcol(".") . "|"
|
|
61 norm 0
|
|
62 let last = search('X\(loop\|path\)INIT\|Xloop\>', "bW")
|
|
63 exec back
|
|
64 let theline = getline(last)
|
|
65 if theline =~ 'X\(loop\|path\)INIT'
|
|
66 let num = 1
|
|
67 else
|
|
68 let num = 2 * substitute(theline, '.*Xloop\s*\(\d\+\).*', '\1', "")
|
|
69 endif
|
|
70 ?X\(loop\|path\)INIT?
|
|
71 \s/\(XloopINIT!\=\s*\d\+\s\+\)\@<=\(\d\+\)/\=2*submatch(2)/
|
|
72 exec back
|
|
73 exec "norm a "
|
|
74 return num . Xcomment(strlen(num))
|
|
75 endfunction
|
|
76
|
|
77 iab Xloop Xloop<Space><C-R>=Xloop()<CR><C-O>x
|
|
78
|
|
79 function! Xpath(loopinit)
|
|
80 let back = line(".") . "|norm" . virtcol(".") . "|"
|
|
81 norm 0
|
|
82 let last = search('XpathINIT\|Xpath\>\|XloopINIT', "bW")
|
|
83 exec back
|
|
84 let theline = getline(last)
|
|
85 if theline =~ 'XpathINIT'
|
|
86 let num = 1
|
|
87 elseif theline =~ 'Xpath\>'
|
|
88 let num = 2 * substitute(theline, '.*Xpath\s*\(\d\+\).*', '\1', "")
|
|
89 else
|
|
90 let pattern = '.*XloopINIT!\=\s*\(\d\+\)\s*\(\d\+\).*'
|
|
91 let num = substitute(theline, pattern, '\1', "")
|
|
92 let factor = substitute(theline, pattern, '\2', "")
|
|
93 " The "<C-O>x" from the "Xpath" iab and the character triggering its
|
|
94 " expansion are in the input buffer. Save and clear typeahead so
|
|
95 " that it is not read away by the call to "input()" below. Restore
|
|
96 " afterwards.
|
|
97 call inputsave()
|
|
98 let loops = input("Number of iterations in previous loop? ")
|
|
99 call inputrestore()
|
|
100 while (loops > 0)
|
|
101 let num = num * factor
|
|
102 let loops = loops - 1
|
|
103 endwhile
|
|
104 endif
|
|
105 exec "norm a "
|
|
106 if a:loopinit
|
|
107 return num . " 1"
|
|
108 endif
|
|
109 return num . Xcomment(strlen(num))
|
|
110 endfunction
|
|
111
|
|
112 iab Xpath Xpath<Space><C-R>=Xpath(0)<CR><C-O>x
|
|
113 iab XloopINIT XloopINIT<Space><C-R>=Xpath(1)<CR><C-O>x
|
|
114
|
|
115 " Also useful (see ExtraVim below):
|
|
116 aug ExtraVim
|
|
117 au!
|
|
118 au BufEnter <sfile> syn region ExtraVim
|
|
119 \ start=+^if\s\+ExtraVim(.*)+ end=+^endif+
|
|
120 \ transparent keepend
|
|
121 au BufEnter <sfile> syn match ExtraComment /^"/
|
|
122 \ contained containedin=ExtraVim
|
|
123 au BufEnter <sfile> hi link ExtraComment vimComment
|
|
124 aug END
|
|
125
|
|
126 aug Xpath
|
|
127 au BufEnter <sfile> syn keyword Xpath
|
|
128 \ XpathINIT Xpath XloopINIT Xloop XloopNEXT Xcheck Xout
|
|
129 au BufEnter <sfile> hi link Xpath Special
|
|
130 aug END
|
|
131
|
|
132 do BufEnter <sfile>
|
|
133
|
|
134 " Do not execute the tests when sourcing this file for getting the functions
|
|
135 " and abbreviations above, which are intended for easily adding new test
|
|
136 " cases; they are not needed for test execution. Unlet the variable
|
|
137 " controlling this so that an explicit ":source" command for this file will
|
|
138 " execute the tests.
|
|
139 unlet test49_set_env
|
|
140 finish
|
|
141
|
|
142 endif
|
|
143
|
|
144
|
|
145 " Commands for recording the execution path. {{{2
|
|
146 "
|
|
147 " The Xpath/Xloop commands can be used for computing the eXecution path by
|
|
148 " adding (different) powers of 2 from those script lines, for which the
|
|
149 " execution should be checked. Xloop provides different addends for each
|
|
150 " execution of a loop. Permittable values are 2^0 to 2^30, so that 31 execution
|
|
151 " points (multiply counted inside loops) can be tested.
|
|
152 "
|
|
153 " Note that the arguments of the following commands can be generated
|
|
154 " automatically, see below.
|
|
155 "
|
|
156 " Usage: {{{3
|
|
157 "
|
|
158 " - Use XpathINIT at the beginning of the test.
|
|
159 "
|
|
160 " - Use Xpath to check if a line is executed.
|
|
161 " Argument: power of 2 (decimal).
|
|
162 "
|
|
163 " - To check multiple execution of loops use Xloop for automatically
|
|
164 " computing Xpath values:
|
|
165 "
|
|
166 " - Use XloopINIT before the loop.
|
|
167 " Two arguments:
|
|
168 " - the first Xpath value (power of 2) to be used (Xnext),
|
|
169 " - factor for computing a new Xnext value when reexecuting a loop
|
|
170 " (by a ":continue" or ":endwhile"); this should be 2^n where
|
|
171 " n is the number of Xloop commands inside the loop.
|
|
172 " If XloopINIT! is used, the first execution of XloopNEXT is
|
|
173 " a no-operation.
|
|
174 "
|
|
175 " - Use Xloop inside the loop:
|
|
176 " One argument:
|
|
177 " The argument and the Xnext value are multiplied to build the
|
|
178 " next Xpath value. No new Xnext value is prepared. The argument
|
|
179 " should be 2^(n-1) for the nth Xloop command inside the loop.
|
|
180 " If the loop has only one Xloop command, the argument can be
|
|
181 " ommitted (default: 1).
|
|
182 "
|
|
183 " - Use XloopNEXT before ":continue" and ":endwhile". This computes a new
|
|
184 " Xnext value for the next execution of the loop by multiplying the old
|
|
185 " one with the factor specified in the XloopINIT command. No Argument.
|
|
186 " Alternatively, when XloopINIT! is used, a single XloopNEXT at the
|
|
187 " beginning of the loop can be used.
|
|
188 "
|
|
189 " Nested loops are not supported.
|
|
190 "
|
|
191 " - Use Xcheck at end of each test. It prints the test number, the expected
|
|
192 " execution path value, the test result ("OK" or "FAIL"), and, if the tests
|
|
193 " fails, the actual execution path.
|
|
194 " One argument:
|
|
195 " Expected Xpath/Xloop sum for the correct execution path.
|
|
196 " In order that this value can be computed automatically, do the
|
|
197 " following: For each line in the test with an Xpath and Xloop
|
|
198 " command, add a comment starting with "X:" and specifying an
|
|
199 " expression that evaluates to the value contributed by this line to
|
|
200 " the correct execution path. (For copying an Xpath argument of at
|
|
201 " least two digits into the comment, press <C-P>.) At the end of the
|
|
202 " test, just type "Xcheck" and press <Esc>.
|
|
203 "
|
|
204 " - In order to add additional information to the test output file, use the
|
|
205 " Xout command. Argument(s) like ":echo".
|
|
206 "
|
|
207 " Automatic argument generation: {{{3
|
|
208 "
|
|
209 " The arguments of the Xpath, XloopINIT, Xloop, and Xcheck commands can be
|
|
210 " generated automatically, so that new tests can easily be written without
|
|
211 " mental arithmetic. The Xcheck argument is computed from the "X:" comments
|
|
212 " of the preceding Xpath and Xloop commands. See the commands and
|
|
213 " abbreviations at the beginning of this file.
|
|
214 "
|
|
215 " Implementation: {{{3
|
|
216 " XpathINIT, Xpath, XloopINIT, Xloop, XloopNEXT, Xcheck, Xout.
|
|
217 "
|
|
218 " The variants for existing g:ExtraVimResult are needed when executing a script
|
|
219 " in an extra Vim process, see ExtraVim below.
|
|
220
|
|
221 " EXTRA_VIM_START - do not change or remove this line.
|
|
222
|
|
223 com! XpathINIT let g:Xpath = 0
|
|
224
|
|
225 if exists("g:ExtraVimResult")
|
|
226 com! -count -bar Xpath exec "!echo <count> >>" . g:ExtraVimResult
|
|
227 else
|
|
228 com! -count -bar Xpath let g:Xpath = g:Xpath + <count>
|
|
229 endif
|
|
230
|
|
231 com! -count -nargs=1 -bang
|
|
232 \ XloopINIT let g:Xnext = <count> |
|
|
233 \ let g:Xfactor = <args> |
|
|
234 \ let g:Xskip = strlen("<bang>")
|
|
235
|
|
236 if exists("g:ExtraVimResult")
|
|
237 com! -count=1 -bar Xloop exec "!echo " . (g:Xnext * <count>) . " >>" .
|
|
238 \ g:ExtraVimResult
|
|
239 else
|
|
240 com! -count=1 -bar Xloop let g:Xpath = g:Xpath + g:Xnext * <count>
|
|
241 endif
|
|
242
|
|
243 com! XloopNEXT let g:Xnext = g:Xnext *
|
|
244 \ (g:Xskip ? 1 : g:Xfactor) |
|
|
245 \ let g:Xskip = 0
|
|
246
|
|
247 let @r = ""
|
|
248 let Xtest = 1
|
|
249 com! -count Xcheck let Xresult = "*** Test " .
|
|
250 \ (Xtest<10?" ":Xtest<100?" ":"") .
|
|
251 \ Xtest . ": " . (
|
|
252 \ (Xpath==<count>) ? "OK (".Xpath.")" :
|
|
253 \ "FAIL (".Xpath." instead of <count>)"
|
|
254 \ ) |
|
|
255 \ let @R = Xresult . "\n" |
|
|
256 \ echo Xresult |
|
|
257 \ let Xtest = Xtest + 1
|
|
258
|
|
259 if exists("g:ExtraVimResult")
|
|
260 com! -nargs=+ Xout exec "exec \"!echo @R:'\" ."
|
|
261 \ 'substitute(substitute("' . <args> .
|
|
262 \ '", "' . "'" . '", ' . "'" . '&\\&&' . "'"
|
|
263 \ . ', "g"), "\n", "@NL@", "g")'
|
|
264 \ ". \"' >>\" . g:ExtraVimResult"
|
|
265 else
|
|
266 com! -nargs=+ Xout exec 'let @R = "--- Test ' .
|
|
267 \ (g:Xtest<10?" ":g:Xtest<100?" ":"") .
|
|
268 \ g:Xtest . ": " .
|
|
269 \ '" . substitute("' . <args> .
|
|
270 \ '", "\n", "&\t ", "g") . "\n"'
|
|
271 endif
|
|
272
|
|
273 " Switch off storing of lines for undoing changes. Speeds things up a little.
|
|
274 set undolevels=-1
|
|
275
|
|
276 " EXTRA_VIM_STOP - do not change or remove this line.
|
|
277
|
|
278
|
|
279 " ExtraVim() - Run a script file in an extra Vim process. {{{2
|
|
280 "
|
|
281 " This is useful for testing immediate abortion of the script processing due to
|
|
282 " an error in a command dynamically enclosed by a :try/:tryend region or when an
|
|
283 " exception is thrown but not caught or when an interrupt occurs. It can also
|
|
284 " be used for testing :finish.
|
|
285 "
|
|
286 " An interrupt location can be specified by an "INTERRUPT" comment. A number
|
|
287 " telling how often this location is reached (in a loop or in several function
|
|
288 " calls) should be specified as argument. When missing, once per script
|
|
289 " invocation or function call is assumed. INTERRUPT locations are tested by
|
|
290 " setting a breakpoint in that line and using the ">quit" debug command when
|
|
291 " the breakpoint is reached. A function for which an INTERRUPT location is
|
|
292 " specified must be defined before calling it (or executing it as a script by
|
|
293 " using ExecAsScript below).
|
|
294 "
|
|
295 " This function is only called in normal modus ("g:ExtraVimResult" undefined).
|
|
296 "
|
|
297 " Tests to be executed as an extra script should be written as follows:
|
|
298 "
|
|
299 " column 1 column 1
|
|
300 " | |
|
|
301 " v v
|
|
302 "
|
|
303 " XpathINIT XpathINIT
|
|
304 " if ExtraVim() if ExtraVim()
|
|
305 " ... " ...
|
|
306 " ... " ...
|
|
307 " endif endif
|
|
308 " Xcheck <number> Xcheck <number>
|
|
309 "
|
|
310 " Double quotes in column 1 are removed before the script is executed.
|
|
311 " They should be used if the test has unbalanced conditionals (:if/:endif,
|
|
312 " :while:/endwhile, :try/:endtry) or for a line with a syntax error. The
|
|
313 " extra script may use Xpath, XloopINIT, Xloop, XloopNEXT, and Xout as usual.
|
|
314 "
|
|
315 " A file name may be specified as argument. All messages of the extra Vim
|
|
316 " process are then redirected to the file. An existing file is overwritten.
|
|
317 "
|
|
318 let ExtraVimCount = 0
|
|
319 let ExtraVimBase = expand("<sfile>")
|
|
320 let ExtraVimTestEnv = ""
|
|
321 "
|
|
322 function! ExtraVim(...)
|
|
323 " Count how often this function is called.
|
|
324 let g:ExtraVimCount = g:ExtraVimCount + 1
|
|
325
|
|
326 " Disable folds to prevent that the ranges in the ":write" commands below
|
|
327 " are extended up to the end of a closed fold. This also speeds things up
|
|
328 " considerably.
|
|
329 set nofoldenable
|
|
330
|
|
331 " Open a buffer for this test script and copy the test environment to
|
|
332 " a temporary file. Take account of parts relevant for the extra script
|
|
333 " execution only.
|
|
334 let current_buffnr = bufnr("%")
|
|
335 execute "view +1" g:ExtraVimBase
|
|
336 if g:ExtraVimCount == 1
|
|
337 let g:ExtraVimTestEnv = tempname()
|
|
338 execute "/E" . "XTRA_VIM_START/+,/E" . "XTRA_VIM_STOP/-w"
|
|
339 \ g:ExtraVimTestEnv "|']+"
|
|
340 execute "/E" . "XTRA_VIM_START/+,/E" . "XTRA_VIM_STOP/-w >>"
|
|
341 \ g:ExtraVimTestEnv "|']+"
|
|
342 execute "/E" . "XTRA_VIM_START/+,/E" . "XTRA_VIM_STOP/-w >>"
|
|
343 \ g:ExtraVimTestEnv "|']+"
|
|
344 execute "/E" . "XTRA_VIM_START/+,/E" . "XTRA_VIM_STOP/-w >>"
|
|
345 \ g:ExtraVimTestEnv "|']+"
|
|
346 endif
|
|
347
|
|
348 " Start the extra Vim script with a ":source" command for the test
|
|
349 " environment. The source line number where the extra script will be
|
|
350 " appended, needs to be passed as variable "ExtraVimBegin" to the script.
|
|
351 let extra_script = tempname()
|
|
352 exec "!echo 'source " . g:ExtraVimTestEnv . "' >" . extra_script
|
|
353 let extra_begin = 1
|
|
354
|
|
355 " Starting behind the test environment, skip over the first g:ExtraVimCount
|
|
356 " occurrences of "if ExtraVim()" and copy the following lines up to the
|
|
357 " matching "endif" to the extra Vim script.
|
|
358 execute "/E" . "ND_OF_TEST_ENVIRONMENT/"
|
|
359 exec 'norm ' . g:ExtraVimCount . '/^\s*if\s\+ExtraVim(.*)/+' . "\n"
|
|
360 execute ".,/^endif/-write >>" . extra_script
|
|
361
|
|
362 " Open a buffer for the extra Vim script, delete all ^", and write the
|
|
363 " script if was actually modified.
|
|
364 execute "edit +" . (extra_begin + 1) extra_script
|
|
365 ,$s/^"//e
|
|
366 update
|
|
367
|
|
368 " Count the INTERRUPTs and build the breakpoint and quit commands.
|
|
369 let breakpoints = ""
|
|
370 let debug_quits = ""
|
|
371 let in_func = 0
|
|
372 exec extra_begin
|
|
373 while search(
|
|
374 \ '"\s*INTERRUPT\h\@!\|^\s*fu\%[nction]\>!\=\s*\%(\u\|s:\)\w*\s*(\|'
|
|
375 \ . '^\s*\\\|^\s*endf\%[unction]\>\|'
|
|
376 \ . '\%(^\s*fu\%[nction]!\=\s*\)\@<!\%(\u\|s:\)\w*\s*(\|'
|
|
377 \ . 'ExecAsScript\s\+\%(\u\|s:\)\w*',
|
|
378 \ "W") > 0
|
|
379 let theline = getline(".")
|
|
380 if theline =~ '^\s*fu'
|
|
381 " Function definition.
|
|
382 let in_func = 1
|
|
383 let func_start = line(".")
|
|
384 let func_name = substitute(theline,
|
|
385 \ '^\s*fu\%[nction]!\=\s*\(\%(\u\|s:\)\w*\).*', '\1', "")
|
|
386 let func_conts = 0
|
|
387 elseif theline =~ '^\s*\\'
|
|
388 if in_func
|
|
389 let func_conts = func_conts + 1
|
|
390 endif
|
|
391 elseif theline =~ '^\s*endf'
|
|
392 " End of function definition.
|
|
393 let in_func = 0
|
|
394 else
|
|
395 let finding = substitute(theline, '.*\(\%' . col(".") . 'c.*\)',
|
|
396 \ '\1', "")
|
|
397 if finding =~ '^"\s*INTERRUPT\h\@!'
|
|
398 " Interrupt comment. Compose as many quit commands as
|
|
399 " specified.
|
|
400 let cnt = substitute(finding,
|
|
401 \ '^"\s*INTERRUPT\s*\(\d*\).*$', '\1', "")
|
|
402 let quits = ""
|
|
403 while cnt > 0
|
|
404 " Use "\r" rather than "\n" to separate the quit commands.
|
|
405 " "\r" is not interpreted as command separator by the ":!"
|
|
406 " command below but works to separate commands in the
|
|
407 " external vim.
|
|
408 let quits = quits . "q\r"
|
|
409 let cnt = cnt - 1
|
|
410 endwhile
|
|
411 if in_func
|
|
412 " Add the function breakpoint and note the number of quits
|
|
413 " to be used, if specified, or one for every call else.
|
|
414 let breakpoints = breakpoints . " -c 'breakadd func " .
|
|
415 \ (line(".") - func_start - func_conts) . " " .
|
|
416 \ func_name . "'"
|
|
417 if quits != ""
|
|
418 let debug_quits = debug_quits . quits
|
|
419 elseif !exists("quits{func_name}")
|
|
420 let quits{func_name} = "q\r"
|
|
421 else
|
|
422 let quits{func_name} = quits{func_name} . "q\r"
|
|
423 endif
|
|
424 else
|
|
425 " Add the file breakpoint and the quits to be used for it.
|
|
426 let breakpoints = breakpoints . " -c 'breakadd file " .
|
|
427 \ line(".") . " " . extra_script . "'"
|
|
428 if quits == ""
|
|
429 let quits = "q\r"
|
|
430 endif
|
|
431 let debug_quits = debug_quits . quits
|
|
432 endif
|
|
433 else
|
|
434 " Add the quits to be used for calling the function or executing
|
|
435 " it as script file.
|
|
436 if finding =~ '^ExecAsScript'
|
|
437 " Sourcing function as script.
|
|
438 let finding = substitute(finding,
|
|
439 \ '^ExecAsScript\s\+\(\%(\u\|s:\)\w*\).*', '\1', "")
|
|
440 else
|
|
441 " Function call.
|
|
442 let finding = substitute(finding,
|
|
443 \ '^\(\%(\u\|s:\)\w*\).*', '\1', "")
|
|
444 endif
|
|
445 if exists("quits{finding}")
|
|
446 let debug_quits = debug_quits . quits{finding}
|
|
447 endif
|
|
448 endif
|
|
449 endif
|
|
450 endwhile
|
|
451
|
|
452 " Close the buffer for the script and create an (empty) resultfile.
|
|
453 bwipeout
|
|
454 let resultfile = tempname()
|
|
455 exec "!>" . resultfile
|
|
456
|
|
457 " Run the script in an extra vim. Switch to extra modus by passing the
|
|
458 " resultfile in ExtraVimResult. Redirect messages to the file specified as
|
|
459 " argument if any. Use ":debuggreedy" so that the commands provided on the
|
|
460 " pipe are consumed at the debug prompt. Use "-N" to enable command-line
|
|
461 " contiunation ("C" in 'cpo'). Add "nviminfo" to 'viminfo' to avoid
|
|
462 " messing up the user's viminfo file.
|
|
463 let redirect = a:0 ?
|
|
464 \ " -c 'au VimLeave * redir END' -c 'redir\\! >" . a:1 . "'" : ""
|
|
465 exec "!echo '" . debug_quits . "q' | ../vim -u NONE -N -Xes" . redirect .
|
|
466 \ " -c 'debuggreedy|set viminfo+=nviminfo'" .
|
|
467 \ " -c 'let ExtraVimBegin = " . extra_begin . "'" .
|
|
468 \ " -c 'let ExtraVimResult = \"" . resultfile . "\"'" . breakpoints .
|
|
469 \ " -S " . extra_script
|
|
470
|
|
471 " Build the resulting sum for resultfile and add it to g:Xpath. Add Xout
|
|
472 " information provided by the extra Vim process to the test output.
|
|
473 let sum = 0
|
|
474 exec "edit" resultfile
|
|
475 let line = 1
|
|
476 while line <= line("$")
|
|
477 let theline = getline(line)
|
|
478 if theline =~ '^@R:'
|
|
479 exec 'Xout "' . substitute(substitute(
|
|
480 \ escape(escape(theline, '"'), '\"'),
|
|
481 \ '^@R:', '', ""), '@NL@', "\n", "g") . '"'
|
|
482 else
|
|
483 let sum = sum + getline(line)
|
|
484 endif
|
|
485 let line = line + 1
|
|
486 endwhile
|
|
487 bwipeout
|
|
488 let g:Xpath = g:Xpath + sum
|
|
489
|
|
490 " Delete the extra script and the resultfile.
|
|
491 call delete(extra_script)
|
|
492 call delete(resultfile)
|
|
493
|
|
494 " Switch back to the buffer that was active when this function was entered.
|
|
495 exec "buffer" current_buffnr
|
|
496
|
|
497 " Return 0. This protects extra scripts from being run in the main Vim
|
|
498 " process.
|
|
499 return 0
|
|
500 endfunction
|
|
501
|
|
502
|
|
503 " ExtraVimThrowpoint() - Relative throwpoint in ExtraVim script {{{2
|
|
504 "
|
|
505 " Evaluates v:throwpoint and returns the throwpoint relativ to the beginning of
|
|
506 " an ExtraVim script as passed by ExtraVim() in ExtraVimBegin.
|
|
507 "
|
|
508 " EXTRA_VIM_START - do not change or remove this line.
|
|
509 function! ExtraVimThrowpoint()
|
|
510 if !exists("g:ExtraVimBegin")
|
|
511 Xout "ExtraVimThrowpoint() used outside ExtraVim() script."
|
|
512 return v:throwpoint
|
|
513 endif
|
|
514
|
|
515 if v:throwpoint =~ '^function\>'
|
|
516 return v:throwpoint
|
|
517 endif
|
|
518
|
|
519 return "line " .
|
|
520 \ (substitute(v:throwpoint, '.*, line ', '', "") - g:ExtraVimBegin) .
|
|
521 \ " of ExtraVim() script"
|
|
522 endfunction
|
|
523 " EXTRA_VIM_STOP - do not change or remove this line.
|
|
524
|
|
525
|
|
526 " MakeScript() - Make a script file from a function. {{{2
|
|
527 "
|
|
528 " Create a script that consists of the body of the function a:funcname.
|
|
529 " Replace any ":return" by a ":finish", any argument variable by a global
|
|
530 " variable, and and every ":call" by a ":source" for the next following argument
|
|
531 " in the variable argument list. This function is useful if similar tests are
|
|
532 " to be made for a ":return" from a function call or a ":finish" in a script
|
|
533 " file.
|
|
534 "
|
|
535 " In order to execute a function specifying an INTERRUPT location (see ExtraVim)
|
|
536 " as a script file, use ExecAsScript below.
|
|
537 "
|
|
538 " EXTRA_VIM_START - do not change or remove this line.
|
|
539 function! MakeScript(funcname, ...)
|
|
540 let script = tempname()
|
|
541 execute "redir! >" . script
|
|
542 execute "function" a:funcname
|
|
543 redir END
|
|
544 execute "edit" script
|
|
545 " Delete the "function" and the "endfunction" lines. Do not include the
|
|
546 " word "function" in the pattern since it might be translated if LANG is
|
|
547 " set. When MakeScript() is being debugged, this deletes also the debugging
|
|
548 " output of its line 3 and 4.
|
|
549 exec '1,/.*' . a:funcname . '(.*)/d'
|
|
550 /^\d*\s*endfunction\>/,$d
|
|
551 %s/^\d*//e
|
|
552 %s/return/finish/e
|
|
553 %s/\<a:\(\h\w*\)/g:\1/ge
|
|
554 normal gg0
|
|
555 let cnt = 0
|
|
556 while search('\<call\s*\%(\u\|s:\)\w*\s*(.*)', 'W') > 0
|
|
557 let cnt = cnt + 1
|
|
558 s/\<call\s*\%(\u\|s:\)\w*\s*(.*)/\='source ' . a:{cnt}/
|
|
559 endwhile
|
|
560 g/^\s*$/d
|
|
561 write
|
|
562 bwipeout
|
|
563 return script
|
|
564 endfunction
|
|
565 " EXTRA_VIM_STOP - do not change or remove this line.
|
|
566
|
|
567
|
|
568 " ExecAsScript - Source a temporary script made from a function. {{{2
|
|
569 "
|
|
570 " Make a temporary script file from the function a:funcname, ":source" it, and
|
|
571 " delete it afterwards.
|
|
572 "
|
|
573 " When inside ":if ExtraVim()", add a file breakpoint for each INTERRUPT
|
|
574 " location specified in the function.
|
|
575 "
|
|
576 " EXTRA_VIM_START - do not change or remove this line.
|
|
577 function! ExecAsScript(funcname)
|
|
578 " Make a script from the function passed as argument.
|
|
579 let script = MakeScript(a:funcname)
|
|
580
|
|
581 " When running in an extra Vim process, add a file breakpoint for each
|
|
582 " function breakpoint set when the extra Vim process was invoked by
|
|
583 " ExtraVim().
|
|
584 if exists("g:ExtraVimResult")
|
|
585 let bplist = tempname()
|
|
586 execute "redir! >" . bplist
|
|
587 breaklist
|
|
588 redir END
|
|
589 execute "edit" bplist
|
|
590 " Get the line number from the function breakpoint. Works also when
|
|
591 " LANG is set.
|
|
592 execute 'v/^\s*\d\+\s\+func\s\+' . a:funcname . '\s.*/d'
|
|
593 %s/^\s*\d\+\s\+func\s\+\%(\u\|s:\)\w*\s\D*\(\d*\).*/\1/e
|
|
594 let cnt = 0
|
|
595 while cnt < line("$")
|
|
596 let cnt = cnt + 1
|
|
597 if getline(cnt) != ""
|
|
598 execute "breakadd file" getline(cnt) script
|
|
599 endif
|
|
600 endwhile
|
|
601 bwipeout!
|
|
602 call delete(bplist)
|
|
603 endif
|
|
604
|
|
605 " Source and delete the script.
|
|
606 exec "source" script
|
|
607 call delete(script)
|
|
608 endfunction
|
|
609
|
|
610 com! -nargs=1 -bar ExecAsScript call ExecAsScript(<f-args>)
|
|
611 " EXTRA_VIM_STOP - do not change or remove this line.
|
|
612
|
|
613
|
|
614 " END_OF_TEST_ENVIRONMENT - do not change or remove this line.
|
|
615
|
|
616
|
|
617 "-------------------------------------------------------------------------------
|
|
618 " Test 1: :endwhile in function {{{1
|
|
619 "
|
|
620 " Detect if a broken loop is (incorrectly) reactivated by the
|
|
621 " :endwhile. Use a :return to prevent an endless loop, and make
|
|
622 " this test first to get a meaningful result on an error before other
|
|
623 " tests will hang.
|
|
624 "-------------------------------------------------------------------------------
|
|
625
|
|
626 XpathINIT
|
|
627
|
|
628 function! F()
|
|
629 Xpath 1 " X: 1
|
|
630 let first = 1
|
|
631 XloopINIT 2 8
|
|
632 while 1
|
|
633 Xloop 1 " X: 2 + 0 * 16
|
|
634 if first
|
|
635 Xloop 2 " X: 4 + 0 * 32
|
|
636 let first = 0
|
|
637 XloopNEXT
|
|
638 break
|
|
639 else
|
|
640 Xloop 4 " X: 0 + 0 * 64
|
|
641 return
|
|
642 endif
|
|
643 endwhile
|
|
644 endfunction
|
|
645
|
|
646 call F()
|
|
647 Xpath 128 " X: 128
|
|
648
|
|
649 function! G()
|
|
650 Xpath 256 " X: 256 + 0 * 2048
|
|
651 let first = 1
|
|
652 XloopINIT 512 8
|
|
653 while 1
|
|
654 Xloop 1 " X: 512 + 0 * 4096
|
|
655 if first
|
|
656 Xloop 2 " X: 1024 + 0 * 8192
|
|
657 let first = 0
|
|
658 XloopNEXT
|
|
659 break
|
|
660 else
|
|
661 Xloop 4 " X: 0 + 0 * 16384
|
|
662 return
|
|
663 endif
|
|
664 if 1 " unmatched :if
|
|
665 endwhile
|
|
666 endfunction
|
|
667
|
|
668 call G()
|
|
669 Xpath 32768 " X: 32768
|
|
670
|
|
671 Xcheck 34695
|
|
672
|
|
673 " Leave F and G for execution as scripts in the next test.
|
|
674
|
|
675
|
|
676 "-------------------------------------------------------------------------------
|
|
677 " Test 2: :endwhile in script {{{1
|
|
678 "
|
|
679 " Detect if a broken loop is (incorrectly) reactivated by the
|
|
680 " :endwhile. Use a :finish to prevent an endless loop, and place
|
|
681 " this test before others that might hang to get a meaningful result
|
|
682 " on an error.
|
|
683 "
|
|
684 " This test executes the bodies of the functions F and G from the
|
|
685 " previous test as script files (:return replaced by :finish).
|
|
686 "-------------------------------------------------------------------------------
|
|
687
|
|
688 XpathINIT
|
|
689
|
|
690 ExecAsScript F " X: 1 + 2 + 4
|
|
691 Xpath 128 " X: 128
|
|
692
|
|
693 ExecAsScript G " X: 256 + 512 + 1024
|
|
694 Xpath 32768 " X: 32768
|
|
695
|
|
696 unlet first
|
|
697 delfunction F
|
|
698 delfunction G
|
|
699
|
|
700 Xcheck 34695
|
|
701
|
|
702
|
|
703 "-------------------------------------------------------------------------------
|
|
704 " Test 3: :if, :elseif, :while, :continue, :break {{{1
|
|
705 "-------------------------------------------------------------------------------
|
|
706
|
|
707 XpathINIT
|
|
708 if 1
|
|
709 Xpath 1 " X: 1
|
|
710 let loops = 3
|
|
711 XloopINIT 2 512
|
|
712 while loops > -1 " main loop: loops == 3, 2, 1 (which breaks)
|
|
713 if loops <= 0
|
|
714 let break_err = 1
|
|
715 let loops = -1
|
|
716 else " 3: 2: 1:
|
|
717 Xloop 1 " X: 2 + 2*512 + 2*512*512
|
|
718 endif
|
|
719 if (loops == 2)
|
|
720 while loops == 2 " dummy loop
|
|
721 Xloop 2 " X: 4*512
|
|
722 let loops = loops - 1
|
|
723 continue " stop dummy loop
|
|
724 Xloop 4 " X: 0
|
|
725 endwhile
|
|
726 XloopNEXT
|
|
727 continue " continue main loop
|
|
728 Xloop 8 " X: 0
|
|
729 elseif (loops == 1)
|
|
730 let p = 1
|
|
731 while p " dummy loop
|
|
732 Xloop 16 " X: 32*512*512
|
|
733 let p = 0
|
|
734 break " break dummy loop
|
|
735 Xloop 32 " X: 0
|
|
736 endwhile
|
|
737 Xloop 64 " X: 128*512*512
|
|
738 unlet p
|
|
739 break " break main loop
|
|
740 Xloop 128 " X: 0
|
|
741 endif
|
|
742 if (loops > 0)
|
|
743 Xloop 256 " X: 512
|
|
744 endif
|
|
745 while loops == 3 " dummy loop
|
|
746 let loops = loops - 1
|
|
747 endwhile " end dummy loop
|
|
748 XloopNEXT
|
|
749 endwhile " end main loop
|
|
750 Xpath 268435456 " X: 1024*512*512
|
|
751 else
|
|
752 Xpath 536870912 " X: 0
|
|
753 endif
|
|
754 Xpath 1073741824 " X: 4096*512*512
|
|
755 if exists("break_err")
|
|
756 " The Xpath command does not accept 2^31 (negative); add explicitly:
|
|
757 let Xpath = Xpath + 2147483648 " X: 0
|
|
758 unlet break_err
|
|
759 endif
|
|
760
|
|
761 unlet loops
|
|
762
|
|
763 Xcheck 1384648195
|
|
764
|
|
765
|
|
766 "-------------------------------------------------------------------------------
|
|
767 " Test 4: :return {{{1
|
|
768 "-------------------------------------------------------------------------------
|
|
769
|
|
770 XpathINIT
|
|
771
|
|
772 function! F()
|
|
773 if 1
|
|
774 Xpath 1 " X: 1
|
|
775 let loops = 3
|
|
776 XloopINIT 2 16
|
|
777 while loops > 0 " 3: 2: 1:
|
|
778 Xloop 1 " X: 2 + 2*16 + 0*16*16
|
|
779 if (loops == 2)
|
|
780 Xloop 2 " X: 4*16
|
|
781 return
|
|
782 Xloop 4 " X: 0
|
|
783 endif
|
|
784 Xloop 8 " X: 16
|
|
785 let loops = loops - 1
|
|
786 XloopNEXT
|
|
787 endwhile
|
|
788 Xpath 8192 " X: 0
|
|
789 else
|
|
790 Xpath 16384 " X: 0
|
|
791 endif
|
|
792 endfunction
|
|
793
|
|
794 call F()
|
|
795 Xpath 32768 " X: 8*16*16*16
|
|
796
|
|
797 Xcheck 32883
|
|
798
|
|
799 " Leave F for execution as a script in the next test.
|
|
800
|
|
801
|
|
802 "-------------------------------------------------------------------------------
|
|
803 " Test 5: :finish {{{1
|
|
804 "
|
|
805 " This test executes the body of the function F from the previous test
|
|
806 " as a script file (:return replaced by :finish).
|
|
807 "-------------------------------------------------------------------------------
|
|
808
|
|
809 XpathINIT
|
|
810
|
|
811 ExecAsScript F " X: 1 + 2 + 2*16 + 4*16 + 16
|
|
812 Xpath 32768 " X: 32768
|
|
813
|
|
814 unlet loops
|
|
815 delfunction F
|
|
816
|
|
817 Xcheck 32883
|
|
818
|
|
819
|
|
820 "-------------------------------------------------------------------------------
|
|
821 " Test 6: Defining functions in :while loops {{{1
|
|
822 "
|
|
823 " Functions can be defined inside other functions. An inner function
|
|
824 " gets defined when the outer function is executed. Functions may
|
|
825 " also be defined inside while loops. Expressions in braces for
|
|
826 " defining the function name are allowed.
|
|
827 "-------------------------------------------------------------------------------
|
|
828
|
|
829 XpathINIT
|
|
830
|
|
831 if ExtraVim()
|
|
832
|
|
833 " The command CALL collects the argument of all its invocations in "calls"
|
|
834 " when used from a function (that is, when the global variable "calls" needs
|
|
835 " the "g:" prefix). This is to check that the function code is skipped when
|
|
836 " the function is defined. For inner functions, do so only if the outer
|
|
837 " function is not being executed.
|
|
838 "
|
|
839 let calls = ""
|
|
840 com! -nargs=1 CALL
|
|
841 \ if !exists("calls") && !exists("outer") |
|
|
842 \ let g:calls = g:calls . <args> |
|
|
843 \ endif
|
|
844
|
|
845
|
|
846 XloopINIT! 1 16
|
|
847
|
|
848 let i = 0
|
|
849 while i < 3
|
|
850
|
|
851 XloopNEXT
|
|
852 let i = i + 1
|
|
853
|
|
854 if i == 1
|
|
855 Xloop 1 " X: 1
|
|
856 function! F1(arg)
|
|
857 CALL a:arg
|
|
858 let outer = 1
|
|
859
|
|
860 XloopINIT! 4096 4
|
|
861 let j = 0
|
|
862 while j < 1
|
|
863 XloopNEXT
|
|
864 Xloop 1 " X: 4096
|
|
865 let j = j + 1
|
|
866 function! G1(arg)
|
|
867 CALL a:arg
|
|
868 endfunction
|
|
869 Xloop 2 " X: 8192
|
|
870 endwhile
|
|
871 endfunction
|
|
872 Xloop 2 " X: 2
|
|
873
|
|
874 continue
|
|
875 endif
|
|
876
|
|
877 Xloop 4 " X: 4 * (16 + 256)
|
|
878 function! F{i}(i, arg)
|
|
879 CALL a:arg
|
|
880 let outer = 1
|
|
881
|
|
882 XloopINIT! 16384 4
|
|
883 if a:i == 3
|
|
884 XloopNEXT
|
|
885 XloopNEXT
|
|
886 XloopNEXT
|
|
887 endif
|
|
888 let k = 0
|
|
889 while k < 3
|
|
890 XloopNEXT
|
|
891 Xloop 1 " X: 16384*(1+4+16+64+256+1024)
|
|
892 let k = k + 1
|
|
893 function! G{a:i}{k}(arg)
|
|
894 CALL a:arg
|
|
895 endfunction
|
|
896 Xloop 2 " X: 32768*(1+4+16+64+256+1024)
|
|
897 endwhile
|
|
898 endfunction
|
|
899 Xloop 8 " X: 8 * (16 + 256)
|
|
900
|
|
901 endwhile
|
|
902
|
|
903 if exists("*G1")
|
|
904 Xpath 67108864 " X: 0
|
|
905 endif
|
|
906 if exists("*F1")
|
|
907 call F1("F1")
|
|
908 if exists("*G1")
|
|
909 call G1("G1")
|
|
910 endif
|
|
911 endif
|
|
912
|
|
913 if exists("G21") || exists("G21") || exists("G21")
|
|
914 Xpath 134217728 " X: 0
|
|
915 endif
|
|
916 if exists("*F2")
|
|
917 call F2(2, "F2")
|
|
918 if exists("*G21")
|
|
919 call G21("G21")
|
|
920 endif
|
|
921 if exists("*G22")
|
|
922 call G22("G22")
|
|
923 endif
|
|
924 if exists("*G23")
|
|
925 call G23("G23")
|
|
926 endif
|
|
927 endif
|
|
928
|
|
929 if exists("G31") || exists("G31") || exists("G31")
|
|
930 Xpath 268435456 " X: 0
|
|
931 endif
|
|
932 if exists("*F3")
|
|
933 call F3(3, "F3")
|
|
934 if exists("*G31")
|
|
935 call G31("G31")
|
|
936 endif
|
|
937 if exists("*G32")
|
|
938 call G32("G32")
|
|
939 endif
|
|
940 if exists("*G33")
|
|
941 call G33("G33")
|
|
942 endif
|
|
943 endif
|
|
944
|
|
945 Xpath 536870912 " X: 536870912
|
|
946
|
|
947 if calls != "F1G1F2G21G22G23F3G31G32G33"
|
|
948 Xpath 1073741824 " X: 0
|
|
949 Xout "calls is" calls
|
|
950 endif
|
|
951
|
|
952 delfunction F1
|
|
953 delfunction G1
|
|
954 delfunction F2
|
|
955 delfunction G21
|
|
956 delfunction G22
|
|
957 delfunction G23
|
|
958 delfunction G31
|
|
959 delfunction G32
|
|
960 delfunction G33
|
|
961
|
|
962 endif
|
|
963
|
|
964 Xcheck 603978947
|
|
965
|
|
966
|
|
967 "-------------------------------------------------------------------------------
|
|
968 " Test 7: Continuing on errors outside functions {{{1
|
|
969 "
|
|
970 " On an error outside a function, the script processing continues
|
|
971 " at the line following the outermost :endif or :endwhile. When not
|
|
972 " inside an :if or :while, the script processing continues at the next
|
|
973 " line.
|
|
974 "-------------------------------------------------------------------------------
|
|
975
|
|
976 XpathINIT
|
|
977
|
|
978 if 1
|
|
979 Xpath 1 " X: 1
|
|
980 while 1
|
|
981 Xpath 2 " X: 2
|
|
982 asdf
|
|
983 Xpath 4 " X: 0
|
|
984 break
|
|
985 endwhile | Xpath 8 " X: 0
|
|
986 Xpath 16 " X: 0
|
|
987 endif | Xpath 32 " X: 0
|
|
988 Xpath 64 " X: 64
|
|
989
|
|
990 while 1
|
|
991 Xpath 128 " X: 128
|
|
992 if 1
|
|
993 Xpath 256 " X: 256
|
|
994 asdf
|
|
995 Xpath 512 " X: 0
|
|
996 endif | Xpath 1024 " X: 0
|
|
997 Xpath 2048 " X: 0
|
|
998 break
|
|
999 endwhile | Xpath 4096 " X: 0
|
|
1000 Xpath 8192 " X: 8192
|
|
1001
|
|
1002 asdf
|
|
1003 Xpath 16384 " X: 16384
|
|
1004
|
|
1005 asdf | Xpath 32768 " X: 0
|
|
1006 Xpath 65536 " X: 65536
|
|
1007
|
|
1008 Xcheck 90563
|
|
1009
|
|
1010
|
|
1011 "-------------------------------------------------------------------------------
|
|
1012 " Test 8: Aborting and continuing on errors inside functions {{{1
|
|
1013 "
|
|
1014 " On an error inside a function without the "abort" attribute, the
|
|
1015 " script processing continues at the next line (unless the error was
|
|
1016 " in a :return command). On an error inside a function with the
|
|
1017 " "abort" attribute, the function is aborted and the script processing
|
|
1018 " continues after the function call; the value -1 is returned then.
|
|
1019 "-------------------------------------------------------------------------------
|
|
1020
|
|
1021 XpathINIT
|
|
1022
|
|
1023 function! F()
|
|
1024 if 1
|
|
1025 Xpath 1 " X: 1
|
|
1026 while 1
|
|
1027 Xpath 2 " X: 2
|
|
1028 asdf
|
|
1029 Xpath 4 " X: 4
|
|
1030 asdf | Xpath 8 " X: 0
|
|
1031 Xpath 16 " X: 16
|
|
1032 break
|
|
1033 endwhile
|
|
1034 Xpath 32 " X: 32
|
|
1035 endif | Xpath 64 " X: 64
|
|
1036 Xpath 128 " X: 128
|
|
1037
|
|
1038 while 1
|
|
1039 Xpath 256 " X: 256
|
|
1040 if 1
|
|
1041 Xpath 512 " X: 512
|
|
1042 asdf
|
|
1043 Xpath 1024 " X: 1024
|
|
1044 asdf | Xpath 2048 " X: 0
|
|
1045 Xpath 4096 " X: 4096
|
|
1046 endif
|
|
1047 Xpath 8192 " X: 8192
|
|
1048 break
|
|
1049 endwhile | Xpath 16384 " X: 16384
|
|
1050 Xpath 32768 " X: 32768
|
|
1051
|
|
1052 return novar " returns (default return value 0)
|
|
1053 Xpath 65536 " X: 0
|
|
1054 return 1 " not reached
|
|
1055 endfunction
|
|
1056
|
|
1057 function! G() abort
|
|
1058 if 1
|
|
1059 Xpath 131072 " X: 131072
|
|
1060 while 1
|
|
1061 Xpath 262144 " X: 262144
|
|
1062 asdf " returns -1
|
|
1063 Xpath 524288 " X: 0
|
|
1064 break
|
|
1065 endwhile
|
|
1066 Xpath 1048576 " X: 0
|
|
1067 endif | Xpath 2097152 " X: 0
|
|
1068 Xpath Xpath 4194304 " X: 0
|
|
1069
|
|
1070 return -4 " not reached
|
|
1071 endfunction
|
|
1072
|
|
1073 function! H() abort
|
|
1074 while 1
|
|
1075 Xpath 8388608 " X: 8388608
|
|
1076 if 1
|
|
1077 Xpath 16777216 " X: 16777216
|
|
1078 asdf " returns -1
|
|
1079 Xpath 33554432 " X: 0
|
|
1080 endif
|
|
1081 Xpath 67108864 " X: 0
|
|
1082 break
|
|
1083 endwhile | Xpath 134217728 " X: 0
|
|
1084 Xpath 268435456 " X: 0
|
|
1085
|
|
1086 return -4 " not reached
|
|
1087 endfunction
|
|
1088
|
|
1089 " Aborted functions (G and H) return -1.
|
|
1090 let sum = (F() + 1) - 4*G() - 8*H()
|
|
1091 Xpath 536870912 " X: 536870912
|
|
1092 if sum != 13
|
|
1093 Xpath 1073741824 " X: 0
|
|
1094 Xout "sum is" sum
|
|
1095 endif
|
|
1096
|
|
1097 unlet sum
|
|
1098 delfunction F
|
|
1099 delfunction G
|
|
1100 delfunction H
|
|
1101
|
|
1102 Xcheck 562493431
|
|
1103
|
|
1104
|
|
1105 "-------------------------------------------------------------------------------
|
|
1106 " Test 9: Continuing after aborted functions {{{1
|
|
1107 "
|
|
1108 " When a function with the "abort" attribute is aborted due to an
|
|
1109 " error, the next function back in the call hierarchy without an
|
|
1110 " "abort" attribute continues; the value -1 is returned then.
|
|
1111 "-------------------------------------------------------------------------------
|
|
1112
|
|
1113 XpathINIT
|
|
1114
|
|
1115 function! F() abort
|
|
1116 Xpath 1 " X: 1
|
|
1117 let result = G() " not aborted
|
|
1118 Xpath 2 " X: 2
|
|
1119 if result != 2
|
|
1120 Xpath 4 " X: 0
|
|
1121 endif
|
|
1122 return 1
|
|
1123 endfunction
|
|
1124
|
|
1125 function! G() " no abort attribute
|
|
1126 Xpath 8 " X: 8
|
|
1127 if H() != -1 " aborted
|
|
1128 Xpath 16 " X: 0
|
|
1129 endif
|
|
1130 Xpath 32 " X: 32
|
|
1131 return 2
|
|
1132 endfunction
|
|
1133
|
|
1134 function! H() abort
|
|
1135 Xpath 64 " X: 64
|
|
1136 call I() " aborted
|
|
1137 Xpath 128 " X: 0
|
|
1138 return 4
|
|
1139 endfunction
|
|
1140
|
|
1141 function! I() abort
|
|
1142 Xpath 256 " X: 256
|
|
1143 asdf " error
|
|
1144 Xpath 512 " X: 0
|
|
1145 return 8
|
|
1146 endfunction
|
|
1147
|
|
1148 if F() != 1
|
|
1149 Xpath 1024 " X: 0
|
|
1150 endif
|
|
1151
|
|
1152 delfunction F
|
|
1153 delfunction G
|
|
1154 delfunction H
|
|
1155 delfunction I
|
|
1156
|
|
1157 Xcheck 363
|
|
1158
|
|
1159
|
|
1160 "-------------------------------------------------------------------------------
|
|
1161 " Test 10: :if, :elseif, :while argument parsing {{{1
|
|
1162 "
|
|
1163 " A '"' or '|' in an argument expression must not be mixed up with
|
|
1164 " a comment or a next command after a bar. Parsing errors should
|
|
1165 " be recognized.
|
|
1166 "-------------------------------------------------------------------------------
|
|
1167
|
|
1168 XpathINIT
|
|
1169
|
|
1170 function! MSG(enr, emsg)
|
|
1171 let english = v:lang == "C" || v:lang =~ '^[Ee]n'
|
|
1172 if a:enr == ""
|
|
1173 Xout "TODO: Add message number for:" a:emsg
|
|
1174 let v:errmsg = ":" . v:errmsg
|
|
1175 endif
|
|
1176 let match = 1
|
|
1177 if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg)
|
|
1178 let match = 0
|
|
1179 if v:errmsg == ""
|
|
1180 Xout "Message missing."
|
|
1181 else
|
|
1182 let v:errmsg = escape(v:errmsg, '"')
|
|
1183 Xout "Unexpected message:" v:errmsg
|
|
1184 endif
|
|
1185 endif
|
|
1186 return match
|
|
1187 endfunction
|
|
1188
|
|
1189 if 1 || strlen("\"") | Xpath 1 " X: 1
|
|
1190 Xpath 2 " X: 2
|
|
1191 endif
|
|
1192 Xpath 4 " X: 4
|
|
1193
|
|
1194 if 0
|
|
1195 elseif 1 || strlen("\"") | Xpath 8 " X: 8
|
|
1196 Xpath 16 " X: 16
|
|
1197 endif
|
|
1198 Xpath 32 " X: 32
|
|
1199
|
|
1200 while 1 || strlen("\"") | Xpath 64 " X: 64
|
|
1201 Xpath 128 " X: 128
|
|
1202 break
|
|
1203 endwhile
|
|
1204 Xpath 256 " X: 256
|
|
1205
|
|
1206 let v:errmsg = ""
|
|
1207 if 1 ||| strlen("\"") | Xpath 512 " X: 0
|
|
1208 Xpath 1024 " X: 0
|
|
1209 endif
|
|
1210 Xpath 2048 " X: 2048
|
|
1211 if !MSG('E15', "Invalid expression")
|
|
1212 Xpath 4096 " X: 0
|
|
1213 endif
|
|
1214
|
|
1215 let v:errmsg = ""
|
|
1216 if 0
|
|
1217 elseif 1 ||| strlen("\"") | Xpath 8192 " X: 0
|
|
1218 Xpath 16384 " X: 0
|
|
1219 endif
|
|
1220 Xpath 32768 " X: 32768
|
|
1221 if !MSG('E15', "Invalid expression")
|
|
1222 Xpath 65536 " X: 0
|
|
1223 endif
|
|
1224
|
|
1225 let v:errmsg = ""
|
|
1226 while 1 ||| strlen("\"") | Xpath 131072 " X: 0
|
|
1227 Xpath 262144 " X: 0
|
|
1228 break
|
|
1229 endwhile
|
|
1230 Xpath 524288 " X: 524288
|
|
1231 if !MSG('E15', "Invalid expression")
|
|
1232 Xpath 1048576 " X: 0
|
|
1233 endif
|
|
1234
|
|
1235 delfunction MSG
|
|
1236
|
|
1237 Xcheck 559615
|
|
1238
|
|
1239
|
|
1240 "-------------------------------------------------------------------------------
|
|
1241 " Test 11: :if, :elseif, :while argument evaluation after abort {{{1
|
|
1242 "
|
|
1243 " When code is skipped over due to an error, the boolean argument to
|
|
1244 " an :if, :elseif, or :while must not be evaluated.
|
|
1245 "-------------------------------------------------------------------------------
|
|
1246
|
|
1247 XpathINIT
|
|
1248
|
|
1249 let calls = 0
|
|
1250
|
|
1251 function! P(num)
|
|
1252 let g:calls = g:calls + a:num " side effect on call
|
|
1253 return 0
|
|
1254 endfunction
|
|
1255
|
|
1256 if 1
|
|
1257 Xpath 1 " X: 1
|
|
1258 asdf " error
|
|
1259 Xpath 2 " X: 0
|
|
1260 if P(1) " should not be called
|
|
1261 Xpath 4 " X: 0
|
|
1262 elseif !P(2) " should not be called
|
|
1263 Xpath 8 " X: 0
|
|
1264 else
|
|
1265 Xpath 16 " X: 0
|
|
1266 endif
|
|
1267 Xpath 32 " X: 0
|
|
1268 while P(4) " should not be called
|
|
1269 Xpath 64 " X: 0
|
|
1270 endwhile
|
|
1271 Xpath 128 " X: 0
|
|
1272 endif
|
|
1273
|
|
1274 if calls % 2
|
|
1275 Xpath 256 " X: 0
|
|
1276 endif
|
|
1277 if (calls/2) % 2
|
|
1278 Xpath 512 " X: 0
|
|
1279 endif
|
|
1280 if (calls/4) % 2
|
|
1281 Xpath 1024 " X: 0
|
|
1282 endif
|
|
1283 Xpath 2048 " X: 2048
|
|
1284
|
|
1285 unlet calls
|
|
1286 delfunction P
|
|
1287
|
|
1288 Xcheck 2049
|
|
1289
|
|
1290
|
|
1291 "-------------------------------------------------------------------------------
|
|
1292 " Test 12: Expressions in braces in skipped code {{{1
|
|
1293 "
|
|
1294 " In code skipped over due to an error or inactive conditional,
|
|
1295 " an expression in braces as part of a variable or function name
|
|
1296 " should not be evaluated.
|
|
1297 "-------------------------------------------------------------------------------
|
|
1298
|
|
1299 XpathINIT
|
|
1300
|
|
1301 XloopINIT 1 8
|
|
1302
|
|
1303 function! NULL()
|
|
1304 Xloop 1 " X: 0
|
|
1305 return 0
|
|
1306 endfunction
|
|
1307
|
|
1308 function! ZERO()
|
|
1309 Xloop 2 " X: 0
|
|
1310 return 0
|
|
1311 endfunction
|
|
1312
|
|
1313 function! F0()
|
|
1314 Xloop 4 " X: 0
|
|
1315 endfunction
|
|
1316
|
|
1317 function! F1(arg)
|
|
1318 Xpath 4096 " X: 0
|
|
1319 endfunction
|
|
1320
|
|
1321 let V0 = 1
|
|
1322
|
|
1323 Xpath 8192 " X: 8192
|
|
1324 echo 0 ? F{NULL() + V{ZERO()}}() : 1
|
|
1325 XloopNEXT
|
|
1326
|
|
1327 Xpath 16384 " X: 16384
|
|
1328 if 0
|
|
1329 Xpath 32768 " X: 0
|
|
1330 call F{NULL() + V{ZERO()}}()
|
|
1331 endif
|
|
1332 XloopNEXT
|
|
1333
|
|
1334 Xpath 65536 " X: 65536
|
|
1335 if 1
|
|
1336 asdf " error
|
|
1337 Xpath 131072 " X: 0
|
|
1338 call F1(F{NULL() + V{ZERO()}}())
|
|
1339 endif
|
|
1340 XloopNEXT
|
|
1341
|
|
1342 Xpath 262144 " X: 262144
|
|
1343 if 1
|
|
1344 asdf " error
|
|
1345 Xpath 524288 " X: 0
|
|
1346 call F{NULL() + V{ZERO()}}()
|
|
1347 endif
|
|
1348
|
|
1349 Xcheck 352256
|
|
1350
|
|
1351
|
|
1352 "-------------------------------------------------------------------------------
|
|
1353 " Test 13: Failure in argument evaluation for :while {{{1
|
|
1354 "
|
|
1355 " A failure in the expression evaluation for the condition of a :while
|
|
1356 " causes the whole :while loop until the matching :endwhile being
|
|
1357 " ignored. Continuation is at the next following line.
|
|
1358 "-------------------------------------------------------------------------------
|
|
1359
|
|
1360 XpathINIT
|
|
1361
|
|
1362 Xpath 1 " X: 1
|
|
1363 while asdf
|
|
1364 Xpath 2 " X: 0
|
|
1365 while 1
|
|
1366 Xpath 4 " X: 0
|
|
1367 break
|
|
1368 endwhile
|
|
1369 Xpath 8 " X: 0
|
|
1370 break
|
|
1371 endwhile
|
|
1372 Xpath 16 " X: 16
|
|
1373
|
|
1374 while asdf | Xpath 32 | endwhile | Xpath 64 " X: 0
|
|
1375 Xpath 128 " X: 128
|
|
1376
|
|
1377 Xcheck 145
|
|
1378
|
|
1379
|
|
1380 "-------------------------------------------------------------------------------
|
|
1381 " Test 14: Failure in argument evaluation for :if {{{1
|
|
1382 "
|
|
1383 " A failure in the expression evaluation for the condition of an :if
|
|
1384 " does not cause the corresponding :else or :endif being matched to
|
|
1385 " a previous :if/:elseif. Neither of both branches of the failed :if
|
|
1386 " are executed.
|
|
1387 "-------------------------------------------------------------------------------
|
|
1388
|
|
1389 XpathINIT
|
|
1390 XloopINIT 1 256
|
|
1391
|
|
1392 function! F()
|
|
1393 Xloop 1 " X: 1 + 256 * 1
|
|
1394 let x = 0
|
|
1395 if x " false
|
|
1396 Xloop 2 " X: 0 + 256 * 0
|
|
1397 elseif !x " always true
|
|
1398 Xloop 4 " X: 4 + 256 * 4
|
|
1399 let x = 1
|
|
1400 if g:boolvar " possibly undefined
|
|
1401 Xloop 8 " X: 8 + 256 * 0
|
|
1402 else
|
|
1403 Xloop 16 " X: 0 + 256 * 0
|
|
1404 endif
|
|
1405 Xloop 32 " X: 32 + 256 * 32
|
|
1406 elseif x " never executed
|
|
1407 Xloop 64 " X: 0 + 256 * 0
|
|
1408 endif
|
|
1409 Xloop 128 " X: 128 + 256 * 128
|
|
1410 endfunction
|
|
1411
|
|
1412 let boolvar = 1
|
|
1413 call F()
|
|
1414
|
|
1415 XloopNEXT
|
|
1416 unlet boolvar
|
|
1417 call F()
|
|
1418
|
|
1419 delfunction F
|
|
1420
|
|
1421 Xcheck 42413
|
|
1422
|
|
1423
|
|
1424 "-------------------------------------------------------------------------------
|
|
1425 " Test 15: Failure in argument evaluation for :if (bar) {{{1
|
|
1426 "
|
|
1427 " Like previous test, except that the failing :if ... | ... | :endif
|
|
1428 " is in a single line.
|
|
1429 "-------------------------------------------------------------------------------
|
|
1430
|
|
1431 XpathINIT
|
|
1432 XloopINIT 1 256
|
|
1433
|
|
1434 function! F()
|
|
1435 Xloop 1 " X: 1 + 256 * 1
|
|
1436 let x = 0
|
|
1437 if x " false
|
|
1438 Xloop 2 " X: 0 + 256 * 0
|
|
1439 elseif !x " always true
|
|
1440 Xloop 4 " X: 4 + 256 * 4
|
|
1441 let x = 1
|
|
1442 if g:boolvar | Xloop 8 | else | Xloop 16 | endif " X: 8
|
|
1443 Xloop 32 " X: 32 + 256 * 32
|
|
1444 elseif x " never executed
|
|
1445 Xloop 64 " X: 0 + 256 * 0
|
|
1446 endif
|
|
1447 Xloop 128 " X: 128 + 256 * 128
|
|
1448 endfunction
|
|
1449
|
|
1450 let boolvar = 1
|
|
1451 call F()
|
|
1452
|
|
1453 XloopNEXT
|
|
1454 unlet boolvar
|
|
1455 call F()
|
|
1456
|
|
1457 delfunction F
|
|
1458
|
|
1459 Xcheck 42413
|
|
1460
|
|
1461
|
|
1462 "-------------------------------------------------------------------------------
|
|
1463 " Test 16: Double :else or :elseif after :else {{{1
|
|
1464 "
|
|
1465 " Multiple :elses or an :elseif after an :else are forbidden.
|
|
1466 "-------------------------------------------------------------------------------
|
|
1467
|
|
1468 XpathINIT
|
|
1469
|
|
1470 function! F() abort
|
|
1471 if 0
|
|
1472 Xpath 1 " X: 0
|
|
1473 else
|
|
1474 Xpath 2 " X: 2
|
|
1475 else " aborts function
|
|
1476 Xpath 4 " X: 0
|
|
1477 endif
|
|
1478 endfunction
|
|
1479
|
|
1480 function! G() abort
|
|
1481 if 0
|
|
1482 Xpath 8 " X: 0
|
|
1483 else
|
|
1484 Xpath 16 " X: 16
|
|
1485 elseif 1 " aborts function
|
|
1486 Xpath 32 " X: 0
|
|
1487 else
|
|
1488 Xpath 64 " X: 0
|
|
1489 endif
|
|
1490 endfunction
|
|
1491
|
|
1492 function! H() abort
|
|
1493 if 0
|
|
1494 Xpath 128 " X: 0
|
|
1495 elseif 0
|
|
1496 Xpath 256 " X: 0
|
|
1497 else
|
|
1498 Xpath 512 " X: 512
|
|
1499 else " aborts function
|
|
1500 Xpath 1024 " X: 0
|
|
1501 endif
|
|
1502 endfunction
|
|
1503
|
|
1504 function! I() abort
|
|
1505 if 0
|
|
1506 Xpath 2048 " X: 0
|
|
1507 elseif 0
|
|
1508 Xpath 4096 " X: 0
|
|
1509 else
|
|
1510 Xpath 8192 " X: 8192
|
|
1511 elseif 1 " aborts function
|
|
1512 Xpath 16384 " X: 0
|
|
1513 else
|
|
1514 Xpath 32768 " X: 0
|
|
1515 endif
|
|
1516 endfunction
|
|
1517
|
|
1518 call F()
|
|
1519 call G()
|
|
1520 call H()
|
|
1521 call I()
|
|
1522
|
|
1523 delfunction F
|
|
1524 delfunction G
|
|
1525 delfunction H
|
|
1526 delfunction I
|
|
1527
|
|
1528 Xcheck 8722
|
|
1529
|
|
1530
|
|
1531 "-------------------------------------------------------------------------------
|
|
1532 " Test 17: Nesting of unmatched :if or :endif inside a :while {{{1
|
|
1533 "
|
|
1534 " The :while/:endwhile takes precedence in nesting over an unclosed
|
|
1535 " :if or an unopened :endif.
|
|
1536 "-------------------------------------------------------------------------------
|
|
1537
|
|
1538 XpathINIT
|
|
1539
|
|
1540 function! MSG(enr, emsg)
|
|
1541 let english = v:lang == "C" || v:lang =~ '^[Ee]n'
|
|
1542 if a:enr == ""
|
|
1543 Xout "TODO: Add message number for:" a:emsg
|
|
1544 let v:errmsg = ":" . v:errmsg
|
|
1545 endif
|
|
1546 let match = 1
|
|
1547 if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg)
|
|
1548 let match = 0
|
|
1549 if v:errmsg == ""
|
|
1550 Xout "Message missing."
|
|
1551 else
|
|
1552 let v:errmsg = escape(v:errmsg, '"')
|
|
1553 Xout "Unexpected message:" v:errmsg
|
|
1554 endif
|
|
1555 endif
|
|
1556 return match
|
|
1557 endfunction
|
|
1558
|
|
1559 let messages = ""
|
|
1560
|
|
1561 " While loops inside a function are continued on error.
|
|
1562 function! F()
|
|
1563 let v:errmsg = ""
|
|
1564 XloopINIT 1 16
|
|
1565 let loops = 3
|
|
1566 while loops > 0
|
|
1567 let loops = loops - 1 " 2: 1: 0:
|
|
1568 Xloop 1 " X: 1 + 1*16 + 1*16*16
|
|
1569 if (loops == 1)
|
|
1570 Xloop 2 " X: 2*16
|
|
1571 XloopNEXT
|
|
1572 continue
|
|
1573 elseif (loops == 0)
|
|
1574 Xloop 4 " X: 4*16*16
|
|
1575 break
|
|
1576 elseif 1
|
|
1577 Xloop 8 " X: 8
|
|
1578 XloopNEXT
|
|
1579 " endif missing!
|
|
1580 endwhile " :endwhile after :if 1
|
|
1581 Xpath 4096 " X: 16*16*16
|
|
1582 if MSG('E171', "Missing :endif")
|
|
1583 let g:messages = g:messages . "A"
|
|
1584 endif
|
|
1585
|
|
1586 let v:errmsg = ""
|
|
1587 XloopINIT! 8192 4
|
|
1588 let loops = 2
|
|
1589 while loops > 0 " 2: 1:
|
|
1590 XloopNEXT
|
|
1591 let loops = loops - 1
|
|
1592 Xloop 1 " X: 8192 + 8192*4
|
|
1593 if 0
|
|
1594 Xloop 2 " X: 0
|
|
1595 " endif missing
|
|
1596 endwhile " :endwhile after :if 0
|
|
1597 Xpath 131072 " X: 8192*4*4
|
|
1598 if MSG('E171', "Missing :endif")
|
|
1599 let g:messages = g:messages . "B"
|
|
1600 endif
|
|
1601
|
|
1602 let v:errmsg = ""
|
|
1603 XloopINIT 262144 4
|
|
1604 let loops = 2
|
|
1605 while loops > 0 " 2: 1:
|
|
1606 let loops = loops - 1
|
|
1607 Xloop 1 " X: 262144 + 262144 * 4
|
|
1608 " if missing!
|
|
1609 endif " :endif without :if in while
|
|
1610 Xloop 2 " X: 524288 + 524288 * 4
|
|
1611 XloopNEXT
|
|
1612 endwhile
|
|
1613 Xpath 4194304 " X: 262144*4*4
|
|
1614 if MSG('E580', ":endif without :if")
|
|
1615 let g:messages = g:messages . "C"
|
|
1616 endif
|
|
1617 endfunction
|
|
1618
|
|
1619 call F()
|
|
1620
|
|
1621 " Error continuation outside a function is at the outermost :endwhile or :endif.
|
|
1622 let v:errmsg = ""
|
|
1623 XloopINIT! 8388608 4
|
|
1624 let loops = 2
|
|
1625 while loops > 0 " 2: 1:
|
|
1626 XloopNEXT
|
|
1627 let loops = loops - 1
|
|
1628 Xloop 1 " X: 8388608 + 0 * 4
|
|
1629 if 0
|
|
1630 Xloop 2 " X: 0
|
|
1631 " endif missing! Following :endwhile fails.
|
|
1632 endwhile | Xpath 134217728 " X: 0
|
|
1633 Xpath 268435456 " X: 2*8388608*4*4
|
|
1634 if MSG('E171', "Missing :endif")
|
|
1635 let messages = g:messages . "D"
|
|
1636 endif
|
|
1637
|
|
1638 if messages != "ABCD"
|
|
1639 Xpath 536870912 " X: 0
|
|
1640 Xout "messages is" messages "instead of ABCD"
|
|
1641 endif
|
|
1642
|
|
1643 unlet loops messages
|
|
1644 delfunction F
|
|
1645 delfunction MSG
|
|
1646
|
|
1647 Xcheck 285127993
|
|
1648
|
|
1649
|
|
1650 "-------------------------------------------------------------------------------
|
|
1651 " Test 18: Interrupt (Ctrl-C pressed) {{{1
|
|
1652 "
|
|
1653 " On an interrupt, the script processing is terminated immediately.
|
|
1654 "-------------------------------------------------------------------------------
|
|
1655
|
|
1656 XpathINIT
|
|
1657
|
|
1658 if ExtraVim()
|
|
1659 if 1
|
|
1660 Xpath 1 " X: 1
|
|
1661 while 1
|
|
1662 Xpath 2 " X: 2
|
|
1663 if 1
|
|
1664 Xpath 4 " X: 4
|
|
1665 "INTERRUPT
|
|
1666 Xpath 8 " X: 0
|
|
1667 break
|
|
1668 finish
|
|
1669 endif | Xpath 16 " X: 0
|
|
1670 Xpath 32 " X: 0
|
|
1671 endwhile | Xpath 64 " X: 0
|
|
1672 Xpath 128 " X: 0
|
|
1673 endif | Xpath 256 " X: 0
|
|
1674 Xpath 512 " X: 0
|
|
1675 endif
|
|
1676
|
|
1677 if ExtraVim()
|
|
1678 try
|
|
1679 Xpath 1024 " X: 1024
|
|
1680 "INTERRUPT
|
|
1681 Xpath 2048 " X: 0
|
|
1682 endtry | Xpath 4096 " X: 0
|
|
1683 Xpath 8192 " X: 0
|
|
1684 endif
|
|
1685
|
|
1686 if ExtraVim()
|
|
1687 function! F()
|
|
1688 if 1
|
|
1689 Xpath 16384 " X: 16384
|
|
1690 while 1
|
|
1691 Xpath 32768 " X: 32768
|
|
1692 if 1
|
|
1693 Xpath 65536 " X: 65536
|
|
1694 "INTERRUPT
|
|
1695 Xpath 131072 " X: 0
|
|
1696 break
|
|
1697 return
|
|
1698 endif | Xpath 262144 " X: 0
|
|
1699 Xpath Xpath 524288 " X: 0
|
|
1700 endwhile | Xpath 1048576 " X: 0
|
|
1701 Xpath Xpath 2097152 " X: 0
|
|
1702 endif | Xpath Xpath 4194304 " X: 0
|
|
1703 Xpath Xpath 8388608 " X: 0
|
|
1704 endfunction
|
|
1705
|
|
1706 call F() | Xpath 16777216 " X: 0
|
|
1707 Xpath 33554432 " X: 0
|
|
1708 endif
|
|
1709
|
|
1710 if ExtraVim()
|
|
1711 function! G()
|
|
1712 try
|
|
1713 Xpath 67108864 " X: 67108864
|
|
1714 "INTERRUPT
|
|
1715 Xpath 134217728 " X: 0
|
|
1716 endtry | Xpath 268435456 " X: 0
|
|
1717 Xpath 536870912 " X: 0
|
|
1718 endfunction
|
|
1719
|
|
1720 call G() | Xpath 1073741824 " X: 0
|
|
1721 " The Xpath command does not accept 2^31 (negative); display explicitly:
|
|
1722 exec "!echo 2147483648 >>" . g:ExtraVimResult
|
|
1723 " X: 0
|
|
1724 endif
|
|
1725
|
|
1726 Xcheck 67224583
|
|
1727
|
|
1728
|
|
1729 "-------------------------------------------------------------------------------
|
|
1730 " Test 19: Aborting on errors inside :try/:endtry {{{1
|
|
1731 "
|
|
1732 " An error in a command dynamically enclosed in a :try/:endtry region
|
|
1733 " aborts script processing immediately. It does not matter whether
|
|
1734 " the failing command is outside or inside a function and whether a
|
|
1735 " function has an "abort" attribute.
|
|
1736 "-------------------------------------------------------------------------------
|
|
1737
|
|
1738 XpathINIT
|
|
1739
|
|
1740 if ExtraVim()
|
|
1741 function! F() abort
|
|
1742 Xpath 1 " X: 1
|
|
1743 asdf
|
|
1744 Xpath 2 " X: 0
|
|
1745 endfunction
|
|
1746
|
|
1747 try
|
|
1748 Xpath 4 " X: 4
|
|
1749 call F()
|
|
1750 Xpath 8 " X: 0
|
|
1751 endtry | Xpath 16 " X: 0
|
|
1752 Xpath 32 " X: 0
|
|
1753 endif
|
|
1754
|
|
1755 if ExtraVim()
|
|
1756 function! G()
|
|
1757 Xpath 64 " X: 64
|
|
1758 asdf
|
|
1759 Xpath 128 " X: 0
|
|
1760 endfunction
|
|
1761
|
|
1762 try
|
|
1763 Xpath 256 " X: 256
|
|
1764 call G()
|
|
1765 Xpath 512 " X: 0
|
|
1766 endtry | Xpath 1024 " X: 0
|
|
1767 Xpath 2048 " X: 0
|
|
1768 endif
|
|
1769
|
|
1770 if ExtraVim()
|
|
1771 try
|
|
1772 Xpath 4096 " X: 4096
|
|
1773 asdf
|
|
1774 Xpath 8192 " X: 0
|
|
1775 endtry | Xpath 16384 " X: 0
|
|
1776 Xpath 32768 " X: 0
|
|
1777 endif
|
|
1778
|
|
1779 if ExtraVim()
|
|
1780 if 1
|
|
1781 try
|
|
1782 Xpath 65536 " X: 65536
|
|
1783 asdf
|
|
1784 Xpath 131072 " X: 0
|
|
1785 endtry | Xpath 262144 " X: 0
|
|
1786 endif | Xpath 524288 " X: 0
|
|
1787 Xpath 1048576 " X: 0
|
|
1788 endif
|
|
1789
|
|
1790 if ExtraVim()
|
|
1791 let p = 1
|
|
1792 while p
|
|
1793 let p = 0
|
|
1794 try
|
|
1795 Xpath 2097152 " X: 2097152
|
|
1796 asdf
|
|
1797 Xpath 4194304 " X: 0
|
|
1798 endtry | Xpath 8388608 " X: 0
|
|
1799 endwhile | Xpath 16777216 " X: 0
|
|
1800 Xpath 33554432 " X: 0
|
|
1801 endif
|
|
1802
|
|
1803 if ExtraVim()
|
|
1804 let p = 1
|
|
1805 while p
|
|
1806 let p = 0
|
|
1807 " try
|
|
1808 Xpath 67108864 " X: 67108864
|
|
1809 endwhile | Xpath 134217728 " X: 0
|
|
1810 Xpath 268435456 " X: 0
|
|
1811 endif
|
|
1812
|
|
1813 Xcheck 69275973
|
|
1814 "-------------------------------------------------------------------------------
|
|
1815 " Test 20: Aborting on errors after :try/:endtry {{{1
|
|
1816 "
|
|
1817 " When an error occurs after the last active :try/:endtry region has
|
|
1818 " been left, termination behavior is as if no :try/:endtry has been
|
|
1819 " seen.
|
|
1820 "-------------------------------------------------------------------------------
|
|
1821
|
|
1822 XpathINIT
|
|
1823
|
|
1824 if ExtraVim()
|
|
1825 let p = 1
|
|
1826 while p
|
|
1827 let p = 0
|
|
1828 try
|
|
1829 Xpath 1 " X: 1
|
|
1830 endtry
|
|
1831 asdf
|
|
1832 endwhile | Xpath 2 " X: 0
|
|
1833 Xpath 4 " X: 4
|
|
1834 endif
|
|
1835
|
|
1836 if ExtraVim()
|
|
1837 while 1
|
|
1838 try
|
|
1839 Xpath 8 " X: 8
|
|
1840 break
|
|
1841 Xpath 16 " X: 0
|
|
1842 endtry
|
|
1843 endwhile
|
|
1844 Xpath 32 " X: 32
|
|
1845 asdf
|
|
1846 Xpath 64 " X: 64
|
|
1847 endif
|
|
1848
|
|
1849 if ExtraVim()
|
|
1850 while 1
|
|
1851 try
|
|
1852 Xpath 128 " X: 128
|
|
1853 break
|
|
1854 Xpath 256 " X: 0
|
|
1855 finally
|
|
1856 Xpath 512 " X: 512
|
|
1857 endtry
|
|
1858 endwhile
|
|
1859 Xpath 1024 " X: 1024
|
|
1860 asdf
|
|
1861 Xpath 2048 " X: 2048
|
|
1862 endif
|
|
1863
|
|
1864 if ExtraVim()
|
|
1865 while 1
|
|
1866 try
|
|
1867 Xpath 4096 " X: 4096
|
|
1868 finally
|
|
1869 Xpath 8192 " X: 8192
|
|
1870 break
|
|
1871 Xpath 16384 " X: 0
|
|
1872 endtry
|
|
1873 endwhile
|
|
1874 Xpath 32768 " X: 32768
|
|
1875 asdf
|
|
1876 Xpath 65536 " X: 65536
|
|
1877 endif
|
|
1878
|
|
1879 if ExtraVim()
|
|
1880 let p = 1
|
|
1881 while p
|
|
1882 let p = 0
|
|
1883 try
|
|
1884 Xpath 131072 " X: 131072
|
|
1885 continue
|
|
1886 Xpath 262144 " X: 0
|
|
1887 endtry
|
|
1888 endwhile
|
|
1889 Xpath 524288 " X: 524288
|
|
1890 asdf
|
|
1891 Xpath 1048576 " X: 1048576
|
|
1892 endif
|
|
1893
|
|
1894 if ExtraVim()
|
|
1895 let p = 1
|
|
1896 while p
|
|
1897 let p = 0
|
|
1898 try
|
|
1899 Xpath 2097152 " X: 2097152
|
|
1900 continue
|
|
1901 Xpath 4194304 " X: 0
|
|
1902 finally
|
|
1903 Xpath 8388608 " X: 8388608
|
|
1904 endtry
|
|
1905 endwhile
|
|
1906 Xpath 16777216 " X: 16777216
|
|
1907 asdf
|
|
1908 Xpath 33554432 " X: 33554432
|
|
1909 endif
|
|
1910
|
|
1911 if ExtraVim()
|
|
1912 let p = 1
|
|
1913 while p
|
|
1914 let p = 0
|
|
1915 try
|
|
1916 Xpath 67108864 " X: 67108864
|
|
1917 finally
|
|
1918 Xpath 134217728 " X: 134217728
|
|
1919 continue
|
|
1920 Xpath 268435456 " X: 0
|
|
1921 endtry
|
|
1922 endwhile
|
|
1923 Xpath 536870912 " X: 536870912
|
|
1924 asdf
|
|
1925 Xpath 1073741824 " X: 1073741824
|
|
1926 endif
|
|
1927
|
|
1928 Xcheck 1874575085
|
|
1929
|
|
1930
|
|
1931 "-------------------------------------------------------------------------------
|
|
1932 " Test 21: :finally for :try after :continue/:break/:return/:finish {{{1
|
|
1933 "
|
|
1934 " If a :try conditional stays inactive due to a preceding :continue,
|
|
1935 " :break, :return, or :finish, its :finally clause should not be
|
|
1936 " executed.
|
|
1937 "-------------------------------------------------------------------------------
|
|
1938
|
|
1939 XpathINIT
|
|
1940
|
|
1941 if ExtraVim()
|
|
1942 function F()
|
|
1943 let loops = 2
|
|
1944 XloopINIT! 1 256
|
|
1945 while loops > 0
|
|
1946 XloopNEXT
|
|
1947 let loops = loops - 1
|
|
1948 try
|
|
1949 if loops == 1
|
|
1950 Xloop 1 " X: 1
|
|
1951 continue
|
|
1952 Xloop 2 " X: 0
|
|
1953 elseif loops == 0
|
|
1954 Xloop 4 " X: 4*256
|
|
1955 break
|
|
1956 Xloop 8 " X: 0
|
|
1957 endif
|
|
1958
|
|
1959 try " inactive
|
|
1960 Xloop 16 " X: 0
|
|
1961 finally
|
|
1962 Xloop 32 " X: 0
|
|
1963 endtry
|
|
1964 finally
|
|
1965 Xloop 64 " X: 64 + 64*256
|
|
1966 endtry
|
|
1967 Xloop 128 " X: 0
|
|
1968 endwhile
|
|
1969
|
|
1970 try
|
|
1971 Xpath 65536 " X: 65536
|
|
1972 return
|
|
1973 Xpath 131072 " X: 0
|
|
1974 try " inactive
|
|
1975 Xpath 262144 " X: 0
|
|
1976 finally
|
|
1977 Xpath 524288 " X: 0
|
|
1978 endtry
|
|
1979 finally
|
|
1980 Xpath 1048576 " X: 1048576
|
|
1981 endtry
|
|
1982 Xpath 2097152 " X: 0
|
|
1983 endfunction
|
|
1984
|
|
1985 try
|
|
1986 Xpath 4194304 " X: 4194304
|
|
1987 call F()
|
|
1988 Xpath 8388608 " X: 8388608
|
|
1989 finish
|
|
1990 Xpath 16777216 " X: 0
|
|
1991 try " inactive
|
|
1992 Xpath 33554432 " X: 0
|
|
1993 finally
|
|
1994 Xpath 67108864 " X: 0
|
|
1995 endtry
|
|
1996 finally
|
|
1997 Xpath 134217728 " X: 134217728
|
|
1998 endtry
|
|
1999 Xpath 268435456 " X: 0
|
|
2000 endif
|
|
2001
|
|
2002 Xcheck 147932225
|
|
2003
|
|
2004
|
|
2005 "-------------------------------------------------------------------------------
|
|
2006 " Test 22: :finally for a :try after an error/interrupt/:throw {{{1
|
|
2007 "
|
|
2008 " If a :try conditional stays inactive due to a preceding error or
|
|
2009 " interrupt or :throw, its :finally clause should not be executed.
|
|
2010 "-------------------------------------------------------------------------------
|
|
2011
|
|
2012 XpathINIT
|
|
2013
|
|
2014 if ExtraVim()
|
|
2015 function! Error()
|
|
2016 try
|
|
2017 asdf " aborting error, triggering error exception
|
|
2018 endtry
|
|
2019 endfunction
|
|
2020
|
|
2021 Xpath 1 " X: 1
|
|
2022 call Error()
|
|
2023 Xpath 2 " X: 0
|
|
2024
|
|
2025 if 1 " not active due to error
|
|
2026 try " not active since :if inactive
|
|
2027 Xpath 4 " X: 0
|
|
2028 finally
|
|
2029 Xpath 8 " X: 0
|
|
2030 endtry
|
|
2031 endif
|
|
2032
|
|
2033 try " not active due to error
|
|
2034 Xpath 16 " X: 0
|
|
2035 finally
|
|
2036 Xpath 32 " X: 0
|
|
2037 endtry
|
|
2038 endif
|
|
2039
|
|
2040 if ExtraVim()
|
|
2041 function! Interrupt()
|
|
2042 try
|
|
2043 "INTERRUPT " triggering interrupt exception
|
|
2044 endtry
|
|
2045 endfunction
|
|
2046
|
|
2047 Xpath 64 " X: 64
|
|
2048 call Interrupt()
|
|
2049 Xpath 128 " X: 0
|
|
2050
|
|
2051 if 1 " not active due to interrupt
|
|
2052 try " not active since :if inactive
|
|
2053 Xpath 256 " X: 0
|
|
2054 finally
|
|
2055 Xpath 512 " X: 0
|
|
2056 endtry
|
|
2057 endif
|
|
2058
|
|
2059 try " not active due to interrupt
|
|
2060 Xpath 1024 " X: 0
|
|
2061 finally
|
|
2062 Xpath 2048 " X: 0
|
|
2063 endtry
|
|
2064 endif
|
|
2065
|
|
2066 if ExtraVim()
|
|
2067 function! Throw()
|
|
2068 throw "xyz"
|
|
2069 endfunction
|
|
2070
|
|
2071 Xpath 4096 " X: 4096
|
|
2072 call Throw()
|
|
2073 Xpath 8192 " X: 0
|
|
2074
|
|
2075 if 1 " not active due to :throw
|
|
2076 try " not active since :if inactive
|
|
2077 Xpath 16384 " X: 0
|
|
2078 finally
|
|
2079 Xpath 32768 " X: 0
|
|
2080 endtry
|
|
2081 endif
|
|
2082
|
|
2083 try " not active due to :throw
|
|
2084 Xpath 65536 " X: 0
|
|
2085 finally
|
|
2086 Xpath 131072 " X: 0
|
|
2087 endtry
|
|
2088 endif
|
|
2089
|
|
2090 Xcheck 4161
|
|
2091
|
|
2092
|
|
2093 "-------------------------------------------------------------------------------
|
|
2094 " Test 23: :catch clauses for a :try after a :throw {{{1
|
|
2095 "
|
|
2096 " If a :try conditional stays inactive due to a preceding :throw,
|
|
2097 " none of its :catch clauses should be executed.
|
|
2098 "-------------------------------------------------------------------------------
|
|
2099
|
|
2100 XpathINIT
|
|
2101
|
|
2102 if ExtraVim()
|
|
2103 try
|
|
2104 Xpath 1 " X: 1
|
|
2105 throw "xyz"
|
|
2106 Xpath 2 " X: 0
|
|
2107
|
|
2108 if 1 " not active due to :throw
|
|
2109 try " not active since :if inactive
|
|
2110 Xpath 4 " X: 0
|
|
2111 catch /xyz/
|
|
2112 Xpath 8 " X: 0
|
|
2113 endtry
|
|
2114 endif
|
|
2115 catch /xyz/
|
|
2116 Xpath 16 " X: 16
|
|
2117 endtry
|
|
2118
|
|
2119 Xpath 32 " X: 32
|
|
2120 throw "abc"
|
|
2121 Xpath 64 " X: 0
|
|
2122
|
|
2123 try " not active due to :throw
|
|
2124 Xpath 128 " X: 0
|
|
2125 catch /abc/
|
|
2126 Xpath 256 " X: 0
|
|
2127 endtry
|
|
2128 endif
|
|
2129
|
|
2130 Xcheck 49
|
|
2131
|
|
2132
|
|
2133 "-------------------------------------------------------------------------------
|
|
2134 " Test 24: :endtry for a :try after a :throw {{{1
|
|
2135 "
|
|
2136 " If a :try conditional stays inactive due to a preceding :throw,
|
|
2137 " its :endtry should not rethrow the exception to the next surrounding
|
|
2138 " active :try conditional.
|
|
2139 "-------------------------------------------------------------------------------
|
|
2140
|
|
2141 XpathINIT
|
|
2142
|
|
2143 if ExtraVim()
|
|
2144 try " try 1
|
|
2145 try " try 2
|
|
2146 Xpath 1 " X: 1
|
|
2147 throw "xyz" " makes try 2 inactive
|
|
2148 Xpath 2 " X: 0
|
|
2149
|
|
2150 try " try 3
|
|
2151 Xpath 4 " X: 0
|
|
2152 endtry " no rethrow to try 1
|
|
2153 catch /xyz/ " should catch although try 2 inactive
|
|
2154 Xpath 8 " X: 8
|
|
2155 endtry
|
|
2156 catch /xyz/ " try 1 active, but exception already caught
|
|
2157 Xpath 16 " X: 0
|
|
2158 endtry
|
|
2159 Xpath 32 " X: 32
|
|
2160 endif
|
|
2161
|
|
2162 Xcheck 41
|
|
2163
|
|
2164
|
|
2165 "-------------------------------------------------------------------------------
|
|
2166 " Test 25: Executing :finally clauses on normal control flow {{{1
|
|
2167 "
|
|
2168 " Control flow in a :try conditional should always fall through to its
|
|
2169 " :finally clause. A :finally clause of a :try conditional inside an
|
|
2170 " inactive conditional should never be executed.
|
|
2171 "-------------------------------------------------------------------------------
|
|
2172
|
|
2173 XpathINIT
|
|
2174
|
|
2175 function! F()
|
|
2176 let loops = 3
|
|
2177 XloopINIT 1 256
|
|
2178 while loops > 0 " 3: 2: 1:
|
|
2179 Xloop 1 " X: 1 + 1*256 + 1*256*256
|
|
2180 if loops >= 2
|
|
2181 try
|
|
2182 Xloop 2 " X: 2 + 2*256
|
|
2183 if loops == 2
|
|
2184 try
|
|
2185 Xloop 4 " X: 4*256
|
|
2186 finally
|
|
2187 Xloop 8 " X: 8*256
|
|
2188 endtry
|
|
2189 endif
|
|
2190 finally
|
|
2191 Xloop 16 " X: 16 + 16*256
|
|
2192 if loops == 2
|
|
2193 try
|
|
2194 Xloop 32 " X: 32*256
|
|
2195 finally
|
|
2196 Xloop 64 " X: 64*256
|
|
2197 endtry
|
|
2198 endif
|
|
2199 endtry
|
|
2200 endif
|
|
2201 Xloop 128 " X: 128 + 128*256 + 128*256*256
|
|
2202 let loops = loops - 1
|
|
2203 XloopNEXT
|
|
2204 endwhile
|
|
2205 Xpath 16777216 " X: 16777216
|
|
2206 endfunction
|
|
2207
|
|
2208 if 1
|
|
2209 try
|
|
2210 Xpath 33554432 " X: 33554432
|
|
2211 call F()
|
|
2212 Xpath 67108864 " X: 67108864
|
|
2213 finally
|
|
2214 Xpath 134217728 " X: 134217728
|
|
2215 endtry
|
|
2216 else
|
|
2217 try
|
|
2218 Xpath 268435456 " X: 0
|
|
2219 finally
|
|
2220 Xpath 536870912 " X: 0
|
|
2221 endtry
|
|
2222 endif
|
|
2223
|
|
2224 delfunction F
|
|
2225
|
|
2226 Xcheck 260177811
|
|
2227
|
|
2228
|
|
2229 "-------------------------------------------------------------------------------
|
|
2230 " Test 26: Executing :finally clauses after :continue or :break {{{1
|
|
2231 "
|
|
2232 " For a :continue or :break dynamically enclosed in a :try/:endtry
|
|
2233 " region inside the next surrounding :while/:endwhile, if the
|
|
2234 " :continue/:break is before the :finally, the :finally clause is
|
|
2235 " executed first. If the :continue/:break is after the :finally, the
|
|
2236 " :finally clause is broken (like an :if/:endif region).
|
|
2237 "-------------------------------------------------------------------------------
|
|
2238
|
|
2239 XpathINIT
|
|
2240
|
|
2241 try
|
|
2242 let loops = 3
|
|
2243 XloopINIT! 1 32
|
|
2244 while loops > 0
|
|
2245 XloopNEXT
|
|
2246 try
|
|
2247 try
|
|
2248 if loops == 2 " 3: 2: 1:
|
|
2249 Xloop 1 " X: 1*32
|
|
2250 let loops = loops - 1
|
|
2251 continue
|
|
2252 elseif loops == 1
|
|
2253 Xloop 2 " X: 2*32*32
|
|
2254 break
|
|
2255 finish
|
|
2256 endif
|
|
2257 Xloop 4 " X: 4
|
|
2258 endtry
|
|
2259 finally
|
|
2260 Xloop 8 " X: 8 + 8*32 + 8*32*32
|
|
2261 endtry
|
|
2262 Xloop 16 " X: 16
|
|
2263 let loops = loops - 1
|
|
2264 endwhile
|
|
2265 Xpath 32768 " X: 32768
|
|
2266 finally
|
|
2267 Xpath 65536 " X: 65536
|
|
2268 let loops = 3
|
|
2269 XloopINIT 131072 16
|
|
2270 while loops > 0
|
|
2271 try
|
|
2272 finally
|
|
2273 try
|
|
2274 if loops == 2
|
|
2275 Xloop 1 " X: 131072*16
|
|
2276 let loops = loops - 1
|
|
2277 XloopNEXT
|
|
2278 continue
|
|
2279 elseif loops == 1
|
|
2280 Xloop 2 " X: 131072*2*16*16
|
|
2281 break
|
|
2282 finish
|
|
2283 endif
|
|
2284 endtry
|
|
2285 Xloop 4 " X: 131072*4
|
|
2286 endtry
|
|
2287 Xloop 8 " X: 131072*8
|
|
2288 let loops = loops - 1
|
|
2289 XloopNEXT
|
|
2290 endwhile
|
|
2291 Xpath 536870912 " X: 536870912
|
|
2292 endtry
|
|
2293 Xpath 1073741824 " X: 1073741824
|
|
2294
|
|
2295 unlet loops
|
|
2296
|
|
2297 Xcheck 1681500476
|
|
2298
|
|
2299
|
|
2300 "-------------------------------------------------------------------------------
|
|
2301 " Test 27: Executing :finally clauses after :return {{{1
|
|
2302 "
|
|
2303 " For a :return command dynamically enclosed in a :try/:endtry region,
|
|
2304 " :finally clauses are executed and the called function is ended.
|
|
2305 "-------------------------------------------------------------------------------
|
|
2306
|
|
2307 XpathINIT
|
|
2308
|
|
2309 function! F()
|
|
2310 try
|
|
2311 Xpath 1 " X: 1
|
|
2312 try
|
|
2313 Xpath 2 " X: 2
|
|
2314 return
|
|
2315 Xpath 4 " X: 0
|
|
2316 finally
|
|
2317 Xpath 8 " X: 8
|
|
2318 endtry
|
|
2319 Xpath 16 " X: 0
|
|
2320 finally
|
|
2321 Xpath 32 " X: 32
|
|
2322 endtry
|
|
2323 Xpath 64 " X: 0
|
|
2324 endfunction
|
|
2325
|
|
2326 function! G()
|
|
2327 try
|
|
2328 Xpath 128 " X: 128
|
|
2329 return
|
|
2330 Xpath 256 " X: 0
|
|
2331 finally
|
|
2332 Xpath 512 " X: 512
|
|
2333 call F()
|
|
2334 Xpath 1024 " X: 1024
|
|
2335 endtry
|
|
2336 Xpath 2048 " X: 0
|
|
2337 endfunction
|
|
2338
|
|
2339 function! H()
|
|
2340 try
|
|
2341 Xpath 4096 " X: 4096
|
|
2342 call G()
|
|
2343 Xpath 8192 " X: 8192
|
|
2344 finally
|
|
2345 Xpath 16384 " X: 16384
|
|
2346 return
|
|
2347 Xpath 32768 " X: 0
|
|
2348 endtry
|
|
2349 Xpath 65536 " X: 0
|
|
2350 endfunction
|
|
2351
|
|
2352 try
|
|
2353 Xpath 131072 " X: 131072
|
|
2354 call H()
|
|
2355 Xpath 262144 " X: 262144
|
|
2356 finally
|
|
2357 Xpath 524288 " X: 524288
|
|
2358 endtry
|
|
2359 Xpath 1048576 " X: 1048576
|
|
2360
|
|
2361 Xcheck 1996459
|
|
2362
|
|
2363 " Leave F, G, and H for execution as scripts in the next test.
|
|
2364
|
|
2365
|
|
2366 "-------------------------------------------------------------------------------
|
|
2367 " Test 28: Executing :finally clauses after :finish {{{1
|
|
2368 "
|
|
2369 " For a :finish command dynamically enclosed in a :try/:endtry region,
|
|
2370 " :finally clauses are executed and the sourced file is finished.
|
|
2371 "
|
|
2372 " This test executes the bodies of the functions F, G, and H from the
|
|
2373 " previous test as script files (:return replaced by :finish).
|
|
2374 "-------------------------------------------------------------------------------
|
|
2375
|
|
2376 XpathINIT
|
|
2377
|
|
2378 let scriptF = MakeScript("F") " X: 1 + 2 + 8 + 32
|
|
2379 let scriptG = MakeScript("G", scriptF) " X: 128 + 512 + 1024
|
|
2380 let scriptH = MakeScript("H", scriptG) " X: 4096 + 8192 + 16384
|
|
2381
|
|
2382 try
|
|
2383 Xpath 131072 " X: 131072
|
|
2384 exec "source" scriptH
|
|
2385 Xpath 262144 " X: 262144
|
|
2386 finally
|
|
2387 Xpath 524288 " X: 524288
|
|
2388 endtry
|
|
2389 Xpath 1048576 " X: 1048576
|
|
2390
|
|
2391 call delete(scriptF)
|
|
2392 call delete(scriptG)
|
|
2393 call delete(scriptH)
|
|
2394 unlet scriptF scriptG scriptH
|
|
2395 delfunction F
|
|
2396 delfunction G
|
|
2397 delfunction H
|
|
2398
|
|
2399 Xcheck 1996459
|
|
2400
|
|
2401
|
|
2402 "-------------------------------------------------------------------------------
|
|
2403 " Test 29: Executing :finally clauses on errors {{{1
|
|
2404 "
|
|
2405 " After an error in a command dynamically enclosed in a :try/:endtry
|
|
2406 " region, :finally clauses are executed and the script processing is
|
|
2407 " terminated.
|
|
2408 "-------------------------------------------------------------------------------
|
|
2409
|
|
2410 XpathINIT
|
|
2411
|
|
2412 if ExtraVim()
|
|
2413 function! F()
|
|
2414 while 1
|
|
2415 try
|
|
2416 Xpath 1 " X: 1
|
|
2417 while 1
|
|
2418 try
|
|
2419 Xpath 2 " X: 2
|
|
2420 asdf " error
|
|
2421 Xpath 4 " X: 0
|
|
2422 finally
|
|
2423 Xpath 8 " X: 8
|
|
2424 endtry | Xpath 16 " X: 0
|
|
2425 Xpath 32 " X: 0
|
|
2426 break
|
|
2427 endwhile
|
|
2428 Xpath 64 " X: 0
|
|
2429 finally
|
|
2430 Xpath 128 " X: 128
|
|
2431 endtry | Xpath 256 " X: 0
|
|
2432 Xpath 512 " X: 0
|
|
2433 break
|
|
2434 endwhile
|
|
2435 Xpath 1024 " X: 0
|
|
2436 endfunction
|
|
2437
|
|
2438 while 1
|
|
2439 try
|
|
2440 Xpath 2048 " X: 2048
|
|
2441 while 1
|
|
2442 call F()
|
|
2443 Xpath 4096 " X: 0
|
|
2444 break
|
|
2445 endwhile | Xpath 8192 " X: 0
|
|
2446 Xpath 16384 " X: 0
|
|
2447 finally
|
|
2448 Xpath 32768 " X: 32768
|
|
2449 endtry | Xpath 65536 " X: 0
|
|
2450 endwhile | Xpath 131072 " X: 0
|
|
2451 Xpath 262144 " X: 0
|
|
2452 endif
|
|
2453
|
|
2454 if ExtraVim()
|
|
2455 function! G() abort
|
|
2456 if 1
|
|
2457 try
|
|
2458 Xpath 524288 " X: 524288
|
|
2459 asdf " error
|
|
2460 Xpath 1048576 " X: 0
|
|
2461 finally
|
|
2462 Xpath 2097152 " X: 2097152
|
|
2463 endtry | Xpath 4194304 " X: 0
|
|
2464 endif | Xpath 8388608 " X: 0
|
|
2465 Xpath 16777216 " X: 0
|
|
2466 endfunction
|
|
2467
|
|
2468 if 1
|
|
2469 try
|
|
2470 Xpath 33554432 " X: 33554432
|
|
2471 call G()
|
|
2472 Xpath 67108864 " X: 0
|
|
2473 finally
|
|
2474 Xpath 134217728 " X: 134217728
|
|
2475 endtry | Xpath 268435456 " X: 0
|
|
2476 endif | Xpath 536870912 " X: 0
|
|
2477 Xpath 1073741824 " X: 0
|
|
2478 endif
|
|
2479
|
|
2480 Xcheck 170428555
|
|
2481
|
|
2482
|
|
2483 "-------------------------------------------------------------------------------
|
|
2484 " Test 30: Executing :finally clauses on interrupt {{{1
|
|
2485 "
|
|
2486 " After an interrupt in a command dynamically enclosed in
|
|
2487 " a :try/:endtry region, :finally clauses are executed and the
|
|
2488 " script processing is terminated.
|
|
2489 "-------------------------------------------------------------------------------
|
|
2490
|
|
2491 XpathINIT
|
|
2492
|
|
2493 if ExtraVim()
|
|
2494 XloopINIT 1 16
|
|
2495
|
|
2496 function! F()
|
|
2497 try
|
|
2498 Xloop 1 " X: 1 + 1*16
|
|
2499 "INTERRUPT
|
|
2500 Xloop 2 " X: 0
|
|
2501 finally
|
|
2502 Xloop 4 " X: 4 + 4*16
|
|
2503 endtry
|
|
2504 Xloop 8 " X: 0
|
|
2505 endfunction
|
|
2506
|
|
2507 try
|
|
2508 Xpath 256 " X: 256
|
|
2509 try
|
|
2510 Xpath 512 " X: 512
|
|
2511 "INTERRUPT
|
|
2512 Xpath 1024 " X: 0
|
|
2513 finally
|
|
2514 Xpath 2048 " X: 2048
|
|
2515 try
|
|
2516 Xpath 4096 " X: 4096
|
|
2517 try
|
|
2518 Xpath 8192 " X: 8192
|
|
2519 finally
|
|
2520 Xpath 16384 " X: 16384
|
|
2521 try
|
|
2522 Xpath 32768 " X: 32768
|
|
2523 "INTERRUPT
|
|
2524 Xpath 65536 " X: 0
|
|
2525 endtry
|
|
2526 Xpath 131072 " X: 0
|
|
2527 endtry
|
|
2528 Xpath 262144 " X: 0
|
|
2529 endtry
|
|
2530 Xpath 524288 " X: 0
|
|
2531 endtry
|
|
2532 Xpath 1048576 " X: 0
|
|
2533 finally
|
|
2534 Xpath 2097152 " X: 2097152
|
|
2535 try
|
|
2536 Xpath 4194304 " X: 4194304
|
|
2537 call F()
|
|
2538 Xpath 8388608 " X: 0
|
|
2539 finally
|
|
2540 Xpath 16777216 " X: 16777216
|
|
2541 try
|
|
2542 Xpath 33554432 " X: 33554432
|
|
2543 XloopNEXT
|
|
2544 ExecAsScript F
|
|
2545 Xpath 67108864 " X: 0
|
|
2546 finally
|
|
2547 Xpath 134217728 " X: 134217728
|
|
2548 endtry
|
|
2549 Xpath 268435456 " X: 0
|
|
2550 endtry
|
|
2551 Xpath 536870912 " X: 0
|
|
2552 endtry
|
|
2553 Xpath 1073741824 " X: 0
|
|
2554 endif
|
|
2555
|
|
2556 Xcheck 190905173
|
|
2557
|
|
2558
|
|
2559 "-------------------------------------------------------------------------------
|
|
2560 " Test 31: Executing :finally clauses after :throw {{{1
|
|
2561 "
|
|
2562 " After a :throw dynamically enclosed in a :try/:endtry region,
|
|
2563 " :finally clauses are executed and the script processing is
|
|
2564 " terminated.
|
|
2565 "-------------------------------------------------------------------------------
|
|
2566
|
|
2567 XpathINIT
|
|
2568
|
|
2569 if ExtraVim()
|
|
2570 XloopINIT 1 16
|
|
2571
|
|
2572 function! F()
|
|
2573 try
|
|
2574 Xloop 1 " X: 1 + 1*16
|
|
2575 throw "exception"
|
|
2576 Xloop 2 " X: 0
|
|
2577 finally
|
|
2578 Xloop 4 " X: 4 + 4*16
|
|
2579 endtry
|
|
2580 Xloop 8 " X: 0
|
|
2581 endfunction
|
|
2582
|
|
2583 try
|
|
2584 Xpath 256 " X: 256
|
|
2585 try
|
|
2586 Xpath 512 " X: 512
|
|
2587 throw "exception"
|
|
2588 Xpath 1024 " X: 0
|
|
2589 finally
|
|
2590 Xpath 2048 " X: 2048
|
|
2591 try
|
|
2592 Xpath 4096 " X: 4096
|
|
2593 try
|
|
2594 Xpath 8192 " X: 8192
|
|
2595 finally
|
|
2596 Xpath 16384 " X: 16384
|
|
2597 try
|
|
2598 Xpath 32768 " X: 32768
|
|
2599 throw "exception"
|
|
2600 Xpath 65536 " X: 0
|
|
2601 endtry
|
|
2602 Xpath 131072 " X: 0
|
|
2603 endtry
|
|
2604 Xpath 262144 " X: 0
|
|
2605 endtry
|
|
2606 Xpath 524288 " X: 0
|
|
2607 endtry
|
|
2608 Xpath 1048576 " X: 0
|
|
2609 finally
|
|
2610 Xpath 2097152 " X: 2097152
|
|
2611 try
|
|
2612 Xpath 4194304 " X: 4194304
|
|
2613 call F()
|
|
2614 Xpath 8388608 " X: 0
|
|
2615 finally
|
|
2616 Xpath 16777216 " X: 16777216
|
|
2617 try
|
|
2618 Xpath 33554432 " X: 33554432
|
|
2619 XloopNEXT
|
|
2620 ExecAsScript F
|
|
2621 Xpath 67108864 " X: 0
|
|
2622 finally
|
|
2623 Xpath 134217728 " X: 134217728
|
|
2624 endtry
|
|
2625 Xpath 268435456 " X: 0
|
|
2626 endtry
|
|
2627 Xpath 536870912 " X: 0
|
|
2628 endtry
|
|
2629 Xpath 1073741824 " X: 0
|
|
2630 endif
|
|
2631
|
|
2632 Xcheck 190905173
|
|
2633
|
|
2634
|
|
2635 "-------------------------------------------------------------------------------
|
|
2636 " Test 32: Remembering the :return value on :finally {{{1
|
|
2637 "
|
|
2638 " If a :finally clause is executed due to a :return specifying
|
|
2639 " a value, this is the value visible to the caller if not overwritten
|
|
2640 " by a new :return in the :finally clause. A :return without a value
|
|
2641 " in the :finally clause overwrites with value 0.
|
|
2642 "-------------------------------------------------------------------------------
|
|
2643
|
|
2644 XpathINIT
|
|
2645
|
|
2646 function! F()
|
|
2647 try
|
|
2648 Xpath 1 " X: 1
|
|
2649 try
|
|
2650 Xpath 2 " X: 2
|
|
2651 return "ABCD"
|
|
2652 Xpath 4 " X: 0
|
|
2653 finally
|
|
2654 Xpath 8 " X: 8
|
|
2655 endtry
|
|
2656 Xpath 16 " X: 0
|
|
2657 finally
|
|
2658 Xpath 32 " X: 32
|
|
2659 endtry
|
|
2660 Xpath 64 " X: 0
|
|
2661 endfunction
|
|
2662
|
|
2663 function! G()
|
|
2664 try
|
|
2665 Xpath 128 " X: 128
|
|
2666 return 8
|
|
2667 Xpath 256 " X: 0
|
|
2668 finally
|
|
2669 Xpath 512 " X: 512
|
|
2670 return 16 + strlen(F())
|
|
2671 Xpath 1024 " X: 0
|
|
2672 endtry
|
|
2673 Xpath 2048 " X: 0
|
|
2674 endfunction
|
|
2675
|
|
2676 function! H()
|
|
2677 try
|
|
2678 Xpath 4096 " X: 4096
|
|
2679 return 32
|
|
2680 Xpath 8192 " X: 0
|
|
2681 finally
|
|
2682 Xpath 16384 " X: 16384
|
|
2683 return
|
|
2684 Xpath 32768 " X: 0
|
|
2685 endtry
|
|
2686 Xpath 65536 " X: 0
|
|
2687 endfunction
|
|
2688
|
|
2689 function! I()
|
|
2690 try
|
|
2691 Xpath 131072 " X: 131072
|
|
2692 finally
|
|
2693 Xpath 262144 " X: 262144
|
|
2694 return G() + H() + 64
|
|
2695 Xpath 524288 " X: 0
|
|
2696 endtry
|
|
2697 Xpath 1048576 " X: 0
|
|
2698 endfunction
|
|
2699
|
|
2700 let retcode = I()
|
|
2701 Xpath 2097152 " X: 2097152
|
|
2702
|
|
2703 if retcode < 0
|
|
2704 Xpath 4194304 " X: 0
|
|
2705 endif
|
|
2706 if retcode % 4
|
|
2707 Xpath 8388608 " X: 0
|
|
2708 endif
|
|
2709 if (retcode/4) % 2
|
|
2710 Xpath 16777216 " X: 16777216
|
|
2711 endif
|
|
2712 if (retcode/8) % 2
|
|
2713 Xpath 33554432 " X: 0
|
|
2714 endif
|
|
2715 if (retcode/16) % 2
|
|
2716 Xpath 67108864 " X: 67108864
|
|
2717 endif
|
|
2718 if (retcode/32) % 2
|
|
2719 Xpath 134217728 " X: 0
|
|
2720 endif
|
|
2721 if (retcode/64) % 2
|
|
2722 Xpath 268435456 " X: 268435456
|
|
2723 endif
|
|
2724 if retcode/128
|
|
2725 Xpath 536870912 " X: 0
|
|
2726 endif
|
|
2727
|
|
2728 unlet retcode
|
|
2729 delfunction F
|
|
2730 delfunction G
|
|
2731 delfunction H
|
|
2732 delfunction I
|
|
2733
|
|
2734 Xcheck 354833067
|
|
2735
|
|
2736
|
|
2737 "-------------------------------------------------------------------------------
|
|
2738 " Test 33: :return under :execute or user command and :finally {{{1
|
|
2739 "
|
|
2740 " A :return command may be executed under an ":execute" or from
|
|
2741 " a user command. Executing of :finally clauses and passing through
|
|
2742 " the return code works also then.
|
|
2743 "-------------------------------------------------------------------------------
|
|
2744 XpathINIT
|
|
2745
|
|
2746 command! -nargs=? RETURN
|
|
2747 \ try | return <args> | finally | return <args> * 2 | endtry
|
|
2748
|
|
2749 function! F()
|
|
2750 try
|
|
2751 RETURN 8
|
|
2752 Xpath 1 " X: 0
|
|
2753 finally
|
|
2754 Xpath 2 " X: 2
|
|
2755 endtry
|
|
2756 Xpath 4 " X: 0
|
|
2757 endfunction
|
|
2758
|
|
2759 function! G()
|
|
2760 try
|
|
2761 RETURN 32
|
|
2762 Xpath 8 " X: 0
|
|
2763 finally
|
|
2764 Xpath 16 " X: 16
|
|
2765 RETURN 128
|
|
2766 Xpath 32 " X: 0
|
|
2767 endtry
|
|
2768 Xpath 64 " X: 0
|
|
2769 endfunction
|
|
2770
|
|
2771 function! H()
|
|
2772 try
|
|
2773 execute "try | return 512 | finally | return 1024 | endtry"
|
|
2774 Xpath 128 " X: 0
|
|
2775 finally
|
|
2776 Xpath 256 " X: 256
|
|
2777 endtry
|
|
2778 Xpath 512 " X: 0
|
|
2779 endfunction
|
|
2780
|
|
2781 function! I()
|
|
2782 try
|
|
2783 execute "try | return 2048 | finally | return 4096 | endtry"
|
|
2784 Xpath 1024 " X: 0
|
|
2785 finally
|
|
2786 Xpath 2048 " X: 2048
|
|
2787 execute "try | return 8192 | finally | return 16384 | endtry"
|
|
2788 Xpath 4096 " X: 0
|
|
2789 endtry
|
|
2790 Xpath 8192 " X: 0
|
|
2791 endfunction
|
|
2792
|
|
2793 function! J()
|
|
2794 try
|
|
2795 RETURN 32768
|
|
2796 Xpath 16384 " X: 0
|
|
2797 finally
|
|
2798 Xpath 32768 " X: 32768
|
|
2799 return
|
|
2800 Xpath 65536 " X: 0
|
|
2801 endtry
|
|
2802 Xpath 131072 " X: 0
|
|
2803 endfunction
|
|
2804
|
|
2805 function! K()
|
|
2806 try
|
|
2807 execute "try | return 131072 | finally | return 262144 | endtry"
|
|
2808 Xpath 262144 " X: 0
|
|
2809 finally
|
|
2810 Xpath 524288 " X: 524288
|
|
2811 execute "try | return 524288 | finally | return | endtry"
|
|
2812 Xpath 1048576 " X: 0
|
|
2813 endtry
|
|
2814 Xpath 2097152 " X: 0
|
|
2815 endfunction
|
|
2816
|
|
2817 function! L()
|
|
2818 try
|
|
2819 return
|
|
2820 Xpath 4194304 " X: 0
|
|
2821 finally
|
|
2822 Xpath 8388608 " X: 8388608
|
|
2823 RETURN 1048576
|
|
2824 Xpath 16777216 " X: 0
|
|
2825 endtry
|
|
2826 Xpath 33554432 " X: 0
|
|
2827 endfunction
|
|
2828
|
|
2829 function! M()
|
|
2830 try
|
|
2831 return
|
|
2832 Xpath 67108864 " X: 0
|
|
2833 finally
|
|
2834 Xpath 134217728 " X: 134217728
|
|
2835 execute "try | return 4194304 | finally | return 8388608 | endtry"
|
|
2836 Xpath 268435456 " X: 0
|
|
2837 endtry
|
|
2838 Xpath 536870912 " X: 0
|
|
2839 endfunction
|
|
2840
|
|
2841 function! N()
|
|
2842 RETURN 16777216
|
|
2843 endfunction
|
|
2844
|
|
2845 function! O()
|
|
2846 execute "try | return 67108864 | finally | return 134217728 | endtry"
|
|
2847 endfunction
|
|
2848
|
|
2849 let sum = F() + G() + H() + I() + J() + K() + L() + M()
|
|
2850 let expected = 16 + 256 + 1024 + 16384 + 0 + 0 + 2097152 + 8388608
|
|
2851 let sum = sum + N() + O()
|
|
2852 let expected = expected + 33554432 + 134217728
|
|
2853
|
|
2854 if sum == expected
|
|
2855 Xout "sum = " . sum . " (ok)"
|
|
2856 else
|
|
2857 Xout "sum = " . sum . ", expected: " . expected
|
|
2858 endif
|
|
2859
|
|
2860 Xpath 1073741824 " X: 1073741824
|
|
2861
|
|
2862 if sum != expected
|
|
2863 " The Xpath command does not accept 2^31 (negative); add explicitly:
|
|
2864 let Xpath = Xpath + 2147483648 " X: 0
|
|
2865 endif
|
|
2866
|
|
2867 unlet sum expected
|
|
2868 delfunction F
|
|
2869 delfunction G
|
|
2870 delfunction H
|
|
2871 delfunction I
|
|
2872 delfunction J
|
|
2873 delfunction K
|
|
2874 delfunction L
|
|
2875 delfunction M
|
|
2876 delfunction N
|
|
2877 delfunction O
|
|
2878
|
|
2879 Xcheck 1216907538
|
|
2880
|
|
2881
|
|
2882 "-------------------------------------------------------------------------------
|
|
2883 " Test 34: :finally reason discarded by :continue {{{1
|
|
2884 "
|
|
2885 " When a :finally clause is executed due to a :continue, :break,
|
|
2886 " :return, :finish, error, interrupt or :throw, the jump reason is
|
|
2887 " discarded by a :continue in the finally clause.
|
|
2888 "-------------------------------------------------------------------------------
|
|
2889
|
|
2890 XpathINIT
|
|
2891
|
|
2892 if ExtraVim()
|
|
2893
|
|
2894 XloopINIT! 1 8
|
|
2895
|
|
2896 function! C(jump)
|
|
2897 XloopNEXT
|
|
2898 let loop = 0
|
|
2899 while loop < 2
|
|
2900 let loop = loop + 1
|
|
2901 if loop == 1
|
|
2902 try
|
|
2903 if a:jump == "continue"
|
|
2904 continue
|
|
2905 elseif a:jump == "break"
|
|
2906 break
|
|
2907 elseif a:jump == "return" || a:jump == "finish"
|
|
2908 return
|
|
2909 elseif a:jump == "error"
|
|
2910 asdf
|
|
2911 elseif a:jump == "interrupt"
|
|
2912 "INTERRUPT
|
|
2913 let dummy = 0
|
|
2914 elseif a:jump == "throw"
|
|
2915 throw "abc"
|
|
2916 endif
|
|
2917 finally
|
|
2918 continue " discards jump that caused the :finally
|
|
2919 Xloop 1 " X: 0
|
|
2920 endtry
|
|
2921 Xloop 2 " X: 0
|
|
2922 elseif loop == 2
|
|
2923 Xloop 4 " X: 4*(1+8+64+512+4096+32768+262144)
|
|
2924 endif
|
|
2925 endwhile
|
|
2926 endfunction
|
|
2927
|
|
2928 call C("continue")
|
|
2929 Xpath 2097152 " X: 2097152
|
|
2930 call C("break")
|
|
2931 Xpath 4194304 " X: 4194304
|
|
2932 call C("return")
|
|
2933 Xpath 8388608 " X: 8388608
|
|
2934 let g:jump = "finish"
|
|
2935 ExecAsScript C
|
|
2936 unlet g:jump
|
|
2937 Xpath 16777216 " X: 16777216
|
|
2938 try
|
|
2939 call C("error")
|
|
2940 Xpath 33554432 " X: 33554432
|
|
2941 finally
|
|
2942 Xpath 67108864 " X: 67108864
|
|
2943 try
|
|
2944 call C("interrupt")
|
|
2945 Xpath 134217728 " X: 134217728
|
|
2946 finally
|
|
2947 Xpath 268435456 " X: 268435456
|
|
2948 call C("throw")
|
|
2949 Xpath 536870912 " X: 536870912
|
|
2950 endtry
|
|
2951 endtry
|
|
2952 Xpath 1073741824 " X: 1073741824
|
|
2953
|
|
2954 delfunction C
|
|
2955
|
|
2956 endif
|
|
2957
|
|
2958 Xcheck 2146584868
|
|
2959
|
|
2960
|
|
2961 "-------------------------------------------------------------------------------
|
|
2962 " Test 35: :finally reason discarded by :break {{{1
|
|
2963 "
|
|
2964 " When a :finally clause is executed due to a :continue, :break,
|
|
2965 " :return, :finish, error, interrupt or :throw, the jump reason is
|
|
2966 " discarded by a :break in the finally clause.
|
|
2967 "-------------------------------------------------------------------------------
|
|
2968
|
|
2969 XpathINIT
|
|
2970
|
|
2971 if ExtraVim()
|
|
2972
|
|
2973 XloopINIT! 1 8
|
|
2974
|
|
2975 function! B(jump)
|
|
2976 XloopNEXT
|
|
2977 let loop = 0
|
|
2978 while loop < 2
|
|
2979 let loop = loop + 1
|
|
2980 if loop == 1
|
|
2981 try
|
|
2982 if a:jump == "continue"
|
|
2983 continue
|
|
2984 elseif a:jump == "break"
|
|
2985 break
|
|
2986 elseif a:jump == "return" || a:jump == "finish"
|
|
2987 return
|
|
2988 elseif a:jump == "error"
|
|
2989 asdf
|
|
2990 elseif a:jump == "interrupt"
|
|
2991 "INTERRUPT
|
|
2992 let dummy = 0
|
|
2993 elseif a:jump == "throw"
|
|
2994 throw "abc"
|
|
2995 endif
|
|
2996 finally
|
|
2997 break " discards jump that caused the :finally
|
|
2998 Xloop 1 " X: 0
|
|
2999 endtry
|
|
3000 elseif loop == 2
|
|
3001 Xloop 2 " X: 0
|
|
3002 endif
|
|
3003 endwhile
|
|
3004 Xloop 4 " X: 4*(1+8+64+512+4096+32768+262144)
|
|
3005 endfunction
|
|
3006
|
|
3007 call B("continue")
|
|
3008 Xpath 2097152 " X: 2097152
|
|
3009 call B("break")
|
|
3010 Xpath 4194304 " X: 4194304
|
|
3011 call B("return")
|
|
3012 Xpath 8388608 " X: 8388608
|
|
3013 let g:jump = "finish"
|
|
3014 ExecAsScript B
|
|
3015 unlet g:jump
|
|
3016 Xpath 16777216 " X: 16777216
|
|
3017 try
|
|
3018 call B("error")
|
|
3019 Xpath 33554432 " X: 33554432
|
|
3020 finally
|
|
3021 Xpath 67108864 " X: 67108864
|
|
3022 try
|
|
3023 call B("interrupt")
|
|
3024 Xpath 134217728 " X: 134217728
|
|
3025 finally
|
|
3026 Xpath 268435456 " X: 268435456
|
|
3027 call B("throw")
|
|
3028 Xpath 536870912 " X: 536870912
|
|
3029 endtry
|
|
3030 endtry
|
|
3031 Xpath 1073741824 " X: 1073741824
|
|
3032
|
|
3033 delfunction B
|
|
3034
|
|
3035 endif
|
|
3036
|
|
3037 Xcheck 2146584868
|
|
3038
|
|
3039
|
|
3040 "-------------------------------------------------------------------------------
|
|
3041 " Test 36: :finally reason discarded by :return {{{1
|
|
3042 "
|
|
3043 " When a :finally clause is executed due to a :continue, :break,
|
|
3044 " :return, :finish, error, interrupt or :throw, the jump reason is
|
|
3045 " discarded by a :return in the finally clause.
|
|
3046 "-------------------------------------------------------------------------------
|
|
3047
|
|
3048 XpathINIT
|
|
3049
|
|
3050 if ExtraVim()
|
|
3051
|
|
3052 XloopINIT! 1 8
|
|
3053
|
|
3054 function! R(jump, retval) abort
|
|
3055 XloopNEXT
|
|
3056 let loop = 0
|
|
3057 while loop < 2
|
|
3058 let loop = loop + 1
|
|
3059 if loop == 1
|
|
3060 try
|
|
3061 if a:jump == "continue"
|
|
3062 continue
|
|
3063 elseif a:jump == "break"
|
|
3064 break
|
|
3065 elseif a:jump == "return"
|
|
3066 return
|
|
3067 elseif a:jump == "error"
|
|
3068 asdf
|
|
3069 elseif a:jump == "interrupt"
|
|
3070 "INTERRUPT
|
|
3071 let dummy = 0
|
|
3072 elseif a:jump == "throw"
|
|
3073 throw "abc"
|
|
3074 endif
|
|
3075 finally
|
|
3076 return a:retval " discards jump that caused the :finally
|
|
3077 Xloop 1 " X: 0
|
|
3078 endtry
|
|
3079 elseif loop == 2
|
|
3080 Xloop 2 " X: 0
|
|
3081 endif
|
|
3082 endwhile
|
|
3083 Xloop 4 " X: 0
|
|
3084 endfunction
|
|
3085
|
|
3086 let sum = -R("continue", -8)
|
|
3087 Xpath 2097152 " X: 2097152
|
|
3088 let sum = sum - R("break", -16)
|
|
3089 Xpath 4194304 " X: 4194304
|
|
3090 let sum = sum - R("return", -32)
|
|
3091 Xpath 8388608 " X: 8388608
|
|
3092 try
|
|
3093 let sum = sum - R("error", -64)
|
|
3094 Xpath 16777216 " X: 16777216
|
|
3095 finally
|
|
3096 Xpath 33554432 " X: 33554432
|
|
3097 try
|
|
3098 let sum = sum - R("interrupt", -128)
|
|
3099 Xpath 67108864 " X: 67108864
|
|
3100 finally
|
|
3101 Xpath 134217728 " X: 134217728
|
|
3102 let sum = sum - R("throw", -256)
|
|
3103 Xpath 268435456 " X: 268435456
|
|
3104 endtry
|
|
3105 endtry
|
|
3106 Xpath 536870912 " X: 536870912
|
|
3107
|
|
3108 let expected = 8 + 16 + 32 + 64 + 128 + 256
|
|
3109 if sum != expected
|
|
3110 Xpath 1073741824 " X: 0
|
|
3111 Xout "sum =" . sum . ", expected: " . expected
|
|
3112 endif
|
|
3113
|
|
3114 unlet sum expected
|
|
3115 delfunction R
|
|
3116
|
|
3117 endif
|
|
3118
|
|
3119 Xcheck 1071644672
|
|
3120
|
|
3121
|
|
3122 "-------------------------------------------------------------------------------
|
|
3123 " Test 37: :finally reason discarded by :finish {{{1
|
|
3124 "
|
|
3125 " When a :finally clause is executed due to a :continue, :break,
|
|
3126 " :return, :finish, error, interrupt or :throw, the jump reason is
|
|
3127 " discarded by a :finish in the finally clause.
|
|
3128 "-------------------------------------------------------------------------------
|
|
3129
|
|
3130 XpathINIT
|
|
3131
|
|
3132 if ExtraVim()
|
|
3133
|
|
3134 XloopINIT! 1 8
|
|
3135
|
|
3136 function! F(jump) " not executed as function, transformed to a script
|
|
3137 XloopNEXT
|
|
3138 let loop = 0
|
|
3139 while loop < 2
|
|
3140 let loop = loop + 1
|
|
3141 if loop == 1
|
|
3142 try
|
|
3143 if a:jump == "continue"
|
|
3144 continue
|
|
3145 elseif a:jump == "break"
|
|
3146 break
|
|
3147 elseif a:jump == "finish"
|
|
3148 finish
|
|
3149 elseif a:jump == "error"
|
|
3150 asdf
|
|
3151 elseif a:jump == "interrupt"
|
|
3152 "INTERRUPT
|
|
3153 let dummy = 0
|
|
3154 elseif a:jump == "throw"
|
|
3155 throw "abc"
|
|
3156 endif
|
|
3157 finally
|
|
3158 finish " discards jump that caused the :finally
|
|
3159 Xloop 1 " X: 0
|
|
3160 endtry
|
|
3161 elseif loop == 2
|
|
3162 Xloop 2 " X: 0
|
|
3163 endif
|
|
3164 endwhile
|
|
3165 Xloop 4 " X: 0
|
|
3166 endfunction
|
|
3167
|
|
3168 let scriptF = MakeScript("F")
|
|
3169 delfunction F
|
|
3170
|
|
3171 let g:jump = "continue"
|
|
3172 exec "source" scriptF
|
|
3173 Xpath 2097152 " X: 2097152
|
|
3174 let g:jump = "break"
|
|
3175 exec "source" scriptF
|
|
3176 Xpath 4194304 " X: 4194304
|
|
3177 let g:jump = "finish"
|
|
3178 exec "source" scriptF
|
|
3179 Xpath 8388608 " X: 8388608
|
|
3180 try
|
|
3181 let g:jump = "error"
|
|
3182 exec "source" scriptF
|
|
3183 Xpath 16777216 " X: 16777216
|
|
3184 finally
|
|
3185 Xpath 33554432 " X: 33554432
|
|
3186 try
|
|
3187 let g:jump = "interrupt"
|
|
3188 exec "source" scriptF
|
|
3189 Xpath 67108864 " X: 67108864
|
|
3190 finally
|
|
3191 Xpath 134217728 " X: 134217728
|
|
3192 try
|
|
3193 let g:jump = "throw"
|
|
3194 exec "source" scriptF
|
|
3195 Xpath 268435456 " X: 268435456
|
|
3196 finally
|
|
3197 Xpath 536870912 " X: 536870912
|
|
3198 endtry
|
|
3199 endtry
|
|
3200 endtry
|
|
3201 unlet g:jump
|
|
3202
|
|
3203 call delete(scriptF)
|
|
3204 unlet scriptF
|
|
3205
|
|
3206 endif
|
|
3207
|
|
3208 Xcheck 1071644672
|
|
3209
|
|
3210
|
|
3211 "-------------------------------------------------------------------------------
|
|
3212 " Test 38: :finally reason discarded by an error {{{1
|
|
3213 "
|
|
3214 " When a :finally clause is executed due to a :continue, :break,
|
|
3215 " :return, :finish, error, interrupt or :throw, the jump reason is
|
|
3216 " discarded by an error in the finally clause.
|
|
3217 "-------------------------------------------------------------------------------
|
|
3218
|
|
3219 XpathINIT
|
|
3220
|
|
3221 if ExtraVim()
|
|
3222
|
|
3223 XloopINIT! 1 4
|
|
3224
|
|
3225 function! E(jump)
|
|
3226 XloopNEXT
|
|
3227 let loop = 0
|
|
3228 while loop < 2
|
|
3229 let loop = loop + 1
|
|
3230 if loop == 1
|
|
3231 try
|
|
3232 if a:jump == "continue"
|
|
3233 continue
|
|
3234 elseif a:jump == "break"
|
|
3235 break
|
|
3236 elseif a:jump == "return" || a:jump == "finish"
|
|
3237 return
|
|
3238 elseif a:jump == "error"
|
|
3239 asdf
|
|
3240 elseif a:jump == "interrupt"
|
|
3241 "INTERRUPT
|
|
3242 let dummy = 0
|
|
3243 elseif a:jump == "throw"
|
|
3244 throw "abc"
|
|
3245 endif
|
|
3246 finally
|
|
3247 asdf " error; discards jump that caused the :finally
|
|
3248 endtry
|
|
3249 elseif loop == 2
|
|
3250 Xloop 1 " X: 0
|
|
3251 endif
|
|
3252 endwhile
|
|
3253 Xloop 2 " X: 0
|
|
3254 endfunction
|
|
3255
|
|
3256 try
|
|
3257 Xpath 16384 " X: 16384
|
|
3258 call E("continue")
|
|
3259 Xpath 32768 " X: 0
|
|
3260 finally
|
|
3261 try
|
|
3262 Xpath 65536 " X: 65536
|
|
3263 call E("break")
|
|
3264 Xpath 131072 " X: 0
|
|
3265 finally
|
|
3266 try
|
|
3267 Xpath 262144 " X: 262144
|
|
3268 call E("return")
|
|
3269 Xpath 524288 " X: 0
|
|
3270 finally
|
|
3271 try
|
|
3272 Xpath 1048576 " X: 1048576
|
|
3273 let g:jump = "finish"
|
|
3274 ExecAsScript E
|
|
3275 Xpath 2097152 " X: 0
|
|
3276 finally
|
|
3277 unlet g:jump
|
|
3278 try
|
|
3279 Xpath 4194304 " X: 4194304
|
|
3280 call E("error")
|
|
3281 Xpath 8388608 " X: 0
|
|
3282 finally
|
|
3283 try
|
|
3284 Xpath 16777216 " X: 16777216
|
|
3285 call E("interrupt")
|
|
3286 Xpath 33554432 " X: 0
|
|
3287 finally
|
|
3288 try
|
|
3289 Xpath 67108864 " X: 67108864
|
|
3290 call E("throw")
|
|
3291 Xpath 134217728 " X: 0
|
|
3292 finally
|
|
3293 Xpath 268435456 " X: 268435456
|
|
3294 delfunction E
|
|
3295 endtry
|
|
3296 endtry
|
|
3297 endtry
|
|
3298 endtry
|
|
3299 endtry
|
|
3300 endtry
|
|
3301 endtry
|
|
3302 Xpath 536870912 " X: 0
|
|
3303
|
|
3304 endif
|
|
3305
|
|
3306 Xcheck 357908480
|
|
3307
|
|
3308
|
|
3309 "-------------------------------------------------------------------------------
|
|
3310 " Test 39: :finally reason discarded by an interrupt {{{1
|
|
3311 "
|
|
3312 " When a :finally clause is executed due to a :continue, :break,
|
|
3313 " :return, :finish, error, interrupt or :throw, the jump reason is
|
|
3314 " discarded by an interrupt in the finally clause.
|
|
3315 "-------------------------------------------------------------------------------
|
|
3316
|
|
3317 XpathINIT
|
|
3318
|
|
3319 if ExtraVim()
|
|
3320
|
|
3321 XloopINIT! 1 4
|
|
3322
|
|
3323 function! I(jump)
|
|
3324 XloopNEXT
|
|
3325 let loop = 0
|
|
3326 while loop < 2
|
|
3327 let loop = loop + 1
|
|
3328 if loop == 1
|
|
3329 try
|
|
3330 if a:jump == "continue"
|
|
3331 continue
|
|
3332 elseif a:jump == "break"
|
|
3333 break
|
|
3334 elseif a:jump == "return" || a:jump == "finish"
|
|
3335 return
|
|
3336 elseif a:jump == "error"
|
|
3337 asdf
|
|
3338 elseif a:jump == "interrupt"
|
|
3339 "INTERRUPT
|
|
3340 let dummy = 0
|
|
3341 elseif a:jump == "throw"
|
|
3342 throw "abc"
|
|
3343 endif
|
|
3344 finally
|
|
3345 "INTERRUPT - discards jump that caused the :finally
|
|
3346 let dummy = 0
|
|
3347 endtry
|
|
3348 elseif loop == 2
|
|
3349 Xloop 1 " X: 0
|
|
3350 endif
|
|
3351 endwhile
|
|
3352 Xloop 2 " X: 0
|
|
3353 endfunction
|
|
3354
|
|
3355 try
|
|
3356 Xpath 16384 " X: 16384
|
|
3357 call I("continue")
|
|
3358 Xpath 32768 " X: 0
|
|
3359 finally
|
|
3360 try
|
|
3361 Xpath 65536 " X: 65536
|
|
3362 call I("break")
|
|
3363 Xpath 131072 " X: 0
|
|
3364 finally
|
|
3365 try
|
|
3366 Xpath 262144 " X: 262144
|
|
3367 call I("return")
|
|
3368 Xpath 524288 " X: 0
|
|
3369 finally
|
|
3370 try
|
|
3371 Xpath 1048576 " X: 1048576
|
|
3372 let g:jump = "finish"
|
|
3373 ExecAsScript I
|
|
3374 Xpath 2097152 " X: 0
|
|
3375 finally
|
|
3376 unlet g:jump
|
|
3377 try
|
|
3378 Xpath 4194304 " X: 4194304
|
|
3379 call I("error")
|
|
3380 Xpath 8388608 " X: 0
|
|
3381 finally
|
|
3382 try
|
|
3383 Xpath 16777216 " X: 16777216
|
|
3384 call I("interrupt")
|
|
3385 Xpath 33554432 " X: 0
|
|
3386 finally
|
|
3387 try
|
|
3388 Xpath 67108864 " X: 67108864
|
|
3389 call I("throw")
|
|
3390 Xpath 134217728 " X: 0
|
|
3391 finally
|
|
3392 Xpath 268435456 " X: 268435456
|
|
3393 delfunction I
|
|
3394 endtry
|
|
3395 endtry
|
|
3396 endtry
|
|
3397 endtry
|
|
3398 endtry
|
|
3399 endtry
|
|
3400 endtry
|
|
3401 Xpath 536870912 " X: 0
|
|
3402
|
|
3403 endif
|
|
3404
|
|
3405 Xcheck 357908480
|
|
3406
|
|
3407
|
|
3408 "-------------------------------------------------------------------------------
|
|
3409 " Test 40: :finally reason discarded by :throw {{{1
|
|
3410 "
|
|
3411 " When a :finally clause is executed due to a :continue, :break,
|
|
3412 " :return, :finish, error, interrupt or :throw, the jump reason is
|
|
3413 " discarded by a :throw in the finally clause.
|
|
3414 "-------------------------------------------------------------------------------
|
|
3415
|
|
3416 XpathINIT
|
|
3417
|
|
3418 if ExtraVim()
|
|
3419
|
|
3420 XloopINIT! 1 4
|
|
3421
|
|
3422 function! T(jump)
|
|
3423 XloopNEXT
|
|
3424 let loop = 0
|
|
3425 while loop < 2
|
|
3426 let loop = loop + 1
|
|
3427 if loop == 1
|
|
3428 try
|
|
3429 if a:jump == "continue"
|
|
3430 continue
|
|
3431 elseif a:jump == "break"
|
|
3432 break
|
|
3433 elseif a:jump == "return" || a:jump == "finish"
|
|
3434 return
|
|
3435 elseif a:jump == "error"
|
|
3436 asdf
|
|
3437 elseif a:jump == "interrupt"
|
|
3438 "INTERRUPT
|
|
3439 let dummy = 0
|
|
3440 elseif a:jump == "throw"
|
|
3441 throw "abc"
|
|
3442 endif
|
|
3443 finally
|
|
3444 throw "xyz" " discards jump that caused the :finally
|
|
3445 endtry
|
|
3446 elseif loop == 2
|
|
3447 Xloop 1 " X: 0
|
|
3448 endif
|
|
3449 endwhile
|
|
3450 Xloop 2 " X: 0
|
|
3451 endfunction
|
|
3452
|
|
3453 try
|
|
3454 Xpath 16384 " X: 16384
|
|
3455 call T("continue")
|
|
3456 Xpath 32768 " X: 0
|
|
3457 finally
|
|
3458 try
|
|
3459 Xpath 65536 " X: 65536
|
|
3460 call T("break")
|
|
3461 Xpath 131072 " X: 0
|
|
3462 finally
|
|
3463 try
|
|
3464 Xpath 262144 " X: 262144
|
|
3465 call T("return")
|
|
3466 Xpath 524288 " X: 0
|
|
3467 finally
|
|
3468 try
|
|
3469 Xpath 1048576 " X: 1048576
|
|
3470 let g:jump = "finish"
|
|
3471 ExecAsScript T
|
|
3472 Xpath 2097152 " X: 0
|
|
3473 finally
|
|
3474 unlet g:jump
|
|
3475 try
|
|
3476 Xpath 4194304 " X: 4194304
|
|
3477 call T("error")
|
|
3478 Xpath 8388608 " X: 0
|
|
3479 finally
|
|
3480 try
|
|
3481 Xpath 16777216 " X: 16777216
|
|
3482 call T("interrupt")
|
|
3483 Xpath 33554432 " X: 0
|
|
3484 finally
|
|
3485 try
|
|
3486 Xpath 67108864 " X: 67108864
|
|
3487 call T("throw")
|
|
3488 Xpath 134217728 " X: 0
|
|
3489 finally
|
|
3490 Xpath 268435456 " X: 268435456
|
|
3491 delfunction T
|
|
3492 endtry
|
|
3493 endtry
|
|
3494 endtry
|
|
3495 endtry
|
|
3496 endtry
|
|
3497 endtry
|
|
3498 endtry
|
|
3499 Xpath 536870912 " X: 0
|
|
3500
|
|
3501 endif
|
|
3502
|
|
3503 Xcheck 357908480
|
|
3504
|
|
3505
|
|
3506 "-------------------------------------------------------------------------------
|
|
3507 " Test 41: Skipped :throw finding next command {{{1
|
|
3508 "
|
|
3509 " A :throw in an inactive conditional must not hide a following
|
|
3510 " command.
|
|
3511 "-------------------------------------------------------------------------------
|
|
3512
|
|
3513 XpathINIT
|
|
3514
|
|
3515 function! F()
|
|
3516 Xpath 1 " X: 1
|
|
3517 if 0 | throw "never" | endif | Xpath 2 " X: 2
|
|
3518 Xpath 4 " X: 4
|
|
3519 endfunction
|
|
3520
|
|
3521 function! G()
|
|
3522 Xpath 8 " X: 8
|
|
3523 while 0 | throw "never" | endwhile | Xpath 16 " X: 16
|
|
3524 Xpath 32 " X: 32
|
|
3525 endfunction
|
|
3526
|
|
3527 function H()
|
|
3528 Xpath 64 " X: 64
|
|
3529 if 0 | try | throw "never" | endtry | endif | Xpath 128 " X: 128
|
|
3530 Xpath 256 " X: 256
|
|
3531 endfunction
|
|
3532
|
|
3533 Xpath 512 " X: 512
|
|
3534
|
|
3535 try
|
|
3536 Xpath 1024 " X: 1024
|
|
3537 call F()
|
|
3538 Xpath 2048 " X: 2048
|
|
3539 catch /.*/
|
|
3540 Xpath 4096 " X: 0
|
|
3541 Xout v:exception "in" v:throwpoint
|
|
3542 endtry
|
|
3543
|
|
3544 Xpath 8192 " X: 8192
|
|
3545
|
|
3546 try
|
|
3547 Xpath 16384 " X: 16384
|
|
3548 call G()
|
|
3549 Xpath 32768 " X: 32768
|
|
3550 catch /.*/
|
|
3551 Xpath 65536 " X: 0
|
|
3552 Xout v:exception "in" v:throwpoint
|
|
3553 endtry
|
|
3554
|
|
3555 Xpath 131072 " X: 131072
|
|
3556
|
|
3557 try
|
|
3558 Xpath 262144 " X: 262144
|
|
3559 call H()
|
|
3560 Xpath 524288 " X: 524288
|
|
3561 catch /.*/
|
|
3562 Xpath 1048576 " X: 0
|
|
3563 Xout v:exception "in" v:throwpoint
|
|
3564 endtry
|
|
3565
|
|
3566 Xpath 2097152 " X: 2097152
|
|
3567
|
|
3568 delfunction F
|
|
3569 delfunction G
|
|
3570 delfunction H
|
|
3571
|
|
3572 Xcheck 3076095
|
|
3573
|
|
3574
|
|
3575 "-------------------------------------------------------------------------------
|
|
3576 " Test 42: Catching number and string exceptions {{{1
|
|
3577 "
|
|
3578 " When a number is thrown, it is converted to a string exception.
|
|
3579 " Numbers and strings may be caught by specifying a regular exception
|
|
3580 " as argument to the :catch command.
|
|
3581 "-------------------------------------------------------------------------------
|
|
3582
|
|
3583 XpathINIT
|
|
3584
|
|
3585 try
|
|
3586
|
|
3587 try
|
|
3588 Xpath 1 " X: 1
|
|
3589 throw 4711
|
|
3590 Xpath 2 " X: 0
|
|
3591 catch /4711/
|
|
3592 Xpath 4 " X: 4
|
|
3593 endtry
|
|
3594
|
|
3595 try
|
|
3596 Xpath 8 " X: 8
|
|
3597 throw 4711
|
|
3598 Xpath 16 " X: 0
|
|
3599 catch /^4711$/
|
|
3600 Xpath 32 " X: 32
|
|
3601 endtry
|
|
3602
|
|
3603 try
|
|
3604 Xpath 64 " X: 64
|
|
3605 throw 4711
|
|
3606 Xpath 128 " X: 0
|
|
3607 catch /\d/
|
|
3608 Xpath 256 " X: 256
|
|
3609 endtry
|
|
3610
|
|
3611 try
|
|
3612 Xpath 512 " X: 512
|
|
3613 throw 4711
|
|
3614 Xpath 1024 " X: 0
|
|
3615 catch /^\d\+$/
|
|
3616 Xpath 2048 " X: 2048
|
|
3617 endtry
|
|
3618
|
|
3619 try
|
|
3620 Xpath 4096 " X: 4096
|
|
3621 throw "arrgh"
|
|
3622 Xpath 8192 " X: 0
|
|
3623 catch /arrgh/
|
|
3624 Xpath 16384 " X: 16384
|
|
3625 endtry
|
|
3626
|
|
3627 try
|
|
3628 Xpath 32768 " X: 32768
|
|
3629 throw "arrgh"
|
|
3630 Xpath 65536 " X: 0
|
|
3631 catch /^arrgh$/
|
|
3632 Xpath 131072 " X: 131072
|
|
3633 endtry
|
|
3634
|
|
3635 try
|
|
3636 Xpath 262144 " X: 262144
|
|
3637 throw "arrgh"
|
|
3638 Xpath 524288 " X: 0
|
|
3639 catch /\l/
|
|
3640 Xpath 1048576 " X: 1048576
|
|
3641 endtry
|
|
3642
|
|
3643 try
|
|
3644 Xpath 2097152 " X: 2097152
|
|
3645 throw "arrgh"
|
|
3646 Xpath 4194304 " X: 0
|
|
3647 catch /^\l\+$/
|
|
3648 Xpath 8388608 " X: 8388608
|
|
3649 endtry
|
|
3650
|
|
3651 try
|
|
3652 try
|
|
3653 Xpath 16777216 " X: 16777216
|
|
3654 throw "ARRGH"
|
|
3655 Xpath 33554432 " X: 0
|
|
3656 catch /^arrgh$/
|
|
3657 Xpath 67108864 " X: 0
|
|
3658 endtry
|
|
3659 catch /^\carrgh$/
|
|
3660 Xpath 134217728 " X: 134217728
|
|
3661 endtry
|
|
3662
|
|
3663 try
|
|
3664 Xpath 268435456 " X: 268435456
|
|
3665 throw ""
|
|
3666 Xpath 536870912 " X: 0
|
|
3667 catch /^$/
|
|
3668 Xpath 1073741824 " X: 1073741824
|
|
3669 endtry
|
|
3670
|
|
3671 catch /.*/
|
|
3672 " The Xpath command does not accept 2^31 (negative); add explicitly:
|
|
3673 let Xpath = Xpath + 2147483648 " X: 0
|
|
3674 Xout v:exception "in" v:throwpoint
|
|
3675 endtry
|
|
3676
|
|
3677 Xcheck 1505155949
|
|
3678
|
|
3679
|
|
3680 "-------------------------------------------------------------------------------
|
|
3681 " Test 43: Selecting the correct :catch clause {{{1
|
|
3682 "
|
|
3683 " When an exception is thrown and there are multiple :catch clauses,
|
|
3684 " the first matching one is taken.
|
|
3685 "-------------------------------------------------------------------------------
|
|
3686
|
|
3687 XpathINIT
|
|
3688
|
|
3689 XloopINIT 1 1024
|
|
3690 let loops = 3
|
|
3691 while loops > 0
|
|
3692 try
|
|
3693 if loops == 3
|
|
3694 Xloop 1 " X: 1
|
|
3695 throw "a"
|
|
3696 Xloop 2 " X: 0
|
|
3697 elseif loops == 2
|
|
3698 Xloop 4 " X: 4*1024
|
|
3699 throw "ab"
|
|
3700 Xloop 8 " X: 0
|
|
3701 elseif loops == 1
|
|
3702 Xloop 16 " X: 16*1024*1024
|
|
3703 throw "abc"
|
|
3704 Xloop 32 " X: 0
|
|
3705 endif
|
|
3706 catch /abc/
|
|
3707 Xloop 64 " X: 64*1024*1024
|
|
3708 catch /ab/
|
|
3709 Xloop 128 " X: 128*1024
|
|
3710 catch /.*/
|
|
3711 Xloop 256 " X: 256
|
|
3712 catch /a/
|
|
3713 Xloop 512 " X: 0
|
|
3714 endtry
|
|
3715
|
|
3716 let loops = loops - 1
|
|
3717 XloopNEXT
|
|
3718 endwhile
|
|
3719 Xpath 1073741824 " X: 1073741824
|
|
3720
|
|
3721 unlet loops
|
|
3722
|
|
3723 Xcheck 1157763329
|
|
3724
|
|
3725
|
|
3726 "-------------------------------------------------------------------------------
|
|
3727 " Test 44: Missing or empty :catch patterns {{{1
|
|
3728 "
|
|
3729 " A missing or empty :catch pattern means the same as /.*/, that is,
|
|
3730 " catches everything. To catch only empty exceptions, /^$/ must be
|
|
3731 " used. A :catch with missing, empty, or /.*/ argument also works
|
|
3732 " when followed by another command separated by a bar on the same
|
|
3733 " line. :catch patterns cannot be specified between ||. But other
|
|
3734 " pattern separators can be used instead of //.
|
|
3735 "-------------------------------------------------------------------------------
|
|
3736
|
|
3737 XpathINIT
|
|
3738
|
|
3739 try
|
|
3740 try
|
|
3741 Xpath 1 " X: 1
|
|
3742 throw ""
|
|
3743 catch /^$/
|
|
3744 Xpath 2 " X: 2
|
|
3745 endtry
|
|
3746
|
|
3747 try
|
|
3748 Xpath 4 " X: 4
|
|
3749 throw ""
|
|
3750 catch /.*/
|
|
3751 Xpath 8 " X: 8
|
|
3752 endtry
|
|
3753
|
|
3754 try
|
|
3755 Xpath 16 " X: 16
|
|
3756 throw ""
|
|
3757 catch //
|
|
3758 Xpath 32 " X: 32
|
|
3759 endtry
|
|
3760
|
|
3761 try
|
|
3762 Xpath 64 " X: 64
|
|
3763 throw ""
|
|
3764 catch
|
|
3765 Xpath 128 " X: 128
|
|
3766 endtry
|
|
3767
|
|
3768 try
|
|
3769 Xpath 256 " X: 256
|
|
3770 throw "oops"
|
|
3771 catch /^$/
|
|
3772 Xpath 512 " X: 0
|
|
3773 catch /.*/
|
|
3774 Xpath 1024 " X: 1024
|
|
3775 endtry
|
|
3776
|
|
3777 try
|
|
3778 Xpath 2048 " X: 2048
|
|
3779 throw "arrgh"
|
|
3780 catch /^$/
|
|
3781 Xpath 4096 " X: 0
|
|
3782 catch //
|
|
3783 Xpath 8192 " X: 8192
|
|
3784 endtry
|
|
3785
|
|
3786 try
|
|
3787 Xpath 16384 " X: 16384
|
|
3788 throw "brrr"
|
|
3789 catch /^$/
|
|
3790 Xpath 32768 " X: 0
|
|
3791 catch
|
|
3792 Xpath 65536 " X: 65536
|
|
3793 endtry
|
|
3794
|
|
3795 try | Xpath 131072 | throw "x" | catch /.*/ | Xpath 262144 | endtry
|
|
3796 " X: 131072 + 262144
|
|
3797
|
|
3798 try | Xpath 524288 | throw "y" | catch // | Xpath 1048576 | endtry
|
|
3799 " X: 524288 + 1048576
|
|
3800
|
|
3801 while 1
|
|
3802 try
|
|
3803 let caught = 0
|
|
3804 let v:errmsg = ""
|
|
3805 " Extra try level: if ":catch" without arguments below raises
|
|
3806 " a syntax error because it misinterprets the "Xpath" as a pattern,
|
|
3807 " let it be caught by the ":catch /.*/" below.
|
|
3808 try
|
|
3809 try | Xpath 2097152 | throw "z" | catch | Xpath 4194304 | :
|
|
3810 endtry " X: 2097152 + 4194304
|
|
3811 endtry
|
|
3812 catch /.*/
|
|
3813 let caught = 1
|
|
3814 Xout v:exception "in" v:throwpoint
|
|
3815 finally
|
|
3816 if $VIMNOERRTHROW && v:errmsg != ""
|
|
3817 Xout v:errmsg
|
|
3818 endif
|
|
3819 if caught || $VIMNOERRTHROW && v:errmsg != ""
|
|
3820 Xpath 8388608 " X: 0
|
|
3821 endif
|
|
3822 break " discard error for $VIMNOERRTHROW
|
|
3823 endtry
|
|
3824 endwhile
|
|
3825
|
|
3826 let cologne = 4711
|
|
3827 try
|
|
3828 try
|
|
3829 Xpath 16777216 " X: 16777216
|
|
3830 throw "throw cologne"
|
|
3831 " Next lines catches all and throws 4711:
|
|
3832 catch |throw cologne|
|
|
3833 Xpath 33554432 " X: 0
|
|
3834 endtry
|
|
3835 catch /4711/
|
|
3836 Xpath 67108864 " X: 67108864
|
|
3837 endtry
|
|
3838
|
|
3839 try
|
|
3840 Xpath 134217728 " X: 134217728
|
|
3841 throw "plus"
|
|
3842 catch +plus+
|
|
3843 Xpath 268435456 " X: 268435456
|
|
3844 endtry
|
|
3845
|
|
3846 Xpath 536870912 " X: 536870912
|
|
3847 catch /.*/
|
|
3848 Xpath 1073741824 " X: 0
|
|
3849 Xout v:exception "in" v:throwpoint
|
|
3850 endtry
|
|
3851
|
|
3852 unlet! caught cologne
|
|
3853
|
|
3854 Xcheck 1031761407
|
|
3855
|
|
3856
|
|
3857 "-------------------------------------------------------------------------------
|
|
3858 " Test 45: Catching exceptions from nested :try blocks {{{1
|
|
3859 "
|
|
3860 " When :try blocks are nested, an exception is caught by the innermost
|
|
3861 " try conditional that has a matching :catch clause.
|
|
3862 "-------------------------------------------------------------------------------
|
|
3863
|
|
3864 XpathINIT
|
|
3865
|
|
3866 XloopINIT 1 1024
|
|
3867 let loops = 3
|
|
3868 while loops > 0
|
|
3869 try
|
|
3870 try
|
|
3871 try
|
|
3872 try
|
|
3873 if loops == 3
|
|
3874 Xloop 1 " X: 1
|
|
3875 throw "a"
|
|
3876 Xloop 2 " X: 0
|
|
3877 elseif loops == 2
|
|
3878 Xloop 4 " X: 4*1024
|
|
3879 throw "ab"
|
|
3880 Xloop 8 " X: 0
|
|
3881 elseif loops == 1
|
|
3882 Xloop 16 " X: 16*1024*1024
|
|
3883 throw "abc"
|
|
3884 Xloop 32 " X: 0
|
|
3885 endif
|
|
3886 catch /abc/
|
|
3887 Xloop 64 " X: 64*1024*1024
|
|
3888 endtry
|
|
3889 catch /ab/
|
|
3890 Xloop 128 " X: 128*1024
|
|
3891 endtry
|
|
3892 catch /.*/
|
|
3893 Xloop 256 " X: 256
|
|
3894 endtry
|
|
3895 catch /a/
|
|
3896 Xloop 512 " X: 0
|
|
3897 endtry
|
|
3898
|
|
3899 let loops = loops - 1
|
|
3900 XloopNEXT
|
|
3901 endwhile
|
|
3902 Xpath 1073741824 " X: 1073741824
|
|
3903
|
|
3904 unlet loops
|
|
3905
|
|
3906 Xcheck 1157763329
|
|
3907
|
|
3908
|
|
3909 "-------------------------------------------------------------------------------
|
|
3910 " Test 46: Executing :finally after a :throw in nested :try {{{1
|
|
3911 "
|
|
3912 " When an exception is thrown from within nested :try blocks, the
|
|
3913 " :finally clauses of the non-catching try conditionals should be
|
|
3914 " executed before the matching :catch of the next surrounding :try
|
|
3915 " gets the control. If this also has a :finally clause, it is
|
|
3916 " executed afterwards.
|
|
3917 "-------------------------------------------------------------------------------
|
|
3918
|
|
3919 XpathINIT
|
|
3920
|
|
3921 let sum = 0
|
|
3922
|
|
3923 try
|
|
3924 Xpath 1 " X: 1
|
|
3925 try
|
|
3926 Xpath 2 " X: 2
|
|
3927 try
|
|
3928 Xpath 4 " X: 4
|
|
3929 try
|
|
3930 Xpath 8 " X: 8
|
|
3931 throw "ABC"
|
|
3932 Xpath 16 " X: 0
|
|
3933 catch /xyz/
|
|
3934 Xpath 32 " X: 0
|
|
3935 finally
|
|
3936 Xpath 64 " X: 64
|
|
3937 if sum != 0
|
|
3938 Xpath 128 " X: 0
|
|
3939 endif
|
|
3940 let sum = sum + 1
|
|
3941 endtry
|
|
3942 Xpath 256 " X: 0
|
|
3943 catch /123/
|
|
3944 Xpath 512 " X: 0
|
|
3945 catch /321/
|
|
3946 Xpath 1024 " X: 0
|
|
3947 finally
|
|
3948 Xpath 2048 " X: 2048
|
|
3949 if sum != 1
|
|
3950 Xpath 4096 " X: 0
|
|
3951 endif
|
|
3952 let sum = sum + 2
|
|
3953 endtry
|
|
3954 Xpath 8192 " X: 0
|
|
3955 finally
|
|
3956 Xpath 16384 " X: 16384
|
|
3957 if sum != 3
|
|
3958 Xpath 32768 " X: 0
|
|
3959 endif
|
|
3960 let sum = sum + 4
|
|
3961 endtry
|
|
3962 Xpath 65536 " X: 0
|
|
3963 catch /ABC/
|
|
3964 Xpath 131072 " X: 131072
|
|
3965 if sum != 7
|
|
3966 Xpath 262144 " X: 0
|
|
3967 endif
|
|
3968 let sum = sum + 8
|
|
3969 finally
|
|
3970 Xpath 524288 " X: 524288
|
|
3971 if sum != 15
|
|
3972 Xpath 1048576 " X: 0
|
|
3973 endif
|
|
3974 let sum = sum + 16
|
|
3975 endtry
|
|
3976 Xpath 65536 " X: 65536
|
|
3977 if sum != 31
|
|
3978 Xpath 131072 " X: 0
|
|
3979 endif
|
|
3980
|
|
3981 unlet sum
|
|
3982
|
|
3983 Xcheck 739407
|
|
3984
|
|
3985
|
|
3986 "-------------------------------------------------------------------------------
|
|
3987 " Test 47: Throwing exceptions from a :catch clause {{{1
|
|
3988 "
|
|
3989 " When an exception is thrown from a :catch clause, it should not be
|
|
3990 " caught by a :catch of the same :try conditional. After executing
|
|
3991 " the :finally clause (if present), surrounding try conditionals
|
|
3992 " should be checked for a matching :catch.
|
|
3993 "-------------------------------------------------------------------------------
|
|
3994
|
|
3995 XpathINIT
|
|
3996
|
|
3997 Xpath 1 " X: 1
|
|
3998 try
|
|
3999 Xpath 2 " X: 2
|
|
4000 try
|
|
4001 Xpath 4 " X: 4
|
|
4002 try
|
|
4003 Xpath 8 " X: 8
|
|
4004 throw "x1"
|
|
4005 Xpath 16 " X: 0
|
|
4006 catch /x1/
|
|
4007 Xpath 32 " X: 32
|
|
4008 try
|
|
4009 Xpath 64 " X: 64
|
|
4010 throw "x2"
|
|
4011 Xpath 128 " X: 0
|
|
4012 catch /x1/
|
|
4013 Xpath 256 " X: 0
|
|
4014 catch /x2/
|
|
4015 Xpath 512 " X: 512
|
|
4016 try
|
|
4017 Xpath 1024 " X: 1024
|
|
4018 throw "x3"
|
|
4019 Xpath 2048 " X: 0
|
|
4020 catch /x1/
|
|
4021 Xpath 4096 " X: 0
|
|
4022 catch /x2/
|
|
4023 Xpath 8192 " X: 0
|
|
4024 finally
|
|
4025 Xpath 16384 " X: 16384
|
|
4026 endtry
|
|
4027 Xpath 32768 " X: 0
|
|
4028 catch /x3/
|
|
4029 Xpath 65536 " X: 0
|
|
4030 endtry
|
|
4031 Xpath 131072 " X: 0
|
|
4032 catch /x1/
|
|
4033 Xpath 262144 " X: 0
|
|
4034 catch /x2/
|
|
4035 Xpath 524288 " X: 0
|
|
4036 catch /x3/
|
|
4037 Xpath 1048576 " X: 0
|
|
4038 finally
|
|
4039 Xpath 2097152 " X: 2097152
|
|
4040 endtry
|
|
4041 Xpath 4194304 " X: 0
|
|
4042 catch /x1/
|
|
4043 Xpath 8388608 " X: 0
|
|
4044 catch /x2/
|
|
4045 Xpath 16777216 " X: 0
|
|
4046 catch /x3/
|
|
4047 Xpath 33554432 " X: 33554432
|
|
4048 endtry
|
|
4049 Xpath 67108864 " X: 67108864
|
|
4050 catch /.*/
|
|
4051 Xpath 134217728 " X: 0
|
|
4052 Xout v:exception "in" v:throwpoint
|
|
4053 endtry
|
|
4054 Xpath 268435456 " X: 268435456
|
|
4055
|
|
4056 Xcheck 371213935
|
|
4057
|
|
4058
|
|
4059 "-------------------------------------------------------------------------------
|
|
4060 " Test 48: Throwing exceptions from a :finally clause {{{1
|
|
4061 "
|
|
4062 " When an exception is thrown from a :finally clause, it should not be
|
|
4063 " caught by a :catch of the same :try conditional. Surrounding try
|
|
4064 " conditionals should be checked for a matching :catch. A previously
|
|
4065 " thrown exception is discarded.
|
|
4066 "-------------------------------------------------------------------------------
|
|
4067
|
|
4068 XpathINIT
|
|
4069
|
|
4070 try
|
|
4071
|
|
4072 try
|
|
4073 try
|
|
4074 Xpath 1 " X: 1
|
|
4075 catch /x1/
|
|
4076 Xpath 2 " X: 0
|
|
4077 finally
|
|
4078 Xpath 4 " X: 4
|
|
4079 throw "x1"
|
|
4080 Xpath 8 " X: 0
|
|
4081 endtry
|
|
4082 Xpath 16 " X: 0
|
|
4083 catch /x1/
|
|
4084 Xpath 32 " X: 32
|
|
4085 endtry
|
|
4086 Xpath 64 " X: 64
|
|
4087
|
|
4088 try
|
|
4089 try
|
|
4090 Xpath 128 " X: 128
|
|
4091 throw "x2"
|
|
4092 Xpath 256 " X: 0
|
|
4093 catch /x2/
|
|
4094 Xpath 512 " X: 512
|
|
4095 catch /x3/
|
|
4096 Xpath 1024 " X: 0
|
|
4097 finally
|
|
4098 Xpath 2048 " X: 2048
|
|
4099 throw "x3"
|
|
4100 Xpath 4096 " X: 0
|
|
4101 endtry
|
|
4102 Xpath 8192 " X: 0
|
|
4103 catch /x2/
|
|
4104 Xpath 16384 " X: 0
|
|
4105 catch /x3/
|
|
4106 Xpath 32768 " X: 32768
|
|
4107 endtry
|
|
4108 Xpath 65536 " X: 65536
|
|
4109
|
|
4110 try
|
|
4111 try
|
|
4112 try
|
|
4113 Xpath 131072 " X: 131072
|
|
4114 throw "x4"
|
|
4115 Xpath 262144 " X: 0
|
|
4116 catch /x5/
|
|
4117 Xpath 524288 " X: 0
|
|
4118 finally
|
|
4119 Xpath 1048576 " X: 1048576
|
|
4120 throw "x5" " discards "x4"
|
|
4121 Xpath 2097152 " X: 0
|
|
4122 endtry
|
|
4123 Xpath 4194304 " X: 0
|
|
4124 catch /x4/
|
|
4125 Xpath 8388608 " X: 0
|
|
4126 finally
|
|
4127 Xpath 16777216 " X: 16777216
|
|
4128 endtry
|
|
4129 Xpath 33554432 " X: 0
|
|
4130 catch /x5/
|
|
4131 Xpath 67108864 " X: 67108864
|
|
4132 endtry
|
|
4133 Xpath 134217728 " X: 134217728
|
|
4134
|
|
4135 catch /.*/
|
|
4136 Xpath 268435456 " X: 0
|
|
4137 Xout v:exception "in" v:throwpoint
|
|
4138 endtry
|
|
4139 Xpath 536870912 " X: 536870912
|
|
4140
|
|
4141 Xcheck 756255461
|
|
4142
|
|
4143
|
|
4144 "-------------------------------------------------------------------------------
|
|
4145 " Test 49: Throwing exceptions accross functions {{{1
|
|
4146 "
|
|
4147 " When an exception is thrown but not caught inside a function, the
|
|
4148 " caller is checked for a matching :catch clause.
|
|
4149 "-------------------------------------------------------------------------------
|
|
4150
|
|
4151 XpathINIT
|
|
4152
|
|
4153 function! C()
|
|
4154 try
|
|
4155 Xpath 1 " X: 1
|
|
4156 throw "arrgh"
|
|
4157 Xpath 2 " X: 0
|
|
4158 catch /arrgh/
|
|
4159 Xpath 4 " X: 4
|
|
4160 endtry
|
|
4161 Xpath 8 " X: 8
|
|
4162 endfunction
|
|
4163
|
|
4164 XloopINIT! 16 16
|
|
4165
|
|
4166 function! T1()
|
|
4167 XloopNEXT
|
|
4168 try
|
|
4169 Xloop 1 " X: 16 + 16*16
|
|
4170 throw "arrgh"
|
|
4171 Xloop 2 " X: 0
|
|
4172 finally
|
|
4173 Xloop 4 " X: 64 + 64*16
|
|
4174 endtry
|
|
4175 Xloop 8 " X: 0
|
|
4176 endfunction
|
|
4177
|
|
4178 function! T2()
|
|
4179 try
|
|
4180 Xpath 4096 " X: 4096
|
|
4181 call T1()
|
|
4182 Xpath 8192 " X: 0
|
|
4183 finally
|
|
4184 Xpath 16384 " X: 16384
|
|
4185 endtry
|
|
4186 Xpath 32768 " X: 0
|
|
4187 endfunction
|
|
4188
|
|
4189 try
|
|
4190 Xpath 65536 " X: 65536
|
|
4191 call C() " throw and catch
|
|
4192 Xpath 131072 " X: 131072
|
|
4193 catch /.*/
|
|
4194 Xpath 262144 " X: 0
|
|
4195 Xout v:exception "in" v:throwpoint
|
|
4196 endtry
|
|
4197
|
|
4198 try
|
|
4199 Xpath 524288 " X: 524288
|
|
4200 call T1() " throw, one level
|
|
4201 Xpath 1048576 " X: 0
|
|
4202 catch /arrgh/
|
|
4203 Xpath 2097152 " X: 2097152
|
|
4204 catch /.*/
|
|
4205 Xpath 4194304 " X: 0
|
|
4206 Xout v:exception "in" v:throwpoint
|
|
4207 endtry
|
|
4208
|
|
4209 try
|
|
4210 Xpath 8388608 " X: 8388608
|
|
4211 call T2() " throw, two levels
|
|
4212 Xpath 16777216 " X: 0
|
|
4213 catch /arrgh/
|
|
4214 Xpath 33554432 " X: 33554432
|
|
4215 catch /.*/
|
|
4216 Xpath 67108864 " X: 0
|
|
4217 Xout v:exception "in" v:throwpoint
|
|
4218 endtry
|
|
4219 Xpath 134217728 " X: 134217728
|
|
4220
|
|
4221 Xcheck 179000669
|
|
4222
|
|
4223 " Leave C, T1, and T2 for execution as scripts in the next test.
|
|
4224
|
|
4225
|
|
4226 "-------------------------------------------------------------------------------
|
|
4227 " Test 50: Throwing exceptions accross script files {{{1
|
|
4228 "
|
|
4229 " When an exception is thrown but not caught inside a script file,
|
|
4230 " the sourcing script or function is checked for a matching :catch
|
|
4231 " clause.
|
|
4232 "
|
|
4233 " This test executes the bodies of the functions C, T1, and T2 from
|
|
4234 " the previous test as script files (:return replaced by :finish).
|
|
4235 "-------------------------------------------------------------------------------
|
|
4236
|
|
4237 XpathINIT
|
|
4238
|
|
4239 let scriptC = MakeScript("C") " X: 1 + 4 + 8
|
|
4240 delfunction C
|
|
4241
|
|
4242 XloopINIT! 16 16
|
|
4243
|
|
4244 let scriptT1 = MakeScript("T1") " X: 16 + 64 + 16*16 + 64*16
|
|
4245 delfunction T1
|
|
4246
|
|
4247 let scriptT2 = MakeScript("T2", scriptT1) " X: 4096 + 16384
|
|
4248 delfunction T2
|
|
4249
|
|
4250 function! F()
|
|
4251 try
|
|
4252 Xpath 65536 " X: 65536
|
|
4253 exec "source" g:scriptC
|
|
4254 Xpath 131072 " X: 131072
|
|
4255 catch /.*/
|
|
4256 Xpath 262144 " X: 0
|
|
4257 Xout v:exception "in" v:throwpoint
|
|
4258 endtry
|
|
4259
|
|
4260 try
|
|
4261 Xpath 524288 " X: 524288
|
|
4262 exec "source" g:scriptT1
|
|
4263 Xpath 1048576 " X: 0
|
|
4264 catch /arrgh/
|
|
4265 Xpath 2097152 " X: 2097152
|
|
4266 catch /.*/
|
|
4267 Xpath 4194304 " X: 0
|
|
4268 Xout v:exception "in" v:throwpoint
|
|
4269 endtry
|
|
4270 endfunction
|
|
4271
|
|
4272 try
|
|
4273 Xpath 8388608 " X: 8388608
|
|
4274 call F()
|
|
4275 Xpath 16777216 " X: 16777216
|
|
4276 exec "source" scriptT2
|
|
4277 Xpath 33554432 " X: 0
|
|
4278 catch /arrgh/
|
|
4279 Xpath 67108864 " X: 67108864
|
|
4280 catch /.*/
|
|
4281 Xpath 134217728 " X: 0
|
|
4282 Xout v:exception "in" v:throwpoint
|
|
4283 endtry
|
|
4284 Xpath 268435456 " X: 268435456
|
|
4285
|
|
4286 call delete(scriptC)
|
|
4287 call delete(scriptT1)
|
|
4288 call delete(scriptT2)
|
|
4289 unlet scriptC scriptT1 scriptT2
|
|
4290 delfunction F
|
|
4291
|
|
4292 Xcheck 363550045
|
|
4293
|
|
4294
|
|
4295 "-------------------------------------------------------------------------------
|
|
4296 " Test 51: Throwing exceptions accross :execute and user commands {{{1
|
|
4297 "
|
|
4298 " A :throw command may be executed under an ":execute" or from
|
|
4299 " a user command.
|
|
4300 "-------------------------------------------------------------------------------
|
|
4301
|
|
4302 XpathINIT
|
|
4303
|
|
4304 command! -nargs=? THROW1 throw <args> | throw 1
|
|
4305 command! -nargs=? THROW2 try | throw <args> | endtry | throw 2
|
|
4306 command! -nargs=? THROW3 try | throw 3 | catch /3/ | throw <args> | endtry
|
|
4307 command! -nargs=? THROW4 try | throw 4 | finally | throw <args> | endtry
|
|
4308
|
|
4309 try
|
|
4310
|
|
4311 try
|
|
4312 try
|
|
4313 Xpath 1 " X: 1
|
|
4314 THROW1 "A"
|
|
4315 catch /A/
|
|
4316 Xpath 2 " X: 2
|
|
4317 endtry
|
|
4318 catch /1/
|
|
4319 Xpath 4 " X: 0
|
|
4320 endtry
|
|
4321
|
|
4322 try
|
|
4323 try
|
|
4324 Xpath 8 " X: 8
|
|
4325 THROW2 "B"
|
|
4326 catch /B/
|
|
4327 Xpath 16 " X: 16
|
|
4328 endtry
|
|
4329 catch /2/
|
|
4330 Xpath 32 " X: 0
|
|
4331 endtry
|
|
4332
|
|
4333 try
|
|
4334 try
|
|
4335 Xpath 64 " X: 64
|
|
4336 THROW3 "C"
|
|
4337 catch /C/
|
|
4338 Xpath 128 " X: 128
|
|
4339 endtry
|
|
4340 catch /3/
|
|
4341 Xpath 256 " X: 0
|
|
4342 endtry
|
|
4343
|
|
4344 try
|
|
4345 try
|
|
4346 Xpath 512 " X: 512
|
|
4347 THROW4 "D"
|
|
4348 catch /D/
|
|
4349 Xpath 1024 " X: 1024
|
|
4350 endtry
|
|
4351 catch /4/
|
|
4352 Xpath 2048 " X: 0
|
|
4353 endtry
|
|
4354
|
|
4355 try
|
|
4356 try
|
|
4357 Xpath 4096 " X: 4096
|
|
4358 execute 'throw "E" | throw 5'
|
|
4359 catch /E/
|
|
4360 Xpath 8192 " X: 8192
|
|
4361 endtry
|
|
4362 catch /5/
|
|
4363 Xpath 16384 " X: 0
|
|
4364 endtry
|
|
4365
|
|
4366 try
|
|
4367 try
|
|
4368 Xpath 32768 " X: 32768
|
|
4369 execute 'try | throw "F" | endtry | throw 6'
|
|
4370 catch /F/
|
|
4371 Xpath 65536 " X: 65536
|
|
4372 endtry
|
|
4373 catch /6/
|
|
4374 Xpath 131072 " X: 0
|
|
4375 endtry
|
|
4376
|
|
4377 try
|
|
4378 try
|
|
4379 Xpath 262144 " X: 262144
|
|
4380 execute'try | throw 7 | catch /7/ | throw "G" | endtry'
|
|
4381 catch /G/
|
|
4382 Xpath 524288 " X: 524288
|
|
4383 endtry
|
|
4384 catch /7/
|
|
4385 Xpath 1048576 " X: 0
|
|
4386 endtry
|
|
4387
|
|
4388 try
|
|
4389 try
|
|
4390 Xpath 2097152 " X: 2097152
|
|
4391 execute 'try | throw 8 | finally | throw "H" | endtry'
|
|
4392 catch /H/
|
|
4393 Xpath 4194304 " X: 4194304
|
|
4394 endtry
|
|
4395 catch /8/
|
|
4396 Xpath 8388608 " X: 0
|
|
4397 endtry
|
|
4398
|
|
4399 catch /.*/
|
|
4400 Xpath 16777216 " X: 0
|
|
4401 Xout v:exception "in" v:throwpoint
|
|
4402 endtry
|
|
4403
|
|
4404 Xpath 33554432 " X: 33554432
|
|
4405
|
|
4406 delcommand THROW1
|
|
4407 delcommand THROW2
|
|
4408 delcommand THROW3
|
|
4409 delcommand THROW4
|
|
4410
|
|
4411 Xcheck 40744667
|
|
4412
|
|
4413
|
|
4414 "-------------------------------------------------------------------------------
|
|
4415 " Test 52: Uncaught exceptions {{{1
|
|
4416 "
|
|
4417 " When an exception is thrown but not caught, an error message is
|
|
4418 " displayed when the script is terminated. In case of an interrupt
|
|
4419 " or error exception, the normal interrupt or error message(s) are
|
|
4420 " displayed.
|
|
4421 "-------------------------------------------------------------------------------
|
|
4422
|
|
4423 XpathINIT
|
|
4424
|
|
4425 let msgfile = tempname()
|
|
4426
|
|
4427 function! MESSAGES(...)
|
|
4428 try
|
|
4429 exec "edit" g:msgfile
|
|
4430 catch /^Vim(edit):/
|
|
4431 return 0
|
|
4432 endtry
|
|
4433
|
|
4434 let english = v:lang == "C" || v:lang =~ '^[Ee]n'
|
|
4435 let match = 1
|
|
4436 norm gg
|
|
4437
|
|
4438 let num = a:0 / 2
|
|
4439 let cnt = 1
|
|
4440 while cnt <= num
|
|
4441 let enr = a:{2*cnt - 1}
|
|
4442 let emsg= a:{2*cnt}
|
|
4443 let cnt = cnt + 1
|
|
4444
|
|
4445 if enr == ""
|
|
4446 Xout "TODO: Add message number for:" emsg
|
|
4447 elseif enr == "INT"
|
|
4448 let enr = ""
|
|
4449 endif
|
|
4450 if enr == "" && !english
|
|
4451 continue
|
|
4452 endif
|
|
4453 let pattern = (enr != "") ? enr . ':.*' : ''
|
|
4454 if english
|
|
4455 let pattern = pattern . emsg
|
|
4456 endif
|
|
4457 if !search(pattern, "W")
|
|
4458 let match = 0
|
|
4459 Xout "No match for:" pattern
|
|
4460 endif
|
|
4461 norm $
|
|
4462 endwhile
|
|
4463
|
|
4464 bwipeout!
|
|
4465 return match
|
|
4466 endfunction
|
|
4467
|
|
4468 if ExtraVim(msgfile)
|
|
4469 Xpath 1 " X: 1
|
|
4470 throw "arrgh"
|
|
4471 endif
|
|
4472
|
|
4473 Xpath 2 " X: 2
|
|
4474 if !MESSAGES('E605', "Exception not caught")
|
|
4475 Xpath 4 " X: 0
|
|
4476 endif
|
|
4477
|
|
4478 if ExtraVim(msgfile)
|
|
4479 try
|
|
4480 Xpath 8 " X: 8
|
|
4481 throw "oops"
|
|
4482 catch /arrgh/
|
|
4483 Xpath 16 " X: 0
|
|
4484 endtry
|
|
4485 Xpath 32 " X: 0
|
|
4486 endif
|
|
4487
|
|
4488 Xpath 64 " X: 64
|
|
4489 if !MESSAGES('E605', "Exception not caught")
|
|
4490 Xpath 128 " X: 0
|
|
4491 endif
|
|
4492
|
|
4493 if ExtraVim(msgfile)
|
|
4494 function! T()
|
|
4495 throw "brrr"
|
|
4496 endfunction
|
|
4497
|
|
4498 try
|
|
4499 Xpath 256 " X: 256
|
|
4500 throw "arrgh"
|
|
4501 catch /.*/
|
|
4502 Xpath 512 " X: 512
|
|
4503 call T()
|
|
4504 endtry
|
|
4505 Xpath 1024 " X: 0
|
|
4506 endif
|
|
4507
|
|
4508 Xpath 2048 " X: 2048
|
|
4509 if !MESSAGES('E605', "Exception not caught")
|
|
4510 Xpath 4096 " X: 0
|
|
4511 endif
|
|
4512
|
|
4513 if ExtraVim(msgfile)
|
|
4514 try
|
|
4515 Xpath 8192 " X: 8192
|
|
4516 throw "arrgh"
|
|
4517 finally
|
|
4518 Xpath 16384 " X: 16384
|
|
4519 throw "brrr"
|
|
4520 endtry
|
|
4521 Xpath 32768 " X: 0
|
|
4522 endif
|
|
4523
|
|
4524 Xpath 65536 " X: 65536
|
|
4525 if !MESSAGES('E605', "Exception not caught")
|
|
4526 Xpath 131072 " X: 0
|
|
4527 endif
|
|
4528
|
|
4529 if ExtraVim(msgfile)
|
|
4530 try
|
|
4531 Xpath 262144 " X: 262144
|
|
4532 "INTERRUPT
|
|
4533 endtry
|
|
4534 Xpath 524288 " X: 0
|
|
4535 endif
|
|
4536
|
|
4537 Xpath 1048576 " X: 1048576
|
|
4538 if !MESSAGES('INT', "Interrupted")
|
|
4539 Xpath 2097152 " X: 0
|
|
4540 endif
|
|
4541
|
|
4542 if ExtraVim(msgfile)
|
|
4543 try
|
|
4544 Xpath 4194304 " X: 4194304
|
|
4545 let x = novar " error E121/E15; exception: E121
|
|
4546 catch /E15:/ " should not catch
|
|
4547 Xpath 8388608 " X: 0
|
|
4548 endtry
|
|
4549 Xpath 16777216 " X: 0
|
|
4550 endif
|
|
4551
|
|
4552 Xpath 33554432 " X: 33554432
|
|
4553 if !MESSAGES('E121', "Undefined variable", 'E15', "Invalid expression")
|
|
4554 Xpath 67108864 " X: 0
|
|
4555 endif
|
|
4556
|
|
4557 if ExtraVim(msgfile)
|
|
4558 try
|
|
4559 Xpath 134217728 " X: 134217728
|
|
4560 " unlet novar # " error E108/E488; exception: E488
|
|
4561 catch /E108:/ " should not catch
|
|
4562 Xpath 268435456 " X: 0
|
|
4563 endtry
|
|
4564 Xpath 536870912 " X: 0
|
|
4565 endif
|
|
4566
|
|
4567 Xpath 1073741824 " X: 1073741824
|
|
4568 if !MESSAGES('E108', "No such variable", 'E488', "Trailing characters")
|
|
4569 " The Xpath command does not accept 2^31 (negative); add explicitly:
|
|
4570 let Xpath = Xpath + 2147483648 " X: 0
|
|
4571 endif
|
|
4572
|
|
4573 call delete(msgfile)
|
|
4574 unlet msgfile
|
|
4575
|
|
4576 Xcheck 1247112011
|
|
4577
|
|
4578 " Leave MESSAGES() for the next tests.
|
|
4579
|
|
4580
|
|
4581 "-------------------------------------------------------------------------------
|
|
4582 " Test 53: Nesting errors: :endif/:else/:elseif {{{1
|
|
4583 "
|
|
4584 " For nesting errors of :if conditionals the correct error messages
|
|
4585 " should be given.
|
|
4586 "
|
|
4587 " This test reuses the function MESSAGES() from the previous test.
|
|
4588 " This functions checks the messages in g:msgfile.
|
|
4589 "-------------------------------------------------------------------------------
|
|
4590
|
|
4591 XpathINIT
|
|
4592
|
|
4593 let msgfile = tempname()
|
|
4594
|
|
4595 if ExtraVim(msgfile)
|
|
4596 " endif
|
|
4597 endif
|
|
4598 if MESSAGES('E580', ":endif without :if")
|
|
4599 Xpath 1 " X: 1
|
|
4600 endif
|
|
4601
|
|
4602 if ExtraVim(msgfile)
|
|
4603 " while 1
|
|
4604 " endif
|
|
4605 " endwhile
|
|
4606 endif
|
|
4607 if MESSAGES('E580', ":endif without :if")
|
|
4608 Xpath 2 " X: 2
|
|
4609 endif
|
|
4610
|
|
4611 if ExtraVim(msgfile)
|
|
4612 " try
|
|
4613 " finally
|
|
4614 " endif
|
|
4615 " endtry
|
|
4616 endif
|
|
4617 if MESSAGES('E580', ":endif without :if")
|
|
4618 Xpath 4 " X: 4
|
|
4619 endif
|
|
4620
|
|
4621 if ExtraVim(msgfile)
|
|
4622 " try
|
|
4623 " endif
|
|
4624 " endtry
|
|
4625 endif
|
|
4626 if MESSAGES('E580', ":endif without :if")
|
|
4627 Xpath 8 " X: 8
|
|
4628 endif
|
|
4629
|
|
4630 if ExtraVim(msgfile)
|
|
4631 " try
|
|
4632 " throw "a"
|
|
4633 " catch /a/
|
|
4634 " endif
|
|
4635 " endtry
|
|
4636 endif
|
|
4637 if MESSAGES('E580', ":endif without :if")
|
|
4638 Xpath 16 " X: 16
|
|
4639 endif
|
|
4640
|
|
4641 if ExtraVim(msgfile)
|
|
4642 " else
|
|
4643 endif
|
|
4644 if MESSAGES('E581', ":else without :if")
|
|
4645 Xpath 32 " X: 32
|
|
4646 endif
|
|
4647
|
|
4648 if ExtraVim(msgfile)
|
|
4649 " while 1
|
|
4650 " else
|
|
4651 " endwhile
|
|
4652 endif
|
|
4653 if MESSAGES('E581', ":else without :if")
|
|
4654 Xpath 64 " X: 64
|
|
4655 endif
|
|
4656
|
|
4657 if ExtraVim(msgfile)
|
|
4658 " try
|
|
4659 " finally
|
|
4660 " else
|
|
4661 " endtry
|
|
4662 endif
|
|
4663 if MESSAGES('E581', ":else without :if")
|
|
4664 Xpath 128 " X: 128
|
|
4665 endif
|
|
4666
|
|
4667 if ExtraVim(msgfile)
|
|
4668 " try
|
|
4669 " else
|
|
4670 " endtry
|
|
4671 endif
|
|
4672 if MESSAGES('E581', ":else without :if")
|
|
4673 Xpath 256 " X: 256
|
|
4674 endif
|
|
4675
|
|
4676 if ExtraVim(msgfile)
|
|
4677 " try
|
|
4678 " throw "a"
|
|
4679 " catch /a/
|
|
4680 " else
|
|
4681 " endtry
|
|
4682 endif
|
|
4683 if MESSAGES('E581', ":else without :if")
|
|
4684 Xpath 512 " X: 512
|
|
4685 endif
|
|
4686
|
|
4687 if ExtraVim(msgfile)
|
|
4688 " elseif
|
|
4689 endif
|
|
4690 if MESSAGES('E582', ":elseif without :if")
|
|
4691 Xpath 1024 " X: 1024
|
|
4692 endif
|
|
4693
|
|
4694 if ExtraVim(msgfile)
|
|
4695 " while 1
|
|
4696 " elseif
|
|
4697 " endwhile
|
|
4698 endif
|
|
4699 if MESSAGES('E582', ":elseif without :if")
|
|
4700 Xpath 2048 " X: 2048
|
|
4701 endif
|
|
4702
|
|
4703 if ExtraVim(msgfile)
|
|
4704 " try
|
|
4705 " finally
|
|
4706 " elseif
|
|
4707 " endtry
|
|
4708 endif
|
|
4709 if MESSAGES('E582', ":elseif without :if")
|
|
4710 Xpath 4096 " X: 4096
|
|
4711 endif
|
|
4712
|
|
4713 if ExtraVim(msgfile)
|
|
4714 " try
|
|
4715 " elseif
|
|
4716 " endtry
|
|
4717 endif
|
|
4718 if MESSAGES('E582', ":elseif without :if")
|
|
4719 Xpath 8192 " X: 8192
|
|
4720 endif
|
|
4721
|
|
4722 if ExtraVim(msgfile)
|
|
4723 " try
|
|
4724 " throw "a"
|
|
4725 " catch /a/
|
|
4726 " elseif
|
|
4727 " endtry
|
|
4728 endif
|
|
4729 if MESSAGES('E582', ":elseif without :if")
|
|
4730 Xpath 16384 " X: 16384
|
|
4731 endif
|
|
4732
|
|
4733 if ExtraVim(msgfile)
|
|
4734 " if 1
|
|
4735 " else
|
|
4736 " else
|
|
4737 " endif
|
|
4738 endif
|
|
4739 if MESSAGES('E583', "multiple :else")
|
|
4740 Xpath 32768 " X: 32768
|
|
4741 endif
|
|
4742
|
|
4743 if ExtraVim(msgfile)
|
|
4744 " if 1
|
|
4745 " else
|
|
4746 " elseif 1
|
|
4747 " endif
|
|
4748 endif
|
|
4749 if MESSAGES('E584', ":elseif after :else")
|
|
4750 Xpath 65536 " X: 65536
|
|
4751 endif
|
|
4752
|
|
4753 call delete(msgfile)
|
|
4754 unlet msgfile
|
|
4755
|
|
4756 Xcheck 131071
|
|
4757
|
|
4758 " Leave MESSAGES() for the next test.
|
|
4759
|
|
4760
|
|
4761 "-------------------------------------------------------------------------------
|
|
4762 " Test 54: Nesting errors: :while/:endwhile {{{1
|
|
4763 "
|
|
4764 " For nesting errors of :while conditionals the correct error messages
|
|
4765 " should be given.
|
|
4766 "
|
|
4767 " This test reuses the function MESSAGES() from the previous test.
|
|
4768 " This functions checks the messages in g:msgfile.
|
|
4769 "-------------------------------------------------------------------------------
|
|
4770
|
|
4771 XpathINIT
|
|
4772
|
|
4773 let msgfile = tempname()
|
|
4774
|
|
4775 if ExtraVim(msgfile)
|
|
4776 " endwhile
|
|
4777 endif
|
|
4778 if MESSAGES('E588', ":endwhile without :while")
|
|
4779 Xpath 1 " X: 1
|
|
4780 endif
|
|
4781
|
|
4782 if ExtraVim(msgfile)
|
|
4783 " if 1
|
|
4784 " endwhile
|
|
4785 " endif
|
|
4786 endif
|
|
4787 if MESSAGES('E588', ":endwhile without :while")
|
|
4788 Xpath 2 " X: 2
|
|
4789 endif
|
|
4790
|
|
4791 if ExtraVim(msgfile)
|
|
4792 " while 1
|
|
4793 " if 1
|
|
4794 " endwhile
|
|
4795 endif
|
|
4796 if MESSAGES('E171', "Missing :endif")
|
|
4797 Xpath 4 " X: 4
|
|
4798 endif
|
|
4799
|
|
4800 if ExtraVim(msgfile)
|
|
4801 " try
|
|
4802 " finally
|
|
4803 " endwhile
|
|
4804 " endtry
|
|
4805 endif
|
|
4806 if MESSAGES('E588', ":endwhile without :while")
|
|
4807 Xpath 8 " X: 8
|
|
4808 endif
|
|
4809
|
|
4810 if ExtraVim(msgfile)
|
|
4811 " while 1
|
|
4812 " try
|
|
4813 " finally
|
|
4814 " endwhile
|
|
4815 endif
|
|
4816 if MESSAGES('E600', "Missing :endtry")
|
|
4817 Xpath 16 " X: 16
|
|
4818 endif
|
|
4819
|
|
4820 if ExtraVim(msgfile)
|
|
4821 " while 1
|
|
4822 " if 1
|
|
4823 " try
|
|
4824 " finally
|
|
4825 " endwhile
|
|
4826 endif
|
|
4827 if MESSAGES('E600', "Missing :endtry")
|
|
4828 Xpath 32 " X: 32
|
|
4829 endif
|
|
4830
|
|
4831 if ExtraVim(msgfile)
|
|
4832 " while 1
|
|
4833 " try
|
|
4834 " finally
|
|
4835 " if 1
|
|
4836 " endwhile
|
|
4837 endif
|
|
4838 if MESSAGES('E171', "Missing :endif")
|
|
4839 Xpath 64 " X: 64
|
|
4840 endif
|
|
4841
|
|
4842 if ExtraVim(msgfile)
|
|
4843 " try
|
|
4844 " endwhile
|
|
4845 " endtry
|
|
4846 endif
|
|
4847 if MESSAGES('E588', ":endwhile without :while")
|
|
4848 Xpath 128 " X: 128
|
|
4849 endif
|
|
4850
|
|
4851 if ExtraVim(msgfile)
|
|
4852 " while 1
|
|
4853 " try
|
|
4854 " endwhile
|
|
4855 " endtry
|
|
4856 " endwhile
|
|
4857 endif
|
|
4858 if MESSAGES('E588', ":endwhile without :while")
|
|
4859 Xpath 256 " X: 256
|
|
4860 endif
|
|
4861
|
|
4862 if ExtraVim(msgfile)
|
|
4863 " try
|
|
4864 " throw "a"
|
|
4865 " catch /a/
|
|
4866 " endwhile
|
|
4867 " endtry
|
|
4868 endif
|
|
4869 if MESSAGES('E588', ":endwhile without :while")
|
|
4870 Xpath 512 " X: 512
|
|
4871 endif
|
|
4872
|
|
4873 if ExtraVim(msgfile)
|
|
4874 " while 1
|
|
4875 " try
|
|
4876 " throw "a"
|
|
4877 " catch /a/
|
|
4878 " endwhile
|
|
4879 " endtry
|
|
4880 " endwhile
|
|
4881 endif
|
|
4882 if MESSAGES('E588', ":endwhile without :while")
|
|
4883 Xpath 1024 " X: 1024
|
|
4884 endif
|
|
4885
|
|
4886
|
|
4887 call delete(msgfile)
|
|
4888 unlet msgfile
|
|
4889
|
|
4890 Xcheck 2047
|
|
4891
|
|
4892 " Leave MESSAGES() for the next test.
|
|
4893
|
|
4894
|
|
4895 "-------------------------------------------------------------------------------
|
|
4896 " Test 55: Nesting errors: :continue/:break {{{1
|
|
4897 "
|
|
4898 " For nesting errors of :continue and :break commands the correct
|
|
4899 " error messages should be given.
|
|
4900 "
|
|
4901 " This test reuses the function MESSAGES() from the previous test.
|
|
4902 " This functions checks the messages in g:msgfile.
|
|
4903 "-------------------------------------------------------------------------------
|
|
4904
|
|
4905 XpathINIT
|
|
4906
|
|
4907 let msgfile = tempname()
|
|
4908
|
|
4909 if ExtraVim(msgfile)
|
|
4910 " continue
|
|
4911 endif
|
|
4912 if MESSAGES('E586', ":continue without :while")
|
|
4913 Xpath 1 " X: 1
|
|
4914 endif
|
|
4915
|
|
4916 if ExtraVim(msgfile)
|
|
4917 " if 1
|
|
4918 " continue
|
|
4919 " endif
|
|
4920 endif
|
|
4921 if MESSAGES('E586', ":continue without :while")
|
|
4922 Xpath 2 " X: 2
|
|
4923 endif
|
|
4924
|
|
4925 if ExtraVim(msgfile)
|
|
4926 " try
|
|
4927 " finally
|
|
4928 " continue
|
|
4929 " endtry
|
|
4930 endif
|
|
4931 if MESSAGES('E586', ":continue without :while")
|
|
4932 Xpath 4 " X: 4
|
|
4933 endif
|
|
4934
|
|
4935 if ExtraVim(msgfile)
|
|
4936 " try
|
|
4937 " continue
|
|
4938 " endtry
|
|
4939 endif
|
|
4940 if MESSAGES('E586', ":continue without :while")
|
|
4941 Xpath 8 " X: 8
|
|
4942 endif
|
|
4943
|
|
4944 if ExtraVim(msgfile)
|
|
4945 " try
|
|
4946 " throw "a"
|
|
4947 " catch /a/
|
|
4948 " continue
|
|
4949 " endtry
|
|
4950 endif
|
|
4951 if MESSAGES('E586', ":continue without :while")
|
|
4952 Xpath 16 " X: 16
|
|
4953 endif
|
|
4954
|
|
4955 if ExtraVim(msgfile)
|
|
4956 " break
|
|
4957 endif
|
|
4958 if MESSAGES('E587', ":break without :while")
|
|
4959 Xpath 32 " X: 32
|
|
4960 endif
|
|
4961
|
|
4962 if ExtraVim(msgfile)
|
|
4963 " if 1
|
|
4964 " break
|
|
4965 " endif
|
|
4966 endif
|
|
4967 if MESSAGES('E587', ":break without :while")
|
|
4968 Xpath 64 " X: 64
|
|
4969 endif
|
|
4970
|
|
4971 if ExtraVim(msgfile)
|
|
4972 " try
|
|
4973 " finally
|
|
4974 " break
|
|
4975 " endtry
|
|
4976 endif
|
|
4977 if MESSAGES('E587', ":break without :while")
|
|
4978 Xpath 128 " X: 128
|
|
4979 endif
|
|
4980
|
|
4981 if ExtraVim(msgfile)
|
|
4982 " try
|
|
4983 " break
|
|
4984 " endtry
|
|
4985 endif
|
|
4986 if MESSAGES('E587', ":break without :while")
|
|
4987 Xpath 256 " X: 256
|
|
4988 endif
|
|
4989
|
|
4990 if ExtraVim(msgfile)
|
|
4991 " try
|
|
4992 " throw "a"
|
|
4993 " catch /a/
|
|
4994 " break
|
|
4995 " endtry
|
|
4996 endif
|
|
4997 if MESSAGES('E587', ":break without :while")
|
|
4998 Xpath 512 " X: 512
|
|
4999 endif
|
|
5000
|
|
5001 call delete(msgfile)
|
|
5002 unlet msgfile
|
|
5003
|
|
5004 Xcheck 1023
|
|
5005
|
|
5006 " Leave MESSAGES() for the next test.
|
|
5007
|
|
5008
|
|
5009 "-------------------------------------------------------------------------------
|
|
5010 " Test 56: Nesting errors: :endtry {{{1
|
|
5011 "
|
|
5012 " For nesting errors of :try conditionals the correct error messages
|
|
5013 " should be given.
|
|
5014 "
|
|
5015 " This test reuses the function MESSAGES() from the previous test.
|
|
5016 " This functions checks the messages in g:msgfile.
|
|
5017 "-------------------------------------------------------------------------------
|
|
5018
|
|
5019 XpathINIT
|
|
5020
|
|
5021 let msgfile = tempname()
|
|
5022
|
|
5023 if ExtraVim(msgfile)
|
|
5024 " endtry
|
|
5025 endif
|
|
5026 if MESSAGES('E602', ":endtry without :try")
|
|
5027 Xpath 1 " X: 1
|
|
5028 endif
|
|
5029
|
|
5030 if ExtraVim(msgfile)
|
|
5031 " if 1
|
|
5032 " endtry
|
|
5033 " endif
|
|
5034 endif
|
|
5035 if MESSAGES('E602', ":endtry without :try")
|
|
5036 Xpath 2 " X: 2
|
|
5037 endif
|
|
5038
|
|
5039 if ExtraVim(msgfile)
|
|
5040 " while 1
|
|
5041 " endtry
|
|
5042 " endwhile
|
|
5043 endif
|
|
5044 if MESSAGES('E602', ":endtry without :try")
|
|
5045 Xpath 4 " X: 4
|
|
5046 endif
|
|
5047
|
|
5048 if ExtraVim(msgfile)
|
|
5049 " try
|
|
5050 " if 1
|
|
5051 " endtry
|
|
5052 endif
|
|
5053 if MESSAGES('E171', "Missing :endif")
|
|
5054 Xpath 8 " X: 8
|
|
5055 endif
|
|
5056
|
|
5057 if ExtraVim(msgfile)
|
|
5058 " try
|
|
5059 " while 1
|
|
5060 " endtry
|
|
5061 endif
|
|
5062 if MESSAGES('E170', "Missing :endwhile")
|
|
5063 Xpath 16 " X: 16
|
|
5064 endif
|
|
5065
|
|
5066 if ExtraVim(msgfile)
|
|
5067 " try
|
|
5068 " finally
|
|
5069 " if 1
|
|
5070 " endtry
|
|
5071 endif
|
|
5072 if MESSAGES('E171', "Missing :endif")
|
|
5073 Xpath 32 " X: 32
|
|
5074 endif
|
|
5075
|
|
5076 if ExtraVim(msgfile)
|
|
5077 " try
|
|
5078 " finally
|
|
5079 " while 1
|
|
5080 " endtry
|
|
5081 endif
|
|
5082 if MESSAGES('E170', "Missing :endwhile")
|
|
5083 Xpath 64 " X: 64
|
|
5084 endif
|
|
5085
|
|
5086 if ExtraVim(msgfile)
|
|
5087 " try
|
|
5088 " throw "a"
|
|
5089 " catch /a/
|
|
5090 " if 1
|
|
5091 " endtry
|
|
5092 endif
|
|
5093 if MESSAGES('E171', "Missing :endif")
|
|
5094 Xpath 128 " X: 128
|
|
5095 endif
|
|
5096
|
|
5097 if ExtraVim(msgfile)
|
|
5098 " try
|
|
5099 " throw "a"
|
|
5100 " catch /a/
|
|
5101 " while 1
|
|
5102 " endtry
|
|
5103 endif
|
|
5104 if MESSAGES('E170', "Missing :endwhile")
|
|
5105 Xpath 256 " X: 256
|
|
5106 endif
|
|
5107
|
|
5108 call delete(msgfile)
|
|
5109 unlet msgfile
|
|
5110
|
|
5111 delfunction MESSAGES
|
|
5112
|
|
5113 Xcheck 511
|
|
5114
|
|
5115
|
|
5116 "-------------------------------------------------------------------------------
|
|
5117 " Test 57: v:exception and v:throwpoint for user exceptions {{{1
|
|
5118 "
|
|
5119 " v:exception evaluates to the value of the exception that was caught
|
|
5120 " most recently and is not finished. (A caught exception is finished
|
|
5121 " when the next ":catch", ":finally", or ":endtry" is reached.)
|
|
5122 " v:throwpoint evaluates to the script/function name and line number
|
|
5123 " where that exception has been thrown.
|
|
5124 "-------------------------------------------------------------------------------
|
|
5125
|
|
5126 XpathINIT
|
|
5127
|
|
5128 function! FuncException()
|
|
5129 let g:exception = v:exception
|
|
5130 endfunction
|
|
5131
|
|
5132 function! FuncThrowpoint()
|
|
5133 let g:throwpoint = v:throwpoint
|
|
5134 endfunction
|
|
5135
|
|
5136 let scriptException = MakeScript("FuncException")
|
|
5137 let scriptThrowPoint = MakeScript("FuncThrowpoint")
|
|
5138
|
|
5139 command! CmdException let g:exception = v:exception
|
|
5140 command! CmdThrowpoint let g:throwpoint = v:throwpoint
|
|
5141
|
|
5142 XloopINIT! 1 2
|
|
5143
|
|
5144 function! CHECK(n, exception, throwname, throwline)
|
|
5145 XloopNEXT
|
|
5146 let error = 0
|
|
5147 if v:exception != a:exception
|
|
5148 Xout a:n.": v:exception is" v:exception "instead of" a:exception
|
|
5149 let error = 1
|
|
5150 endif
|
|
5151 if v:throwpoint !~ a:throwname
|
|
5152 let name = escape(a:throwname, '\')
|
|
5153 Xout a:n.": v:throwpoint (".v:throwpoint.") does not match" name
|
|
5154 let error = 1
|
|
5155 endif
|
|
5156 if v:throwpoint !~ a:throwline
|
|
5157 let line = escape(a:throwline, '\')
|
|
5158 Xout a:n.": v:throwpoint (".v:throwpoint.") does not match" line
|
|
5159 let error = 1
|
|
5160 endif
|
|
5161 if error
|
|
5162 Xloop 1 " X: 0
|
|
5163 endif
|
|
5164 endfunction
|
|
5165
|
|
5166 function! T(arg, line)
|
|
5167 if a:line == 2
|
|
5168 throw a:arg " in line 2
|
|
5169 elseif a:line == 4
|
|
5170 throw a:arg " in line 4
|
|
5171 elseif a:line == 6
|
|
5172 throw a:arg " in line 6
|
|
5173 elseif a:line == 8
|
|
5174 throw a:arg " in line 8
|
|
5175 endif
|
|
5176 endfunction
|
|
5177
|
|
5178 function! G(arg, line)
|
|
5179 call T(a:arg, a:line)
|
|
5180 endfunction
|
|
5181
|
|
5182 function! F(arg, line)
|
|
5183 call G(a:arg, a:line)
|
|
5184 endfunction
|
|
5185
|
|
5186 let scriptT = MakeScript("T")
|
|
5187 let scriptG = MakeScript("G", scriptT)
|
|
5188 let scriptF = MakeScript("F", scriptG)
|
|
5189
|
|
5190 try
|
|
5191 Xpath 32768 " X: 32768
|
|
5192 call F("oops", 2)
|
|
5193 catch /.*/
|
|
5194 Xpath 65536 " X: 65536
|
|
5195 let exception = v:exception
|
|
5196 let throwpoint = v:throwpoint
|
|
5197 call CHECK(1, "oops", '\<F\.\.G\.\.T\>', '\<2\>')
|
|
5198 exec "let exception = v:exception"
|
|
5199 exec "let throwpoint = v:throwpoint"
|
|
5200 call CHECK(2, "oops", '\<F\.\.G\.\.T\>', '\<2\>')
|
|
5201 CmdException
|
|
5202 CmdThrowpoint
|
|
5203 call CHECK(3, "oops", '\<F\.\.G\.\.T\>', '\<2\>')
|
|
5204 call FuncException()
|
|
5205 call FuncThrowpoint()
|
|
5206 call CHECK(4, "oops", '\<F\.\.G\.\.T\>', '\<2\>')
|
|
5207 exec "source" scriptException
|
|
5208 exec "source" scriptThrowPoint
|
|
5209 call CHECK(5, "oops", '\<F\.\.G\.\.T\>', '\<2\>')
|
|
5210 try
|
|
5211 Xpath 131072 " X: 131072
|
|
5212 call G("arrgh", 4)
|
|
5213 catch /.*/
|
|
5214 Xpath 262144 " X: 262144
|
|
5215 let exception = v:exception
|
|
5216 let throwpoint = v:throwpoint
|
|
5217 call CHECK(6, "arrgh", '\<G\.\.T\>', '\<4\>')
|
|
5218 try
|
|
5219 Xpath 524288 " X: 524288
|
|
5220 let g:arg = "autsch"
|
|
5221 let g:line = 6
|
|
5222 exec "source" scriptF
|
|
5223 catch /.*/
|
|
5224 Xpath 1048576 " X: 1048576
|
|
5225 let exception = v:exception
|
|
5226 let throwpoint = v:throwpoint
|
|
5227 " Symbolic links in tempname()s are not resolved, whereas resolving
|
|
5228 " is done for v:throwpoint. Resolve the temporary file name for
|
|
5229 " scriptT, so that it can be matched against v:throwpoint.
|
|
5230 call CHECK(7, "autsch", resolve(scriptT), '\<6\>')
|
|
5231 finally
|
|
5232 Xpath 2097152 " X: 2097152
|
|
5233 let exception = v:exception
|
|
5234 let throwpoint = v:throwpoint
|
|
5235 call CHECK(8, "arrgh", '\<G\.\.T\>', '\<4\>')
|
|
5236 try
|
|
5237 Xpath 4194304 " X: 4194304
|
|
5238 let g:arg = "brrrr"
|
|
5239 let g:line = 8
|
|
5240 exec "source" scriptG
|
|
5241 catch /.*/
|
|
5242 Xpath 8388608 " X: 8388608
|
|
5243 let exception = v:exception
|
|
5244 let throwpoint = v:throwpoint
|
|
5245 " Resolve scriptT for matching it against v:throwpoint.
|
|
5246 call CHECK(9, "brrrr", resolve(scriptT), '\<8\>')
|
|
5247 finally
|
|
5248 Xpath 16777216 " X: 16777216
|
|
5249 let exception = v:exception
|
|
5250 let throwpoint = v:throwpoint
|
|
5251 call CHECK(10, "arrgh", '\<G\.\.T\>', '\<4\>')
|
|
5252 endtry
|
|
5253 Xpath 33554432 " X: 33554432
|
|
5254 let exception = v:exception
|
|
5255 let throwpoint = v:throwpoint
|
|
5256 call CHECK(11, "arrgh", '\<G\.\.T\>', '\<4\>')
|
|
5257 endtry
|
|
5258 Xpath 67108864 " X: 67108864
|
|
5259 let exception = v:exception
|
|
5260 let throwpoint = v:throwpoint
|
|
5261 call CHECK(12, "arrgh", '\<G\.\.T\>', '\<4\>')
|
|
5262 finally
|
|
5263 Xpath 134217728 " X: 134217728
|
|
5264 let exception = v:exception
|
|
5265 let throwpoint = v:throwpoint
|
|
5266 call CHECK(13, "oops", '\<F\.\.G\.\.T\>', '\<2\>')
|
|
5267 endtry
|
|
5268 Xpath 268435456 " X: 268435456
|
|
5269 let exception = v:exception
|
|
5270 let throwpoint = v:throwpoint
|
|
5271 call CHECK(14, "oops", '\<F\.\.G\.\.T\>', '\<2\>')
|
|
5272 finally
|
|
5273 Xpath 536870912 " X: 536870912
|
|
5274 let exception = v:exception
|
|
5275 let throwpoint = v:throwpoint
|
|
5276 call CHECK(15, "", '^$', '^$')
|
|
5277 endtry
|
|
5278
|
|
5279 Xpath 1073741824 " X: 1073741824
|
|
5280
|
|
5281 unlet exception throwpoint
|
|
5282 delfunction FuncException
|
|
5283 delfunction FuncThrowpoint
|
|
5284 call delete(scriptException)
|
|
5285 call delete(scriptThrowPoint)
|
|
5286 unlet scriptException scriptThrowPoint
|
|
5287 delcommand CmdException
|
|
5288 delcommand CmdThrowpoint
|
|
5289 delfunction T
|
|
5290 delfunction G
|
|
5291 delfunction F
|
|
5292 call delete(scriptT)
|
|
5293 call delete(scriptG)
|
|
5294 call delete(scriptF)
|
|
5295 unlet scriptT scriptG scriptF
|
|
5296
|
|
5297 Xcheck 2147450880
|
|
5298
|
|
5299
|
|
5300 "-------------------------------------------------------------------------------
|
|
5301 "
|
|
5302 " Test 58: v:exception and v:throwpoint for error/interrupt exceptions {{{1
|
|
5303 "
|
|
5304 " v:exception and v:throwpoint work also for error and interrupt
|
|
5305 " exceptions.
|
|
5306 "-------------------------------------------------------------------------------
|
|
5307
|
|
5308 XpathINIT
|
|
5309
|
|
5310 if ExtraVim()
|
|
5311
|
|
5312 function! T(line)
|
|
5313 if a:line == 2
|
|
5314 delfunction T " error (function in use) in line 2
|
|
5315 elseif a:line == 4
|
|
5316 let dummy = 0 " INTERRUPT1 - interrupt in line 4
|
|
5317 endif
|
|
5318 endfunction
|
|
5319
|
|
5320 while 1
|
|
5321 try
|
|
5322 Xpath 1 " X: 1
|
|
5323 let caught = 0
|
|
5324 call T(2)
|
|
5325 catch /.*/
|
|
5326 let caught = 1
|
|
5327 if v:exception !~ 'Vim(delfunction):'
|
|
5328 Xpath 2 " X: 0
|
|
5329 endif
|
|
5330 if v:throwpoint !~ '\<T\>'
|
|
5331 Xpath 4 " X: 0
|
|
5332 endif
|
|
5333 if v:throwpoint !~ '\<2\>'
|
|
5334 Xpath 8 " X: 0
|
|
5335 endif
|
|
5336 finally
|
|
5337 Xpath 16 " X: 16
|
|
5338 if caught || $VIMNOERRTHROW
|
|
5339 Xpath 32 " X: 32
|
|
5340 endif
|
|
5341 if v:exception != ""
|
|
5342 Xpath 64 " X: 0
|
|
5343 endif
|
|
5344 if v:throwpoint != ""
|
|
5345 Xpath 128 " X: 0
|
|
5346 endif
|
|
5347 break " discard error for $VIMNOERRTHROW
|
|
5348 endtry
|
|
5349 endwhile
|
|
5350
|
|
5351 Xpath 256 " X: 256
|
|
5352 if v:exception != ""
|
|
5353 Xpath 512 " X: 0
|
|
5354 endif
|
|
5355 if v:throwpoint != ""
|
|
5356 Xpath 1024 " X: 0
|
|
5357 endif
|
|
5358
|
|
5359 while 1
|
|
5360 try
|
|
5361 Xpath 2048 " X: 2048
|
|
5362 let caught = 0
|
|
5363 call T(4)
|
|
5364 catch /.*/
|
|
5365 let caught = 1
|
|
5366 if v:exception != 'Vim:Interrupt'
|
|
5367 Xpath 4096 " X: 0
|
|
5368 endif
|
|
5369 if v:throwpoint !~ '\<T\>'
|
|
5370 Xpath 8192 " X: 0
|
|
5371 endif
|
|
5372 if v:throwpoint !~ '\<4\>'
|
|
5373 Xpath 16384 " X: 0
|
|
5374 endif
|
|
5375 finally
|
|
5376 Xpath 32768 " X: 32768
|
|
5377 if caught || $VIMNOINTTHROW
|
|
5378 Xpath 65536 " X: 65536
|
|
5379 endif
|
|
5380 if v:exception != ""
|
|
5381 Xpath 131072 " X: 0
|
|
5382 endif
|
|
5383 if v:throwpoint != ""
|
|
5384 Xpath 262144 " X: 0
|
|
5385 endif
|
|
5386 break " discard error for $VIMNOERRTHROW
|
|
5387 endtry
|
|
5388 endwhile
|
|
5389
|
|
5390 Xpath 524288 " X: 524288
|
|
5391 if v:exception != ""
|
|
5392 Xpath 1048576 " X: 0
|
|
5393 endif
|
|
5394 if v:throwpoint != ""
|
|
5395 Xpath 2097152 " X: 0
|
|
5396 endif
|
|
5397
|
|
5398 endif
|
|
5399
|
|
5400 Xcheck 624945
|
|
5401
|
|
5402
|
|
5403 "-------------------------------------------------------------------------------
|
|
5404 "
|
|
5405 " Test 59: v:exception and v:throwpoint when discarding exceptions {{{1
|
|
5406 "
|
|
5407 " When a :catch clause is left by a ":break" etc or an error or
|
|
5408 " interrupt exception, v:exception and v:throwpoint are reset. They
|
|
5409 " are not affected by an exception that is discarded before being
|
|
5410 " caught.
|
|
5411 "-------------------------------------------------------------------------------
|
|
5412
|
|
5413 XpathINIT
|
|
5414
|
|
5415 if ExtraVim()
|
|
5416
|
|
5417 XloopINIT! 1 2
|
|
5418
|
|
5419 let sfile = expand("<sfile>")
|
|
5420
|
|
5421 function! LineNumber()
|
|
5422 return substitute(substitute(v:throwpoint, g:sfile, '', ""),
|
|
5423 \ '\D*\(\d*\).*', '\1', "")
|
|
5424 endfunction
|
|
5425
|
|
5426 command! -nargs=1 SetLineNumber
|
|
5427 \ try | throw "line" | catch /.*/ | let <args> = LineNumber() | endtry
|
|
5428
|
|
5429 " Check v:exception/v:throwpoint against second/fourth parameter if
|
|
5430 " specified, check for being empty else.
|
|
5431 function! CHECK(n, ...)
|
|
5432 XloopNEXT
|
|
5433 let exception = a:0 != 0 ? a:1 : "" " second parameter (optional)
|
|
5434 let emsg = a:0 != 0 ? a:2 : "" " third parameter (optional)
|
|
5435 let line = a:0 != 0 ? a:3 : 0 " fourth parameter (optional)
|
|
5436 let error = 0
|
|
5437 if emsg != ""
|
|
5438 " exception is the error number, emsg the english error message text
|
|
5439 if exception !~ '^E\d\+$'
|
|
5440 Xout "TODO: Add message number for:" emsg
|
|
5441 elseif v:lang == "C" || v:lang =~ '^[Ee]n'
|
|
5442 if exception == "E492" && emsg == "Not an editor command"
|
|
5443 let exception = '^Vim:' . exception . ': ' . emsg
|
|
5444 else
|
|
5445 let exception = '^Vim(\a\+):' . exception . ': ' . emsg
|
|
5446 endif
|
|
5447 else
|
|
5448 if exception == "E492"
|
|
5449 let exception = '^Vim:' . exception
|
|
5450 else
|
|
5451 let exception = '^Vim(\a\+):' . exception
|
|
5452 endif
|
|
5453 endif
|
|
5454 endif
|
|
5455 if exception == "" && v:exception != ""
|
|
5456 Xout a:n.": v:exception is set:" v:exception
|
|
5457 let error = 1
|
|
5458 elseif exception != "" && v:exception !~ exception
|
|
5459 Xout a:n.": v:exception (".v:exception.") does not match" exception
|
|
5460 let error = 1
|
|
5461 endif
|
|
5462 if line == 0 && v:throwpoint != ""
|
|
5463 Xout a:n.": v:throwpoint is set:" v:throwpoint
|
|
5464 let error = 1
|
|
5465 elseif line != 0 && v:throwpoint !~ '\<' . line . '\>'
|
|
5466 Xout a:n.": v:throwpoint (".v:throwpoint.") does not match" line
|
|
5467 let error = 1
|
|
5468 endif
|
|
5469 if !error
|
|
5470 Xloop 1 " X: 2097151
|
|
5471 endif
|
|
5472 endfunction
|
|
5473
|
|
5474 while 1
|
|
5475 try
|
|
5476 throw "x1"
|
|
5477 catch /.*/
|
|
5478 break
|
|
5479 endtry
|
|
5480 endwhile
|
|
5481 call CHECK(1)
|
|
5482
|
|
5483 while 1
|
|
5484 try
|
|
5485 throw "x2"
|
|
5486 catch /.*/
|
|
5487 break
|
|
5488 finally
|
|
5489 call CHECK(2)
|
|
5490 endtry
|
|
5491 break
|
|
5492 endwhile
|
|
5493 call CHECK(3)
|
|
5494
|
|
5495 while 1
|
|
5496 try
|
|
5497 let errcaught = 0
|
|
5498 try
|
|
5499 try
|
|
5500 throw "x3"
|
|
5501 catch /.*/
|
|
5502 SetLineNumber line_before_error
|
|
5503 asdf
|
|
5504 endtry
|
|
5505 catch /.*/
|
|
5506 let errcaught = 1
|
|
5507 call CHECK(4, 'E492', "Not an editor command",
|
|
5508 \ line_before_error + 1)
|
|
5509 endtry
|
|
5510 finally
|
|
5511 if !errcaught && $VIMNOERRTHROW
|
|
5512 call CHECK(4)
|
|
5513 endif
|
|
5514 break " discard error for $VIMNOERRTHROW
|
|
5515 endtry
|
|
5516 endwhile
|
|
5517 call CHECK(5)
|
|
5518
|
|
5519 Xpath 2097152 " X: 2097152
|
|
5520
|
|
5521 while 1
|
|
5522 try
|
|
5523 let intcaught = 0
|
|
5524 try
|
|
5525 try
|
|
5526 throw "x4"
|
|
5527 catch /.*/
|
|
5528 SetLineNumber two_lines_before_interrupt
|
|
5529 "INTERRUPT
|
|
5530 let dummy = 0
|
|
5531 endtry
|
|
5532 catch /.*/
|
|
5533 let intcaught = 1
|
|
5534 call CHECK(6, "Vim:Interrupt", '',
|
|
5535 \ two_lines_before_interrupt + 2)
|
|
5536 endtry
|
|
5537 finally
|
|
5538 if !intcaught && $VIMNOINTTHROW
|
|
5539 call CHECK(6)
|
|
5540 endif
|
|
5541 break " discard interrupt for $VIMNOINTTHROW
|
|
5542 endtry
|
|
5543 endwhile
|
|
5544 call CHECK(7)
|
|
5545
|
|
5546 Xpath 4194304 " X: 4194304
|
|
5547
|
|
5548 while 1
|
|
5549 try
|
|
5550 let errcaught = 0
|
|
5551 try
|
|
5552 try
|
|
5553 " if 1
|
|
5554 SetLineNumber line_before_throw
|
|
5555 throw "x5"
|
|
5556 " missing endif
|
|
5557 catch /.*/
|
|
5558 Xpath 8388608 " X: 0
|
|
5559 endtry
|
|
5560 catch /.*/
|
|
5561 let errcaught = 1
|
|
5562 call CHECK(8, 'E171', "Missing :endif", line_before_throw + 3)
|
|
5563 endtry
|
|
5564 finally
|
|
5565 if !errcaught && $VIMNOERRTHROW
|
|
5566 call CHECK(8)
|
|
5567 endif
|
|
5568 break " discard error for $VIMNOERRTHROW
|
|
5569 endtry
|
|
5570 endwhile
|
|
5571 call CHECK(9)
|
|
5572
|
|
5573 Xpath 16777216 " X: 16777216
|
|
5574
|
|
5575 try
|
|
5576 while 1
|
|
5577 try
|
|
5578 throw "x6"
|
|
5579 finally
|
|
5580 break
|
|
5581 endtry
|
|
5582 break
|
|
5583 endwhile
|
|
5584 catch /.*/
|
|
5585 Xpath 33554432 " X: 0
|
|
5586 endtry
|
|
5587 call CHECK(10)
|
|
5588
|
|
5589 try
|
|
5590 while 1
|
|
5591 try
|
|
5592 throw "x7"
|
|
5593 finally
|
|
5594 break
|
|
5595 endtry
|
|
5596 break
|
|
5597 endwhile
|
|
5598 catch /.*/
|
|
5599 Xpath 67108864 " X: 0
|
|
5600 finally
|
|
5601 call CHECK(11)
|
|
5602 endtry
|
|
5603 call CHECK(12)
|
|
5604
|
|
5605 while 1
|
|
5606 try
|
|
5607 let errcaught = 0
|
|
5608 try
|
|
5609 try
|
|
5610 throw "x8"
|
|
5611 finally
|
|
5612 SetLineNumber line_before_error
|
|
5613 asdf
|
|
5614 endtry
|
|
5615 catch /.*/
|
|
5616 let errcaught = 1
|
|
5617 call CHECK(13, 'E492', "Not an editor command",
|
|
5618 \ line_before_error + 1)
|
|
5619 endtry
|
|
5620 finally
|
|
5621 if !errcaught && $VIMNOERRTHROW
|
|
5622 call CHECK(13)
|
|
5623 endif
|
|
5624 break " discard error for $VIMNOERRTHROW
|
|
5625 endtry
|
|
5626 endwhile
|
|
5627 call CHECK(14)
|
|
5628
|
|
5629 Xpath 134217728 " X: 134217728
|
|
5630
|
|
5631 while 1
|
|
5632 try
|
|
5633 let intcaught = 0
|
|
5634 try
|
|
5635 try
|
|
5636 throw "x9"
|
|
5637 finally
|
|
5638 SetLineNumber two_lines_before_interrupt
|
|
5639 "INTERRUPT
|
|
5640 endtry
|
|
5641 catch /.*/
|
|
5642 let intcaught = 1
|
|
5643 call CHECK(15, "Vim:Interrupt", '',
|
|
5644 \ two_lines_before_interrupt + 2)
|
|
5645 endtry
|
|
5646 finally
|
|
5647 if !intcaught && $VIMNOINTTHROW
|
|
5648 call CHECK(15)
|
|
5649 endif
|
|
5650 break " discard interrupt for $VIMNOINTTHROW
|
|
5651 endtry
|
|
5652 endwhile
|
|
5653 call CHECK(16)
|
|
5654
|
|
5655 Xpath 268435456 " X: 268435456
|
|
5656
|
|
5657 while 1
|
|
5658 try
|
|
5659 let errcaught = 0
|
|
5660 try
|
|
5661 try
|
|
5662 " if 1
|
|
5663 SetLineNumber line_before_throw
|
|
5664 throw "x10"
|
|
5665 " missing endif
|
|
5666 finally
|
|
5667 call CHECK(17)
|
|
5668 endtry
|
|
5669 catch /.*/
|
|
5670 let errcaught = 1
|
|
5671 call CHECK(18, 'E171', "Missing :endif", line_before_throw + 3)
|
|
5672 endtry
|
|
5673 finally
|
|
5674 if !errcaught && $VIMNOERRTHROW
|
|
5675 call CHECK(18)
|
|
5676 endif
|
|
5677 break " discard error for $VIMNOERRTHROW
|
|
5678 endtry
|
|
5679 endwhile
|
|
5680 call CHECK(19)
|
|
5681
|
|
5682 Xpath 536870912 " X: 536870912
|
|
5683
|
|
5684 while 1
|
|
5685 try
|
|
5686 let errcaught = 0
|
|
5687 try
|
|
5688 try
|
|
5689 " if 1
|
|
5690 SetLineNumber line_before_throw
|
|
5691 throw "x11"
|
|
5692 " missing endif
|
|
5693 endtry
|
|
5694 catch /.*/
|
|
5695 let errcaught = 1
|
|
5696 call CHECK(20, 'E171', "Missing :endif", line_before_throw + 3)
|
|
5697 endtry
|
|
5698 finally
|
|
5699 if !errcaught && $VIMNOERRTHROW
|
|
5700 call CHECK(20)
|
|
5701 endif
|
|
5702 break " discard error for $VIMNOERRTHROW
|
|
5703 endtry
|
|
5704 endwhile
|
|
5705 call CHECK(21)
|
|
5706
|
|
5707 Xpath 1073741824 " X: 1073741824
|
|
5708
|
|
5709 endif
|
|
5710
|
|
5711 Xcheck 2038431743
|
|
5712
|
|
5713
|
|
5714 "-------------------------------------------------------------------------------
|
|
5715 "
|
|
5716 " Test 60: (Re)throwing v:exception; :echoerr. {{{1
|
|
5717 "
|
|
5718 " A user exception can be rethrown after catching by throwing
|
|
5719 " v:exception. An error or interrupt exception cannot be rethrown
|
|
5720 " because Vim exceptions cannot be faked. A Vim exception using the
|
|
5721 " value of v:exception can, however, be triggered by the :echoerr
|
|
5722 " command.
|
|
5723 "-------------------------------------------------------------------------------
|
|
5724
|
|
5725 XpathINIT
|
|
5726
|
|
5727 try
|
|
5728 try
|
|
5729 Xpath 1 " X: 1
|
|
5730 throw "oops"
|
|
5731 catch /oops/
|
|
5732 Xpath 2 " X: 2
|
|
5733 throw v:exception " rethrow user exception
|
|
5734 catch /.*/
|
|
5735 Xpath 4 " X: 0
|
|
5736 endtry
|
|
5737 catch /^oops$/ " catches rethrown user exception
|
|
5738 Xpath 8 " X: 8
|
|
5739 catch /.*/
|
|
5740 Xpath 16 " X: 0
|
|
5741 endtry
|
|
5742
|
|
5743 function! F()
|
|
5744 try
|
|
5745 let caught = 0
|
|
5746 try
|
|
5747 Xpath 32 " X: 32
|
|
5748 write /n/o/n/w/r/i/t/a/b/l/e/_/f/i/l/e
|
|
5749 Xpath 64 " X: 0
|
|
5750 Xout "did_emsg was reset before executing " .
|
|
5751 \ "BufWritePost autocommands."
|
|
5752 catch /^Vim(write):/
|
|
5753 let caught = 1
|
|
5754 throw v:exception " throw error: cannot fake Vim exception
|
|
5755 catch /.*/
|
|
5756 Xpath 128 " X: 0
|
|
5757 finally
|
|
5758 Xpath 256 " X: 256
|
|
5759 if !caught && !$VIMNOERRTHROW
|
|
5760 Xpath 512 " X: 0
|
|
5761 endif
|
|
5762 endtry
|
|
5763 catch /^Vim(throw):/ " catches throw error
|
|
5764 let caught = caught + 1
|
|
5765 catch /.*/
|
|
5766 Xpath 1024 " X: 0
|
|
5767 finally
|
|
5768 Xpath 2048 " X: 2048
|
|
5769 if caught != 2
|
|
5770 if !caught && !$VIMNOERRTHROW
|
|
5771 Xpath 4096 " X: 0
|
|
5772 elseif caught
|
|
5773 Xpath 8192 " X: 0
|
|
5774 endif
|
|
5775 return | " discard error for $VIMNOERRTHROW
|
|
5776 endif
|
|
5777 endtry
|
|
5778 endfunction
|
|
5779
|
|
5780 call F()
|
|
5781 delfunction F
|
|
5782
|
|
5783 function! G()
|
|
5784 try
|
|
5785 let caught = 0
|
|
5786 try
|
|
5787 Xpath 16384 " X: 16384
|
|
5788 asdf
|
|
5789 catch /^Vim/ " catch error exception
|
|
5790 let caught = 1
|
|
5791 " Trigger Vim error exception with value specified after :echoerr
|
|
5792 let value = substitute(v:exception, '^Vim\((.*)\)\=:', '', "")
|
|
5793 echoerr value
|
|
5794 catch /.*/
|
|
5795 Xpath 32768 " X: 0
|
|
5796 finally
|
|
5797 Xpath 65536 " X: 65536
|
|
5798 if !caught
|
|
5799 if !$VIMNOERRTHROW
|
|
5800 Xpath 131072 " X: 0
|
|
5801 else
|
|
5802 let value = "Error"
|
|
5803 echoerr value
|
|
5804 endif
|
|
5805 endif
|
|
5806 endtry
|
|
5807 catch /^Vim(echoerr):/
|
|
5808 let caught = caught + 1
|
|
5809 if v:exception !~ value
|
|
5810 Xpath 262144 " X: 0
|
|
5811 endif
|
|
5812 catch /.*/
|
|
5813 Xpath 524288 " X: 0
|
|
5814 finally
|
|
5815 Xpath 1048576 " X: 1048576
|
|
5816 if caught != 2
|
|
5817 if !caught && !$VIMNOERRTHROW
|
|
5818 Xpath 2097152 " X: 0
|
|
5819 elseif caught
|
|
5820 Xpath 4194304 " X: 0
|
|
5821 endif
|
|
5822 return | " discard error for $VIMNOERRTHROW
|
|
5823 endif
|
|
5824 endtry
|
|
5825 endfunction
|
|
5826
|
|
5827 call G()
|
|
5828 delfunction G
|
|
5829
|
|
5830 unlet! value caught
|
|
5831
|
|
5832 if ExtraVim()
|
|
5833 try
|
|
5834 let errcaught = 0
|
|
5835 try
|
|
5836 Xpath 8388608 " X: 8388608
|
|
5837 let intcaught = 0
|
|
5838 "INTERRUPT
|
|
5839 catch /^Vim:/ " catch interrupt exception
|
|
5840 let intcaught = 1
|
|
5841 " Trigger Vim error exception with value specified after :echoerr
|
|
5842 echoerr substitute(v:exception, '^Vim\((.*)\)\=:', '', "")
|
|
5843 catch /.*/
|
|
5844 Xpath 16777216 " X: 0
|
|
5845 finally
|
|
5846 Xpath 33554432 " X: 33554432
|
|
5847 if !intcaught
|
|
5848 if !$VIMNOINTTHROW
|
|
5849 Xpath 67108864 " X: 0
|
|
5850 else
|
|
5851 echoerr "Interrupt"
|
|
5852 endif
|
|
5853 endif
|
|
5854 endtry
|
|
5855 catch /^Vim(echoerr):/
|
|
5856 let errcaught = 1
|
|
5857 if v:exception !~ "Interrupt"
|
|
5858 Xpath 134217728 " X: 0
|
|
5859 endif
|
|
5860 finally
|
|
5861 Xpath 268435456 " X: 268435456
|
|
5862 if !errcaught && !$VIMNOERRTHROW
|
|
5863 Xpath 536870912 " X: 0
|
|
5864 endif
|
|
5865 endtry
|
|
5866 endif
|
|
5867
|
|
5868 Xcheck 311511339
|
|
5869
|
|
5870
|
|
5871 "-------------------------------------------------------------------------------
|
|
5872 " Test 61: Catching interrupt exceptions {{{1
|
|
5873 "
|
|
5874 " When an interrupt occurs inside a :try/:endtry region, an
|
|
5875 " interrupt exception is thrown and can be caught. Its value is
|
|
5876 " "Vim:Interrupt". If the interrupt occurs after an error or a :throw
|
|
5877 " but before a matching :catch is reached, all following :catches of
|
|
5878 " that try block are ignored, but the interrupt exception can be
|
|
5879 " caught by the next surrounding try conditional. An interrupt is
|
|
5880 " ignored when there is a previous interrupt that has not been caught
|
|
5881 " or causes a :finally clause to be executed.
|
|
5882 "-------------------------------------------------------------------------------
|
|
5883
|
|
5884 XpathINIT
|
|
5885
|
|
5886 if ExtraVim()
|
|
5887
|
|
5888 while 1
|
|
5889 try
|
|
5890 try
|
|
5891 Xpath 1 " X: 1
|
|
5892 let caught = 0
|
|
5893 "INTERRUPT
|
|
5894 Xpath 2 " X: 0
|
|
5895 catch /^Vim:Interrupt$/
|
|
5896 let caught = 1
|
|
5897 finally
|
|
5898 Xpath 4 " X: 4
|
|
5899 if caught || $VIMNOINTTHROW
|
|
5900 Xpath 8 " X: 8
|
|
5901 endif
|
|
5902 endtry
|
|
5903 catch /.*/
|
|
5904 Xpath 16 " X: 0
|
|
5905 Xout v:exception "in" v:throwpoint
|
|
5906 finally
|
|
5907 break " discard interrupt for $VIMNOINTTHROW
|
|
5908 endtry
|
|
5909 endwhile
|
|
5910
|
|
5911 while 1
|
|
5912 try
|
|
5913 try
|
|
5914 let caught = 0
|
|
5915 try
|
|
5916 Xpath 32 " X: 32
|
|
5917 asdf
|
|
5918 Xpath 64 " X: 0
|
|
5919 catch /do_not_catch/
|
|
5920 Xpath 128 " X: 0
|
|
5921 catch /.*/ "INTERRUPT - throw interrupt if !$VIMNOERRTHROW
|
|
5922 Xpath 256 " X: 0
|
|
5923 catch /.*/
|
|
5924 Xpath 512 " X: 0
|
|
5925 finally "INTERRUPT - throw interrupt if $VIMNOERRTHROW
|
|
5926 Xpath 1024 " X: 1024
|
|
5927 endtry
|
|
5928 catch /^Vim:Interrupt$/
|
|
5929 let caught = 1
|
|
5930 finally
|
|
5931 Xpath 2048 " X: 2048
|
|
5932 if caught || $VIMNOINTTHROW
|
|
5933 Xpath 4096 " X: 4096
|
|
5934 endif
|
|
5935 endtry
|
|
5936 catch /.*/
|
|
5937 Xpath 8192 " X: 0
|
|
5938 Xout v:exception "in" v:throwpoint
|
|
5939 finally
|
|
5940 break " discard interrupt for $VIMNOINTTHROW
|
|
5941 endtry
|
|
5942 endwhile
|
|
5943
|
|
5944 while 1
|
|
5945 try
|
|
5946 try
|
|
5947 let caught = 0
|
|
5948 try
|
|
5949 Xpath 16384 " X: 16384
|
|
5950 throw "x"
|
|
5951 Xpath 32768 " X: 0
|
|
5952 catch /do_not_catch/
|
|
5953 Xpath 65536 " X: 0
|
|
5954 catch /x/ "INTERRUPT
|
|
5955 Xpath 131072 " X: 0
|
|
5956 catch /.*/
|
|
5957 Xpath 262144 " X: 0
|
|
5958 endtry
|
|
5959 catch /^Vim:Interrupt$/
|
|
5960 let caught = 1
|
|
5961 finally
|
|
5962 Xpath 524288 " X: 524288
|
|
5963 if caught || $VIMNOINTTHROW
|
|
5964 Xpath 1048576 " X: 1048576
|
|
5965 endif
|
|
5966 endtry
|
|
5967 catch /.*/
|
|
5968 Xpath 2097152 " X: 0
|
|
5969 Xout v:exception "in" v:throwpoint
|
|
5970 finally
|
|
5971 break " discard interrupt for $VIMNOINTTHROW
|
|
5972 endtry
|
|
5973 endwhile
|
|
5974
|
|
5975 while 1
|
|
5976 try
|
|
5977 let caught = 0
|
|
5978 try
|
|
5979 Xpath 4194304 " X: 4194304
|
|
5980 "INTERRUPT
|
|
5981 Xpath 8388608 " X: 0
|
|
5982 catch /do_not_catch/ "INTERRUPT
|
|
5983 Xpath 16777216 " X: 0
|
|
5984 catch /^Vim:Interrupt$/
|
|
5985 let caught = 1
|
|
5986 finally
|
|
5987 Xpath 33554432 " X: 33554432
|
|
5988 if caught || $VIMNOINTTHROW
|
|
5989 Xpath 67108864 " X: 67108864
|
|
5990 endif
|
|
5991 endtry
|
|
5992 catch /.*/
|
|
5993 Xpath 134217728 " X: 0
|
|
5994 Xout v:exception "in" v:throwpoint
|
|
5995 finally
|
|
5996 break " discard interrupt for $VIMNOINTTHROW
|
|
5997 endtry
|
|
5998 endwhile
|
|
5999
|
|
6000 Xpath 268435456 " X: 268435456
|
|
6001
|
|
6002 endif
|
|
6003
|
|
6004 Xcheck 374889517
|
|
6005
|
|
6006
|
|
6007 "-------------------------------------------------------------------------------
|
|
6008 " Test 62: Catching error exceptions {{{1
|
|
6009 "
|
|
6010 " An error inside a :try/:endtry region is converted to an exception
|
|
6011 " and can be caught. The error exception has a "Vim(cmdname):" prefix
|
|
6012 " where cmdname is the name of the failing command, or a "Vim:" prefix
|
|
6013 " if no command name is known. The "Vim" prefixes cannot be faked.
|
|
6014 "-------------------------------------------------------------------------------
|
|
6015
|
|
6016 XpathINIT
|
|
6017
|
|
6018 function! MSG(enr, emsg)
|
|
6019 let english = v:lang == "C" || v:lang =~ '^[Ee]n'
|
|
6020 if a:enr == ""
|
|
6021 Xout "TODO: Add message number for:" a:emsg
|
|
6022 let v:errmsg = ":" . v:errmsg
|
|
6023 endif
|
|
6024 let match = 1
|
|
6025 if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg)
|
|
6026 let match = 0
|
|
6027 if v:errmsg == ""
|
|
6028 Xout "Message missing."
|
|
6029 else
|
|
6030 let v:errmsg = escape(v:errmsg, '"')
|
|
6031 Xout "Unexpected message:" v:errmsg
|
|
6032 endif
|
|
6033 endif
|
|
6034 return match
|
|
6035 endfunction
|
|
6036
|
|
6037 while 1
|
|
6038 try
|
|
6039 try
|
|
6040 let caught = 0
|
|
6041 unlet novar
|
|
6042 catch /^Vim(unlet):/
|
|
6043 let caught = 1
|
|
6044 let v:errmsg = substitute(v:exception, '^Vim(unlet):', '', "")
|
|
6045 finally
|
|
6046 Xpath 1 " X: 1
|
|
6047 if !caught && !$VIMNOERRTHROW
|
|
6048 Xpath 2 " X: 0
|
|
6049 endif
|
|
6050 if !MSG('E108', "No such variable")
|
|
6051 Xpath 4 " X: 0
|
|
6052 endif
|
|
6053 endtry
|
|
6054 catch /.*/
|
|
6055 Xpath 8 " X: 0
|
|
6056 Xout v:exception "in" v:throwpoint
|
|
6057 finally
|
|
6058 break " discard error for $VIMNOERRTHROW
|
|
6059 endtry
|
|
6060 endwhile
|
|
6061
|
|
6062 while 1
|
|
6063 try
|
|
6064 try
|
|
6065 let caught = 0
|
|
6066 throw novar " error in :throw
|
|
6067 catch /^Vim(throw):/
|
|
6068 let caught = 1
|
|
6069 let v:errmsg = substitute(v:exception, '^Vim(throw):', '', "")
|
|
6070 finally
|
|
6071 Xpath 16 " X: 16
|
|
6072 if !caught && !$VIMNOERRTHROW
|
|
6073 Xpath 32 " X: 0
|
|
6074 endif
|
|
6075 if caught ? !MSG('E121', "Undefined variable")
|
|
6076 \ : !MSG('E15', "Invalid expression")
|
|
6077 Xpath 64 " X: 0
|
|
6078 endif
|
|
6079 endtry
|
|
6080 catch /.*/
|
|
6081 Xpath 128 " X: 0
|
|
6082 Xout v:exception "in" v:throwpoint
|
|
6083 finally
|
|
6084 break " discard error for $VIMNOERRTHROW
|
|
6085 endtry
|
|
6086 endwhile
|
|
6087
|
|
6088 while 1
|
|
6089 try
|
|
6090 try
|
|
6091 let caught = 0
|
|
6092 throw "Vim:faked" " error: cannot fake Vim exception
|
|
6093 catch /^Vim(throw):/
|
|
6094 let caught = 1
|
|
6095 let v:errmsg = substitute(v:exception, '^Vim(throw):', '', "")
|
|
6096 finally
|
|
6097 Xpath 256 " X: 256
|
|
6098 if !caught && !$VIMNOERRTHROW
|
|
6099 Xpath 512 " X: 0
|
|
6100 endif
|
|
6101 if !MSG('E608', "Cannot :throw exceptions with 'Vim' prefix")
|
|
6102 Xpath 1024 " X: 0
|
|
6103 endif
|
|
6104 endtry
|
|
6105 catch /.*/
|
|
6106 Xpath 2048 " X: 0
|
|
6107 Xout v:exception "in" v:throwpoint
|
|
6108 finally
|
|
6109 break " discard error for $VIMNOERRTHROW
|
|
6110 endtry
|
|
6111 endwhile
|
|
6112
|
|
6113 function! F()
|
|
6114 while 1
|
|
6115 " Missing :endwhile
|
|
6116 endfunction
|
|
6117
|
|
6118 while 1
|
|
6119 try
|
|
6120 try
|
|
6121 let caught = 0
|
|
6122 call F()
|
|
6123 catch /^Vim(endfunction):/
|
|
6124 let caught = 1
|
|
6125 let v:errmsg = substitute(v:exception, '^Vim(endfunction):', '', "")
|
|
6126 finally
|
|
6127 Xpath 4096 " X: 4096
|
|
6128 if !caught && !$VIMNOERRTHROW
|
|
6129 Xpath 8192 " X: 0
|
|
6130 endif
|
|
6131 if !MSG('E170', "Missing :endwhile")
|
|
6132 Xpath 16384 " X: 0
|
|
6133 endif
|
|
6134 endtry
|
|
6135 catch /.*/
|
|
6136 Xpath 32768 " X: 0
|
|
6137 Xout v:exception "in" v:throwpoint
|
|
6138 finally
|
|
6139 break " discard error for $VIMNOERRTHROW
|
|
6140 endtry
|
|
6141 endwhile
|
|
6142
|
|
6143 while 1
|
|
6144 try
|
|
6145 try
|
|
6146 let caught = 0
|
|
6147 ExecAsScript F
|
|
6148 catch /^Vim:/
|
|
6149 let caught = 1
|
|
6150 let v:errmsg = substitute(v:exception, '^Vim:', '', "")
|
|
6151 finally
|
|
6152 Xpath 65536 " X: 65536
|
|
6153 if !caught && !$VIMNOERRTHROW
|
|
6154 Xpath 131072 " X: 0
|
|
6155 endif
|
|
6156 if !MSG('E170', "Missing :endwhile")
|
|
6157 Xpath 262144 " X: 0
|
|
6158 endif
|
|
6159 endtry
|
|
6160 catch /.*/
|
|
6161 Xpath 524288 " X: 0
|
|
6162 Xout v:exception "in" v:throwpoint
|
|
6163 finally
|
|
6164 break " discard error for $VIMNOERRTHROW
|
|
6165 endtry
|
|
6166 endwhile
|
|
6167
|
|
6168 function! G()
|
|
6169 call G()
|
|
6170 endfunction
|
|
6171
|
|
6172 while 1
|
|
6173 try
|
|
6174 let mfd_save = &mfd
|
|
6175 set mfd=3
|
|
6176 try
|
|
6177 let caught = 0
|
|
6178 call G()
|
|
6179 catch /^Vim(call):/
|
|
6180 let caught = 1
|
|
6181 let v:errmsg = substitute(v:exception, '^Vim(call):', '', "")
|
|
6182 finally
|
|
6183 Xpath 1048576 " X: 1048576
|
|
6184 if !caught && !$VIMNOERRTHROW
|
|
6185 Xpath 2097152 " X: 0
|
|
6186 endif
|
|
6187 if !MSG('E132', "Function call depth is higher than 'maxfuncdepth'")
|
|
6188 Xpath 4194304 " X: 0
|
|
6189 endif
|
|
6190 endtry
|
|
6191 catch /.*/
|
|
6192 Xpath 8388608 " X: 0
|
|
6193 Xout v:exception "in" v:throwpoint
|
|
6194 finally
|
|
6195 let &mfd = mfd_save
|
|
6196 break " discard error for $VIMNOERRTHROW
|
|
6197 endtry
|
|
6198 endwhile
|
|
6199
|
|
6200 function! H()
|
|
6201 return H()
|
|
6202 endfunction
|
|
6203
|
|
6204 while 1
|
|
6205 try
|
|
6206 let mfd_save = &mfd
|
|
6207 set mfd=3
|
|
6208 try
|
|
6209 let caught = 0
|
|
6210 call H()
|
|
6211 catch /^Vim(return):/
|
|
6212 let caught = 1
|
|
6213 let v:errmsg = substitute(v:exception, '^Vim(return):', '', "")
|
|
6214 finally
|
|
6215 Xpath 16777216 " X: 16777216
|
|
6216 if !caught && !$VIMNOERRTHROW
|
|
6217 Xpath 33554432 " X: 0
|
|
6218 endif
|
|
6219 if !MSG('E132', "Function call depth is higher than 'maxfuncdepth'")
|
|
6220 Xpath 67108864 " X: 0
|
|
6221 endif
|
|
6222 endtry
|
|
6223 catch /.*/
|
|
6224 Xpath 134217728 " X: 0
|
|
6225 Xout v:exception "in" v:throwpoint
|
|
6226 finally
|
|
6227 let &mfd = mfd_save
|
|
6228 break " discard error for $VIMNOERRTHROW
|
|
6229 endtry
|
|
6230 endwhile
|
|
6231
|
|
6232 unlet! caught mfd_save
|
|
6233 delfunction F
|
|
6234 delfunction G
|
|
6235 delfunction H
|
|
6236 Xpath 268435456 " X: 268435456
|
|
6237
|
|
6238 Xcheck 286331153
|
|
6239
|
|
6240 " Leave MSG() for the next test.
|
|
6241
|
|
6242
|
|
6243 "-------------------------------------------------------------------------------
|
|
6244 " Test 63: Suppressing error exceptions by :silent!. {{{1
|
|
6245 "
|
|
6246 " A :silent! command inside a :try/:endtry region suppresses the
|
|
6247 " conversion of errors to an exception and the immediate abortion on
|
|
6248 " error. When the commands executed by the :silent! themselves open
|
|
6249 " a new :try/:endtry region, conversion of errors to exception and
|
|
6250 " immediate abortion is switched on again - until the next :silent!
|
|
6251 " etc. The :silent! has the effect of setting v:errmsg to the error
|
|
6252 " message text (without displaying it) and continuing with the next
|
|
6253 " script line.
|
|
6254 "
|
|
6255 " When a command triggering autocommands is executed by :silent!
|
|
6256 " inside a :try/:endtry, the autocommand execution is not suppressed
|
|
6257 " on error.
|
|
6258 "
|
|
6259 " This test reuses the function MSG() from the previous test.
|
|
6260 "-------------------------------------------------------------------------------
|
|
6261
|
|
6262 XpathINIT
|
|
6263
|
|
6264 XloopINIT! 1 4
|
|
6265
|
|
6266 let taken = ""
|
|
6267
|
|
6268 function! S(n) abort
|
|
6269 XloopNEXT
|
|
6270 let g:taken = g:taken . "E" . a:n
|
|
6271 let v:errmsg = ""
|
|
6272 exec "asdf" . a:n
|
|
6273
|
|
6274 " Check that ":silent!" continues:
|
|
6275 Xloop 1
|
|
6276
|
|
6277 " Check that ":silent!" sets "v:errmsg":
|
|
6278 if MSG('E492', "Not an editor command")
|
|
6279 Xloop 2
|
|
6280 endif
|
|
6281 endfunction
|
|
6282
|
|
6283 function! Foo()
|
|
6284 while 1
|
|
6285 try
|
|
6286 try
|
|
6287 let caught = 0
|
|
6288 " This is not silent:
|
|
6289 call S(3) " X: 0 * 16
|
|
6290 catch /^Vim:/
|
|
6291 let caught = 1
|
|
6292 let errmsg3 = substitute(v:exception, '^Vim:', '', "")
|
|
6293 silent! call S(4) " X: 3 * 64
|
|
6294 finally
|
|
6295 if !caught
|
|
6296 let errmsg3 = v:errmsg
|
|
6297 " Do call S(4) here if not executed in :catch.
|
|
6298 silent! call S(4)
|
|
6299 endif
|
|
6300 Xpath 1048576 " X: 1048576
|
|
6301 if !caught && !$VIMNOERRTHROW
|
|
6302 Xpath 2097152 " X: 0
|
|
6303 endif
|
|
6304 let v:errmsg = errmsg3
|
|
6305 if !MSG('E492', "Not an editor command")
|
|
6306 Xpath 4194304 " X: 0
|
|
6307 endif
|
|
6308 silent! call S(5) " X: 3 * 256
|
|
6309 " Break out of try conds that cover ":silent!". This also
|
|
6310 " discards the aborting error when $VIMNOERRTHROW is non-zero.
|
|
6311 break
|
|
6312 endtry
|
|
6313 catch /.*/
|
|
6314 Xpath 8388608 " X: 0
|
|
6315 Xout v:exception "in" v:throwpoint
|
|
6316 endtry
|
|
6317 endwhile
|
|
6318 " This is a double ":silent!" (see caller).
|
|
6319 silent! call S(6) " X: 3 * 1024
|
|
6320 endfunction
|
|
6321
|
|
6322 function! Bar()
|
|
6323 try
|
|
6324 silent! call S(2) " X: 3 * 4
|
|
6325 " X: 3 * 4096
|
|
6326 silent! execute "call Foo() | call S(7)"
|
|
6327 silent! call S(8) " X: 3 * 16384
|
|
6328 endtry " normal end of try cond that covers ":silent!"
|
|
6329 " This has a ":silent!" from the caller:
|
|
6330 call S(9) " X: 3 * 65536
|
|
6331 endfunction
|
|
6332
|
|
6333 silent! call S(1) " X: 3 * 1
|
|
6334 silent! call Bar()
|
|
6335 silent! call S(10) " X: 3 * 262144
|
|
6336
|
|
6337 let expected = "E1E2E3E4E5E6E7E8E9E10"
|
|
6338 if taken != expected
|
|
6339 Xpath 16777216 " X: 0
|
|
6340 Xout "'taken' is" taken "instead of" expected
|
|
6341 endif
|
|
6342
|
|
6343 augroup TMP
|
|
6344 autocmd BufWritePost * Xpath 33554432 " X: 33554432
|
|
6345 augroup END
|
|
6346
|
|
6347 Xpath 67108864 " X: 67108864
|
|
6348 write /i/m/p/o/s/s/i/b/l/e
|
|
6349 Xpath 134217728 " X: 134217728
|
|
6350
|
|
6351 autocmd! TMP
|
|
6352 unlet! caught errmsg3 taken expected
|
|
6353 delfunction S
|
|
6354 delfunction Foo
|
|
6355 delfunction Bar
|
|
6356 delfunction MSG
|
|
6357
|
|
6358 Xcheck 236978127
|
|
6359
|
|
6360
|
|
6361 "-------------------------------------------------------------------------------
|
|
6362 " Test 64: Error exceptions after error, interrupt or :throw {{{1
|
|
6363 "
|
|
6364 " When an error occurs after an interrupt or a :throw but before
|
|
6365 " a matching :catch is reached, all following :catches of that try
|
|
6366 " block are ignored, but the error exception can be caught by the next
|
|
6367 " surrounding try conditional. Any previous error exception is
|
|
6368 " discarded. An error is ignored when there is a previous error that
|
|
6369 " has not been caught.
|
|
6370 "-------------------------------------------------------------------------------
|
|
6371
|
|
6372 XpathINIT
|
|
6373
|
|
6374 if ExtraVim()
|
|
6375
|
|
6376 while 1
|
|
6377 try
|
|
6378 try
|
|
6379 Xpath 1 " X: 1
|
|
6380 let caught = 0
|
|
6381 while 1
|
|
6382 " if 1
|
|
6383 " Missing :endif
|
|
6384 endwhile " throw error exception
|
|
6385 catch /^Vim(/
|
|
6386 let caught = 1
|
|
6387 finally
|
|
6388 Xpath 2 " X: 2
|
|
6389 if caught || $VIMNOERRTHROW
|
|
6390 Xpath 4 " X: 4
|
|
6391 endif
|
|
6392 endtry
|
|
6393 catch /.*/
|
|
6394 Xpath 8 " X: 0
|
|
6395 Xout v:exception "in" v:throwpoint
|
|
6396 finally
|
|
6397 break " discard error for $VIMNOERRTHROW
|
|
6398 endtry
|
|
6399 endwhile
|
|
6400
|
|
6401 while 1
|
|
6402 try
|
|
6403 try
|
|
6404 Xpath 16 " X: 16
|
|
6405 let caught = 0
|
|
6406 try
|
|
6407 " if 1
|
|
6408 " Missing :endif
|
|
6409 catch /.*/ " throw error exception
|
|
6410 Xpath 32 " X: 0
|
|
6411 catch /.*/
|
|
6412 Xpath 64 " X: 0
|
|
6413 endtry
|
|
6414 catch /^Vim(/
|
|
6415 let caught = 1
|
|
6416 finally
|
|
6417 Xpath 128 " X: 128
|
|
6418 if caught || $VIMNOERRTHROW
|
|
6419 Xpath 256 " X: 256
|
|
6420 endif
|
|
6421 endtry
|
|
6422 catch /.*/
|
|
6423 Xpath 512 " X: 0
|
|
6424 Xout v:exception "in" v:throwpoint
|
|
6425 finally
|
|
6426 break " discard error for $VIMNOERRTHROW
|
|
6427 endtry
|
|
6428 endwhile
|
|
6429
|
|
6430 while 1
|
|
6431 try
|
|
6432 try
|
|
6433 let caught = 0
|
|
6434 try
|
|
6435 Xpath 1024 " X: 1024
|
|
6436 "INTERRUPT
|
|
6437 catch /do_not_catch/
|
|
6438 Xpath 2048 " X: 0
|
|
6439 " if 1
|
|
6440 " Missing :endif
|
|
6441 catch /.*/ " throw error exception
|
|
6442 Xpath 4096 " X: 0
|
|
6443 catch /.*/
|
|
6444 Xpath 8192 " X: 0
|
|
6445 endtry
|
|
6446 catch /^Vim(/
|
|
6447 let caught = 1
|
|
6448 finally
|
|
6449 Xpath 16384 " X: 16384
|
|
6450 if caught || $VIMNOERRTHROW
|
|
6451 Xpath 32768 " X: 32768
|
|
6452 endif
|
|
6453 endtry
|
|
6454 catch /.*/
|
|
6455 Xpath 65536 " X: 0
|
|
6456 Xout v:exception "in" v:throwpoint
|
|
6457 finally
|
|
6458 break " discard error for $VIMNOERRTHROW
|
|
6459 endtry
|
|
6460 endwhile
|
|
6461
|
|
6462 while 1
|
|
6463 try
|
|
6464 try
|
|
6465 let caught = 0
|
|
6466 try
|
|
6467 Xpath 131072 " X: 131072
|
|
6468 throw "x"
|
|
6469 catch /do_not_catch/
|
|
6470 Xpath 262144 " X: 0
|
|
6471 " if 1
|
|
6472 " Missing :endif
|
|
6473 catch /x/ " throw error exception
|
|
6474 Xpath 524288 " X: 0
|
|
6475 catch /.*/
|
|
6476 Xpath 1048576 " X: 0
|
|
6477 endtry
|
|
6478 catch /^Vim(/
|
|
6479 let caught = 1
|
|
6480 finally
|
|
6481 Xpath 2097152 " X: 2097152
|
|
6482 if caught || $VIMNOERRTHROW
|
|
6483 Xpath 4194304 " X: 4194304
|
|
6484 endif
|
|
6485 endtry
|
|
6486 catch /.*/
|
|
6487 Xpath 8388608 " X: 0
|
|
6488 Xout v:exception "in" v:throwpoint
|
|
6489 finally
|
|
6490 break " discard error for $VIMNOERRTHROW
|
|
6491 endtry
|
|
6492 endwhile
|
|
6493
|
|
6494 while 1
|
|
6495 try
|
|
6496 try
|
|
6497 let caught = 0
|
|
6498 Xpath 16777216 " X: 16777216
|
|
6499 " endif " :endif without :if; throw error exception
|
|
6500 " if 1
|
|
6501 " Missing :endif
|
|
6502 catch /do_not_catch/ " ignore new error
|
|
6503 Xpath 33554432 " X: 0
|
|
6504 catch /^Vim(endif):/
|
|
6505 let caught = 1
|
|
6506 catch /^Vim(/
|
|
6507 Xpath 67108864 " X: 0
|
|
6508 finally
|
|
6509 Xpath 134217728 " X: 134217728
|
|
6510 if caught || $VIMNOERRTHROW
|
|
6511 Xpath 268435456 " X: 268435456
|
|
6512 endif
|
|
6513 endtry
|
|
6514 catch /.*/
|
|
6515 Xpath 536870912 " X: 0
|
|
6516 Xout v:exception "in" v:throwpoint
|
|
6517 finally
|
|
6518 break " discard error for $VIMNOERRTHROW
|
|
6519 endtry
|
|
6520 endwhile
|
|
6521
|
|
6522 Xpath 1073741824 " X: 1073741824
|
|
6523
|
|
6524 endif
|
|
6525
|
|
6526 Xcheck 1499645335
|
|
6527
|
|
6528
|
|
6529 "-------------------------------------------------------------------------------
|
|
6530 " Test 65: Errors in the /pattern/ argument of a :catch {{{1
|
|
6531 "
|
|
6532 " On an error in the /pattern/ argument of a :catch, the :catch does
|
|
6533 " not match. Any following :catches of the same :try/:endtry don't
|
|
6534 " match either. Finally clauses are executed.
|
|
6535 "-------------------------------------------------------------------------------
|
|
6536
|
|
6537 XpathINIT
|
|
6538
|
|
6539 function! MSG(enr, emsg)
|
|
6540 let english = v:lang == "C" || v:lang =~ '^[Ee]n'
|
|
6541 if a:enr == ""
|
|
6542 Xout "TODO: Add message number for:" a:emsg
|
|
6543 let v:errmsg = ":" . v:errmsg
|
|
6544 endif
|
|
6545 let match = 1
|
|
6546 if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg)
|
|
6547 let match = 0
|
|
6548 if v:errmsg == ""
|
|
6549 Xout "Message missing."
|
|
6550 else
|
|
6551 let v:errmsg = escape(v:errmsg, '"')
|
|
6552 Xout "Unexpected message:" v:errmsg
|
|
6553 endif
|
|
6554 endif
|
|
6555 return match
|
|
6556 endfunction
|
|
6557
|
|
6558 try
|
|
6559 try
|
|
6560 Xpath 1 " X: 1
|
|
6561 throw "oops"
|
|
6562 catch /^oops$/
|
|
6563 Xpath 2 " X: 2
|
|
6564 catch /\)/ " not checked; exception has already been caught
|
|
6565 Xpath 4 " X: 0
|
|
6566 endtry
|
|
6567 Xpath 8 " X: 8
|
|
6568 catch /.*/
|
|
6569 Xpath 16 " X: 0
|
|
6570 Xout v:exception "in" v:throwpoint
|
|
6571 endtry
|
|
6572
|
|
6573 function! F()
|
|
6574 try
|
|
6575 let caught = 0
|
|
6576 try
|
|
6577 try
|
|
6578 Xpath 32 " X: 32
|
|
6579 throw "ab"
|
|
6580 catch /abc/ " does not catch
|
|
6581 Xpath 64 " X: 0
|
|
6582 catch /\)/ " error; discards exception
|
|
6583 Xpath 128 " X: 0
|
|
6584 catch /.*/ " not checked
|
|
6585 Xpath 256 " X: 0
|
|
6586 finally
|
|
6587 Xpath 512 " X: 512
|
|
6588 endtry
|
|
6589 Xpath 1024 " X: 0
|
|
6590 catch /^ab$/ " checked, but original exception is discarded
|
|
6591 Xpath 2048 " X: 0
|
|
6592 catch /^Vim(catch):/
|
|
6593 let caught = 1
|
|
6594 let v:errmsg = substitute(v:exception, '^Vim(catch):', '', "")
|
|
6595 finally
|
|
6596 Xpath 4096 " X: 4096
|
|
6597 if !caught && !$VIMNOERRTHROW
|
|
6598 Xpath 8192 " X: 0
|
|
6599 endif
|
|
6600 if caught ? !MSG('E55', 'Unmatched \\)')
|
|
6601 \ : !MSG('E475', "Invalid argument")
|
|
6602 Xpath 16384 " X: 0
|
|
6603 endif
|
|
6604 if !caught
|
|
6605 return | " discard error
|
|
6606 endif
|
|
6607 endtry
|
|
6608 catch /.*/
|
|
6609 Xpath 32768 " X: 0
|
|
6610 Xout v:exception "in" v:throwpoint
|
|
6611 endtry
|
|
6612 endfunction
|
|
6613
|
|
6614 call F()
|
|
6615 Xpath 65536 " X: 65536
|
|
6616
|
|
6617 delfunction MSG
|
|
6618 delfunction F
|
|
6619 unlet! caught
|
|
6620
|
|
6621 Xcheck 70187
|
|
6622
|
|
6623
|
|
6624 "-------------------------------------------------------------------------------
|
|
6625 " Test 66: Stop range :call on error, interrupt, or :throw {{{1
|
|
6626 "
|
|
6627 " When a function which is multiply called for a range since it
|
|
6628 " doesn't handle the range itself has an error in a command
|
|
6629 " dynamically enclosed by :try/:endtry or gets an interrupt or
|
|
6630 " executes a :throw, no more calls for the remaining lines in the
|
|
6631 " range are made. On an error in a command not dynamically enclosed
|
|
6632 " by :try/:endtry, the function is executed again for the remaining
|
|
6633 " lines in the range.
|
|
6634 "-------------------------------------------------------------------------------
|
|
6635
|
|
6636 XpathINIT
|
|
6637
|
|
6638 if ExtraVim()
|
|
6639
|
|
6640 let file = tempname()
|
|
6641 exec "edit" file
|
|
6642
|
|
6643 insert
|
|
6644 line 1
|
|
6645 line 2
|
|
6646 line 3
|
|
6647 .
|
|
6648
|
|
6649 XloopINIT! 1 2
|
|
6650
|
|
6651 let taken = ""
|
|
6652 let expected = "G1EF1E(1)F1E(2)F1E(3)G2EF2E(1)G3IF3I(1)G4TF4T(1)G5AF5A(1)"
|
|
6653
|
|
6654 function! F(reason, n) abort
|
|
6655 let g:taken = g:taken . "F" . a:n .
|
|
6656 \ substitute(a:reason, '\(\l\).*', '\u\1', "") .
|
|
6657 \ "(" . line(".") . ")"
|
|
6658
|
|
6659 if a:reason == "error"
|
|
6660 asdf
|
|
6661 elseif a:reason == "interrupt"
|
|
6662 "INTERRUPT
|
|
6663 let dummy = 0
|
|
6664 elseif a:reason == "throw"
|
|
6665 throw "xyz"
|
|
6666 elseif a:reason == "aborting error"
|
|
6667 XloopNEXT
|
|
6668 if g:taken != g:expected
|
|
6669 Xloop 1 " X: 0
|
|
6670 Xout "'taken' is" g:taken "instead of" g:expected
|
|
6671 endif
|
|
6672 try
|
|
6673 bwipeout!
|
|
6674 call delete(file)
|
|
6675 asdf
|
|
6676 endtry
|
|
6677 endif
|
|
6678 endfunction
|
|
6679
|
|
6680 function! G(reason, n)
|
|
6681 let g:taken = g:taken . "G" . a:n .
|
|
6682 \ substitute(a:reason, '\(\l\).*', '\u\1', "")
|
|
6683 1,3call F(a:reason, a:n)
|
|
6684 endfunction
|
|
6685
|
|
6686 Xpath 8 " X: 8
|
|
6687 call G("error", 1)
|
|
6688 try
|
|
6689 Xpath 16 " X: 16
|
|
6690 try
|
|
6691 call G("error", 2)
|
|
6692 Xpath 32 " X: 0
|
|
6693 finally
|
|
6694 Xpath 64 " X: 64
|
|
6695 try
|
|
6696 call G("interrupt", 3)
|
|
6697 Xpath 128 " X: 0
|
|
6698 finally
|
|
6699 Xpath 256 " X: 256
|
|
6700 try
|
|
6701 call G("throw", 4)
|
|
6702 Xpath 512 " X: 0
|
|
6703 endtry
|
|
6704 endtry
|
|
6705 endtry
|
|
6706 catch /xyz/
|
|
6707 Xpath 1024 " X: 1024
|
|
6708 catch /.*/
|
|
6709 Xpath 2048 " X: 0
|
|
6710 Xout v:exception "in" ExtraVimThrowpoint()
|
|
6711 endtry
|
|
6712 Xpath 4096 " X: 4096
|
|
6713 call G("aborting error", 5)
|
|
6714 Xpath 8192 " X: 0
|
|
6715 Xout "'taken' is" taken "instead of" expected
|
|
6716
|
|
6717 endif
|
|
6718
|
|
6719 Xcheck 5464
|
|
6720
|
|
6721
|
|
6722 "-------------------------------------------------------------------------------
|
|
6723 " Test 67: :throw accross :call command {{{1
|
|
6724 "
|
|
6725 " On a call command, an exception might be thrown when evaluating the
|
|
6726 " function name, during evaluation of the arguments, or when the
|
|
6727 " function is being executed. The exception can be caught by the
|
|
6728 " caller.
|
|
6729 "-------------------------------------------------------------------------------
|
|
6730
|
|
6731 XpathINIT
|
|
6732
|
|
6733 function! THROW(x, n)
|
|
6734 if a:n == 1
|
|
6735 Xpath 1 " X: 1
|
|
6736 elseif a:n == 2
|
|
6737 Xpath 2 " X: 2
|
|
6738 elseif a:n == 3
|
|
6739 Xpath 4 " X: 4
|
|
6740 endif
|
|
6741 throw a:x
|
|
6742 endfunction
|
|
6743
|
|
6744 function! NAME(x, n)
|
|
6745 if a:n == 1
|
|
6746 Xpath 8 " X: 0
|
|
6747 elseif a:n == 2
|
|
6748 Xpath 16 " X: 16
|
|
6749 elseif a:n == 3
|
|
6750 Xpath 32 " X: 32
|
|
6751 elseif a:n == 4
|
|
6752 Xpath 64 " X: 64
|
|
6753 endif
|
|
6754 return a:x
|
|
6755 endfunction
|
|
6756
|
|
6757 function! ARG(x, n)
|
|
6758 if a:n == 1
|
|
6759 Xpath 128 " X: 0
|
|
6760 elseif a:n == 2
|
|
6761 Xpath 256 " X: 0
|
|
6762 elseif a:n == 3
|
|
6763 Xpath 512 " X: 512
|
|
6764 elseif a:n == 4
|
|
6765 Xpath 1024 " X: 1024
|
|
6766 endif
|
|
6767 return a:x
|
|
6768 endfunction
|
|
6769
|
|
6770 function! F(x, n)
|
|
6771 if a:n == 2
|
|
6772 Xpath 2048 " X: 0
|
|
6773 elseif a:n == 4
|
|
6774 Xpath 4096 " X: 4096
|
|
6775 endif
|
|
6776 endfunction
|
|
6777
|
|
6778 try
|
|
6779
|
|
6780 try
|
|
6781 Xpath 8192 " X: 8192
|
|
6782 call {NAME(THROW("name", 1), 1)}(ARG(4711, 1), 1)
|
|
6783 Xpath 16384 " X: 0
|
|
6784 catch /^name$/
|
|
6785 Xpath 32768 " X: 32768
|
|
6786 catch /.*/
|
|
6787 Xpath 65536 " X: 0
|
|
6788 Xout "1:" v:exception "in" v:throwpoint
|
|
6789 endtry
|
|
6790
|
|
6791 try
|
|
6792 Xpath 131072 " X: 131072
|
|
6793 call {NAME("F", 2)}(ARG(THROW("arg", 2), 2), 2)
|
|
6794 Xpath 262144 " X: 0
|
|
6795 catch /^arg$/
|
|
6796 Xpath 524288 " X: 524288
|
|
6797 catch /.*/
|
|
6798 Xpath 1048576 " X: 0
|
|
6799 Xout "2:" v:exception "in" v:throwpoint
|
|
6800 endtry
|
|
6801
|
|
6802 try
|
|
6803 Xpath 2097152 " X: 2097152
|
|
6804 call {NAME("THROW", 3)}(ARG("call", 3), 3)
|
|
6805 Xpath 4194304 " X: 0
|
|
6806 catch /^call$/
|
|
6807 Xpath 8388608 " X: 8388608
|
|
6808 catch /^0$/ " default return value
|
|
6809 Xpath 16777216 " X: 0
|
|
6810 Xout "3:" v:throwpoint
|
|
6811 catch /.*/
|
|
6812 Xpath 33554432 " X: 0
|
|
6813 Xout "3:" v:exception "in" v:throwpoint
|
|
6814 endtry
|
|
6815
|
|
6816 try
|
|
6817 Xpath 67108864 " X: 67108864
|
|
6818 call {NAME("F", 4)}(ARG(4711, 4), 4)
|
|
6819 Xpath 134217728 " X: 134217728
|
|
6820 catch /.*/
|
|
6821 Xpath 268435456 " X: 0
|
|
6822 Xout "4:" v:exception "in" v:throwpoint
|
|
6823 endtry
|
|
6824
|
|
6825 catch /^0$/ " default return value
|
|
6826 Xpath 536870912 " X: 0
|
|
6827 Xout v:throwpoint
|
|
6828 catch /.*/
|
|
6829 Xpath 1073741824 " X: 0
|
|
6830 Xout v:exception "in" v:throwpoint
|
|
6831 endtry
|
|
6832
|
|
6833 delfunction F
|
|
6834
|
|
6835 Xcheck 212514423
|
|
6836
|
|
6837 " Leave THROW(), NAME(), and ARG() for the next test.
|
|
6838
|
|
6839
|
|
6840 "-------------------------------------------------------------------------------
|
|
6841 " Test 68: :throw accross function calls in expressions {{{1
|
|
6842 "
|
|
6843 " On a function call within an expression, an exception might be
|
|
6844 " thrown when evaluating the function name, during evaluation of the
|
|
6845 " arguments, or when the function is being executed. The exception
|
|
6846 " can be caught by the caller.
|
|
6847 "
|
|
6848 " This test reuses the functions THROW(), NAME(), and ARG() from the
|
|
6849 " previous test.
|
|
6850 "-------------------------------------------------------------------------------
|
|
6851
|
|
6852 XpathINIT
|
|
6853
|
|
6854 function! F(x, n)
|
|
6855 if a:n == 2
|
|
6856 Xpath 2048 " X: 0
|
|
6857 elseif a:n == 4
|
|
6858 Xpath 4096 " X: 4096
|
|
6859 endif
|
|
6860 return a:x
|
|
6861 endfunction
|
|
6862
|
|
6863 unlet! var1 var2 var3 var4
|
|
6864
|
|
6865 try
|
|
6866
|
|
6867 try
|
|
6868 Xpath 8192 " X: 8192
|
|
6869 let var1 = {NAME(THROW("name", 1), 1)}(ARG(4711, 1), 1)
|
|
6870 Xpath 16384 " X: 0
|
|
6871 catch /^name$/
|
|
6872 Xpath 32768 " X: 32768
|
|
6873 catch /.*/
|
|
6874 Xpath 65536 " X: 0
|
|
6875 Xout "1:" v:exception "in" v:throwpoint
|
|
6876 endtry
|
|
6877
|
|
6878 try
|
|
6879 Xpath 131072 " X: 131072
|
|
6880 let var2 = {NAME("F", 2)}(ARG(THROW("arg", 2), 2), 2)
|
|
6881 Xpath 262144 " X: 0
|
|
6882 catch /^arg$/
|
|
6883 Xpath 524288 " X: 524288
|
|
6884 catch /.*/
|
|
6885 Xpath 1048576 " X: 0
|
|
6886 Xout "2:" v:exception "in" v:throwpoint
|
|
6887 endtry
|
|
6888
|
|
6889 try
|
|
6890 Xpath 2097152 " X: 2097152
|
|
6891 let var3 = {NAME("THROW", 3)}(ARG("call", 3), 3)
|
|
6892 Xpath 4194304 " X: 0
|
|
6893 catch /^call$/
|
|
6894 Xpath 8388608 " X: 8388608
|
|
6895 catch /^0$/ " default return value
|
|
6896 Xpath 16777216 " X: 0
|
|
6897 Xout "3:" v:throwpoint
|
|
6898 catch /.*/
|
|
6899 Xpath 33554432 " X: 0
|
|
6900 Xout "3:" v:exception "in" v:throwpoint
|
|
6901 endtry
|
|
6902
|
|
6903 try
|
|
6904 Xpath 67108864 " X: 67108864
|
|
6905 let var4 = {NAME("F", 4)}(ARG(4711, 4), 4)
|
|
6906 Xpath 134217728 " X: 134217728
|
|
6907 catch /.*/
|
|
6908 Xpath 268435456 " X: 0
|
|
6909 Xout "4:" v:exception "in" v:throwpoint
|
|
6910 endtry
|
|
6911
|
|
6912 catch /^0$/ " default return value
|
|
6913 Xpath 536870912 " X: 0
|
|
6914 Xout v:throwpoint
|
|
6915 catch /.*/
|
|
6916 Xpath 1073741824 " X: 0
|
|
6917 Xout v:exception "in" v:throwpoint
|
|
6918 endtry
|
|
6919
|
|
6920 if exists("var1") || exists("var2") || exists("var3") ||
|
|
6921 \ !exists("var4") || var4 != 4711
|
|
6922 " The Xpath command does not accept 2^31 (negative); add explicitly:
|
|
6923 let Xpath = Xpath + 2147483648 " X: 0
|
|
6924 if exists("var1")
|
|
6925 Xout "var1 =" var1
|
|
6926 endif
|
|
6927 if exists("var2")
|
|
6928 Xout "var2 =" var2
|
|
6929 endif
|
|
6930 if exists("var3")
|
|
6931 Xout "var3 =" var3
|
|
6932 endif
|
|
6933 if !exists("var4")
|
|
6934 Xout "var4 unset"
|
|
6935 elseif var4 != 4711
|
|
6936 Xout "var4 =" var4
|
|
6937 endif
|
|
6938 endif
|
|
6939
|
|
6940 unlet! var1 var2 var3 var4
|
|
6941 delfunction THROW
|
|
6942 delfunction NAME
|
|
6943 delfunction ARG
|
|
6944 delfunction F
|
|
6945
|
|
6946 Xcheck 212514423
|
|
6947
|
|
6948
|
|
6949 "-------------------------------------------------------------------------------
|
|
6950 " Test 69: :throw accross :if, :elseif, :while {{{1
|
|
6951 "
|
|
6952 " On an :if, :elseif, or :while command, an exception might be thrown
|
|
6953 " during evaluation of the expression to test. The exception can be
|
|
6954 " caught by the script.
|
|
6955 "-------------------------------------------------------------------------------
|
|
6956
|
|
6957 XpathINIT
|
|
6958
|
|
6959 XloopINIT! 1 2
|
|
6960
|
|
6961 function! THROW(x)
|
|
6962 XloopNEXT
|
|
6963 Xloop 1 " X: 1 + 2 + 4
|
|
6964 throw a:x
|
|
6965 endfunction
|
|
6966
|
|
6967 try
|
|
6968
|
|
6969 try
|
|
6970 Xpath 8 " X: 8
|
|
6971 if 4711 == THROW("if") + 111
|
|
6972 Xpath 16 " X: 0
|
|
6973 else
|
|
6974 Xpath 32 " X: 0
|
|
6975 endif
|
|
6976 Xpath 64 " X: 0
|
|
6977 catch /^if$/
|
|
6978 Xpath 128 " X: 128
|
|
6979 catch /.*/
|
|
6980 Xpath 256 " X: 0
|
|
6981 Xout "if:" v:exception "in" v:throwpoint
|
|
6982 endtry
|
|
6983
|
|
6984 try
|
|
6985 Xpath 512 " X: 512
|
|
6986 if 4711 == 4 + 7 + 1 + 1
|
|
6987 Xpath 1024 " X: 0
|
|
6988 elseif 4711 == THROW("elseif") + 222
|
|
6989 Xpath 2048 " X: 0
|
|
6990 else
|
|
6991 Xpath 4096 " X: 0
|
|
6992 endif
|
|
6993 Xpath 8192 " X: 0
|
|
6994 catch /^elseif$/
|
|
6995 Xpath 16384 " X: 16384
|
|
6996 catch /.*/
|
|
6997 Xpath 32768 " X: 0
|
|
6998 Xout "elseif:" v:exception "in" v:throwpoint
|
|
6999 endtry
|
|
7000
|
|
7001 try
|
|
7002 Xpath 65536 " X: 65536
|
|
7003 while 4711 == THROW("while") + 4711
|
|
7004 Xpath 131072 " X: 0
|
|
7005 break
|
|
7006 endwhile
|
|
7007 Xpath 262144 " X: 0
|
|
7008 catch /^while$/
|
|
7009 Xpath 524288 " X: 524288
|
|
7010 catch /.*/
|
|
7011 Xpath 1048576 " X: 0
|
|
7012 Xout "while:" v:exception "in" v:throwpoint
|
|
7013 endtry
|
|
7014
|
|
7015 catch /^0$/ " default return value
|
|
7016 Xpath 2097152 " X: 0
|
|
7017 Xout v:throwpoint
|
|
7018 catch /.*/
|
|
7019 Xout v:exception "in" v:throwpoint
|
|
7020 Xpath 4194304 " X: 0
|
|
7021 endtry
|
|
7022
|
|
7023 Xpath 8388608 " X: 8388608
|
|
7024
|
|
7025 delfunction THROW
|
|
7026
|
|
7027 Xcheck 8995471
|
|
7028
|
|
7029
|
|
7030 "-------------------------------------------------------------------------------
|
|
7031 " Test 70: :throw accross :return or :throw {{{1
|
|
7032 "
|
|
7033 " On a :return or :throw command, an exception might be thrown during
|
|
7034 " evaluation of the expression to return or throw, respectively. The
|
|
7035 " exception can be caught by the script.
|
|
7036 "-------------------------------------------------------------------------------
|
|
7037
|
|
7038 XpathINIT
|
|
7039
|
|
7040 let taken = ""
|
|
7041
|
|
7042 function! THROW(x, n)
|
|
7043 let g:taken = g:taken . "T" . a:n
|
|
7044 throw a:x
|
|
7045 endfunction
|
|
7046
|
|
7047 function! F(x, y, n)
|
|
7048 let g:taken = g:taken . "F" . a:n
|
|
7049 return a:x + THROW(a:y, a:n)
|
|
7050 endfunction
|
|
7051
|
|
7052 function! G(x, y, n)
|
|
7053 let g:taken = g:taken . "G" . a:n
|
|
7054 throw a:x . THROW(a:y, a:n)
|
|
7055 return a:x
|
|
7056 endfunction
|
|
7057
|
|
7058 try
|
|
7059 try
|
|
7060 Xpath 1 " X: 1
|
|
7061 call F(4711, "return", 1)
|
|
7062 Xpath 2 " X: 0
|
|
7063 catch /^return$/
|
|
7064 Xpath 4 " X: 4
|
|
7065 catch /.*/
|
|
7066 Xpath 8 " X: 0
|
|
7067 Xout "return:" v:exception "in" v:throwpoint
|
|
7068 endtry
|
|
7069
|
|
7070 try
|
|
7071 Xpath 16 " X: 16
|
|
7072 let var = F(4712, "return-var", 2)
|
|
7073 Xpath 32 " X: 0
|
|
7074 catch /^return-var$/
|
|
7075 Xpath 64 " X: 64
|
|
7076 catch /.*/
|
|
7077 Xpath 128 " X: 0
|
|
7078 Xout "return-var:" v:exception "in" v:throwpoint
|
|
7079 finally
|
|
7080 unlet! var
|
|
7081 endtry
|
|
7082
|
|
7083 try
|
|
7084 Xpath 256 " X: 256
|
|
7085 throw "except1" . THROW("throw1", 3)
|
|
7086 Xpath 512 " X: 0
|
|
7087 catch /^except1/
|
|
7088 Xpath 1024 " X: 0
|
|
7089 catch /^throw1$/
|
|
7090 Xpath 2048 " X: 2048
|
|
7091 catch /.*/
|
|
7092 Xpath 4096 " X: 0
|
|
7093 Xout "throw1:" v:exception "in" v:throwpoint
|
|
7094 endtry
|
|
7095
|
|
7096 try
|
|
7097 Xpath 8192 " X: 8192
|
|
7098 call G("except2", "throw2", 4)
|
|
7099 Xpath 16384 " X: 0
|
|
7100 catch /^except2/
|
|
7101 Xpath 32768 " X: 0
|
|
7102 catch /^throw2$/
|
|
7103 Xpath 65536 " X: 65536
|
|
7104 catch /.*/
|
|
7105 Xpath 131072 " X: 0
|
|
7106 Xout "throw2:" v:exception "in" v:throwpoint
|
|
7107 endtry
|
|
7108
|
|
7109 try
|
|
7110 Xpath 262144 " X: 262144
|
|
7111 let var = G("except3", "throw3", 5)
|
|
7112 Xpath 524288 " X: 0
|
|
7113 catch /^except3/
|
|
7114 Xpath 1048576 " X: 0
|
|
7115 catch /^throw3$/
|
|
7116 Xpath 2097152 " X: 2097152
|
|
7117 catch /.*/
|
|
7118 Xpath 4194304 " X: 0
|
|
7119 Xout "throw3:" v:exception "in" v:throwpoint
|
|
7120 finally
|
|
7121 unlet! var
|
|
7122 endtry
|
|
7123
|
|
7124 let expected = "F1T1F2T2T3G4T4G5T5"
|
|
7125 if taken != expected
|
|
7126 Xpath 8388608 " X: 0
|
|
7127 Xout "'taken' is" taken "instead of" expected
|
|
7128 endif
|
|
7129
|
|
7130 catch /^0$/ " default return value
|
|
7131 Xpath 16777216 " X: 0
|
|
7132 Xout v:throwpoint
|
|
7133 catch /.*/
|
|
7134 Xpath 33554432 " X: 0
|
|
7135 Xout v:exception "in" v:throwpoint
|
|
7136 endtry
|
|
7137
|
|
7138 Xpath 67108864 " X: 67108864
|
|
7139
|
|
7140 unlet taken expected
|
|
7141 delfunction THROW
|
|
7142 delfunction F
|
|
7143 delfunction G
|
|
7144
|
|
7145 Xcheck 69544277
|
|
7146
|
|
7147
|
|
7148 "-------------------------------------------------------------------------------
|
|
7149 " Test 71: :throw accross :echo variants and :execute {{{1
|
|
7150 "
|
|
7151 " On an :echo, :echon, :echomsg, :echoerr, or :execute command, an
|
|
7152 " exception might be thrown during evaluation of the arguments to
|
|
7153 " be displayed or executed as a command, respectively. Any following
|
|
7154 " arguments are not evaluated, then. The exception can be caught by
|
|
7155 " the script.
|
|
7156 "-------------------------------------------------------------------------------
|
|
7157
|
|
7158 XpathINIT
|
|
7159
|
|
7160 let taken = ""
|
|
7161
|
|
7162 function! THROW(x, n)
|
|
7163 let g:taken = g:taken . "T" . a:n
|
|
7164 throw a:x
|
|
7165 endfunction
|
|
7166
|
|
7167 function! F(n)
|
|
7168 let g:taken = g:taken . "F" . a:n
|
|
7169 return "F" . a:n
|
|
7170 endfunction
|
|
7171
|
|
7172 try
|
|
7173 try
|
|
7174 Xpath 1 " X: 1
|
|
7175 echo "echo" . THROW("echo-except", 1) F(1)
|
|
7176 Xpath 2 " X: 0
|
|
7177 catch /^echo-except$/
|
|
7178 Xpath 4 " X: 4
|
|
7179 catch /.*/
|
|
7180 Xpath 8 " X: 0
|
|
7181 Xout "echo:" v:exception "in" v:throwpoint
|
|
7182 endtry
|
|
7183
|
|
7184 try
|
|
7185 Xpath 16 " X: 16
|
|
7186 echon "echon" . THROW("echon-except", 2) F(2)
|
|
7187 Xpath 32 " X: 0
|
|
7188 catch /^echon-except$/
|
|
7189 Xpath 64 " X: 64
|
|
7190 catch /.*/
|
|
7191 Xpath 128 " X: 0
|
|
7192 Xout "echon:" v:exception "in" v:throwpoint
|
|
7193 endtry
|
|
7194
|
|
7195 try
|
|
7196 Xpath 256 " X: 256
|
|
7197 echomsg "echomsg" . THROW("echomsg-except", 3) F(3)
|
|
7198 Xpath 512 " X: 0
|
|
7199 catch /^echomsg-except$/
|
|
7200 Xpath 1024 " X: 1024
|
|
7201 catch /.*/
|
|
7202 Xpath 2048 " X: 0
|
|
7203 Xout "echomsg:" v:exception "in" v:throwpoint
|
|
7204 endtry
|
|
7205
|
|
7206 try
|
|
7207 Xpath 4096 " X: 4096
|
|
7208 echoerr "echoerr" . THROW("echoerr-except", 4) F(4)
|
|
7209 Xpath 8192 " X: 0
|
|
7210 catch /^echoerr-except$/
|
|
7211 Xpath 16384 " X: 16384
|
|
7212 catch /Vim/
|
|
7213 Xpath 32768 " X: 0
|
|
7214 catch /echoerr/
|
|
7215 Xpath 65536 " X: 0
|
|
7216 catch /.*/
|
|
7217 Xpath 131072 " X: 0
|
|
7218 Xout "echoerr:" v:exception "in" v:throwpoint
|
|
7219 endtry
|
|
7220
|
|
7221 try
|
|
7222 Xpath 262144 " X: 262144
|
|
7223 execute "echo 'execute" . THROW("execute-except", 5) F(5) "'"
|
|
7224 Xpath 524288 " X: 0
|
|
7225 catch /^execute-except$/
|
|
7226 Xpath 1048576 " X: 1048576
|
|
7227 catch /.*/
|
|
7228 Xpath 2097152 " X: 0
|
|
7229 Xout "execute:" v:exception "in" v:throwpoint
|
|
7230 endtry
|
|
7231
|
|
7232 let expected = "T1T2T3T4T5"
|
|
7233 if taken != expected
|
|
7234 Xpath 4194304 " X: 0
|
|
7235 Xout "'taken' is" taken "instead of" expected
|
|
7236 endif
|
|
7237
|
|
7238 catch /^0$/ " default return value
|
|
7239 Xpath 8388608 " X: 0
|
|
7240 Xout v:throwpoint
|
|
7241 catch /.*/
|
|
7242 Xpath 16777216 " X: 0
|
|
7243 Xout v:exception "in" v:throwpoint
|
|
7244 endtry
|
|
7245
|
|
7246 Xpath 33554432 " X: 33554432
|
|
7247
|
|
7248 unlet taken expected
|
|
7249 delfunction THROW
|
|
7250 delfunction F
|
|
7251
|
|
7252 Xcheck 34886997
|
|
7253
|
|
7254
|
|
7255 "-------------------------------------------------------------------------------
|
|
7256 " Test 72: :throw accross :let or :unlet {{{1
|
|
7257 "
|
|
7258 " On a :let command, an exception might be thrown during evaluation
|
|
7259 " of the expression to assign. On an :let or :unlet command, the
|
|
7260 " evaluation of the name of the variable to be assigned or list or
|
|
7261 " deleted, respectively, may throw an exception. Any following
|
|
7262 " arguments are not evaluated, then. The exception can be caught by
|
|
7263 " the script.
|
|
7264 "-------------------------------------------------------------------------------
|
|
7265
|
|
7266 XpathINIT
|
|
7267
|
|
7268 let throwcount = 0
|
|
7269
|
|
7270 function! THROW(x)
|
|
7271 let g:throwcount = g:throwcount + 1
|
|
7272 throw a:x
|
|
7273 endfunction
|
|
7274
|
|
7275 try
|
|
7276 try
|
|
7277 let $VAR = "old_value"
|
|
7278 Xpath 1 " X: 1
|
|
7279 let $VAR = "let(" . THROW("var") . ")"
|
|
7280 Xpath 2 " X: 0
|
|
7281 catch /^var$/
|
|
7282 Xpath 4 " X: 4
|
|
7283 finally
|
|
7284 if $VAR != "old_value"
|
|
7285 Xpath 8 " X: 0
|
|
7286 endif
|
|
7287 endtry
|
|
7288
|
|
7289 try
|
|
7290 let @a = "old_value"
|
|
7291 Xpath 16 " X: 16
|
|
7292 let @a = "let(" . THROW("reg") . ")"
|
|
7293 Xpath 32 " X: 0
|
|
7294 catch /^reg$/
|
|
7295 try
|
|
7296 Xpath 64 " X: 64
|
|
7297 let @A = "let(" . THROW("REG") . ")"
|
|
7298 Xpath 128 " X: 0
|
|
7299 catch /^REG$/
|
|
7300 Xpath 256 " X: 256
|
|
7301 endtry
|
|
7302 finally
|
|
7303 if @a != "old_value"
|
|
7304 Xpath 512 " X: 0
|
|
7305 endif
|
|
7306 if @A != "old_value"
|
|
7307 Xpath 1024 " X: 0
|
|
7308 endif
|
|
7309 endtry
|
|
7310
|
|
7311 try
|
|
7312 let saved_gpath = &g:path
|
|
7313 let saved_lpath = &l:path
|
|
7314 Xpath 2048 " X: 2048
|
|
7315 let &path = "let(" . THROW("opt") . ")"
|
|
7316 Xpath 4096 " X: 0
|
|
7317 catch /^opt$/
|
|
7318 try
|
|
7319 Xpath 8192 " X: 8192
|
|
7320 let &g:path = "let(" . THROW("gopt") . ")"
|
|
7321 Xpath 16384 " X: 0
|
|
7322 catch /^gopt$/
|
|
7323 try
|
|
7324 Xpath 32768 " X: 32768
|
|
7325 let &l:path = "let(" . THROW("lopt") . ")"
|
|
7326 Xpath 65536 " X: 0
|
|
7327 catch /^lopt$/
|
|
7328 Xpath 131072 " X: 131072
|
|
7329 endtry
|
|
7330 endtry
|
|
7331 finally
|
|
7332 if &g:path != saved_gpath || &l:path != saved_lpath
|
|
7333 Xpath 262144 " X: 0
|
|
7334 endif
|
|
7335 let &g:path = saved_gpath
|
|
7336 let &l:path = saved_lpath
|
|
7337 endtry
|
|
7338
|
|
7339 unlet! var1 var2 var3
|
|
7340
|
|
7341 try
|
|
7342 Xpath 524288 " X: 524288
|
|
7343 let var1 = "let(" . THROW("var1") . ")"
|
|
7344 Xpath 1048576 " X: 0
|
|
7345 catch /^var1$/
|
|
7346 Xpath 2097152 " X: 2097152
|
|
7347 finally
|
|
7348 if exists("var1")
|
|
7349 Xpath 4194304 " X: 0
|
|
7350 endif
|
|
7351 endtry
|
|
7352
|
|
7353 try
|
|
7354 let var2 = "old_value"
|
|
7355 Xpath 8388608 " X: 8388608
|
|
7356 let var2 = "let(" . THROW("var2"). ")"
|
|
7357 Xpath 16777216 " X: 0
|
|
7358 catch /^var2$/
|
|
7359 Xpath 33554432 " X: 33554432
|
|
7360 finally
|
|
7361 if var2 != "old_value"
|
|
7362 Xpath 67108864 " X: 0
|
|
7363 endif
|
|
7364 endtry
|
|
7365
|
|
7366 try
|
|
7367 Xpath 134217728 " X: 134217728
|
|
7368 let var{THROW("var3")} = 4711
|
|
7369 Xpath 268435456 " X: 0
|
|
7370 catch /^var3$/
|
|
7371 Xpath 536870912 " X: 536870912
|
|
7372 endtry
|
|
7373
|
|
7374 let addpath = ""
|
|
7375
|
|
7376 function ADDPATH(p)
|
|
7377 let g:addpath = g:addpath . a:p
|
|
7378 endfunction
|
|
7379
|
|
7380 try
|
|
7381 call ADDPATH("T1")
|
|
7382 let var{THROW("var4")} var{ADDPATH("T2")} | call ADDPATH("T3")
|
|
7383 call ADDPATH("T4")
|
|
7384 catch /^var4$/
|
|
7385 call ADDPATH("T5")
|
|
7386 endtry
|
|
7387
|
|
7388 try
|
|
7389 call ADDPATH("T6")
|
|
7390 unlet var{THROW("var5")} var{ADDPATH("T7")} | call ADDPATH("T8")
|
|
7391 call ADDPATH("T9")
|
|
7392 catch /^var5$/
|
|
7393 call ADDPATH("T10")
|
|
7394 endtry
|
|
7395
|
|
7396 if addpath != "T1T5T6T10" || throwcount != 11
|
|
7397 throw "addpath: " . addpath . ", throwcount: " . throwcount
|
|
7398 endif
|
|
7399
|
|
7400 Xpath 1073741824 " X: 1073741824
|
|
7401
|
|
7402 catch /.*/
|
|
7403 " The Xpath command does not accept 2^31 (negative); add explicitly:
|
|
7404 let Xpath = Xpath + 2147483648 " X: 0
|
|
7405 Xout v:exception "in" v:throwpoint
|
|
7406 endtry
|
|
7407
|
|
7408 unlet! var1 var2 var3 addpath throwcount
|
|
7409 delfunction THROW
|
|
7410
|
|
7411 Xcheck 1789569365
|
|
7412
|
|
7413
|
|
7414 "-------------------------------------------------------------------------------
|
|
7415 " Test 73: :throw accross :function, :delfunction {{{1
|
|
7416 "
|
|
7417 " The :function and :delfunction commands may cause an expression
|
|
7418 " specified in braces to be evaluated. During evaluation, an
|
|
7419 " exception might be thrown. The exception can be caught by the
|
|
7420 " script.
|
|
7421 "-------------------------------------------------------------------------------
|
|
7422
|
|
7423 XpathINIT
|
|
7424
|
|
7425 let taken = ""
|
|
7426
|
|
7427 function! THROW(x, n)
|
|
7428 let g:taken = g:taken . "T" . a:n
|
|
7429 throw a:x
|
|
7430 endfunction
|
|
7431
|
|
7432 function! EXPR(x, n)
|
|
7433 let g:taken = g:taken . "E" . a:n
|
|
7434 if a:n % 2 == 0
|
|
7435 call THROW(a:x, a:n)
|
|
7436 endif
|
|
7437 return 2 - a:n % 2
|
|
7438 endfunction
|
|
7439
|
|
7440 try
|
|
7441 try
|
|
7442 " Define function.
|
|
7443 Xpath 1 " X: 1
|
|
7444 function! F0()
|
|
7445 endfunction
|
|
7446 Xpath 2 " X: 2
|
|
7447 function! F{EXPR("function-def-ok", 1)}()
|
|
7448 endfunction
|
|
7449 Xpath 4 " X: 4
|
|
7450 function! F{EXPR("function-def", 2)}()
|
|
7451 endfunction
|
|
7452 Xpath 8 " X: 0
|
|
7453 catch /^function-def-ok$/
|
|
7454 Xpath 16 " X: 0
|
|
7455 catch /^function-def$/
|
|
7456 Xpath 32 " X: 32
|
|
7457 catch /.*/
|
|
7458 Xpath 64 " X: 0
|
|
7459 Xout "def:" v:exception "in" v:throwpoint
|
|
7460 endtry
|
|
7461
|
|
7462 try
|
|
7463 " List function.
|
|
7464 Xpath 128 " X: 128
|
|
7465 function F0
|
|
7466 Xpath 256 " X: 256
|
|
7467 function F{EXPR("function-lst-ok", 3)}
|
|
7468 Xpath 512 " X: 512
|
|
7469 function F{EXPR("function-lst", 4)}
|
|
7470 Xpath 1024 " X: 0
|
|
7471 catch /^function-lst-ok$/
|
|
7472 Xpath 2048 " X: 0
|
|
7473 catch /^function-lst$/
|
|
7474 Xpath 4096 " X: 4096
|
|
7475 catch /.*/
|
|
7476 Xpath 8192 " X: 0
|
|
7477 Xout "lst:" v:exception "in" v:throwpoint
|
|
7478 endtry
|
|
7479
|
|
7480 try
|
|
7481 " Delete function
|
|
7482 Xpath 16384 " X: 16384
|
|
7483 delfunction F0
|
|
7484 Xpath 32768 " X: 32768
|
|
7485 delfunction F{EXPR("function-del-ok", 5)}
|
|
7486 Xpath 65536 " X: 65536
|
|
7487 delfunction F{EXPR("function-del", 6)}
|
|
7488 Xpath 131072 " X: 0
|
|
7489 catch /^function-del-ok$/
|
|
7490 Xpath 262144 " X: 0
|
|
7491 catch /^function-del$/
|
|
7492 Xpath 524288 " X: 524288
|
|
7493 catch /.*/
|
|
7494 Xpath 1048576 " X: 0
|
|
7495 Xout "del:" v:exception "in" v:throwpoint
|
|
7496 endtry
|
|
7497
|
|
7498 let expected = "E1E2T2E3E4T4E5E6T6"
|
|
7499 if taken != expected
|
|
7500 Xpath 2097152 " X: 0
|
|
7501 Xout "'taken' is" taken "instead of" expected
|
|
7502 endif
|
|
7503
|
|
7504 catch /.*/
|
|
7505 Xpath 4194304 " X: 0
|
|
7506 Xout v:exception "in" v:throwpoint
|
|
7507 endtry
|
|
7508
|
|
7509 Xpath 8388608 " X: 8388608
|
|
7510
|
|
7511 unlet taken expected
|
|
7512 delfunction THROW
|
|
7513 delfunction EXPR
|
|
7514
|
|
7515 Xcheck 9032615
|
|
7516
|
|
7517
|
|
7518 "-------------------------------------------------------------------------------
|
|
7519 " Test 74: :throw accross builtin functions and commands {{{1
|
|
7520 "
|
|
7521 " Some functions like exists(), searchpair() take expression
|
|
7522 " arguments, other functions or commands like substitute() or
|
|
7523 " :substitute cause an expression (specified in the regular
|
|
7524 " expression) to be evaluated. During evaluation an exception
|
|
7525 " might be thrown. The exception can be caught by the script.
|
|
7526 "-------------------------------------------------------------------------------
|
|
7527
|
|
7528 XpathINIT
|
|
7529
|
|
7530 let taken = ""
|
|
7531
|
|
7532 function! THROW(x, n)
|
|
7533 let g:taken = g:taken . "T" . a:n
|
|
7534 throw a:x
|
|
7535 endfunction
|
|
7536
|
|
7537 function! EXPR(x, n)
|
|
7538 let g:taken = g:taken . "E" . a:n
|
|
7539 call THROW(a:x . a:n, a:n)
|
|
7540 return "EXPR"
|
|
7541 endfunction
|
|
7542
|
|
7543 function! SKIP(x, n)
|
|
7544 let g:taken = g:taken . "S" . a:n . "(" . line(".")
|
|
7545 let theline = getline(".")
|
|
7546 if theline =~ "skip"
|
|
7547 let g:taken = g:taken . "s)"
|
|
7548 return 1
|
|
7549 elseif theline =~ "throw"
|
|
7550 let g:taken = g:taken . "t)"
|
|
7551 call THROW(a:x . a:n, a:n)
|
|
7552 else
|
|
7553 let g:taken = g:taken . ")"
|
|
7554 return 0
|
|
7555 endif
|
|
7556 endfunction
|
|
7557
|
|
7558 function! SUBST(x, n)
|
|
7559 let g:taken = g:taken . "U" . a:n . "(" . line(".")
|
|
7560 let theline = getline(".")
|
|
7561 if theline =~ "not" " SUBST() should not be called for this line
|
|
7562 let g:taken = g:taken . "n)"
|
|
7563 call THROW(a:x . a:n, a:n)
|
|
7564 elseif theline =~ "throw"
|
|
7565 let g:taken = g:taken . "t)"
|
|
7566 call THROW(a:x . a:n, a:n)
|
|
7567 else
|
|
7568 let g:taken = g:taken . ")"
|
|
7569 return "replaced"
|
|
7570 endif
|
|
7571 endfunction
|
|
7572
|
|
7573 try
|
|
7574 try
|
|
7575 Xpath 1 " X: 1
|
|
7576 let result = exists('*{EXPR("exists", 1)}')
|
|
7577 Xpath 2 " X: 0
|
|
7578 catch /^exists1$/
|
|
7579 Xpath 4 " X: 4
|
|
7580 try
|
|
7581 let result = exists('{EXPR("exists", 2)}')
|
|
7582 Xpath 8 " X: 0
|
|
7583 catch /^exists2$/
|
|
7584 Xpath 16 " X: 16
|
|
7585 catch /.*/
|
|
7586 Xpath 32 " X: 0
|
|
7587 Xout "exists2:" v:exception "in" v:throwpoint
|
|
7588 endtry
|
|
7589 catch /.*/
|
|
7590 Xpath 64 " X: 0
|
|
7591 Xout "exists1:" v:exception "in" v:throwpoint
|
|
7592 endtry
|
|
7593
|
|
7594 try
|
|
7595 let file = tempname()
|
|
7596 exec "edit" file
|
|
7597 insert
|
|
7598 begin
|
|
7599 xx
|
|
7600 middle 3
|
|
7601 xx
|
|
7602 middle 5 skip
|
|
7603 xx
|
|
7604 middle 7 throw
|
|
7605 xx
|
|
7606 end
|
|
7607 .
|
|
7608 normal! gg
|
|
7609 Xpath 128 " X: 128
|
|
7610 let result =
|
|
7611 \ searchpair("begin", "middle", "end", '', 'SKIP("searchpair", 3)')
|
|
7612 Xpath 256 " X: 256
|
|
7613 let result =
|
|
7614 \ searchpair("begin", "middle", "end", '', 'SKIP("searchpair", 4)')
|
|
7615 Xpath 512 " X: 0
|
|
7616 let result =
|
|
7617 \ searchpair("begin", "middle", "end", '', 'SKIP("searchpair", 5)')
|
|
7618 Xpath 1024 " X: 0
|
|
7619 catch /^searchpair[35]$/
|
|
7620 Xpath 2048 " X: 0
|
|
7621 catch /^searchpair4$/
|
|
7622 Xpath 4096 " X: 4096
|
|
7623 catch /.*/
|
|
7624 Xpath 8192 " X: 0
|
|
7625 Xout "searchpair:" v:exception "in" v:throwpoint
|
|
7626 finally
|
|
7627 bwipeout!
|
|
7628 call delete(file)
|
|
7629 endtry
|
|
7630
|
|
7631 try
|
|
7632 let file = tempname()
|
|
7633 exec "edit" file
|
|
7634 insert
|
|
7635 subst 1
|
|
7636 subst 2
|
|
7637 not
|
|
7638 subst 4
|
|
7639 subst throw
|
|
7640 subst 6
|
|
7641 .
|
|
7642 normal! gg
|
|
7643 Xpath 16384 " X: 16384
|
|
7644 1,2substitute/subst/\=SUBST("substitute", 6)/
|
|
7645 try
|
|
7646 Xpath 32768 " X: 32768
|
|
7647 try
|
|
7648 let v:errmsg = ""
|
|
7649 3substitute/subst/\=SUBST("substitute", 7)/
|
|
7650 finally
|
|
7651 if v:errmsg != ""
|
|
7652 " If exceptions are not thrown on errors, fake the error
|
|
7653 " exception in order to get the same execution path.
|
|
7654 throw "faked Vim(substitute)"
|
|
7655 endif
|
|
7656 endtry
|
|
7657 catch /Vim(substitute)/ " Pattern not found ('e' flag missing)
|
|
7658 Xpath 65536 " X: 65536
|
|
7659 3substitute/subst/\=SUBST("substitute", 8)/e
|
|
7660 Xpath 131072 " X: 131072
|
|
7661 endtry
|
|
7662 Xpath 262144 " X: 262144
|
|
7663 4,6substitute/subst/\=SUBST("substitute", 9)/
|
|
7664 Xpath 524288 " X: 0
|
|
7665 catch /^substitute[678]/
|
|
7666 Xpath 1048576 " X: 0
|
|
7667 catch /^substitute9/
|
|
7668 Xpath 2097152 " X: 2097152
|
|
7669 finally
|
|
7670 bwipeout!
|
|
7671 call delete(file)
|
|
7672 endtry
|
|
7673
|
|
7674 try
|
|
7675 Xpath 4194304 " X: 4194304
|
|
7676 let var = substitute("sub", "sub", '\=THROW("substitute()y", 10)', '')
|
|
7677 Xpath 8388608 " X: 0
|
|
7678 catch /substitute()y/
|
|
7679 Xpath 16777216 " X: 16777216
|
|
7680 catch /.*/
|
|
7681 Xpath 33554432 " X: 0
|
|
7682 Xout "substitute()y:" v:exception "in" v:throwpoint
|
|
7683 endtry
|
|
7684
|
|
7685 try
|
|
7686 Xpath 67108864 " X: 67108864
|
|
7687 let var = substitute("not", "sub", '\=THROW("substitute()n", 11)', '')
|
|
7688 Xpath 134217728 " X: 134217728
|
|
7689 catch /substitute()n/
|
|
7690 Xpath 268435456 " X: 0
|
|
7691 catch /.*/
|
|
7692 Xpath 536870912 " X: 0
|
|
7693 Xout "substitute()n:" v:exception "in" v:throwpoint
|
|
7694 endtry
|
|
7695
|
|
7696 let expected = "E1T1E2T2S3(3)S4(5s)S4(7t)T4U6(1)U6(2)U9(4)U9(5t)T9T10"
|
|
7697 if taken != expected
|
|
7698 Xpath 1073741824 " X: 0
|
|
7699 Xout "'taken' is" taken "instead of" expected
|
|
7700 endif
|
|
7701
|
|
7702 catch /.*/
|
|
7703 " The Xpath command does not accept 2^31 (negative); add explicitly:
|
|
7704 let Xpath = Xpath + 2147483648 " X: 0
|
|
7705 Xout v:exception "in" v:throwpoint
|
|
7706 endtry
|
|
7707
|
|
7708 unlet result var taken expected
|
|
7709 delfunction THROW
|
|
7710 delfunction EXPR
|
|
7711 delfunction SKIP
|
|
7712 delfunction SUBST
|
|
7713
|
|
7714 Xcheck 224907669
|
|
7715
|
|
7716
|
|
7717 "-------------------------------------------------------------------------------
|
|
7718 " Test 75: Errors in builtin functions. {{{1
|
|
7719 "
|
|
7720 " On an error in a builtin function called inside a :try/:endtry
|
|
7721 " region, the evaluation of the expression calling that function and
|
|
7722 " the command containing that expression are abandoned. The error can
|
|
7723 " be caught as an exception.
|
|
7724 "
|
|
7725 " A simple :call of the builtin function is a trivial case. If the
|
|
7726 " builtin function is called in the argument list of another function,
|
|
7727 " no further arguments are evaluated, and the other function is not
|
|
7728 " executed. If the builtin function is called from the argument of
|
|
7729 " a :return command, the :return command is not executed. If the
|
|
7730 " builtin function is called from the argument of a :throw command,
|
|
7731 " the :throw command is not executed. The evaluation of the
|
|
7732 " expression calling the builtin function is abandoned.
|
|
7733 "-------------------------------------------------------------------------------
|
|
7734
|
|
7735 XpathINIT
|
|
7736
|
|
7737 function! F1(arg1)
|
|
7738 Xpath 1 " X: 0
|
|
7739 endfunction
|
|
7740
|
|
7741 function! F2(arg1, arg2)
|
|
7742 Xpath 2 " X: 0
|
|
7743 endfunction
|
|
7744
|
|
7745 function! G()
|
|
7746 Xpath 4 " X: 0
|
|
7747 endfunction
|
|
7748
|
|
7749 function! H()
|
|
7750 Xpath 8 " X: 0
|
|
7751 endfunction
|
|
7752
|
|
7753 function! R()
|
|
7754 while 1
|
|
7755 try
|
|
7756 let caught = 0
|
|
7757 let v:errmsg = ""
|
|
7758 Xpath 16 " X: 16
|
|
7759 return append(1, "s")
|
|
7760 catch /E21/
|
|
7761 let caught = 1
|
|
7762 catch /.*/
|
|
7763 Xpath 32 " X: 0
|
|
7764 finally
|
|
7765 Xpath 64 " X: 64
|
|
7766 if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21'
|
|
7767 Xpath 128 " X: 128
|
|
7768 endif
|
|
7769 break " discard error for $VIMNOERRTHROW
|
|
7770 endtry
|
|
7771 endwhile
|
|
7772 Xpath 256 " X: 256
|
|
7773 endfunction
|
|
7774
|
|
7775 try
|
|
7776 set noma " let append() fail with "E21"
|
|
7777
|
|
7778 while 1
|
|
7779 try
|
|
7780 let caught = 0
|
|
7781 let v:errmsg = ""
|
|
7782 Xpath 512 " X: 512
|
|
7783 call append(1, "s")
|
|
7784 catch /E21/
|
|
7785 let caught = 1
|
|
7786 catch /.*/
|
|
7787 Xpath 1024 " X: 0
|
|
7788 finally
|
|
7789 Xpath 2048 " X: 2048
|
|
7790 if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21'
|
|
7791 Xpath 4096 " X: 4096
|
|
7792 endif
|
|
7793 break " discard error for $VIMNOERRTHROW
|
|
7794 endtry
|
|
7795 endwhile
|
|
7796
|
|
7797 while 1
|
|
7798 try
|
|
7799 let caught = 0
|
|
7800 let v:errmsg = ""
|
|
7801 Xpath 8192 " X: 8192
|
|
7802 call F1('x' . append(1, "s"))
|
|
7803 catch /E21/
|
|
7804 let caught = 1
|
|
7805 catch /.*/
|
|
7806 Xpath 16384 " X: 0
|
|
7807 finally
|
|
7808 Xpath 32768 " X: 32768
|
|
7809 if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21'
|
|
7810 Xpath 65536 " X: 65536
|
|
7811 endif
|
|
7812 break " discard error for $VIMNOERRTHROW
|
|
7813 endtry
|
|
7814 endwhile
|
|
7815
|
|
7816 while 1
|
|
7817 try
|
|
7818 let caught = 0
|
|
7819 let v:errmsg = ""
|
|
7820 Xpath 131072 " X: 131072
|
|
7821 call F2('x' . append(1, "s"), G())
|
|
7822 catch /E21/
|
|
7823 let caught = 1
|
|
7824 catch /.*/
|
|
7825 Xpath 262144 " X: 0
|
|
7826 finally
|
|
7827 Xpath 524288 " X: 524288
|
|
7828 if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21'
|
|
7829 Xpath 1048576 " X: 1048576
|
|
7830 endif
|
|
7831 break " discard error for $VIMNOERRTHROW
|
|
7832 endtry
|
|
7833 endwhile
|
|
7834
|
|
7835 call R()
|
|
7836
|
|
7837 while 1
|
|
7838 try
|
|
7839 let caught = 0
|
|
7840 let v:errmsg = ""
|
|
7841 Xpath 2097152 " X: 2097152
|
|
7842 throw "T" . append(1, "s")
|
|
7843 catch /E21/
|
|
7844 let caught = 1
|
|
7845 catch /^T.*/
|
|
7846 Xpath 4194304 " X: 0
|
|
7847 catch /.*/
|
|
7848 Xpath 8388608 " X: 0
|
|
7849 finally
|
|
7850 Xpath 16777216 " X: 16777216
|
|
7851 if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21'
|
|
7852 Xpath 33554432 " X: 33554432
|
|
7853 endif
|
|
7854 break " discard error for $VIMNOERRTHROW
|
|
7855 endtry
|
|
7856 endwhile
|
|
7857
|
|
7858 while 1
|
|
7859 try
|
|
7860 let caught = 0
|
|
7861 let v:errmsg = ""
|
|
7862 Xpath 67108864 " X: 67108864
|
|
7863 let x = "a"
|
|
7864 let x = x . "b" . append(1, "s") . H()
|
|
7865 catch /E21/
|
|
7866 let caught = 1
|
|
7867 catch /.*/
|
|
7868 Xpath 134217728 " X: 0
|
|
7869 finally
|
|
7870 Xpath 268435456 " X: 268435456
|
|
7871 if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21'
|
|
7872 Xpath 536870912 " X: 536870912
|
|
7873 endif
|
|
7874 if x == "a"
|
|
7875 Xpath 1073741824 " X: 1073741824
|
|
7876 endif
|
|
7877 break " discard error for $VIMNOERRTHROW
|
|
7878 endtry
|
|
7879 endwhile
|
|
7880 catch /.*/
|
|
7881 " The Xpath command does not accept 2^31 (negative); add explicitly:
|
|
7882 let Xpath = Xpath + 2147483648 " X: 0
|
|
7883 Xout v:exception "in" v:throwpoint
|
|
7884 finally
|
|
7885 set ma&
|
|
7886 endtry
|
|
7887
|
|
7888 unlet! caught x
|
|
7889 delfunction F1
|
|
7890 delfunction F2
|
|
7891 delfunction G
|
|
7892 delfunction H
|
|
7893 delfunction R
|
|
7894
|
|
7895 Xcheck 2000403408
|
|
7896
|
|
7897
|
|
7898 "-------------------------------------------------------------------------------
|
|
7899 " Test 76: Errors, interupts, :throw during expression evaluation {{{1
|
|
7900 "
|
|
7901 " When a function call made during expression evaluation is aborted
|
|
7902 " due to an error inside a :try/:endtry region or due to an interrupt
|
|
7903 " or a :throw, the expression evaluation is aborted as well. No
|
|
7904 " message is displayed for the cancelled expression evaluation. On an
|
|
7905 " error not inside :try/:endtry, the expression evaluation continues.
|
|
7906 "-------------------------------------------------------------------------------
|
|
7907
|
|
7908 XpathINIT
|
|
7909
|
|
7910 if ExtraVim()
|
|
7911
|
|
7912 let taken = ""
|
|
7913
|
|
7914 function! ERR(n)
|
|
7915 let g:taken = g:taken . "E" . a:n
|
|
7916 asdf
|
|
7917 endfunction
|
|
7918
|
|
7919 function! ERRabort(n) abort
|
|
7920 let g:taken = g:taken . "A" . a:n
|
|
7921 asdf
|
|
7922 endfunction " returns -1
|
|
7923
|
|
7924 function! INT(n)
|
|
7925 let g:taken = g:taken . "I" . a:n
|
|
7926 "INTERRUPT9
|
|
7927 let dummy = 0
|
|
7928 endfunction
|
|
7929
|
|
7930 function! THR(n)
|
|
7931 let g:taken = g:taken . "T" . a:n
|
|
7932 throw "should not be caught"
|
|
7933 endfunction
|
|
7934
|
|
7935 function! CONT(n)
|
|
7936 let g:taken = g:taken . "C" . a:n
|
|
7937 endfunction
|
|
7938
|
|
7939 function! MSG(n)
|
|
7940 let g:taken = g:taken . "M" . a:n
|
|
7941 if (a:n >= 10 && a:n <= 27) ? v:errmsg != "" : v:errmsg !~ "asdf"
|
|
7942 let g:taken = g:taken . "x"
|
|
7943 endif
|
|
7944 let v:errmsg = ""
|
|
7945 endfunction
|
|
7946
|
|
7947 let v:errmsg = ""
|
|
7948
|
|
7949 try
|
|
7950 let t = 1
|
|
7951 XloopINIT 1 2
|
|
7952 while t <= 9
|
|
7953 Xloop 1 " X: 511
|
|
7954 try
|
|
7955 if t == 1
|
|
7956 let v{ERR(t) + CONT(t)} = 0
|
|
7957 elseif t == 2
|
|
7958 let v{ERR(t) + CONT(t)}
|
|
7959 elseif t == 3
|
|
7960 let var = exists('v{ERR(t) + CONT(t)}')
|
|
7961 elseif t == 4
|
|
7962 unlet v{ERR(t) + CONT(t)}
|
|
7963 elseif t == 5
|
|
7964 function F{ERR(t) + CONT(t)}()
|
|
7965 endfunction
|
|
7966 elseif t == 6
|
|
7967 function F{ERR(t) + CONT(t)}
|
|
7968 elseif t == 7
|
|
7969 let var = exists('*F{ERR(t) + CONT(t)}')
|
|
7970 elseif t == 8
|
|
7971 delfunction F{ERR(t) + CONT(t)}
|
|
7972 elseif t == 9
|
|
7973 let var = ERR(t) + CONT(t)
|
|
7974 endif
|
|
7975 catch /asdf/
|
|
7976 " v:errmsg is not set when the error message is converted to an
|
|
7977 " exception. Set it to the original error message.
|
|
7978 let v:errmsg = substitute(v:exception, '^Vim:', '', "")
|
|
7979 catch /^Vim\((\a\+)\)\=:/
|
|
7980 " An error exception has been thrown after the original error.
|
|
7981 let v:errmsg = ""
|
|
7982 finally
|
|
7983 call MSG(t)
|
|
7984 let t = t + 1
|
|
7985 XloopNEXT
|
|
7986 continue " discard an aborting error
|
|
7987 endtry
|
|
7988 endwhile
|
|
7989 catch /.*/
|
|
7990 Xpath 512 " X: 0
|
|
7991 Xout v:exception "in" ExtraVimThrowpoint()
|
|
7992 endtry
|
|
7993
|
|
7994 try
|
|
7995 let t = 10
|
|
7996 XloopINIT 1024 2
|
|
7997 while t <= 18
|
|
7998 Xloop 1 " X: 1024 * 511
|
|
7999 try
|
|
8000 if t == 10
|
|
8001 let v{INT(t) + CONT(t)} = 0
|
|
8002 elseif t == 11
|
|
8003 let v{INT(t) + CONT(t)}
|
|
8004 elseif t == 12
|
|
8005 let var = exists('v{INT(t) + CONT(t)}')
|
|
8006 elseif t == 13
|
|
8007 unlet v{INT(t) + CONT(t)}
|
|
8008 elseif t == 14
|
|
8009 function F{INT(t) + CONT(t)}()
|
|
8010 endfunction
|
|
8011 elseif t == 15
|
|
8012 function F{INT(t) + CONT(t)}
|
|
8013 elseif t == 16
|
|
8014 let var = exists('*F{INT(t) + CONT(t)}')
|
|
8015 elseif t == 17
|
|
8016 delfunction F{INT(t) + CONT(t)}
|
|
8017 elseif t == 18
|
|
8018 let var = INT(t) + CONT(t)
|
|
8019 endif
|
|
8020 catch /^Vim\((\a\+)\)\=:\(Interrupt\)\@!/
|
|
8021 " An error exception has been triggered after the interrupt.
|
|
8022 let v:errmsg = substitute(v:exception,
|
|
8023 \ '^Vim\((\a\+)\)\=:', '', "")
|
|
8024 finally
|
|
8025 call MSG(t)
|
|
8026 let t = t + 1
|
|
8027 XloopNEXT
|
|
8028 continue " discard interrupt
|
|
8029 endtry
|
|
8030 endwhile
|
|
8031 catch /.*/
|
|
8032 Xpath 524288 " X: 0
|
|
8033 Xout v:exception "in" ExtraVimThrowpoint()
|
|
8034 endtry
|
|
8035
|
|
8036 try
|
|
8037 let t = 19
|
|
8038 XloopINIT 1048576 2
|
|
8039 while t <= 27
|
|
8040 Xloop 1 " X: 1048576 * 511
|
|
8041 try
|
|
8042 if t == 19
|
|
8043 let v{THR(t) + CONT(t)} = 0
|
|
8044 elseif t == 20
|
|
8045 let v{THR(t) + CONT(t)}
|
|
8046 elseif t == 21
|
|
8047 let var = exists('v{THR(t) + CONT(t)}')
|
|
8048 elseif t == 22
|
|
8049 unlet v{THR(t) + CONT(t)}
|
|
8050 elseif t == 23
|
|
8051 function F{THR(t) + CONT(t)}()
|
|
8052 endfunction
|
|
8053 elseif t == 24
|
|
8054 function F{THR(t) + CONT(t)}
|
|
8055 elseif t == 25
|
|
8056 let var = exists('*F{THR(t) + CONT(t)}')
|
|
8057 elseif t == 26
|
|
8058 delfunction F{THR(t) + CONT(t)}
|
|
8059 elseif t == 27
|
|
8060 let var = THR(t) + CONT(t)
|
|
8061 endif
|
|
8062 catch /^Vim\((\a\+)\)\=:/
|
|
8063 " An error exception has been triggered after the :throw.
|
|
8064 let v:errmsg = substitute(v:exception,
|
|
8065 \ '^Vim\((\a\+)\)\=:', '', "")
|
|
8066 finally
|
|
8067 call MSG(t)
|
|
8068 let t = t + 1
|
|
8069 XloopNEXT
|
|
8070 continue " discard exception
|
|
8071 endtry
|
|
8072 endwhile
|
|
8073 catch /.*/
|
|
8074 Xpath 536870912 " X: 0
|
|
8075 Xout v:exception "in" ExtraVimThrowpoint()
|
|
8076 endtry
|
|
8077
|
|
8078 let v{ERR(28) + CONT(28)} = 0
|
|
8079 call MSG(28)
|
|
8080 let v{ERR(29) + CONT(29)}
|
|
8081 call MSG(29)
|
|
8082 let var = exists('v{ERR(30) + CONT(30)}')
|
|
8083 call MSG(30)
|
|
8084 unlet v{ERR(31) + CONT(31)}
|
|
8085 call MSG(31)
|
|
8086 function F{ERR(32) + CONT(32)}()
|
|
8087 endfunction
|
|
8088 call MSG(32)
|
|
8089 function F{ERR(33) + CONT(33)}
|
|
8090 call MSG(33)
|
|
8091 let var = exists('*F{ERR(34) + CONT(34)}')
|
|
8092 call MSG(34)
|
|
8093 delfunction F{ERR(35) + CONT(35)}
|
|
8094 call MSG(35)
|
|
8095 let var = ERR(36) + CONT(36)
|
|
8096 call MSG(36)
|
|
8097
|
|
8098 let v{ERRabort(37) + CONT(37)} = 0
|
|
8099 call MSG(37)
|
|
8100 let v{ERRabort(38) + CONT(38)}
|
|
8101 call MSG(38)
|
|
8102 let var = exists('v{ERRabort(39) + CONT(39)}')
|
|
8103 call MSG(39)
|
|
8104 unlet v{ERRabort(40) + CONT(40)}
|
|
8105 call MSG(40)
|
|
8106 function F{ERRabort(41) + CONT(41)}()
|
|
8107 endfunction
|
|
8108 call MSG(41)
|
|
8109 function F{ERRabort(42) + CONT(42)}
|
|
8110 call MSG(42)
|
|
8111 let var = exists('*F{ERRabort(43) + CONT(43)}')
|
|
8112 call MSG(43)
|
|
8113 delfunction F{ERRabort(44) + CONT(44)}
|
|
8114 call MSG(44)
|
|
8115 let var = ERRabort(45) + CONT(45)
|
|
8116 call MSG(45)
|
|
8117
|
|
8118 Xpath 1073741824 " X: 1073741824
|
|
8119
|
|
8120 let expected = ""
|
|
8121 \ . "E1M1E2M2E3M3E4M4E5M5E6M6E7M7E8M8E9M9"
|
|
8122 \ . "I10M10I11M11I12M12I13M13I14M14I15M15I16M16I17M17I18M18"
|
|
8123 \ . "T19M19T20M20T21M21T22M22T23M23T24M24T25M25T26M26T27M27"
|
|
8124 \ . "E28C28M28E29C29M29E30C30M30E31C31M31E32C32M32E33C33M33"
|
|
8125 \ . "E34C34M34E35C35M35E36C36M36"
|
|
8126 \ . "A37C37M37A38C38M38A39C39M39A40C40M40A41C41M41A42C42M42"
|
|
8127 \ . "A43C43M43A44C44M44A45C45M45"
|
|
8128
|
|
8129 if taken != expected
|
|
8130 " The Xpath command does not accept 2^31 (negative); display explicitly:
|
|
8131 exec "!echo 2147483648 >>" . g:ExtraVimResult
|
|
8132 " X: 0
|
|
8133 Xout "'taken' is" taken "instead of" expected
|
|
8134 if substitute(taken,
|
|
8135 \ '\(.*\)E3C3M3x\(.*\)E30C30M30x\(.*\)A39C39M39x\(.*\)',
|
|
8136 \ '\1E3M3\2E30C30M30\3A39C39M39\4',
|
|
8137 \ "") == expected
|
|
8138 Xout "Is ++emsg_skip for var with expr_start non-NULL"
|
|
8139 \ "in f_exists ok?"
|
|
8140 endif
|
|
8141 endif
|
|
8142
|
|
8143 unlet! var taken expected
|
|
8144 call delete(WA_t5)
|
|
8145 call delete(WA_t14)
|
|
8146 call delete(WA_t23)
|
|
8147 unlet! WA_t5 WA_t14 WA_t23
|
|
8148 delfunction WA_t5
|
|
8149 delfunction WA_t14
|
|
8150 delfunction WA_t23
|
|
8151
|
|
8152 endif
|
|
8153
|
|
8154 Xcheck 1610087935
|
|
8155
|
|
8156
|
|
8157 "-------------------------------------------------------------------------------
|
|
8158 " Test 77: Errors, interupts, :throw in name{brace-expression} {{{1
|
|
8159 "
|
|
8160 " When a function call made during evaluation of an expression in
|
|
8161 " braces as part of a function name after ":function" is aborted due
|
|
8162 " to an error inside a :try/:endtry region or due to an interrupt or
|
|
8163 " a :throw, the expression evaluation is aborted as well, and the
|
|
8164 " function definition is ignored, skipping all commands to the
|
|
8165 " ":endfunction". On an error not inside :try/:endtry, the expression
|
|
8166 " evaluation continues and the function gets defined, and can be
|
|
8167 " called and deleted.
|
|
8168 "-------------------------------------------------------------------------------
|
|
8169
|
|
8170 XpathINIT
|
|
8171
|
|
8172 XloopINIT 1 4
|
|
8173
|
|
8174 function! ERR() abort
|
|
8175 Xloop 1 " X: 1 + 4 + 16 + 64
|
|
8176 asdf
|
|
8177 endfunction " returns -1
|
|
8178
|
|
8179 function! OK()
|
|
8180 Xloop 2 " X: 2 * (1 + 4 + 16)
|
|
8181 let v:errmsg = ""
|
|
8182 return 0
|
|
8183 endfunction
|
|
8184
|
|
8185 let v:errmsg = ""
|
|
8186
|
|
8187 Xpath 4096 " X: 4096
|
|
8188 function! F{1 + ERR() + OK()}(arg)
|
|
8189 " F0 should be defined.
|
|
8190 if exists("a:arg") && a:arg == "calling"
|
|
8191 Xpath 8192 " X: 8192
|
|
8192 else
|
|
8193 Xpath 16384 " X: 0
|
|
8194 endif
|
|
8195 endfunction
|
|
8196 if v:errmsg != ""
|
|
8197 Xpath 32768 " X: 0
|
|
8198 endif
|
|
8199 XloopNEXT
|
|
8200
|
|
8201 Xpath 65536 " X: 65536
|
|
8202 call F{1 + ERR() + OK()}("calling")
|
|
8203 if v:errmsg != ""
|
|
8204 Xpath 131072 " X: 0
|
|
8205 endif
|
|
8206 XloopNEXT
|
|
8207
|
|
8208 Xpath 262144 " X: 262144
|
|
8209 delfunction F{1 + ERR() + OK()}
|
|
8210 if v:errmsg != ""
|
|
8211 Xpath 524288 " X: 0
|
|
8212 endif
|
|
8213 XloopNEXT
|
|
8214
|
|
8215 try
|
|
8216 while 1
|
|
8217 let caught = 0
|
|
8218 try
|
|
8219 Xpath 1048576 " X: 1048576
|
|
8220 function! G{1 + ERR() + OK()}(arg)
|
|
8221 " G0 should not be defined, and the function body should be
|
|
8222 " skipped.
|
|
8223 if exists("a:arg") && a:arg == "calling"
|
|
8224 Xpath 2097152 " X: 0
|
|
8225 else
|
|
8226 Xpath 4194304 " X: 0
|
|
8227 endif
|
|
8228 " Use an unmatched ":finally" to check whether the body is
|
|
8229 " skipped when an error occurs in ERR(). This works whether or
|
|
8230 " not the exception is converted to an exception.
|
|
8231 finally
|
|
8232 Xpath 8388608 " X: 0
|
|
8233 Xout "Body of G{1 + ERR() + OK()}() not skipped"
|
|
8234 " Discard the aborting error or exception, and break the
|
|
8235 " while loop.
|
|
8236 break
|
|
8237 " End the try conditional and start a new one to avoid
|
|
8238 " ":catch after :finally" errors.
|
|
8239 endtry
|
|
8240 try
|
|
8241 Xpath 16777216 " X: 0
|
|
8242 endfunction
|
|
8243
|
|
8244 " When the function was not defined, this won't be reached - whether
|
|
8245 " the body was skipped or not. When the function was defined, it
|
|
8246 " can be called and deleted here.
|
|
8247 Xpath 33554432 " X: 0
|
|
8248 Xout "G0() has been defined"
|
|
8249 XloopNEXT
|
|
8250 try
|
|
8251 call G{1 + ERR() + OK()}("calling")
|
|
8252 catch /.*/
|
|
8253 Xpath 67108864 " X: 0
|
|
8254 endtry
|
|
8255 Xpath 134217728 " X: 0
|
|
8256 XloopNEXT
|
|
8257 try
|
|
8258 delfunction G{1 + ERR() + OK()}
|
|
8259 catch /.*/
|
|
8260 Xpath 268435456 " X: 0
|
|
8261 endtry
|
|
8262 catch /asdf/
|
|
8263 " Jumped to when the function is not defined and the body is
|
|
8264 " skipped.
|
|
8265 let caught = 1
|
|
8266 catch /.*/
|
|
8267 Xpath 536870912 " X: 0
|
|
8268 finally
|
|
8269 if !caught && !$VIMNOERRTHROW
|
|
8270 Xpath 1073741824 " X: 0
|
|
8271 endif
|
|
8272 break " discard error for $VIMNOERRTHROW
|
|
8273 endtry " jumped to when the body is not skipped
|
|
8274 endwhile
|
|
8275 catch /.*/
|
|
8276 " The Xpath command does not accept 2^31 (negative); add explicitly:
|
|
8277 let Xpath = Xpath + 2147483648 " X: 0
|
|
8278 Xout "Body of G{1 + ERR() + OK()}() not skipped, exception caught"
|
|
8279 Xout v:exception "in" v:throwpoint
|
|
8280 endtry
|
|
8281
|
|
8282 Xcheck 1388671
|
|
8283
|
|
8284
|
|
8285 "-------------------------------------------------------------------------------
|
|
8286 " Test 78: Messages on parsing errors in expression evaluation {{{1
|
|
8287 "
|
|
8288 " When an expression evaluation detects a parsing error, an error
|
|
8289 " message is given and converted to an exception, and the expression
|
|
8290 " evaluation is aborted.
|
|
8291 "-------------------------------------------------------------------------------
|
|
8292
|
|
8293 XpathINIT
|
|
8294
|
|
8295 if ExtraVim()
|
|
8296
|
|
8297 let taken = ""
|
|
8298
|
|
8299 function! F(n)
|
|
8300 let g:taken = g:taken . "F" . a:n
|
|
8301 endfunction
|
|
8302
|
|
8303 function! MSG(n, enr, emsg)
|
|
8304 let g:taken = g:taken . "M" . a:n
|
|
8305 let english = v:lang == "C" || v:lang =~ '^[Ee]n'
|
|
8306 if a:enr == ""
|
|
8307 Xout "TODO: Add message number for:" a:emsg
|
|
8308 let v:errmsg = ":" . v:errmsg
|
|
8309 endif
|
|
8310 if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg)
|
|
8311 if v:errmsg == ""
|
|
8312 Xout "Expr" a:n.": Message missing."
|
|
8313 let g:taken = g:taken . "x"
|
|
8314 else
|
|
8315 let v:errmsg = escape(v:errmsg, '"')
|
|
8316 Xout "Expr" a:n.": Unexpected message:" v:errmsg
|
|
8317 let g:taken = g:taken . "X"
|
|
8318 endif
|
|
8319 endif
|
|
8320 endfunction
|
|
8321
|
|
8322 function! CONT(n)
|
|
8323 let g:taken = g:taken . "C" . a:n
|
|
8324 endfunction
|
|
8325
|
|
8326 let v:errmsg = ""
|
|
8327 XloopINIT 1 2
|
|
8328
|
|
8329 try
|
|
8330 let t = 1
|
|
8331 while t <= 14
|
|
8332 let g:taken = g:taken . "T" . t
|
|
8333 let v:errmsg = ""
|
|
8334 try
|
|
8335 let caught = 0
|
|
8336 if t == 1
|
|
8337 let v{novar + CONT(t)} = 0
|
|
8338 elseif t == 2
|
|
8339 let v{novar + CONT(t)}
|
|
8340 elseif t == 3
|
|
8341 let var = exists('v{novar + CONT(t)}')
|
|
8342 elseif t == 4
|
|
8343 unlet v{novar + CONT(t)}
|
|
8344 elseif t == 5
|
|
8345 function F{novar + CONT(t)}()
|
|
8346 endfunction
|
|
8347 elseif t == 6
|
|
8348 function F{novar + CONT(t)}
|
|
8349 elseif t == 7
|
|
8350 let var = exists('*F{novar + CONT(t)}')
|
|
8351 elseif t == 8
|
|
8352 delfunction F{novar + CONT(t)}
|
|
8353 elseif t == 9
|
|
8354 echo novar + CONT(t)
|
|
8355 elseif t == 10
|
|
8356 echo v{novar + CONT(t)}
|
|
8357 elseif t == 11
|
|
8358 echo F{novar + CONT(t)}
|
|
8359 elseif t == 12
|
|
8360 let var = novar + CONT(t)
|
|
8361 elseif t == 13
|
|
8362 let var = v{novar + CONT(t)}
|
|
8363 elseif t == 14
|
|
8364 let var = F{novar + CONT(t)}()
|
|
8365 endif
|
|
8366 catch /^Vim\((\a\+)\)\=:/
|
|
8367 " v:errmsg is not set when the error message is converted to an
|
|
8368 " exception. Set it to the original error message.
|
|
8369 let v:errmsg = substitute(v:exception,
|
|
8370 \ '^Vim\((\a\+)\)\=:', '', "")
|
|
8371 let caught = 1
|
|
8372 finally
|
|
8373 if !caught " no error exceptions ($VIMNOERRTHROW set)
|
|
8374 if t <= 8 && t != 3
|
|
8375 call MSG(t, 'E475', 'Invalid argument\>')
|
|
8376 else
|
|
8377 call MSG(t, 'E15', "Invalid expression")
|
|
8378 endif
|
|
8379 else
|
|
8380 if t == 2 || t == 4
|
|
8381 call MSG(t, 'E475', 'Invalid argument\>')
|
|
8382 else
|
|
8383 call MSG(t, 'E121', "Undefined variable")
|
|
8384 endif
|
|
8385 endif
|
|
8386 let t = t + 1
|
|
8387 XloopNEXT
|
|
8388 continue " discard an aborting error
|
|
8389 endtry
|
|
8390 endwhile
|
|
8391 catch /.*/
|
|
8392 Xloop 1 " X: 0
|
|
8393 Xout t.":" v:exception "in" ExtraVimThrowpoint()
|
|
8394 endtry
|
|
8395
|
|
8396 function! T(n, expr, enr, emsg)
|
|
8397 try
|
|
8398 let g:taken = g:taken . "T" . a:n
|
|
8399 let v:errmsg = ""
|
|
8400 try
|
|
8401 let caught = 0
|
|
8402 execute "let var = " . a:expr
|
|
8403 catch /^Vim\((\a\+)\)\=:/
|
|
8404 " v:errmsg is not set when the error message is converted to an
|
|
8405 " exception. Set it to the original error message.
|
|
8406 let v:errmsg = substitute(v:exception,
|
|
8407 \ '^Vim\((\a\+)\)\=:', '', "")
|
|
8408 let caught = 1
|
|
8409 finally
|
|
8410 if !caught " no error exceptions ($VIMNOERRTHROW set)
|
|
8411 call MSG(a:n, 'E15', "Invalid expression")
|
|
8412 else
|
|
8413 call MSG(a:n, a:enr, a:emsg)
|
|
8414 endif
|
|
8415 XloopNEXT
|
|
8416 " Discard an aborting error:
|
|
8417 return
|
|
8418 endtry
|
|
8419 catch /.*/
|
|
8420 Xloop 1 " X: 0
|
|
8421 Xout a:n.":" v:exception "in" ExtraVimThrowpoint()
|
|
8422 endtry
|
|
8423 endfunction
|
|
8424
|
|
8425 call T(15, 'Nofunc() + CONT(15)', 'E117', "Unknown function")
|
|
8426 call T(16, 'F(1 2 + CONT(16))', 'E116', "Invalid arguments")
|
|
8427 call T(17, 'F(1, 2) + CONT(17)', 'E118', "Too many arguments")
|
|
8428 call T(18, 'F() + CONT(18)', 'E119', "Not enough arguments")
|
|
8429 call T(19, '{(1} + CONT(19)', 'E110', "Missing ')'")
|
|
8430 call T(20, '("abc"[1) + CONT(20)', 'E111', "Missing ']'")
|
|
8431 call T(21, '(1 +) + CONT(21)', 'E15', "Invalid expression")
|
|
8432 call T(22, '1 2 + CONT(22)', 'E15', "Invalid expression")
|
|
8433 call T(23, '(1 ? 2) + CONT(23)', 'E109', "Missing ':' after '?'")
|
|
8434 call T(24, '("abc) + CONT(24)', 'E114', "Missing quote")
|
|
8435 call T(25, "('abc) + CONT(25)", 'E115', "Missing quote")
|
95
|
8436 call T(26, '& + CONT(26)', 'E712', "Using & outside of map()")
|
7
|
8437 call T(27, '&asdf + CONT(27)', 'E113', "Unknown option")
|
|
8438
|
|
8439 Xpath 134217728 " X: 134217728
|
|
8440
|
|
8441 let expected = ""
|
|
8442 \ . "T1M1T2M2T3M3T4M4T5M5T6M6T7M7T8M8T9M9T10M10T11M11T12M12T13M13T14M14"
|
|
8443 \ . "T15M15T16M16T17M17T18M18T19M19T20M20T21M21T22M22T23M23T24M24T25M25"
|
|
8444 \ . "T26M26T27M27"
|
|
8445
|
|
8446 if taken != expected
|
|
8447 Xpath 268435456 " X: 0
|
|
8448 Xout "'taken' is" taken "instead of" expected
|
|
8449 if substitute(taken, '\(.*\)T3M3x\(.*\)', '\1T3M3\2', "") == expected
|
|
8450 Xout "Is ++emsg_skip for var with expr_start non-NULL"
|
|
8451 \ "in f_exists ok?"
|
|
8452 endif
|
|
8453 endif
|
|
8454
|
|
8455 unlet! var caught taken expected
|
|
8456 call delete(WA_t5)
|
|
8457 unlet! WA_t5
|
|
8458 delfunction WA_t5
|
|
8459
|
|
8460 endif
|
|
8461
|
|
8462 Xcheck 134217728
|
|
8463
|
|
8464
|
|
8465 "-------------------------------------------------------------------------------
|
|
8466 " Test 79: Throwing one of several errors for the same command {{{1
|
|
8467 "
|
|
8468 " When several errors appear in a row (for instance during expression
|
|
8469 " evaluation), the first as the most specific one is used when
|
|
8470 " throwing an error exception. If, however, a syntax error is
|
|
8471 " detected afterwards, this one is used for the error exception.
|
|
8472 " On a syntax error, the next command is not executed, on a normal
|
|
8473 " error, however, it is (relevant only in a function without the
|
|
8474 " "abort" flag). v:errmsg is not set.
|
|
8475 "
|
|
8476 " If throwing error exceptions is configured off, v:errmsg is always
|
|
8477 " set to the latest error message, that is, to the more general
|
|
8478 " message or the syntax error, respectively.
|
|
8479 "-------------------------------------------------------------------------------
|
|
8480
|
|
8481 XpathINIT
|
|
8482
|
|
8483 XloopINIT 1 2
|
|
8484
|
|
8485 function! NEXT(cmd)
|
|
8486 exec a:cmd . " | Xloop 1"
|
|
8487 endfunction
|
|
8488
|
|
8489 call NEXT('echo novar') " X: 1 * 1 (checks nextcmd)
|
|
8490 XloopNEXT
|
|
8491 call NEXT('let novar #') " X: 0 * 2 (skips nextcmd)
|
|
8492 XloopNEXT
|
|
8493 call NEXT('unlet novar #') " X: 0 * 4 (skips nextcmd)
|
|
8494 XloopNEXT
|
|
8495 call NEXT('let {novar}') " X: 0 * 8 (skips nextcmd)
|
|
8496 XloopNEXT
|
|
8497 call NEXT('unlet{ novar}') " X: 0 * 16 (skips nextcmd)
|
|
8498
|
|
8499 function! EXEC(cmd)
|
|
8500 exec a:cmd
|
|
8501 endfunction
|
|
8502
|
|
8503 function! MATCH(expected, msg, enr, emsg)
|
|
8504 let msg = a:msg
|
|
8505 if a:enr == ""
|
|
8506 Xout "TODO: Add message number for:" a:emsg
|
|
8507 let msg = ":" . msg
|
|
8508 endif
|
|
8509 let english = v:lang == "C" || v:lang =~ '^[Ee]n'
|
|
8510 if msg !~ '^'.a:enr.':' || (english && msg !~ a:emsg)
|
|
8511 let match = 0
|
|
8512 if a:expected " no match although expected
|
|
8513 if a:msg == ""
|
|
8514 Xout "Message missing."
|
|
8515 else
|
|
8516 let msg = escape(msg, '"')
|
|
8517 Xout "Unexpected message:" msg
|
|
8518 endif
|
|
8519 endif
|
|
8520 else
|
|
8521 let match = 1
|
|
8522 if !a:expected " match although not expected
|
|
8523 let msg = escape(msg, '"')
|
|
8524 Xout "Unexpected message:" msg
|
|
8525 endif
|
|
8526 endif
|
|
8527 return match
|
|
8528 endfunction
|
|
8529
|
|
8530 try
|
|
8531
|
|
8532 while 1 " dummy loop
|
|
8533 try
|
|
8534 let v:errmsg = ""
|
|
8535 let caught = 0
|
|
8536 let thrmsg = ""
|
|
8537 call EXEC('echo novar') " normal error
|
|
8538 catch /^Vim\((\a\+)\)\=:/
|
|
8539 let caught = 1
|
|
8540 let thrmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "")
|
|
8541 finally
|
|
8542 Xpath 32 " X: 32
|
|
8543 if !caught
|
|
8544 if !$VIMNOERRTHROW
|
|
8545 Xpath 64 " X: 0
|
|
8546 endif
|
|
8547 elseif !MATCH(1, thrmsg, 'E121', "Undefined variable")
|
|
8548 \ || v:errmsg != ""
|
|
8549 Xpath 128 " X: 0
|
|
8550 endif
|
|
8551 if !caught && !MATCH(1, v:errmsg, 'E15', "Invalid expression")
|
|
8552 Xpath 256 " X: 0
|
|
8553 endif
|
|
8554 break " discard error if $VIMNOERRTHROW == 1
|
|
8555 endtry
|
|
8556 endwhile
|
|
8557
|
|
8558 Xpath 512 " X: 512
|
|
8559 let cmd = "let"
|
|
8560 XloopINIT 1024 32
|
|
8561 while cmd != ""
|
|
8562 try
|
|
8563 let v:errmsg = ""
|
|
8564 let caught = 0
|
|
8565 let thrmsg = ""
|
|
8566 call EXEC(cmd . ' novar #') " normal plus syntax error
|
|
8567 catch /^Vim\((\a\+)\)\=:/
|
|
8568 let caught = 1
|
|
8569 let thrmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "")
|
|
8570 finally
|
|
8571 Xloop 1 " X: 1024 * (1 + 32)
|
|
8572 if !caught
|
|
8573 if !$VIMNOERRTHROW
|
|
8574 Xloop 2 " X: 0
|
|
8575 endif
|
|
8576 else
|
|
8577 if cmd == "let"
|
|
8578 let match = MATCH(0, thrmsg, 'E106', "Unknown variable")
|
|
8579 elseif cmd == "unlet"
|
|
8580 let match = MATCH(0, thrmsg, 'E108', "No such variable")
|
|
8581 endif
|
|
8582 if match " normal error
|
|
8583 Xloop 4 " X: 0
|
|
8584 endif
|
|
8585 if !MATCH(1, thrmsg, 'E488', "Trailing characters")
|
|
8586 \|| v:errmsg != ""
|
|
8587 " syntax error
|
|
8588 Xloop 8 " X: 0
|
|
8589 endif
|
|
8590 endif
|
|
8591 if !caught && !MATCH(1, v:errmsg, 'E488', "Trailing characters")
|
|
8592 " last error
|
|
8593 Xloop 16 " X: 0
|
|
8594 endif
|
|
8595 if cmd == "let"
|
|
8596 let cmd = "unlet"
|
|
8597 else
|
|
8598 let cmd = ""
|
|
8599 endif
|
|
8600 XloopNEXT
|
|
8601 continue " discard error if $VIMNOERRTHROW == 1
|
|
8602 endtry
|
|
8603 endwhile
|
|
8604
|
|
8605 Xpath 1048576 " X: 1048576
|
|
8606 let cmd = "let"
|
|
8607 XloopINIT 2097152 32
|
|
8608 while cmd != ""
|
|
8609 try
|
|
8610 let v:errmsg = ""
|
|
8611 let caught = 0
|
|
8612 let thrmsg = ""
|
|
8613 call EXEC(cmd . ' {novar}') " normal plus syntax error
|
|
8614 catch /^Vim\((\a\+)\)\=:/
|
|
8615 let caught = 1
|
|
8616 let thrmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "")
|
|
8617 finally
|
|
8618 Xloop 1 " X: 2097152 * (1 + 32)
|
|
8619 if !caught
|
|
8620 if !$VIMNOERRTHROW
|
|
8621 Xloop 2 " X: 0
|
|
8622 endif
|
|
8623 else
|
|
8624 if MATCH(0, thrmsg, 'E121', "Undefined variable") " normal error
|
|
8625 Xloop 4 " X: 0
|
|
8626 endif
|
|
8627 if !MATCH(1, thrmsg, 'E475', 'Invalid argument\>')
|
|
8628 \ || v:errmsg != "" " syntax error
|
|
8629 Xloop 8 " X: 0
|
|
8630 endif
|
|
8631 endif
|
|
8632 if !caught && !MATCH(1, v:errmsg, 'E475', 'Invalid argument\>')
|
|
8633 " last error
|
|
8634 Xloop 16 " X: 0
|
|
8635 endif
|
|
8636 if cmd == "let"
|
|
8637 let cmd = "unlet"
|
|
8638 else
|
|
8639 let cmd = ""
|
|
8640 endif
|
|
8641 XloopNEXT
|
|
8642 continue " discard error if $VIMNOERRTHROW == 1
|
|
8643 endtry
|
|
8644 endwhile
|
|
8645
|
|
8646 catch /.*/
|
|
8647 " The Xpath command does not accept 2^31 (negative); add explicitly:
|
|
8648 let Xpath = Xpath + 2147483648 " X: 0
|
|
8649 Xout v:exception "in" v:throwpoint
|
|
8650 endtry
|
|
8651
|
|
8652 unlet! next_command thrmsg match
|
|
8653 delfunction NEXT
|
|
8654 delfunction EXEC
|
|
8655 delfunction MATCH
|
|
8656
|
|
8657 Xcheck 70288929
|
|
8658
|
|
8659
|
|
8660 "-------------------------------------------------------------------------------
|
|
8661 " Test 80: Syntax error in expression for illegal :elseif {{{1
|
|
8662 "
|
|
8663 " If there is a syntax error in the expression after an illegal
|
|
8664 " :elseif, an error message is given (or an error exception thrown)
|
|
8665 " for the illegal :elseif rather than the expression error.
|
|
8666 "-------------------------------------------------------------------------------
|
|
8667
|
|
8668 XpathINIT
|
|
8669
|
|
8670 function! MSG(enr, emsg)
|
|
8671 let english = v:lang == "C" || v:lang =~ '^[Ee]n'
|
|
8672 if a:enr == ""
|
|
8673 Xout "TODO: Add message number for:" a:emsg
|
|
8674 let v:errmsg = ":" . v:errmsg
|
|
8675 endif
|
|
8676 let match = 1
|
|
8677 if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg)
|
|
8678 let match = 0
|
|
8679 if v:errmsg == ""
|
|
8680 Xout "Message missing."
|
|
8681 else
|
|
8682 let v:errmsg = escape(v:errmsg, '"')
|
|
8683 Xout "Unexpected message:" v:errmsg
|
|
8684 endif
|
|
8685 endif
|
|
8686 return match
|
|
8687 endfunction
|
|
8688
|
|
8689 let v:errmsg = ""
|
|
8690 if 0
|
|
8691 else
|
|
8692 elseif 1 ||| 2
|
|
8693 endif
|
|
8694 Xpath 1 " X: 1
|
|
8695 if !MSG('E584', ":elseif after :else")
|
|
8696 Xpath 2 " X: 0
|
|
8697 endif
|
|
8698
|
|
8699 let v:errmsg = ""
|
|
8700 if 1
|
|
8701 else
|
|
8702 elseif 1 ||| 2
|
|
8703 endif
|
|
8704 Xpath 4 " X: 4
|
|
8705 if !MSG('E584', ":elseif after :else")
|
|
8706 Xpath 8 " X: 0
|
|
8707 endif
|
|
8708
|
|
8709 let v:errmsg = ""
|
|
8710 elseif 1 ||| 2
|
|
8711 Xpath 16 " X: 16
|
|
8712 if !MSG('E582', ":elseif without :if")
|
|
8713 Xpath 32 " X: 0
|
|
8714 endif
|
|
8715
|
|
8716 let v:errmsg = ""
|
|
8717 while 1
|
|
8718 elseif 1 ||| 2
|
|
8719 endwhile
|
|
8720 Xpath 64 " X: 64
|
|
8721 if !MSG('E582', ":elseif without :if")
|
|
8722 Xpath 128 " X: 0
|
|
8723 endif
|
|
8724
|
|
8725 while 1
|
|
8726 try
|
|
8727 try
|
|
8728 let v:errmsg = ""
|
|
8729 let caught = 0
|
|
8730 if 0
|
|
8731 else
|
|
8732 elseif 1 ||| 2
|
|
8733 endif
|
|
8734 catch /^Vim\((\a\+)\)\=:/
|
|
8735 let caught = 1
|
|
8736 let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "")
|
|
8737 finally
|
|
8738 Xpath 256 " X: 256
|
|
8739 if !caught && !$VIMNOERRTHROW
|
|
8740 Xpath 512 " X: 0
|
|
8741 endif
|
|
8742 if !MSG('E584', ":elseif after :else")
|
|
8743 Xpath 1024 " X: 0
|
|
8744 endif
|
|
8745 endtry
|
|
8746 catch /.*/
|
|
8747 Xpath 2048 " X: 0
|
|
8748 Xout v:exception "in" v:throwpoint
|
|
8749 finally
|
|
8750 break " discard error for $VIMNOERRTHROW
|
|
8751 endtry
|
|
8752 endwhile
|
|
8753
|
|
8754 while 1
|
|
8755 try
|
|
8756 try
|
|
8757 let v:errmsg = ""
|
|
8758 let caught = 0
|
|
8759 if 1
|
|
8760 else
|
|
8761 elseif 1 ||| 2
|
|
8762 endif
|
|
8763 catch /^Vim\((\a\+)\)\=:/
|
|
8764 let caught = 1
|
|
8765 let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "")
|
|
8766 finally
|
|
8767 Xpath 4096 " X: 4096
|
|
8768 if !caught && !$VIMNOERRTHROW
|
|
8769 Xpath 8192 " X: 0
|
|
8770 endif
|
|
8771 if !MSG('E584', ":elseif after :else")
|
|
8772 Xpath 16384 " X: 0
|
|
8773 endif
|
|
8774 endtry
|
|
8775 catch /.*/
|
|
8776 Xpath 32768 " X: 0
|
|
8777 Xout v:exception "in" v:throwpoint
|
|
8778 finally
|
|
8779 break " discard error for $VIMNOERRTHROW
|
|
8780 endtry
|
|
8781 endwhile
|
|
8782
|
|
8783 while 1
|
|
8784 try
|
|
8785 try
|
|
8786 let v:errmsg = ""
|
|
8787 let caught = 0
|
|
8788 elseif 1 ||| 2
|
|
8789 catch /^Vim\((\a\+)\)\=:/
|
|
8790 let caught = 1
|
|
8791 let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "")
|
|
8792 finally
|
|
8793 Xpath 65536 " X: 65536
|
|
8794 if !caught && !$VIMNOERRTHROW
|
|
8795 Xpath 131072 " X: 0
|
|
8796 endif
|
|
8797 if !MSG('E582', ":elseif without :if")
|
|
8798 Xpath 262144 " X: 0
|
|
8799 endif
|
|
8800 endtry
|
|
8801 catch /.*/
|
|
8802 Xpath 524288 " X: 0
|
|
8803 Xout v:exception "in" v:throwpoint
|
|
8804 finally
|
|
8805 break " discard error for $VIMNOERRTHROW
|
|
8806 endtry
|
|
8807 endwhile
|
|
8808
|
|
8809 while 1
|
|
8810 try
|
|
8811 try
|
|
8812 let v:errmsg = ""
|
|
8813 let caught = 0
|
|
8814 while 1
|
|
8815 elseif 1 ||| 2
|
|
8816 endwhile
|
|
8817 catch /^Vim\((\a\+)\)\=:/
|
|
8818 let caught = 1
|
|
8819 let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "")
|
|
8820 finally
|
|
8821 Xpath 1048576 " X: 1048576
|
|
8822 if !caught && !$VIMNOERRTHROW
|
|
8823 Xpath 2097152 " X: 0
|
|
8824 endif
|
|
8825 if !MSG('E582', ":elseif without :if")
|
|
8826 Xpath 4194304 " X: 0
|
|
8827 endif
|
|
8828 endtry
|
|
8829 catch /.*/
|
|
8830 Xpath 8388608 " X: 0
|
|
8831 Xout v:exception "in" v:throwpoint
|
|
8832 finally
|
|
8833 break " discard error for $VIMNOERRTHROW
|
|
8834 endtry
|
|
8835 endwhile
|
|
8836
|
|
8837 Xpath 16777216 " X: 16777216
|
|
8838
|
|
8839 unlet! caught
|
|
8840 delfunction MSG
|
|
8841
|
|
8842 Xcheck 17895765
|
|
8843
|
|
8844
|
|
8845 "-------------------------------------------------------------------------------
|
|
8846 " Test 81: Discarding exceptions after an error or interrupt {{{1
|
|
8847 "
|
|
8848 " When an exception is thrown from inside a :try conditional without
|
|
8849 " :catch and :finally clauses and an error or interrupt occurs before
|
|
8850 " the :endtry is reached, the exception is discarded.
|
|
8851 "-------------------------------------------------------------------------------
|
|
8852
|
|
8853 XpathINIT
|
|
8854
|
|
8855 if ExtraVim()
|
|
8856 try
|
|
8857 Xpath 1 " X: 1
|
|
8858 try
|
|
8859 Xpath 2 " X: 2
|
|
8860 throw "arrgh"
|
|
8861 Xpath 4 " X: 0
|
|
8862 " if 1
|
|
8863 Xpath 8 " X: 0
|
|
8864 " error after :throw: missing :endif
|
|
8865 endtry
|
|
8866 Xpath 16 " X: 0
|
|
8867 catch /arrgh/
|
|
8868 Xpath 32 " X: 0
|
|
8869 endtry
|
|
8870 Xpath 64 " X: 0
|
|
8871 endif
|
|
8872
|
|
8873 if ExtraVim()
|
|
8874 try
|
|
8875 Xpath 128 " X: 128
|
|
8876 try
|
|
8877 Xpath 256 " X: 256
|
|
8878 throw "arrgh"
|
|
8879 Xpath 512 " X: 0
|
|
8880 endtry " INTERRUPT
|
|
8881 Xpath 1024 " X: 0
|
|
8882 catch /arrgh/
|
|
8883 Xpath 2048 " X: 0
|
|
8884 endtry
|
|
8885 Xpath 4096 " X: 0
|
|
8886 endif
|
|
8887
|
|
8888 Xcheck 387
|
|
8889
|
|
8890
|
|
8891 "-------------------------------------------------------------------------------
|
|
8892 " Test 82: Ignoring :catch clauses after an error or interrupt {{{1
|
|
8893 "
|
|
8894 " When an exception is thrown and an error or interrupt occurs before
|
|
8895 " the matching :catch clause is reached, the exception is discarded
|
|
8896 " and the :catch clause is ignored (also for the error or interrupt
|
|
8897 " exception being thrown then).
|
|
8898 "-------------------------------------------------------------------------------
|
|
8899
|
|
8900 XpathINIT
|
|
8901
|
|
8902 if ExtraVim()
|
|
8903 try
|
|
8904 try
|
|
8905 Xpath 1 " X: 1
|
|
8906 throw "arrgh"
|
|
8907 Xpath 2 " X: 0
|
|
8908 " if 1
|
|
8909 Xpath 4 " X: 0
|
|
8910 " error after :throw: missing :endif
|
|
8911 catch /.*/
|
|
8912 Xpath 8 " X: 0
|
|
8913 Xout v:exception "in" ExtraVimThrowpoint()
|
|
8914 catch /.*/
|
|
8915 Xpath 16 " X: 0
|
|
8916 Xout v:exception "in" ExtraVimThrowpoint()
|
|
8917 endtry
|
|
8918 Xpath 32 " X: 0
|
|
8919 catch /arrgh/
|
|
8920 Xpath 64 " X: 0
|
|
8921 endtry
|
|
8922 Xpath 128 " X: 0
|
|
8923 endif
|
|
8924
|
|
8925 if ExtraVim()
|
|
8926 function! E()
|
|
8927 try
|
|
8928 try
|
|
8929 Xpath 256 " X: 256
|
|
8930 throw "arrgh"
|
|
8931 Xpath 512 " X: 0
|
|
8932 " if 1
|
|
8933 Xpath 1024 " X: 0
|
|
8934 " error after :throw: missing :endif
|
|
8935 catch /.*/
|
|
8936 Xpath 2048 " X: 0
|
|
8937 Xout v:exception "in" ExtraVimThrowpoint()
|
|
8938 catch /.*/
|
|
8939 Xpath 4096 " X: 0
|
|
8940 Xout v:exception "in" ExtraVimThrowpoint()
|
|
8941 endtry
|
|
8942 Xpath 8192 " X: 0
|
|
8943 catch /arrgh/
|
|
8944 Xpath 16384 " X: 0
|
|
8945 endtry
|
|
8946 endfunction
|
|
8947
|
|
8948 call E()
|
|
8949 Xpath 32768 " X: 0
|
|
8950 endif
|
|
8951
|
|
8952 if ExtraVim()
|
|
8953 try
|
|
8954 try
|
|
8955 Xpath 65536 " X: 65536
|
|
8956 throw "arrgh"
|
|
8957 Xpath 131072 " X: 0
|
|
8958 catch /.*/ "INTERRUPT
|
|
8959 Xpath 262144 " X: 0
|
|
8960 Xout v:exception "in" ExtraVimThrowpoint()
|
|
8961 catch /.*/
|
|
8962 Xpath 524288 " X: 0
|
|
8963 Xout v:exception "in" ExtraVimThrowpoint()
|
|
8964 endtry
|
|
8965 Xpath 1048576 " X: 0
|
|
8966 catch /arrgh/
|
|
8967 Xpath 2097152 " X: 0
|
|
8968 endtry
|
|
8969 Xpath 4194304 " X: 0
|
|
8970 endif
|
|
8971
|
|
8972 if ExtraVim()
|
|
8973 function I()
|
|
8974 try
|
|
8975 try
|
|
8976 Xpath 8388608 " X: 8388608
|
|
8977 throw "arrgh"
|
|
8978 Xpath 16777216 " X: 0
|
|
8979 catch /.*/ "INTERRUPT
|
|
8980 Xpath 33554432 " X: 0
|
|
8981 Xout v:exception "in" ExtraVimThrowpoint()
|
|
8982 catch /.*/
|
|
8983 Xpath 67108864 " X: 0
|
|
8984 Xout v:exception "in" ExtraVimThrowpoint()
|
|
8985 endtry
|
|
8986 Xpath 134217728 " X: 0
|
|
8987 catch /arrgh/
|
|
8988 Xpath 268435456 " X: 0
|
|
8989 endtry
|
|
8990 endfunction
|
|
8991
|
|
8992 call I()
|
|
8993 Xpath 536870912 " X: 0
|
|
8994 endif
|
|
8995
|
|
8996 Xcheck 8454401
|
|
8997
|
|
8998
|
|
8999 "-------------------------------------------------------------------------------
|
|
9000 " Test 83: Executing :finally clauses after an error or interrupt {{{1
|
|
9001 "
|
|
9002 " When an exception is thrown and an error or interrupt occurs before
|
|
9003 " the :finally of the innermost :try is reached, the exception is
|
|
9004 " discarded and the :finally clause is executed.
|
|
9005 "-------------------------------------------------------------------------------
|
|
9006
|
|
9007 XpathINIT
|
|
9008
|
|
9009 if ExtraVim()
|
|
9010 try
|
|
9011 Xpath 1 " X: 1
|
|
9012 try
|
|
9013 Xpath 2 " X: 2
|
|
9014 throw "arrgh"
|
|
9015 Xpath 4 " X: 0
|
|
9016 " if 1
|
|
9017 Xpath 8 " X: 0
|
|
9018 " error after :throw: missing :endif
|
|
9019 finally
|
|
9020 Xpath 16 " X: 16
|
|
9021 endtry
|
|
9022 Xpath 32 " X: 0
|
|
9023 catch /arrgh/
|
|
9024 Xpath 64 " X: 0
|
|
9025 endtry
|
|
9026 Xpath 128 " X: 0
|
|
9027 endif
|
|
9028
|
|
9029 if ExtraVim()
|
|
9030 try
|
|
9031 Xpath 256 " X: 256
|
|
9032 try
|
|
9033 Xpath 512 " X: 512
|
|
9034 throw "arrgh"
|
|
9035 Xpath 1024 " X: 0
|
|
9036 finally "INTERRUPT
|
|
9037 Xpath 2048 " X: 2048
|
|
9038 endtry
|
|
9039 Xpath 4096 " X: 0
|
|
9040 catch /arrgh/
|
|
9041 Xpath 8192 " X: 0
|
|
9042 endtry
|
|
9043 Xpath 16384 " X: 0
|
|
9044 endif
|
|
9045
|
|
9046 Xcheck 2835
|
|
9047
|
|
9048
|
|
9049 "-------------------------------------------------------------------------------
|
|
9050 " Test 84: Exceptions in autocommand sequences. {{{1
|
|
9051 "
|
|
9052 " When an exception occurs in a sequence of autocommands for
|
|
9053 " a specific event, the rest of the sequence is not executed. The
|
|
9054 " command that triggered the autocommand execution aborts, and the
|
|
9055 " exception is propagated to the caller.
|
|
9056 "
|
|
9057 " For the FuncUndefined event under a function call expression or
|
|
9058 " :call command, the function is not exexecuted, even when it has
|
|
9059 " been defined by the autocommands before the exception occurred.
|
|
9060 "-------------------------------------------------------------------------------
|
|
9061
|
|
9062 XpathINIT
|
|
9063
|
|
9064 if ExtraVim()
|
|
9065
|
|
9066 function! INT()
|
|
9067 "INTERRUPT
|
|
9068 let dummy = 0
|
|
9069 endfunction
|
|
9070
|
|
9071 aug TMP
|
|
9072 autocmd!
|
|
9073
|
|
9074 autocmd User x1 Xpath 1 " X: 1
|
|
9075 autocmd User x1 throw "x1"
|
|
9076 autocmd User x1 Xpath 2 " X: 0
|
|
9077
|
|
9078 autocmd User x2 Xpath 4 " X: 4
|
|
9079 autocmd User x2 asdf
|
|
9080 autocmd User x2 Xpath 8 " X: 0
|
|
9081
|
|
9082 autocmd User x3 Xpath 16 " X: 16
|
|
9083 autocmd User x3 call INT()
|
|
9084 autocmd User x3 Xpath 32 " X: 0
|
|
9085
|
|
9086 autocmd FuncUndefined U1 function! U1()
|
|
9087 autocmd FuncUndefined U1 Xpath 64 " X: 0
|
|
9088 autocmd FuncUndefined U1 endfunction
|
|
9089 autocmd FuncUndefined U1 Xpath 128 " X: 128
|
|
9090 autocmd FuncUndefined U1 throw "U1"
|
|
9091 autocmd FuncUndefined U1 Xpath 256 " X: 0
|
|
9092
|
|
9093 autocmd FuncUndefined U2 function! U2()
|
|
9094 autocmd FuncUndefined U2 Xpath 512 " X: 0
|
|
9095 autocmd FuncUndefined U2 endfunction
|
|
9096 autocmd FuncUndefined U2 Xpath 1024 " X: 1024
|
|
9097 autocmd FuncUndefined U2 ASDF
|
|
9098 autocmd FuncUndefined U2 Xpath 2048 " X: 0
|
|
9099
|
|
9100 autocmd FuncUndefined U3 function! U3()
|
|
9101 autocmd FuncUndefined U3 Xpath 4096 " X: 0
|
|
9102 autocmd FuncUndefined U3 endfunction
|
|
9103 autocmd FuncUndefined U3 Xpath 8192 " X: 8192
|
|
9104 autocmd FuncUndefined U3 call INT()
|
|
9105 autocmd FuncUndefined U3 Xpath 16384 " X: 0
|
|
9106 aug END
|
|
9107
|
|
9108 try
|
|
9109 try
|
|
9110 Xpath 32768 " X: 32768
|
|
9111 doautocmd User x1
|
|
9112 catch /x1/
|
|
9113 Xpath 65536 " X: 65536
|
|
9114 endtry
|
|
9115
|
|
9116 while 1
|
|
9117 try
|
|
9118 Xpath 131072 " X: 131072
|
|
9119 let caught = 0
|
|
9120 doautocmd User x2
|
|
9121 catch /asdf/
|
|
9122 let caught = 1
|
|
9123 finally
|
|
9124 Xpath 262144 " X: 262144
|
|
9125 if !caught && !$VIMNOERRTHROW
|
|
9126 Xpath 524288 " X: 0
|
|
9127 " Propagate uncaught error exception,
|
|
9128 else
|
|
9129 " ... but break loop for caught error exception,
|
|
9130 " or discard error and break loop if $VIMNOERRTHROW
|
|
9131 break
|
|
9132 endif
|
|
9133 endtry
|
|
9134 endwhile
|
|
9135
|
|
9136 while 1
|
|
9137 try
|
|
9138 Xpath 1048576 " X: 1048576
|
|
9139 let caught = 0
|
|
9140 doautocmd User x3
|
|
9141 catch /Vim:Interrupt/
|
|
9142 let caught = 1
|
|
9143 finally
|
|
9144 Xpath 2097152 " X: 2097152
|
|
9145 if !caught && !$VIMNOINTTHROW
|
|
9146 Xpath 4194304 " X: 0
|
|
9147 " Propagate uncaught interrupt exception,
|
|
9148 else
|
|
9149 " ... but break loop for caught interrupt exception,
|
|
9150 " or discard interrupt and break loop if $VIMNOINTTHROW
|
|
9151 break
|
|
9152 endif
|
|
9153 endtry
|
|
9154 endwhile
|
|
9155
|
|
9156 if exists("*U1") | delfunction U1 | endif
|
|
9157 if exists("*U2") | delfunction U2 | endif
|
|
9158 if exists("*U3") | delfunction U3 | endif
|
|
9159
|
|
9160 try
|
|
9161 Xpath 8388608 " X: 8388608
|
|
9162 call U1()
|
|
9163 catch /U1/
|
|
9164 Xpath 16777216 " X: 16777216
|
|
9165 endtry
|
|
9166
|
|
9167 while 1
|
|
9168 try
|
|
9169 Xpath 33554432 " X: 33554432
|
|
9170 let caught = 0
|
|
9171 call U2()
|
|
9172 catch /ASDF/
|
|
9173 let caught = 1
|
|
9174 finally
|
|
9175 Xpath 67108864 " X: 67108864
|
|
9176 if !caught && !$VIMNOERRTHROW
|
|
9177 Xpath 134217728 " X: 0
|
|
9178 " Propagate uncaught error exception,
|
|
9179 else
|
|
9180 " ... but break loop for caught error exception,
|
|
9181 " or discard error and break loop if $VIMNOERRTHROW
|
|
9182 break
|
|
9183 endif
|
|
9184 endtry
|
|
9185 endwhile
|
|
9186
|
|
9187 while 1
|
|
9188 try
|
|
9189 Xpath 268435456 " X: 268435456
|
|
9190 let caught = 0
|
|
9191 call U3()
|
|
9192 catch /Vim:Interrupt/
|
|
9193 let caught = 1
|
|
9194 finally
|
|
9195 Xpath 536870912 " X: 536870912
|
|
9196 if !caught && !$VIMNOINTTHROW
|
|
9197 Xpath 1073741824 " X: 0
|
|
9198 " Propagate uncaught interrupt exception,
|
|
9199 else
|
|
9200 " ... but break loop for caught interrupt exception,
|
|
9201 " or discard interrupt and break loop if $VIMNOINTTHROW
|
|
9202 break
|
|
9203 endif
|
|
9204 endtry
|
|
9205 endwhile
|
|
9206 catch /.*/
|
|
9207 " The Xpath command does not accept 2^31 (negative); display explicitly:
|
|
9208 exec "!echo 2147483648 >>" . g:ExtraVimResult
|
|
9209 Xout "Caught" v:exception "in" v:throwpoint
|
|
9210 endtry
|
|
9211
|
|
9212 unlet caught
|
|
9213 delfunction INT
|
|
9214 delfunction U1
|
|
9215 delfunction U2
|
|
9216 delfunction U3
|
|
9217 au! TMP
|
|
9218 aug! TMP
|
|
9219 endif
|
|
9220
|
|
9221 Xcheck 934782101
|
|
9222
|
|
9223
|
|
9224 "-------------------------------------------------------------------------------
|
|
9225 " Test 85: Error exceptions in autocommands for I/O command events {{{1
|
|
9226 "
|
|
9227 " When an I/O command is inside :try/:endtry, autocommands to be
|
|
9228 " executed after it should be skipped on an error (exception) in the
|
|
9229 " command itself or in autocommands to be executed before the command.
|
|
9230 " In the latter case, the I/O command should not be executed either.
|
|
9231 " Example 1: BufWritePre, :write, BufWritePost
|
|
9232 " Example 2: FileReadPre, :read, FileReadPost.
|
|
9233 "-------------------------------------------------------------------------------
|
|
9234
|
|
9235 XpathINIT
|
|
9236
|
|
9237 function! MSG(enr, emsg)
|
|
9238 let english = v:lang == "C" || v:lang =~ '^[Ee]n'
|
|
9239 if a:enr == ""
|
|
9240 Xout "TODO: Add message number for:" a:emsg
|
|
9241 let v:errmsg = ":" . v:errmsg
|
|
9242 endif
|
|
9243 let match = 1
|
|
9244 if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg)
|
|
9245 let match = 0
|
|
9246 if v:errmsg == ""
|
|
9247 Xout "Message missing."
|
|
9248 else
|
|
9249 let v:errmsg = escape(v:errmsg, '"')
|
|
9250 Xout "Unexpected message:" v:errmsg
|
|
9251 endif
|
|
9252 endif
|
|
9253 return match
|
|
9254 endfunction
|
|
9255
|
|
9256 " Remove the autocommands for the events specified as arguments in all used
|
|
9257 " autogroups.
|
|
9258 function! Delete_autocommands(...)
|
|
9259 let augfile = tempname()
|
|
9260 while 1
|
|
9261 try
|
|
9262 exec "redir >" . augfile
|
|
9263 aug
|
|
9264 redir END
|
|
9265 exec "edit" augfile
|
|
9266 g/^$/d
|
|
9267 norm G$
|
|
9268 let wrap = "w"
|
|
9269 while search('\%( \|^\)\@<=.\{-}\%( \)\@=', wrap) > 0
|
|
9270 let wrap = "W"
|
|
9271 exec "norm y/ \n"
|
|
9272 let argno = 1
|
|
9273 while argno <= a:0
|
|
9274 exec "au!" escape(@", " ") a:{argno}
|
|
9275 let argno = argno + 1
|
|
9276 endwhile
|
|
9277 endwhile
|
|
9278 catch /.*/
|
|
9279 finally
|
|
9280 bwipeout!
|
|
9281 call delete(augfile)
|
|
9282 break " discard errors for $VIMNOERRTHROW
|
|
9283 endtry
|
|
9284 endwhile
|
|
9285 endfunction
|
|
9286
|
|
9287 call Delete_autocommands("BufWritePre", "BufWritePost")
|
|
9288
|
|
9289 while 1
|
|
9290 try
|
|
9291 try
|
|
9292 let post = 0
|
|
9293 aug TMP
|
|
9294 au! BufWritePost * let post = 1
|
|
9295 aug END
|
|
9296 let caught = 0
|
|
9297 write /n/o/n/e/x/i/s/t/e/n/t
|
|
9298 catch /^Vim(write):/
|
|
9299 let caught = 1
|
|
9300 let v:errmsg = substitute(v:exception, '^Vim(write):', '', "")
|
|
9301 finally
|
|
9302 Xpath 1 " X: 1
|
|
9303 if !caught && !$VIMNOERRTHROW
|
|
9304 Xpath 2 " X: 0
|
|
9305 endif
|
|
9306 let v:errmsg = substitute(v:errmsg, '^"/n/o/n/e/x/i/s/t/e/n/t" ',
|
|
9307 \ '', "")
|
|
9308 if !MSG('E212', "Can't open file for writing")
|
|
9309 Xpath 4 " X: 0
|
|
9310 endif
|
|
9311 if post
|
|
9312 Xpath 8 " X: 0
|
|
9313 Xout "BufWritePost commands executed after write error"
|
|
9314 endif
|
|
9315 au! TMP
|
|
9316 aug! TMP
|
|
9317 endtry
|
|
9318 catch /.*/
|
|
9319 Xpath 16 " X: 0
|
|
9320 Xout v:exception "in" v:throwpoint
|
|
9321 finally
|
|
9322 break " discard error for $VIMNOERRTHROW
|
|
9323 endtry
|
|
9324 endwhile
|
|
9325
|
|
9326 while 1
|
|
9327 try
|
|
9328 try
|
|
9329 let post = 0
|
|
9330 aug TMP
|
|
9331 au! BufWritePre * asdf
|
|
9332 au! BufWritePost * let post = 1
|
|
9333 aug END
|
|
9334 let tmpfile = tempname()
|
|
9335 let caught = 0
|
|
9336 exec "write" tmpfile
|
|
9337 catch /^Vim\((write)\)\=:/
|
|
9338 let caught = 1
|
|
9339 let v:errmsg = substitute(v:exception, '^Vim\((write)\)\=:', '', "")
|
|
9340 finally
|
|
9341 Xpath 32 " X: 32
|
|
9342 if !caught && !$VIMNOERRTHROW
|
|
9343 Xpath 64 " X: 0
|
|
9344 endif
|
|
9345 let v:errmsg = substitute(v:errmsg, '^"'.tmpfile.'" ', '', "")
|
|
9346 if !MSG('E492', "Not an editor command")
|
|
9347 Xpath 128 " X: 0
|
|
9348 endif
|
|
9349 if filereadable(tmpfile)
|
|
9350 Xpath 256 " X: 0
|
|
9351 Xout ":write command not suppressed after BufWritePre error"
|
|
9352 endif
|
|
9353 if post
|
|
9354 Xpath 512 " X: 0
|
|
9355 Xout "BufWritePost commands executed after BufWritePre error"
|
|
9356 endif
|
|
9357 au! TMP
|
|
9358 aug! TMP
|
|
9359 endtry
|
|
9360 catch /.*/
|
|
9361 Xpath 1024 " X: 0
|
|
9362 Xout v:exception "in" v:throwpoint
|
|
9363 finally
|
|
9364 break " discard error for $VIMNOERRTHROW
|
|
9365 endtry
|
|
9366 endwhile
|
|
9367
|
|
9368 call delete(tmpfile)
|
|
9369
|
|
9370 call Delete_autocommands("BufWritePre", "BufWritePost",
|
|
9371 \ "BufReadPre", "BufReadPost", "FileReadPre", "FileReadPost")
|
|
9372
|
|
9373 while 1
|
|
9374 try
|
|
9375 try
|
|
9376 let post = 0
|
|
9377 aug TMP
|
|
9378 au! FileReadPost * let post = 1
|
|
9379 aug END
|
|
9380 let caught = 0
|
|
9381 read /n/o/n/e/x/i/s/t/e/n/t
|
|
9382 catch /^Vim(read):/
|
|
9383 let caught = 1
|
|
9384 let v:errmsg = substitute(v:exception, '^Vim(read):', '', "")
|
|
9385 finally
|
|
9386 Xpath 2048 " X: 2048
|
|
9387 if !caught && !$VIMNOERRTHROW
|
|
9388 Xpath 4096 " X: 0
|
|
9389 endif
|
|
9390 let v:errmsg = substitute(v:errmsg, ' /n/o/n/e/x/i/s/t/e/n/t$',
|
|
9391 \ '', "")
|
|
9392 if !MSG('E484', "Can't open file")
|
|
9393 Xpath 8192 " X: 0
|
|
9394 endif
|
|
9395 if post
|
|
9396 Xpath 16384 " X: 0
|
|
9397 Xout "FileReadPost commands executed after write error"
|
|
9398 endif
|
|
9399 au! TMP
|
|
9400 aug! TMP
|
|
9401 endtry
|
|
9402 catch /.*/
|
|
9403 Xpath 32768 " X: 0
|
|
9404 Xout v:exception "in" v:throwpoint
|
|
9405 finally
|
|
9406 break " discard error for $VIMNOERRTHROW
|
|
9407 endtry
|
|
9408 endwhile
|
|
9409
|
|
9410 while 1
|
|
9411 try
|
|
9412 let infile = tempname()
|
|
9413 let tmpfile = tempname()
|
|
9414 exec "!echo XYZ >" . infile
|
|
9415 exec "edit" tmpfile
|
|
9416 try
|
|
9417 Xpath 65536 " X: 65536
|
|
9418 try
|
|
9419 let post = 0
|
|
9420 aug TMP
|
|
9421 au! FileReadPre * asdf
|
|
9422 au! FileReadPost * let post = 1
|
|
9423 aug END
|
|
9424 let caught = 0
|
|
9425 exec "0read" infile
|
|
9426 catch /^Vim\((read)\)\=:/
|
|
9427 let caught = 1
|
|
9428 let v:errmsg = substitute(v:exception, '^Vim\((read)\)\=:', '',
|
|
9429 \ "")
|
|
9430 finally
|
|
9431 Xpath 131072 " X: 131072
|
|
9432 if !caught && !$VIMNOERRTHROW
|
|
9433 Xpath 262144 " X: 0
|
|
9434 endif
|
|
9435 let v:errmsg = substitute(v:errmsg, ' '.infile.'$', '', "")
|
|
9436 if !MSG('E492', "Not an editor command")
|
|
9437 Xpath 524288 " X: 0
|
|
9438 endif
|
|
9439 if getline("1") == "XYZ"
|
|
9440 Xpath 1048576 " X: 0
|
|
9441 Xout ":read command not suppressed after FileReadPre error"
|
|
9442 endif
|
|
9443 if post
|
|
9444 Xpath 2097152 " X: 0
|
|
9445 Xout "FileReadPost commands executed after " .
|
|
9446 \ "FileReadPre error"
|
|
9447 endif
|
|
9448 au! TMP
|
|
9449 aug! TMP
|
|
9450 endtry
|
|
9451 finally
|
|
9452 bwipeout!
|
|
9453 endtry
|
|
9454 catch /.*/
|
|
9455 Xpath 4194304 " X: 0
|
|
9456 Xout v:exception "in" v:throwpoint
|
|
9457 finally
|
|
9458 break " discard error for $VIMNOERRTHROW
|
|
9459 endtry
|
|
9460 endwhile
|
|
9461
|
|
9462 call delete(infile)
|
|
9463 call delete(tmpfile)
|
|
9464 unlet! caught post infile tmpfile
|
|
9465 delfunction MSG
|
|
9466 delfunction Delete_autocommands
|
|
9467
|
|
9468 Xcheck 198689
|
|
9469
|
|
9470
|
|
9471 "-------------------------------------------------------------------------------
|
|
9472 " Test 86: $VIMNOERRTHROW and $VIMNOINTTHROW support {{{1
|
|
9473 "
|
|
9474 " It is possible to configure Vim for throwing exceptions on error
|
|
9475 " or interrupt, controlled by variables $VIMNOERRTHROW and
|
|
9476 " $VIMNOINTTHROW. This is just for increasing the number of tests.
|
|
9477 " All tests here should run for all four combinations of setting
|
|
9478 " these variables to 0 or 1. The variables are intended for the
|
|
9479 " development phase only. In the final release, Vim should be
|
|
9480 " configured to always use error and interrupt exceptions.
|
|
9481 "
|
|
9482 " The test result is "OK",
|
|
9483 "
|
|
9484 " - if the $VIMNOERRTHROW and the $VIMNOINTTHROW control are not
|
|
9485 " configured and exceptions are thrown on error and on
|
|
9486 " interrupt.
|
|
9487 "
|
|
9488 " - if the $VIMNOERRTHROW or the $VIMNOINTTHROW control is
|
|
9489 " configured and works as intended.
|
|
9490 "
|
|
9491 " What actually happens, is shown in the test output.
|
|
9492 "
|
|
9493 " Otherwise, the test result is "FAIL", and the test output describes
|
|
9494 " the problem.
|
|
9495 "
|
|
9496 " IMPORTANT: This must be the last test because it sets $VIMNOERRTHROW and
|
|
9497 " $VIMNOINTTHROW.
|
|
9498 "-------------------------------------------------------------------------------
|
|
9499
|
|
9500 XpathINIT
|
|
9501
|
|
9502 if ExtraVim()
|
|
9503
|
|
9504 function! ThrowOnError()
|
|
9505 XloopNEXT
|
|
9506 let caught = 0
|
|
9507 try
|
|
9508 Xloop 1 " X: 1 + 8 + 64
|
|
9509 asdf
|
|
9510 catch /.*/
|
|
9511 let caught = 1 " error exception caught
|
|
9512 finally
|
|
9513 Xloop 2 " X: 2 + 16 + 128
|
|
9514 return caught " discard aborting error
|
|
9515 endtry
|
|
9516 Xloop 4 " X: 0
|
|
9517 endfunction
|
|
9518
|
|
9519 let quits_skipped = 0
|
|
9520
|
|
9521 function! ThrowOnInterrupt()
|
|
9522 XloopNEXT
|
|
9523 let caught = 0
|
|
9524 try
|
|
9525 Xloop 1 " X: (1 + 8 + 64) * 512
|
|
9526 "INTERRUPT3
|
|
9527 let dummy = 0
|
|
9528 let g:quits_skipped = g:quits_skipped + 1
|
|
9529 catch /.*/
|
|
9530 let caught = 1 " interrupt exception caught
|
|
9531 finally
|
|
9532 Xloop 2 " X: (2 + 16 + 128) * 512
|
|
9533 return caught " discard interrupt
|
|
9534 endtry
|
|
9535 Xloop 4 " X: 0
|
|
9536 endfunction
|
|
9537
|
|
9538 function! CheckThrow(Type)
|
|
9539 execute 'return ThrowOn' . a:Type . '()'
|
|
9540 endfunction
|
|
9541
|
|
9542 function! CheckConfiguration(type) " type is "error" or "interrupt"
|
|
9543
|
|
9544 let type = a:type
|
|
9545 let Type = substitute(type, '.*', '\u&', "")
|
|
9546 let VAR = '$VIMNO' . substitute(type, '\(...\).*', '\U\1', "") . 'THROW'
|
|
9547
|
|
9548 if type == "error"
|
|
9549 XloopINIT! 1 8
|
|
9550 elseif type == "interrupt"
|
|
9551 XloopINIT! 512 8
|
|
9552 endif
|
|
9553
|
|
9554 exec 'let requested_for_tests = exists(VAR) && ' . VAR . ' == 0'
|
|
9555 exec 'let suppressed_for_tests = ' . VAR . ' != 0'
|
|
9556 let used_in_tests = CheckThrow(Type)
|
|
9557
|
|
9558 exec 'let ' . VAR . ' = 0'
|
|
9559 let request_works = CheckThrow(Type)
|
|
9560
|
|
9561 exec 'let ' . VAR . ' = 1'
|
|
9562 let suppress_works = !CheckThrow(Type)
|
|
9563
|
|
9564 if type == "error"
|
|
9565 XloopINIT! 262144 8
|
|
9566 elseif type == "interrupt"
|
|
9567 XloopINIT! 2097152 8
|
|
9568
|
|
9569 if g:quits_skipped != 0
|
|
9570 Xloop 1 " X: 0*2097152
|
|
9571 Xout "Test environment error. Interrupt breakpoints skipped: "
|
|
9572 \ . g:quits_skipped . ".\n"
|
|
9573 \ . "Cannot check whether interrupt exceptions are thrown."
|
|
9574 return
|
|
9575 endif
|
|
9576 endif
|
|
9577
|
|
9578 let failure =
|
|
9579 \ !suppressed_for_tests && !used_in_tests
|
|
9580 \ || !request_works
|
|
9581
|
|
9582 let contradiction =
|
|
9583 \ used_in_tests
|
|
9584 \ ? suppressed_for_tests && !request_works
|
|
9585 \ : !suppressed_for_tests
|
|
9586
|
|
9587 if failure
|
|
9588 " Failure in configuration.
|
|
9589 Xloop 2 " X: 0 * 2* (262144 + 2097152)
|
|
9590 elseif contradiction
|
|
9591 " Failure in test logic. Should not happen.
|
|
9592 Xloop 4 " X: 0 * 4 * (262144 + 2097152)
|
|
9593 endif
|
|
9594
|
|
9595 let var_control_configured =
|
|
9596 \ request_works != used_in_tests
|
|
9597 \ || suppress_works == used_in_tests
|
|
9598
|
|
9599 let var_control_not_configured =
|
|
9600 \ requested_for_tests || suppressed_for_tests
|
|
9601 \ ? request_works && !suppress_works
|
|
9602 \ : request_works == used_in_tests
|
|
9603 \ && suppress_works != used_in_tests
|
|
9604
|
|
9605 let with = used_in_tests ? "with" : "without"
|
|
9606
|
|
9607 let set = suppressed_for_tests ? "non-zero" :
|
|
9608 \ requested_for_tests ? "0" : "unset"
|
|
9609
|
|
9610 let although = contradiction && !var_control_not_configured
|
|
9611 \ ? ",\nalthough "
|
|
9612 \ : ".\n"
|
|
9613
|
|
9614 let output = "All tests were run " . with . " throwing exceptions on "
|
|
9615 \ . type . although
|
|
9616
|
|
9617 if !var_control_not_configured
|
|
9618 let output = output . VAR . " was " . set . "."
|
|
9619
|
|
9620 if !request_works && !requested_for_tests
|
|
9621 let output = output .
|
|
9622 \ "\n" . Type . " exceptions are not thrown when " . VAR .
|
|
9623 \ " is\nset to 0."
|
|
9624 endif
|
|
9625
|
|
9626 if !suppress_works && (!used_in_tests ||
|
|
9627 \ !request_works &&
|
|
9628 \ !requested_for_tests && !suppressed_for_tests)
|
|
9629 let output = output .
|
|
9630 \ "\n" . Type . " exceptions are thrown when " . VAR .
|
|
9631 \ " is set to 1."
|
|
9632 endif
|
|
9633
|
|
9634 if !failure && var_control_configured
|
|
9635 let output = output .
|
|
9636 \ "\nRun tests also with " . substitute(VAR, '^\$', '', "")
|
|
9637 \ . "=" . used_in_tests . "."
|
|
9638 \ . "\nThis is for testing in the development phase only."
|
|
9639 \ . " Remove the \n"
|
|
9640 \ . VAR . " control in the final release."
|
|
9641 endif
|
|
9642 else
|
|
9643 let output = output .
|
|
9644 \ "The " . VAR . " control is not configured."
|
|
9645 endif
|
|
9646
|
|
9647 Xout output
|
|
9648 endfunction
|
|
9649
|
|
9650 call CheckConfiguration("error")
|
|
9651 Xpath 16777216 " X: 16777216
|
|
9652 call CheckConfiguration("interrupt")
|
|
9653 Xpath 33554432 " X: 33554432
|
|
9654 endif
|
|
9655
|
|
9656 Xcheck 50443995
|
|
9657
|
|
9658 " IMPORTANT: No test should be added after this test because it changes
|
|
9659 " $VIMNOERRTHROW and $VIMNOINTTHROW.
|
|
9660
|
|
9661
|
|
9662 "-------------------------------------------------------------------------------
|
|
9663 " Modelines {{{1
|
|
9664 " vim: ts=8 sw=4 tw=80 fdm=marker
|
|
9665 " vim: fdt=substitute(substitute(foldtext(),\ '\\%(^+--\\)\\@<=\\(\\s*\\)\\(.\\{-}\\)\:\ \\%(\"\ \\)\\=\\(Test\ \\d*\\)\:\\s*',\ '\\3\ (\\2)\:\ \\1',\ \"\"),\ '\\(Test\\s*\\)\\(\\d\\)\\D\\@=',\ '\\1\ \\2',\ "")
|
|
9666 "-------------------------------------------------------------------------------
|