robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.4 KiB84 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 clear = n.clear
6local eq = t.eq
7local eval = n.eval
8local api = n.api
9local source = n.source
10local command = n.command
11local feed = n.feed
12
13describe('CursorMoved', function()
14  before_each(clear)
15
16  it('is triggered after BufEnter when changing or splitting windows #11878 #12031', function()
17    source([[
18      call setline(1, 'foo')
19      let g:log = []
20      autocmd BufEnter * let g:log += ['BufEnter' .. expand("<abuf>")]
21      autocmd CursorMoved * let g:log += ['CursorMoved' .. expand("<abuf>")]
22    ]])
23    eq({}, eval('g:log'))
24    command('new')
25    eq({ 'BufEnter2', 'CursorMoved2' }, eval('g:log'))
26    command('wincmd w')
27    eq({ 'BufEnter2', 'CursorMoved2', 'BufEnter1', 'CursorMoved1' }, eval('g:log'))
28  end)
29
30  it('is not triggered by temporarily switching window', function()
31    source([[
32      let g:cursormoved = 0
33      vnew
34      autocmd CursorMoved * let g:cursormoved += 1
35    ]])
36    command('wincmd w | wincmd p')
37    eq(0, eval('g:cursormoved'))
38  end)
39
40  it("is not triggered by functions that don't change the window", function()
41    source([[
42      let g:cursormoved = 0
43      let g:buf = bufnr('%')
44      vsplit foo
45      autocmd CursorMoved * let g:cursormoved += 1
46    ]])
47    api.nvim_buf_set_lines(eval('g:buf'), 0, -1, true, { 'aaa' })
48    eq(0, eval('g:cursormoved'))
49    eq({ 'aaa' }, api.nvim_buf_get_lines(eval('g:buf'), 0, -1, true))
50    eq(0, eval('g:cursormoved'))
51  end)
52
53  it('is not triggered by cursor movement prior to first CursorMoved instantiation', function()
54    eq({}, api.nvim_get_autocmds({ event = 'CursorMoved' }))
55    feed('ifoobar<Esc>')
56    source([[
57      let g:cursormoved = 0
58      autocmd CursorMoved * let g:cursormoved += 1
59    ]])
60    eq(0, eval('g:cursormoved'))
61    feed('<Ignore>')
62    eq(0, eval('g:cursormoved'))
63    feed('0')
64    eq(1, eval('g:cursormoved'))
65  end)
66end)
67
68describe('CursorMovedI', function()
69  before_each(clear)
70
71  it('is not triggered by cursor movement prior to first CursorMovedI instantiation', function()
72    eq({}, api.nvim_get_autocmds({ event = 'CursorMovedI' }))
73    feed('ifoobar')
74    source([[
75      let g:cursormovedi = 0
76      autocmd CursorMovedI * let g:cursormovedi += 1
77    ]])
78    eq(0, eval('g:cursormovedi'))
79    feed('<Ignore>')
80    eq(0, eval('g:cursormovedi'))
81    feed('<Home>')
82    eq(1, eval('g:cursormovedi'))
83  end)
84end)