neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

num_options_spec.lua (3865B)


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