aboutsummaryrefslogtreecommitdiff
path: root/test/old/testdir/test_options.vim
diff options
context:
space:
mode:
Diffstat (limited to 'test/old/testdir/test_options.vim')
-rw-r--r--test/old/testdir/test_options.vim167
1 files changed, 167 insertions, 0 deletions
diff --git a/test/old/testdir/test_options.vim b/test/old/testdir/test_options.vim
index aabb11a76a..563709b9a3 100644
--- a/test/old/testdir/test_options.vim
+++ b/test/old/testdir/test_options.vim
@@ -1682,4 +1682,171 @@ func Test_string_option_revert_on_failure()
bw!
endfunc
+func Test_set_option_window_global_local()
+ new Xbuffer1
+ let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
+ setlocal scrolloff=2
+ setglobal scrolloff=3
+ setl modified
+ " A new buffer has its own window-local options
+ hide enew
+ call assert_equal(-1, &l:scrolloff)
+ call assert_equal(3, &g:scrolloff)
+ " A new window opened with its own buffer-local options
+ new
+ call assert_equal(-1, &l:scrolloff)
+ call assert_equal(3, &g:scrolloff)
+ " Re-open Xbuffer1 and it should use
+ " the previous set window-local options
+ b Xbuffer1
+ call assert_equal(2, &l:scrolloff)
+ call assert_equal(3, &g:scrolloff)
+ bw!
+ bw!
+ let &g:scrolloff = _gso
+endfunc
+
+func GetGlobalLocalWindowOptions()
+ new
+ sil! r $VIMRUNTIME/doc/options.txt
+ " Filter for global or local to window
+ v/^'.*'.*\n.*global or local to window |global-local/d
+ " get option value and type
+ sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
+ " sil %s/empty/""/g
+ " split the result
+ " let result=getline(1,'$')->map({_, val -> split(val, ' ')})
+ let result = getline(1, '$')->map({_, val -> matchlist(val, '\([^ ]\+\) \+\([^ ]\+\) \+\(.*\)')[1:3]})
+ bw!
+ return result
+endfunc
+
+func Test_set_option_window_global_local_all()
+ new Xbuffer2
+
+ let optionlist = GetGlobalLocalWindowOptions()
+ for [opt, type, default] in optionlist
+ let _old = eval('&g:' .. opt)
+ if type == 'string'
+ if opt == 'fillchars'
+ exe 'setl ' .. opt .. '=vert:+'
+ exe 'setg ' .. opt .. '=vert:+,fold:+'
+ elseif opt == 'listchars'
+ exe 'setl ' .. opt .. '=tab:>>'
+ exe 'setg ' .. opt .. '=tab:++'
+ elseif opt == 'virtualedit'
+ exe 'setl ' .. opt .. '=all'
+ exe 'setg ' .. opt .. '=block'
+ else
+ exe 'setl ' .. opt .. '=Local'
+ exe 'setg ' .. opt .. '=Global'
+ endif
+ elseif type == 'number'
+ exe 'setl ' .. opt .. '=5'
+ exe 'setg ' .. opt .. '=10'
+ endif
+ setl modified
+ hide enew
+ if type == 'string'
+ call assert_equal('', eval('&l:' .. opt))
+ if opt == 'fillchars'
+ call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
+ elseif opt == 'listchars'
+ call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
+ elseif opt == 'virtualedit'
+ call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
+ else
+ call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
+ endif
+ elseif type == 'number'
+ call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
+ call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
+ endif
+ bw!
+ exe 'let &g:' .. opt .. '=' .. default
+ endfor
+ bw!
+endfunc
+
+func Test_paste_depending_options()
+ " setting the paste option, resets all dependent options
+ " and will be reported correctly using :verbose set <option>?
+ let lines =<< trim [CODE]
+ " set paste test
+ set autoindent
+ set expandtab
+ " disabled, because depends on compiled feature set
+ " set hkmap
+ " set revins
+ " set varsofttabstop=8,32,8
+ set ruler
+ set showmatch
+ set smarttab
+ set softtabstop=4
+ set textwidth=80
+ set wrapmargin=10
+
+ source Xvimrc_paste2
+
+ redir > Xoutput_paste
+ verbose set expandtab?
+ verbose setg expandtab?
+ verbose setl expandtab?
+ redir END
+
+ qall!
+ [CODE]
+
+ call writefile(lines, 'Xvimrc_paste', 'D')
+ call writefile(['set paste'], 'Xvimrc_paste2', 'D')
+ if !RunVim([], lines, '--clean')
+ return
+ endif
+
+ let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
+ call assert_equal('noexpandtab', result[0])
+ call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
+ call assert_equal('noexpandtab', result[2])
+ call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
+ call assert_equal('noexpandtab', result[4])
+ call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
+
+ call delete('Xoutput_paste')
+endfunc
+
+func Test_binary_depending_options()
+ " setting the paste option, resets all dependent options
+ " and will be reported correctly using :verbose set <option>?
+ let lines =<< trim [CODE]
+ " set binary test
+ set expandtab
+
+ source Xvimrc_bin2
+
+ redir > Xoutput_bin
+ verbose set expandtab?
+ verbose setg expandtab?
+ verbose setl expandtab?
+ redir END
+
+ qall!
+ [CODE]
+
+ call writefile(lines, 'Xvimrc_bin', 'D')
+ call writefile(['set binary'], 'Xvimrc_bin2', 'D')
+ if !RunVim([], lines, '--clean')
+ return
+ endif
+
+ let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
+ call assert_equal('noexpandtab', result[0])
+ call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
+ call assert_equal('noexpandtab', result[2])
+ call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
+ call assert_equal('noexpandtab', result[4])
+ call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
+
+ call delete('Xoutput_bin')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab