1- " Script to generate testdir/opt_test.vim from optiondefs.h
1+ " Script to generate src/testdir/opt_test.vim from src/optiondefs.h and
2+ " runtime/doc/options.txt
23
34set cpo = &vim
45
@@ -11,19 +12,65 @@ set nomore
1112
1213const K_KENTER = -16715
1314
15+ " Get global-local options.
16+ " "key" is full-name of the option.
17+ " "value" is the local value to switch back to the global value.
18+ b options .txt
19+ call cursor (1 , 1 )
20+ let global_locals = {}
21+ while search (" ^'[^']*'.*\\ n.*|global-local" , ' W' )
22+ let fullname = getline (' .' )- >matchstr (" ^'\\ zs[^']*" )
23+ let global_locals[fullname] = ' '
24+ endwhile
25+ call extend (global_locals, #{
26+ \ scrolloff : -1 ,
27+ \ sidescrolloff : -1 ,
28+ \ undolevels : -12345 ,
29+ \} )
30+
31+ " Get local-noglobal options.
32+ " "key" is full-name of the option.
33+ " "value" is no used.
34+ b options .txt
35+ call cursor (1 , 1 )
36+ let local_noglobals = {}
37+ while search (" ^'[^']*'.*\\ n.*|local-noglobal" , ' W' )
38+ let fullname = getline (' .' )- >matchstr (" ^'\\ zs[^']*" )
39+ let local_noglobals[fullname] = v: true
40+ endwhile
41+
42+ " Options to skip `setglobal` tests.
43+ " "key" is full-name of the option.
44+ " "value" is the reason.
45+ let skip_setglobal_reasons = #{
46+ \ iminsert : ' The global value is always overwritten by the local value' ,
47+ \ imsearch : ' The global value is always overwritten by the local value' ,
48+ \ breakindentopt : ' TODO: fix missing error handling for setglobal' ,
49+ \ colorcolumn : ' TODO: fix missing error handling for setglobal' ,
50+ \ conceallevel: ' TODO: fix missing error handling for setglobal' ,
51+ \ foldcolumn : ' TODO: fix missing error handling for setglobal' ,
52+ \ foldmethod : ' TODO: fix `setglobal fdm=` not given an error' ,
53+ \ iskeyword : ' TODO: fix missing error handling for setglobal' ,
54+ \ numberwidth : ' TODO: fix missing error handling for setglobal' ,
55+ \ scrolloff : ' TODO: fix missing error handling for setglobal' ,
56+ \ shiftwidth : ' TODO: fix missing error handling for setglobal' ,
57+ \ sidescrolloff : ' TODO: fix missing error handling for setglobal' ,
58+ \ tabstop : ' TODO: fix missing error handling for setglobal' ,
59+ \ termwinkey : ' TODO: fix missing error handling for setglobal' ,
60+ \ termwinsize : ' TODO: fix missing error handling for setglobal' ,
61+ \ textwidth : ' TODO: fix missing error handling for setglobal' ,
62+ \}
63+
1464" The terminal size is restored at the end.
15- " Clear out t_WS, we don't want to resize the actual terminal.
1665let script = [
1766 \ ' " DO NOT EDIT: Generated with gen_opt_test.vim' ,
18- \ ' " Used by test_options .vim.' ,
67+ \ ' " Used by test_options_all .vim.' ,
1968 \ ' ' ,
20- \ ' let save_columns = &columns' ,
21- \ ' let save_lines = &lines' ,
22- \ ' set t_WS=' ,
69+ \ ' scriptencoding utf-8' ,
2370 \ ]
2471
25- /# define p_term
26- let end = line ( ' . ' )
72+ b optiondefs. h
73+ const end = search ( ' #define p_term ' , ' nw ' )
2774
2875" font name that works everywhere (hopefully)
2976let fontname = has (' win32' ) ? ' fixedsys' : ' fixed'
@@ -295,76 +342,132 @@ let test_values = {
295342 \ ' otherstring' : [[' ' , ' xxx' ], []],
296343 \}
297344
345+ " Two lists with values: values that pre- and post-processing in test.
346+ " Clear out t_WS: we don't want to resize the actual terminal.
347+ let test_prepost = {
348+ \ ' browsedir' : [[" call mkdir('Xdir with space', 'D')" ], []],
349+ \ ' columns' : [[
350+ \ ' set t_WS=' ,
351+ \ ' let save_columns = &columns'
352+ \ ], [
353+ \ ' let &columns = save_columns' ,
354+ \ ' set t_WS&'
355+ \ ]],
356+ \ ' lines' : [[
357+ \ ' set t_WS=' ,
358+ \ ' let save_lines = &lines'
359+ \ ], [
360+ \ ' let &lines = save_lines' ,
361+ \ ' set t_WS&'
362+ \ ]],
363+ \ ' verbosefile' : [[], [' call delete("Xfile")' ]],
364+ \}
365+
298366const invalid_options = test_values- >keys ()
299367 \- >filter ({- > v: val !~# ' ^other' && ! exists ($ " &{v:val}" )})
300368if ! empty (invalid_options)
301369 throw $ " Invalid option name in test_values: '{invalid_options->join(" ' , ' " )}'"
302370endif
303371
3043721
305- / struct vimoption options
373+ call search ( ' struct vimoption options' )
306374while 1
307- /{"
308- if line (' .' ) > end
375+ if search (' {"' , ' W' ) > end
309376 break
310377 endif
311378 let line = getline (' .' )
312- let name = substitute (line , ' .*{"\([^"]*\)".*' , ' \1' , ' ' )
379+ let fullname = substitute (line , ' .*{"\([^"]*\)".*' , ' \1' , ' ' )
313380 let shortname = substitute (line , ' .*"\([^"]*\)".*' , ' \1' , ' ' )
314381
315- if has_key (test_values, name)
316- let a = test_values[name]
317- elseif line = ~ ' P_NUM'
318- let a = test_values[' othernum' ]
319- else
320- let a = test_values[' otherstring' ]
382+ let [valid_values, invalid_values] = test_values[
383+ \ has_key (test_values, fullname) ? fullname
384+ \ : line = ~ ' P_NUM' ? ' othernum'
385+ \ : ' otherstring' ]
386+
387+ if empty (valid_values) && empty (invalid_values)
388+ continue
321389 endif
322- if len (a [0 ]) > 0 || len (a [1 ]) > 0
323- if name == ' browsedir'
324- call add (script , ' call mkdir("Xdir with space")' )
325- endif
326390
327- if line = ~ ' P_BOOL'
328- call add (script , ' set ' . name)
329- call add (script , ' set ' . shortname )
330- call add (script , ' set no' . name)
331- call add (script , ' set no' . shortname )
332- else
333- for val in a [0 ]
334- call add (script , ' set ' . name . ' =' . val)
335- call add (script , ' set ' . shortname . ' =' . val)
336- endfor
391+ call add (script , $ " func Test_opt_set_{fullname}()" )
392+ call add (script , $ " if exists('+{fullname}') && execute('set!') =~# '\\ n..{fullname}\\ ([=\\ n]\\ |$\\ )'" )
393+ call add (script , $ " let l:saved = [&g:{fullname}, &l:{fullname}]" )
394+ call add (script , ' endif' )
395+
396+ let [pre_processing, post_processing] = get (test_prepost, fullname, [[], []])
397+ let script += pre_processing
337398
338- " setting an option can only fail when it's implemented.
339- call add (script , " if exists('+" . name . " ')" )
340- for val in a [1 ]
341- call add (script , " silent! call assert_fails('set " . name . " =" . val . " ')" )
342- call add (script , " silent! call assert_fails('set " . shortname . " =" . val . " ')" )
399+ if line = ~ ' P_BOOL'
400+ for opt in [fullname, shortname ]
401+ for cmd in [' set' , ' setlocal' , ' setglobal' ]
402+ call add (script , $ ' {cmd} {opt}' )
403+ call add (script , $ ' {cmd} no{opt}' )
404+ call add (script , $ ' {cmd} inv{opt}' )
405+ call add (script , $ ' {cmd} {opt}!' )
343406 endfor
344- call add (script , " endif" )
345- endif
407+ endfor
408+ else " P_NUM || P_STRING
409+ " Normal tests
410+ for opt in [fullname, shortname ]
411+ for cmd in [' set' , ' setlocal' , ' setglobal' ]
412+ for val in valid_values
413+ if local_noglobals- >has_key (fullname) && cmd == # ' setglobal'
414+ " Skip `:setglobal {option}={val}` for local-noglobal option.
415+ " It has no effect.
416+ let pre = ' " Skip local-noglobal: '
417+ else
418+ let pre = ' '
419+ endif
420+ call add (script , $ ' {pre}{cmd} {opt}={val}' )
421+ endfor
422+ endfor
423+ " Testing to clear the local value and switch back to the global value.
424+ if global_locals- >has_key (fullname)
425+ let swichback_val = global_locals[fullname]
426+ call add (script , $ ' setlocal {opt}={swichback_val}' )
427+ endif
428+ endfor
346429
347- " cannot change 'termencoding' in GTK
348- if name != ' termencoding' || ! has (' gui_gtk' )
349- call add (script , ' set ' . name . ' &' )
350- call add (script , ' set ' . shortname . ' &' )
351- endif
352- if name == ' browsedir'
353- call add (script , ' call delete("Xdir with space", "d")' )
354- elseif name == ' verbosefile'
355- call add (script , ' call delete("Xfile")' )
356- endif
430+ " Failure tests
431+ " Setting an option can only fail when it's implemented.
432+ call add (script , $ " if exists('+{fullname}')" )
433+ for opt in [fullname, shortname ]
434+ for cmd in [' set' , ' setlocal' , ' setglobal' ]
435+ for val in invalid_values
436+ if val is # global_locals- >get (fullname, {}) && cmd == # ' setlocal'
437+ " Skip setlocal switchback-value to global-local option. It will
438+ " not result in failure.
439+ let pre = ' " Skip global-local: '
440+ elseif local_noglobals- >has_key (fullname) && cmd == # ' setglobal'
441+ " Skip setglobal to local-noglobal option. It will not result in
442+ " failure.
443+ let pre = ' " Skip local-noglobal: '
444+ elseif skip_setglobal_reasons- >has_key (fullname) && cmd == # ' setglobal'
445+ " Skip setglobal to reasoned option. It will not result in failure.
446+ let reason = skip_setglobal_reasons[fullname]
447+ let pre = $ ' " Skip {reason}: '
448+ else
449+ let pre = ' '
450+ endif
451+ let cmdline = $ ' {cmd} {opt}={val}'
452+ call add (script , $ " {pre}silent! call assert_fails({string(cmdline)})" )
453+ endfor
454+ endfor
455+ endfor
456+ call add (script , " endif" )
457+ endif
357458
358- if name == ' more'
359- call add (script , ' set nomore' )
360- elseif name == ' lines'
361- call add (script , ' let &lines = save_lines' )
362- endif
459+ " Cannot change 'termencoding' in GTK
460+ if fullname != ' termencoding' || ! has (' gui_gtk' )
461+ call add (script , $ ' set {fullname}&' )
462+ call add (script , $ ' set {shortname}&' )
463+ call add (script , $ " if exists('l:saved')" )
464+ call add (script , $ " let [&g:{fullname}, &l:{fullname}] = l:saved" )
465+ call add (script , ' endif' )
363466 endif
364- endwhile
365467
366- call add (script , ' let &columns = save_columns' )
367- call add (script , ' let &lines = save_lines' )
468+ let script += post_processing
469+ call add (script , ' endfunc' )
470+ endwhile
368471
369472call writefile (script , ' opt_test.vim' )
370473
@@ -381,3 +484,5 @@ endtry
381484endif
382485
383486qa !
487+
488+ " vim:sw = 2 :ts = 8 :noet :nolist :nosta :
0 commit comments