robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
1.6 KiB48 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 command = n.command
7local eq = t.eq
8local eval = n.eval
9local request = n.request
10local source = n.source
11
12describe('autocmd BufEnter', function()
13  before_each(clear)
14
15  it("triggered by nvim_command('edit <dir>')", function()
16    command("autocmd BufEnter * if isdirectory(expand('<afile>')) | let g:dir_bufenter = 1 | endif")
17    request('nvim_command', 'split .')
18    eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory.
19    eq(2, eval("bufnr('%')")) -- Switched to the dir buffer.
20  end)
21
22  it('triggered by "try|:split <dir>|endtry" in a function', function()
23    command("autocmd BufEnter * if isdirectory(expand('<afile>')) | let g:dir_bufenter = 1 | endif")
24    source([[
25      function! Test()
26        try
27          exe 'split .'
28        catch
29        endtry
30      endfunction
31    ]])
32    command('call Test()')
33    eq(1, eval("exists('g:dir_bufenter')")) -- Did BufEnter for the directory.
34    eq(2, eval("bufnr('%')")) -- Switched to the dir buffer.
35  end)
36
37  it('triggered by ":split normal|:help|:bw"', function()
38    n.add_builddir_to_rtp()
39    command('split normal')
40    command('wincmd j')
41    command('help')
42    command('wincmd L')
43    command('autocmd BufEnter normal let g:bufentered = 1')
44    command('bw')
45    eq(1, eval('bufnr("%")')) -- The cursor is back to the bottom window
46    eq(0, eval("exists('g:bufentered')")) -- The autocmd hasn't been triggered
47  end)
48end)