comparison src/testdir/test_options.vim @ 32788:80152cf7ce63 v9.0.1710

patch 9.0.1710: scrolloff options work slightly different Commit: https://github.com/vim/vim/commit/4a8eb6e7a9df10f79bf95301ced012f0d6a13088 Author: Christian Brabandt <cb@256bit.org> Date: Sun Aug 13 19:43:42 2023 +0200 patch 9.0.1710: scrolloff options work slightly different Problem: sidescrolloff and scrolloff options work slightly different than other global-local options Solution: Make it behave consistent for all global-local options It was noticed, that sidescrolloff and scrolloff options behave differently in comparison to other global-local window options like 'listchars' So make those two behave like other global-local options. Also add some extra documentation for a few special local-window options. Add a few tests to make sure all global-local window options behave similar closes: #12956 closes: #12643 Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 13 Aug 2023 20:00:04 +0200
parents 1b9a29f7fe86
children 7771cb060685
comparison
equal deleted inserted replaced
32787:e79ea0930857 32788:80152cf7ce63
1687 exe $"let &{opt[0]} = save_opt" 1687 exe $"let &{opt[0]} = save_opt"
1688 endfor 1688 endfor
1689 bw! 1689 bw!
1690 endfunc 1690 endfunc
1691 1691
1692 func Test_set_option_window_global_local()
1693 new Xbuffer1
1694 let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
1695 setlocal scrolloff=2
1696 setglobal scrolloff=3
1697 setl modified
1698 " A new buffer has its own window-local options
1699 hide enew
1700 call assert_equal(-1, &l:scrolloff)
1701 call assert_equal(3, &g:scrolloff)
1702 " A new window opened with its own buffer-local options
1703 new
1704 call assert_equal(-1, &l:scrolloff)
1705 call assert_equal(3, &g:scrolloff)
1706 " Re-open Xbuffer1 and it should use
1707 " the previous set window-local options
1708 b Xbuffer1
1709 call assert_equal(2, &l:scrolloff)
1710 call assert_equal(3, &g:scrolloff)
1711 bw!
1712 bw!
1713 let &g:scrolloff = _gso
1714 endfunc
1715
1716 func GetGlobalLocalWindowOptions()
1717 new
1718 sil! r $VIMRUNTIME/doc/options.txt
1719 " Filter for global or local to window
1720 v/^'.*'.*\n.*global or local to window |global-local/d
1721 " get option value and type
1722 sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
1723 sil %s/empty/""/g
1724 " split the result
1725 let result=getline(1,'$')->map({_, val -> split(val, ' ')})
1726 bw!
1727 return result
1728 endfunc
1729
1730 func Test_set_option_window_global_local_all()
1731 new Xbuffer2
1732
1733 let optionlist = GetGlobalLocalWindowOptions()
1734 for [opt, type, default] in optionlist
1735 let _old = eval('&g:' .. opt)
1736 if type == 'string'
1737 if opt == 'fillchars'
1738 exe 'setl ' .. opt .. '=vert:+'
1739 exe 'setg ' .. opt .. '=vert:+,fold:+'
1740 elseif opt == 'listchars'
1741 exe 'setl ' .. opt .. '=tab:>>'
1742 exe 'setg ' .. opt .. '=tab:++'
1743 elseif opt == 'virtualedit'
1744 exe 'setl ' .. opt .. '=all'
1745 exe 'setg ' .. opt .. '=block'
1746 else
1747 exe 'setl ' .. opt .. '=Local'
1748 exe 'setg ' .. opt .. '=Global'
1749 endif
1750 elseif type == 'number'
1751 exe 'setl ' .. opt .. '=5'
1752 exe 'setg ' .. opt .. '=10'
1753 endif
1754 setl modified
1755 hide enew
1756 if type == 'string'
1757 call assert_equal('', eval('&l:' .. opt))
1758 if opt == 'fillchars'
1759 call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
1760 elseif opt == 'listchars'
1761 call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
1762 elseif opt == 'virtualedit'
1763 call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
1764 else
1765 call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
1766 endif
1767 elseif type == 'number'
1768 call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
1769 call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
1770 endif
1771 bw!
1772 exe 'let &g:' .. opt .. '=' .. default
1773 endfor
1774 bw!
1775 endfunc
1776
1692 " vim: shiftwidth=2 sts=2 expandtab 1777 " vim: shiftwidth=2 sts=2 expandtab