robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
1.9 KiB60 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each = t.describe, t.it, t.before_each
5local eq = t.eq
6local eval = n.eval
7local clear = n.clear
8local command = n.command
9local source = n.source
10local request = n.request
11
12describe('autocmd', function()
13  describe('OptionSet modified', function()
14    before_each(clear)
15
16    it('is triggered when modified and un-modified', function()
17      source([[
18      let g:modified = 0
19      autocmd OptionSet modified let g:modified += 1
20      ]])
21      request('nvim_command', [[normal! aa\<Esc>]])
22      eq(1, eval('g:modified'))
23      request('nvim_command', [[normal! u]])
24      eq(2, eval('g:modified'))
25    end)
26
27    it('triggers when writes non-current buffer #32817', function()
28      source([[
29      let g:modified = 0
30      let g:second_trigger_buf = 0
31      autocmd OptionSet modified let g:modified += 1 | if g:modified == 2 | let g:second_trigger_buf = bufnr() | endif
32      ]])
33      request('nvim_command', [[edit test_a | badd test_b]])
34      request('nvim_command', [[normal! aa\<Esc>]])
35      request('nvim_command', [[let g:buf_a = bufnr()]])
36      request('nvim_command', [[bn]])
37      request('nvim_command', [[wa]])
38      os.remove('test_a')
39      eq({ 2, true }, { eval('g:modified'), eval('g:buf_a') == eval('g:second_trigger_buf') })
40    end)
41
42    it('OptionSet triggers correctly when modified changes', function()
43      command([[
44        autocmd OptionSet modified call add(g:messages, string(!!v:option_old) . ' -> ' . string(!!v:option_new) . ' - actual: ' . &modified)
45      ]])
46      command('let g:messages = []')
47      local fname = t.tmpname()
48      command('new ' .. fname)
49      command("call setline(1, 'hi')")
50      command('write')
51      command('set modified')
52      eq({
53        '0 -> 1 - actual: 1',
54        '1 -> 0 - actual: 0',
55        '0 -> 1 - actual: 1',
56      }, eval('g:messages'))
57      os.remove(fname)
58    end)
59  end)
60end)