robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
3.8 KiB109 linesraw
1-- Tests for :setlocal and :setglobal
2
3local t = require('test.testutil')
4local n = require('test.functional.testnvim')()
5
6local describe, it, before_each = t.describe, t.it, t.before_each
7local clear, command, eval, eq, api = n.clear, n.command, n.eval, t.eq, n.api
8local matches, pcall_err = t.matches, t.pcall_err
9
10local function should_fail(opt, value, errmsg)
11  matches(errmsg .. ':', pcall_err(command, 'setglobal ' .. opt .. '=' .. value))
12  matches(errmsg .. ':', pcall_err(command, 'setlocal ' .. opt .. '=' .. value))
13  matches(errmsg .. ':', pcall_err(api.nvim_set_option_value, opt, value, {}))
14end
15
16local function should_succeed(opt, value)
17  command('setglobal ' .. opt .. '=' .. value)
18  command('setlocal ' .. opt .. '=' .. value)
19  api.nvim_set_option_value(opt, value, {})
20  eq(value, api.nvim_get_option_value(opt, {}))
21end
22
23describe(':setlocal', function()
24  before_each(clear)
25
26  it('setlocal sets only local value', function()
27    eq(0, api.nvim_get_option_value('iminsert', { scope = 'global' }))
28    command('setlocal iminsert=1')
29    eq(0, api.nvim_get_option_value('iminsert', { scope = 'global' }))
30    eq(-1, api.nvim_get_option_value('imsearch', { scope = 'global' }))
31    command('setlocal imsearch=1')
32    eq(-1, api.nvim_get_option_value('imsearch', { scope = 'global' }))
33  end)
34end)
35
36describe(':set validation', function()
37  before_each(clear)
38
39  it('setlocal and setglobal validate values', function()
40    should_fail('shiftwidth', -10, 'E487')
41    should_succeed('shiftwidth', 0)
42    should_fail('tabstop', -10, 'E487')
43    should_fail('winheight', -10, 'E487')
44    should_fail('winheight', 0, 'E487')
45    should_fail('winminheight', -1, 'E487')
46    should_succeed('winminheight', 0)
47    should_fail('winwidth', 0, 'E487')
48    should_fail('helpheight', -1, 'E487')
49    should_fail('iminsert', 3, 'E474')
50    should_fail('imsearch', 3, 'E474')
51    should_fail('titlelen', -1, 'E487')
52    should_fail('cmdheight', -1, 'E487')
53    should_fail('updatecount', -1, 'E487')
54    should_fail('textwidth', -1, 'E487')
55    should_fail('tabstop', 0, 'E487')
56    should_fail('timeoutlen', -1, 'E487')
57    should_fail('history', 1000000, 'E474')
58    should_fail('regexpengine', -1, 'E474')
59    should_fail('regexpengine', 3, 'E474')
60    should_succeed('regexpengine', 2)
61    should_fail('report', -1, 'E487')
62    should_succeed('report', 0)
63    should_fail('sidescroll', -1, 'E487')
64    should_fail('cmdwinheight', 0, 'E487')
65    should_fail('updatetime', -1, 'E487')
66
67    should_fail('foldlevel', -5, 'E487')
68    should_fail('foldcolumn', '13', 'E474')
69    should_fail('conceallevel', 4, 'E474')
70    should_fail('numberwidth', 21, 'E474')
71    should_fail('numberwidth', 0, 'E487')
72
73    -- If smaller than 1 this one is set to 'lines'-1
74    command('setglobal window=-10')
75    api.nvim_set_option_value('window', -10, {})
76    eq(23, api.nvim_get_option_value('window', {}))
77    eq('', eval('v:errmsg'))
78
79    -- 'scrolloff' and 'sidescrolloff' can have a -1 value when
80    -- set for the current window, but not globally
81    matches('E487:', pcall_err(command, 'setglobal scrolloff=-1'))
82    matches('E487:', pcall_err(command, 'setglobal sidescrolloff=-1'))
83
84    eq(true, pcall(command, 'setlocal scrolloff=-1'))
85    eq(true, pcall(command, 'setlocal sidescrolloff=-1'))
86  end)
87
88  it('set wmh/wh wmw/wiw checks', function()
89    command('set winheight=2')
90    matches('E591:', pcall_err(command, 'set winminheight=3'))
91
92    command('set winwidth=2')
93    matches('E592:', pcall_err(command, 'set winminwidth=3'))
94  end)
95
96  it('set maxcombine resets to 6', function()
97    local function setto(value)
98      command('setglobal maxcombine=' .. value)
99      command('setlocal maxcombine=' .. value)
100      api.nvim_set_option_value('maxcombine', value, {})
101      eq(6, api.nvim_get_option_value('maxcombine', {}))
102      eq('', eval('v:errmsg'))
103    end
104    setto(0)
105    setto(1)
106    setto(6)
107    setto(7)
108  end)
109end)