neovim

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

autocmd_option_spec.lua (25605B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 
      4 local clear, eq, neq, eval = n.clear, t.eq, t.neq, n.eval
      5 local api = n.api
      6 local curbuf = n.api.nvim_get_current_buf
      7 local curwin = n.api.nvim_get_current_win
      8 local exec_capture = n.exec_capture
      9 local source, command = n.source, n.command
     10 
     11 local function declare_hook_function()
     12  source([[
     13    fu! AutoCommand(match, bufnr, winnr)
     14      let l:acc = {
     15      \   'option'   : a:match,
     16      \   'oldval'   : v:option_old,
     17      \   'oldval_l' : v:option_oldlocal,
     18      \   'oldval_g' : v:option_oldglobal,
     19      \   'newval'   : v:option_new,
     20      \   'scope'    : v:option_type,
     21      \   'cmd'      : v:option_command,
     22      \   'attr'     : {
     23      \     'bufnr' : a:bufnr,
     24      \     'winnr' : a:winnr,
     25      \   }
     26      \ }
     27      call add(g:ret, l:acc)
     28    endfu
     29  ]])
     30 end
     31 
     32 local function set_hook(pattern)
     33  command(
     34    'au OptionSet ' .. pattern .. ' :call AutoCommand(expand("<amatch>"), bufnr("%"), winnr())'
     35  )
     36 end
     37 
     38 local function init_var()
     39  command('let g:ret = []')
     40 end
     41 
     42 local function get_result()
     43  local ret = api.nvim_get_var('ret')
     44  init_var()
     45  return ret
     46 end
     47 
     48 local function expected_table(option, oldval, oldval_l, oldval_g, newval, scope, cmd, attr)
     49  return {
     50    option = option,
     51    oldval = oldval,
     52    oldval_l = oldval_l,
     53    oldval_g = oldval_g,
     54    newval = newval,
     55    scope = scope,
     56    cmd = cmd,
     57    attr = attr,
     58  }
     59 end
     60 
     61 local function expected_combination(...)
     62  local args = { ... }
     63  local ret = get_result()
     64 
     65  if not (#args == #ret) then
     66    local expecteds = {}
     67    for _, v in pairs(args) do
     68      table.insert(expecteds, expected_table(unpack(v)))
     69    end
     70    eq(expecteds, ret)
     71    return
     72  end
     73 
     74  for i, v in ipairs(args) do
     75    local attr = v[8]
     76    if not attr then
     77      -- remove attr entries
     78      ret[i].attr = nil
     79    else
     80      -- remove attr entries which are not required
     81      for k in pairs(ret[i].attr) do
     82        if not attr[k] then
     83          ret[i].attr[k] = nil
     84        end
     85      end
     86    end
     87    eq(expected_table(unpack(v)), ret[i])
     88  end
     89 end
     90 
     91 local function expected_empty()
     92  eq({}, get_result())
     93 end
     94 
     95 local function make_buffer()
     96  local old_buf = curbuf()
     97  command('botright new')
     98  local new_buf = curbuf()
     99  command('wincmd p') -- move previous window
    100 
    101  neq(old_buf, new_buf)
    102  eq(old_buf, curbuf())
    103 
    104  return new_buf
    105 end
    106 
    107 local function get_new_window_number()
    108  local old_win = curwin()
    109  command('botright new')
    110  local new_win = curwin()
    111  local new_winnr = exec_capture('echo winnr()')
    112  command('wincmd p') -- move previous window
    113 
    114  neq(old_win, new_win)
    115  eq(old_win, curwin())
    116 
    117  return new_winnr
    118 end
    119 
    120 describe('au OptionSet', function()
    121  describe('with any option (*)', function()
    122    before_each(function()
    123      clear()
    124      declare_hook_function()
    125      init_var()
    126      set_hook('*')
    127    end)
    128 
    129    it('should be called in setting number option', function()
    130      command('set nu')
    131      expected_combination({ 'number', false, false, false, true, 'global', 'set' })
    132 
    133      command('setlocal nonu')
    134      expected_combination({ 'number', true, true, '', false, 'local', 'setlocal' })
    135 
    136      command('setglobal nonu')
    137      expected_combination({ 'number', true, '', true, false, 'global', 'setglobal' })
    138    end)
    139 
    140    it('should be called in setting autoindent option', function()
    141      command('setlocal ai')
    142      expected_combination({ 'autoindent', false, false, '', true, 'local', 'setlocal' })
    143 
    144      command('setglobal ai')
    145      expected_combination({ 'autoindent', false, '', false, true, 'global', 'setglobal' })
    146 
    147      command('set noai')
    148      expected_combination({ 'autoindent', true, true, true, false, 'global', 'set' })
    149    end)
    150 
    151    it('should be called in inverting global autoindent option', function()
    152      command('set ai!')
    153      expected_combination({ 'autoindent', false, false, false, true, 'global', 'set' })
    154    end)
    155 
    156    it('should be called in being unset local autoindent option', function()
    157      command('setlocal ai')
    158      expected_combination({ 'autoindent', false, false, '', true, 'local', 'setlocal' })
    159 
    160      command('setlocal ai<')
    161      expected_combination({ 'autoindent', true, true, '', false, 'local', 'setlocal' })
    162    end)
    163 
    164    it('should be called in setting global list and number option at the same time', function()
    165      command('set list nu')
    166      expected_combination(
    167        { 'list', false, false, false, true, 'global', 'set' },
    168        { 'number', false, false, false, true, 'global', 'set' }
    169      )
    170    end)
    171 
    172    it('should not print anything, use :noa', function()
    173      command('noa set nolist nonu')
    174      expected_empty()
    175    end)
    176 
    177    it('should be called in setting local acd', function()
    178      command('setlocal acd')
    179      expected_combination({ 'autochdir', false, false, '', true, 'local', 'setlocal' })
    180    end)
    181 
    182    it('should be called in setting autoread', function()
    183      command('set noar')
    184      expected_combination({ 'autoread', true, true, true, false, 'global', 'set' })
    185 
    186      command('setlocal ar')
    187      expected_combination({ 'autoread', false, false, '', true, 'local', 'setlocal' })
    188    end)
    189 
    190    it('should be called in inverting global autoread', function()
    191      command('setglobal invar')
    192      expected_combination({ 'autoread', true, '', true, false, 'global', 'setglobal' })
    193    end)
    194 
    195    it('should be called in setting backspace option through :let', function()
    196      local oldval = eval('&backspace')
    197 
    198      command('let &bs=""')
    199      expected_combination({ 'backspace', oldval, oldval, oldval, '', 'global', 'set' })
    200    end)
    201 
    202    describe('being set by setbufvar()', function()
    203      it('should not trigger because option name is invalid', function()
    204        command('silent! call setbufvar(1, "&l:bk", 1)')
    205        expected_empty()
    206      end)
    207 
    208      it('should trigger using correct option name', function()
    209        command('call setbufvar(1, "&backup", 1)')
    210        expected_combination({ 'backup', false, false, '', true, 'local', 'setlocal' })
    211      end)
    212 
    213      it('should trigger if the current buffer is different from the targeted buffer', function()
    214        local new_buffer = make_buffer()
    215        local new_bufnr = api.nvim_buf_get_number(new_buffer)
    216 
    217        command('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")')
    218        expected_combination({
    219          'buftype',
    220          '',
    221          '',
    222          '',
    223          'nofile',
    224          'local',
    225          'setlocal',
    226          { bufnr = new_bufnr },
    227        })
    228      end)
    229    end)
    230 
    231    it('with string global option', function()
    232      local oldval = eval('&backupext')
    233 
    234      command('set backupext=foo')
    235      expected_combination({ 'backupext', oldval, oldval, oldval, 'foo', 'global', 'set' })
    236 
    237      command('set backupext&')
    238      expected_combination({ 'backupext', 'foo', 'foo', 'foo', oldval, 'global', 'set' })
    239 
    240      command('setglobal backupext=bar')
    241      expected_combination({ 'backupext', oldval, '', oldval, 'bar', 'global', 'setglobal' })
    242 
    243      command('noa set backupext&')
    244      -- As this is a global option this sets the global value even though :setlocal is used!
    245      command('setlocal backupext=baz')
    246      expected_combination({ 'backupext', oldval, oldval, '', 'baz', 'local', 'setlocal' })
    247 
    248      command('noa setglobal backupext=ext_global')
    249      command('noa setlocal backupext=ext_local') -- Sets the global(!) value
    250      command('set backupext=foo')
    251      expected_combination({
    252        'backupext',
    253        'ext_local',
    254        'ext_local',
    255        'ext_local',
    256        'foo',
    257        'global',
    258        'set',
    259      })
    260    end)
    261 
    262    it('with string global-local (to buffer) option', function()
    263      local oldval = eval('&tags')
    264 
    265      command('set tags=tagpath')
    266      expected_combination({ 'tags', oldval, oldval, oldval, 'tagpath', 'global', 'set' })
    267 
    268      command('set tags&')
    269      expected_combination({ 'tags', 'tagpath', 'tagpath', 'tagpath', oldval, 'global', 'set' })
    270 
    271      command('setglobal tags=tagpath1')
    272      expected_combination({ 'tags', oldval, '', oldval, 'tagpath1', 'global', 'setglobal' })
    273 
    274      command('setlocal tags=tagpath2')
    275      expected_combination({ 'tags', 'tagpath1', 'tagpath1', '', 'tagpath2', 'local', 'setlocal' })
    276 
    277      -- Note: v:option_old is the old global value for global-local options.
    278      -- but the old local value for all other kinds of options.
    279      command('noa setglobal tags=tag_global')
    280      command('noa setlocal tags=tag_local')
    281      command('set tags=tagpath')
    282      expected_combination({
    283        'tags',
    284        'tag_global',
    285        'tag_local',
    286        'tag_global',
    287        'tagpath',
    288        'global',
    289        'set',
    290      })
    291 
    292      -- Note: v:option_old is the old global value for global-local options.
    293      -- but the old local value for all other kinds of options.
    294      command('noa set tags=tag_global')
    295      command('noa setlocal tags=')
    296      command('set tags=tagpath')
    297      expected_combination({
    298        'tags',
    299        'tag_global',
    300        'tag_global',
    301        'tag_global',
    302        'tagpath',
    303        'global',
    304        'set',
    305      })
    306    end)
    307 
    308    it('with string local (to buffer) option', function()
    309      local oldval = eval('&spelllang')
    310 
    311      command('set spelllang=elvish,klingon')
    312      expected_combination({
    313        'spelllang',
    314        oldval,
    315        oldval,
    316        oldval,
    317        'elvish,klingon',
    318        'global',
    319        'set',
    320      })
    321 
    322      command('set spelllang&')
    323      expected_combination({
    324        'spelllang',
    325        'elvish,klingon',
    326        'elvish,klingon',
    327        'elvish,klingon',
    328        oldval,
    329        'global',
    330        'set',
    331      })
    332 
    333      command('setglobal spelllang=elvish')
    334      expected_combination({ 'spelllang', oldval, '', oldval, 'elvish', 'global', 'setglobal' })
    335 
    336      command('noa set spelllang&')
    337      command('setlocal spelllang=klingon')
    338      expected_combination({ 'spelllang', oldval, oldval, '', 'klingon', 'local', 'setlocal' })
    339 
    340      -- Note: v:option_old is the old global value for global-local options.
    341      -- but the old local value for all other kinds of options.
    342      command('noa setglobal spelllang=spellglobal')
    343      command('noa setlocal spelllang=spelllocal')
    344      command('set spelllang=foo')
    345      expected_combination({
    346        'spelllang',
    347        'spelllocal',
    348        'spelllocal',
    349        'spellglobal',
    350        'foo',
    351        'global',
    352        'set',
    353      })
    354    end)
    355 
    356    it('with string global-local (to window) option', function()
    357      local oldval = eval('&statusline')
    358      local default_statusline = api.nvim_get_option_info2('statusline', {}).default
    359 
    360      command('set statusline=foo')
    361      expected_combination({
    362        'statusline',
    363        oldval,
    364        oldval,
    365        oldval,
    366        'foo',
    367        'global',
    368        'set',
    369      })
    370 
    371      -- Note: v:option_old is the old global value for global-local options.
    372      -- but the old local value for all other kinds of options.
    373      command('set statusline&')
    374      expected_combination({
    375        'statusline',
    376        'foo',
    377        'foo',
    378        'foo',
    379        default_statusline,
    380        'global',
    381        'set',
    382      })
    383 
    384      command('setglobal statusline=bar')
    385      expected_combination({
    386        'statusline',
    387        default_statusline,
    388        '',
    389        default_statusline,
    390        'bar',
    391        'global',
    392        'setglobal',
    393      })
    394 
    395      command('noa set statusline&')
    396      command('setlocal statusline=baz')
    397      expected_combination({
    398        'statusline',
    399        default_statusline,
    400        default_statusline,
    401        '',
    402        'baz',
    403        'local',
    404        'setlocal',
    405      })
    406 
    407      -- Note: v:option_old is the old global value for global-local options.
    408      -- but the old local value for all other kinds of options.
    409      command('noa setglobal statusline=bar')
    410      command('noa setlocal statusline=baz')
    411      command('set statusline=foo')
    412      expected_combination({ 'statusline', 'bar', 'baz', 'bar', 'foo', 'global', 'set' })
    413    end)
    414 
    415    it('with string local (to window) option', function()
    416      local oldval = eval('&foldignore')
    417 
    418      command('set foldignore=fo')
    419      expected_combination({ 'foldignore', oldval, oldval, oldval, 'fo', 'global', 'set' })
    420 
    421      command('set foldignore&')
    422      expected_combination({ 'foldignore', 'fo', 'fo', 'fo', oldval, 'global', 'set' })
    423 
    424      command('setglobal foldignore=bar')
    425      expected_combination({ 'foldignore', oldval, '', oldval, 'bar', 'global', 'setglobal' })
    426 
    427      command('noa set foldignore&')
    428      command('setlocal foldignore=baz')
    429      expected_combination({ 'foldignore', oldval, oldval, '', 'baz', 'local', 'setlocal' })
    430 
    431      command('noa setglobal foldignore=glob')
    432      command('noa setlocal foldignore=loc')
    433      command('set foldignore=fo')
    434      expected_combination({ 'foldignore', 'loc', 'loc', 'glob', 'fo', 'global', 'set' })
    435    end)
    436 
    437    it('with number global option', function()
    438      command('noa setglobal cmdheight=8')
    439      command('noa setlocal cmdheight=1') -- Sets the global(!) value
    440      command('setglobal cmdheight=2')
    441      expected_combination({ 'cmdheight', 1, '', 1, 2, 'global', 'setglobal' })
    442 
    443      command('noa setglobal cmdheight=8')
    444      command('noa setlocal cmdheight=1') -- Sets the global(!) value
    445      command('setlocal cmdheight=2')
    446      expected_combination({ 'cmdheight', 1, 1, '', 2, 'local', 'setlocal' })
    447 
    448      -- Note: v:option_old is the old global value for global-local options.
    449      -- but the old local value for all other kinds of options.
    450      command('noa setglobal cmdheight=8')
    451      command('noa setlocal cmdheight=1') -- Sets the global(!) value
    452      command('set cmdheight=2')
    453      expected_combination({ 'cmdheight', 1, 1, 1, 2, 'global', 'set' })
    454 
    455      -- Note: v:option_old is the old global value for global-local options.
    456      -- but the old local value for all other kinds of options.
    457      command('noa set cmdheight=8')
    458      command('set cmdheight=2')
    459      expected_combination({ 'cmdheight', 8, 8, 8, 2, 'global', 'set' })
    460    end)
    461 
    462    it('with number global-local (to buffer) option', function()
    463      command('noa setglobal undolevels=8')
    464      command('noa setlocal undolevels=1')
    465      command('setglobal undolevels=2')
    466      expected_combination({ 'undolevels', 8, '', 8, 2, 'global', 'setglobal' })
    467 
    468      command('noa setglobal undolevels=8')
    469      command('noa setlocal undolevels=1')
    470      command('setlocal undolevels=2')
    471      expected_combination({ 'undolevels', 1, 1, '', 2, 'local', 'setlocal' })
    472 
    473      -- Note: v:option_old is the old global value for global-local options.
    474      -- but the old local value for all other kinds of options.
    475      command('noa setglobal undolevels=8')
    476      command('noa setlocal undolevels=1')
    477      command('set undolevels=2')
    478      expected_combination({ 'undolevels', 8, 1, 8, 2, 'global', 'set' })
    479 
    480      -- Note: v:option_old is the old global value for global-local options.
    481      -- but the old local value for all other kinds of options.
    482      command('noa set undolevels=8')
    483      command('set undolevels=2')
    484      expected_combination({ 'undolevels', 8, 8, 8, 2, 'global', 'set' })
    485    end)
    486 
    487    it('with number local (to buffer) option', function()
    488      command('noa setglobal wrapmargin=8')
    489      command('noa setlocal wrapmargin=1')
    490      command('setglobal wrapmargin=2')
    491      expected_combination({ 'wrapmargin', 8, '', 8, 2, 'global', 'setglobal' })
    492 
    493      command('noa setglobal wrapmargin=8')
    494      command('noa setlocal wrapmargin=1')
    495      command('setlocal wrapmargin=2')
    496      expected_combination({ 'wrapmargin', 1, 1, '', 2, 'local', 'setlocal' })
    497 
    498      command('noa setglobal wrapmargin=8')
    499      command('noa setlocal wrapmargin=1')
    500      command('set wrapmargin=2')
    501      expected_combination({ 'wrapmargin', 1, 1, 8, 2, 'global', 'set' })
    502 
    503      command('noa set wrapmargin=8')
    504      command('set wrapmargin=2')
    505      expected_combination({ 'wrapmargin', 8, 8, 8, 2, 'global', 'set' })
    506    end)
    507 
    508    it('with number global-local (to window) option', function()
    509      command('noa setglobal scrolloff=8')
    510      command('noa setlocal scrolloff=1')
    511      command('setglobal scrolloff=2')
    512      expected_combination({ 'scrolloff', 8, '', 8, 2, 'global', 'setglobal' })
    513 
    514      command('noa setglobal scrolloff=8')
    515      command('noa setlocal scrolloff=1')
    516      command('setlocal scrolloff=2')
    517      expected_combination({ 'scrolloff', 1, 1, '', 2, 'local', 'setlocal' })
    518 
    519      -- Note: v:option_old is the old global value for global-local options.
    520      -- but the old local value for all other kinds of options.
    521      command('noa setglobal scrolloff=8')
    522      command('noa setlocal scrolloff=1')
    523      command('set scrolloff=2')
    524      expected_combination({ 'scrolloff', 8, 1, 8, 2, 'global', 'set' })
    525 
    526      -- Note: v:option_old is the old global value for global-local options.
    527      -- but the old local value for all other kinds of options.
    528      command('noa set scrolloff=8')
    529      command('set scrolloff=2')
    530      expected_combination({ 'scrolloff', 8, 8, 8, 2, 'global', 'set' })
    531    end)
    532 
    533    it('with number local (to window) option', function()
    534      command('noa setglobal foldcolumn=8')
    535      command('noa setlocal foldcolumn=1')
    536      command('setglobal foldcolumn=2')
    537      expected_combination({ 'foldcolumn', '8', '', '8', '2', 'global', 'setglobal' })
    538 
    539      command('noa setglobal foldcolumn=8')
    540      command('noa setlocal foldcolumn=1')
    541      command('setlocal foldcolumn=2')
    542      expected_combination({ 'foldcolumn', '1', '1', '', '2', 'local', 'setlocal' })
    543 
    544      command('noa setglobal foldcolumn=8')
    545      command('noa setlocal foldcolumn=1')
    546      command('set foldcolumn=2')
    547      expected_combination({ 'foldcolumn', '1', '1', '8', '2', 'global', 'set' })
    548 
    549      command('noa set foldcolumn=8')
    550      command('set foldcolumn=2')
    551      expected_combination({ 'foldcolumn', '8', '8', '8', '2', 'global', 'set' })
    552    end)
    553 
    554    it('with boolean global option', function()
    555      command('noa setglobal nowrapscan')
    556      command('noa setlocal wrapscan') -- Sets the global(!) value
    557      command('setglobal nowrapscan')
    558      expected_combination({ 'wrapscan', true, '', true, false, 'global', 'setglobal' })
    559 
    560      command('noa setglobal nowrapscan')
    561      command('noa setlocal wrapscan') -- Sets the global(!) value
    562      command('setlocal nowrapscan')
    563      expected_combination({ 'wrapscan', true, true, '', false, 'local', 'setlocal' })
    564 
    565      command('noa setglobal nowrapscan')
    566      command('noa setlocal wrapscan') -- Sets the global(!) value
    567      command('set nowrapscan')
    568      expected_combination({ 'wrapscan', true, true, true, false, 'global', 'set' })
    569 
    570      command('noa set nowrapscan')
    571      command('set wrapscan')
    572      expected_combination({ 'wrapscan', false, false, false, true, 'global', 'set' })
    573    end)
    574 
    575    it('with boolean global-local (to buffer) option', function()
    576      command('noa setglobal noautoread')
    577      command('noa setlocal autoread')
    578      command('setglobal autoread')
    579      expected_combination({ 'autoread', false, '', false, true, 'global', 'setglobal' })
    580 
    581      command('noa setglobal noautoread')
    582      command('noa setlocal autoread')
    583      command('setlocal noautoread')
    584      expected_combination({ 'autoread', true, true, '', false, 'local', 'setlocal' })
    585 
    586      -- Note: v:option_old is the old global value for global-local options.
    587      -- but the old local value for all other kinds of options.
    588      command('noa setglobal noautoread')
    589      command('noa setlocal autoread')
    590      command('set autoread')
    591      expected_combination({ 'autoread', false, true, false, true, 'global', 'set' })
    592 
    593      -- Note: v:option_old is the old global value for global-local options.
    594      -- but the old local value for all other kinds of options.
    595      command('noa set noautoread')
    596      command('set autoread')
    597      expected_combination({ 'autoread', false, false, false, true, 'global', 'set' })
    598    end)
    599 
    600    it('with boolean local (to buffer) option', function()
    601      command('noa setglobal nocindent')
    602      command('noa setlocal cindent')
    603      command('setglobal cindent')
    604      expected_combination({ 'cindent', false, '', false, true, 'global', 'setglobal' })
    605 
    606      command('noa setglobal nocindent')
    607      command('noa setlocal cindent')
    608      command('setlocal nocindent')
    609      expected_combination({ 'cindent', true, true, '', false, 'local', 'setlocal' })
    610 
    611      command('noa setglobal nocindent')
    612      command('noa setlocal cindent')
    613      command('set cindent')
    614      expected_combination({ 'cindent', true, true, false, true, 'global', 'set' })
    615 
    616      command('noa set nocindent')
    617      command('set cindent')
    618      expected_combination({ 'cindent', false, false, false, true, 'global', 'set' })
    619    end)
    620 
    621    it('with boolean local (to window) option', function()
    622      command('noa setglobal nocursorcolumn')
    623      command('noa setlocal cursorcolumn')
    624      command('setglobal cursorcolumn')
    625      expected_combination({ 'cursorcolumn', false, '', false, true, 'global', 'setglobal' })
    626 
    627      command('noa setglobal nocursorcolumn')
    628      command('noa setlocal cursorcolumn')
    629      command('setlocal nocursorcolumn')
    630      expected_combination({ 'cursorcolumn', true, true, '', false, 'local', 'setlocal' })
    631 
    632      command('noa setglobal nocursorcolumn')
    633      command('noa setlocal cursorcolumn')
    634      command('set cursorcolumn')
    635      expected_combination({ 'cursorcolumn', true, true, false, true, 'global', 'set' })
    636 
    637      command('noa set nocursorcolumn')
    638      command('set cursorcolumn')
    639      expected_combination({ 'cursorcolumn', false, false, false, true, 'global', 'set' })
    640    end)
    641  end)
    642 
    643  describe('with specific option', function()
    644    before_each(function()
    645      clear()
    646      declare_hook_function()
    647      init_var()
    648    end)
    649 
    650    it('should be called iff setting readonly', function()
    651      set_hook('readonly')
    652 
    653      command('set nu')
    654      expected_empty()
    655 
    656      command('setlocal ro')
    657      expected_combination({ 'readonly', false, false, '', true, 'local', 'setlocal' })
    658 
    659      command('setglobal ro')
    660      expected_combination({ 'readonly', false, '', false, true, 'global', 'setglobal' })
    661 
    662      command('set noro')
    663      expected_combination({ 'readonly', true, true, true, false, 'global', 'set' })
    664    end)
    665 
    666    describe('being set by setbufvar()', function()
    667      it('should not trigger because option name does not match with backup', function()
    668        set_hook('backup')
    669 
    670        command('silent! call setbufvar(1, "&l:bk", 1)')
    671        expected_empty()
    672      end)
    673 
    674      it('should trigger, use correct option name backup', function()
    675        set_hook('backup')
    676 
    677        command('call setbufvar(1, "&backup", 1)')
    678        expected_combination({ 'backup', false, false, '', true, 'local', 'setlocal' })
    679      end)
    680 
    681      it('should trigger if the current buffer is different from the targeted buffer', function()
    682        set_hook('buftype')
    683 
    684        local new_buffer = make_buffer()
    685        local new_bufnr = api.nvim_buf_get_number(new_buffer)
    686 
    687        command('call setbufvar(' .. new_bufnr .. ', "&buftype", "nofile")')
    688        expected_combination({
    689          'buftype',
    690          '',
    691          '',
    692          '',
    693          'nofile',
    694          'local',
    695          'setlocal',
    696          { bufnr = new_bufnr },
    697        })
    698      end)
    699    end)
    700 
    701    describe('being set by setwinvar()', function()
    702      it('should not trigger because option name does not match with backup', function()
    703        set_hook('backup')
    704 
    705        command('silent! call setwinvar(1, "&l:bk", 1)')
    706        expected_empty()
    707      end)
    708 
    709      it('should trigger, use correct option name backup', function()
    710        set_hook('backup')
    711 
    712        command('call setwinvar(1, "&backup", 1)')
    713        expected_combination({ 'backup', false, false, '', true, 'local', 'setlocal' })
    714      end)
    715 
    716      it(
    717        'should not trigger if the current window is different from the targeted window',
    718        function()
    719          set_hook('cursorcolumn')
    720 
    721          local new_winnr = get_new_window_number()
    722 
    723          command('call setwinvar(' .. new_winnr .. ', "&cursorcolumn", 1)')
    724          -- expected_combination({'cursorcolumn', false, true, 'local', {winnr = new_winnr}})
    725          expected_empty()
    726        end
    727      )
    728    end)
    729 
    730    describe('being set by neovim api', function()
    731      it('should trigger if a boolean option be set globally', function()
    732        set_hook('autochdir')
    733 
    734        api.nvim_set_option_value('autochdir', true, { scope = 'global' })
    735        eq(true, api.nvim_get_option_value('autochdir', { scope = 'global' }))
    736        expected_combination({ 'autochdir', false, '', false, true, 'global', 'setglobal' })
    737      end)
    738 
    739      it('should trigger if a number option be set globally', function()
    740        set_hook('cmdheight')
    741 
    742        api.nvim_set_option_value('cmdheight', 5, { scope = 'global' })
    743        eq(5, api.nvim_get_option_value('cmdheight', { scope = 'global' }))
    744        expected_combination({ 'cmdheight', 1, '', 1, 5, 'global', 'setglobal' })
    745      end)
    746 
    747      it('should trigger if a string option be set globally', function()
    748        set_hook('ambiwidth')
    749 
    750        api.nvim_set_option_value('ambiwidth', 'double', { scope = 'global' })
    751        eq('double', api.nvim_get_option_value('ambiwidth', { scope = 'global' }))
    752        expected_combination({
    753          'ambiwidth',
    754          'single',
    755          '',
    756          'single',
    757          'double',
    758          'global',
    759          'setglobal',
    760        })
    761      end)
    762    end)
    763  end)
    764 end)