2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2022-04-02 19:55:41 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2021-05-28 12:45:34 -07:00
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local clear = n.clear
|
|
|
|
local command = n.command
|
2024-04-08 02:03:20 -07:00
|
|
|
local dedent = t.dedent
|
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
local fn = n.fn
|
|
|
|
local eval = n.eval
|
|
|
|
local exec = n.exec
|
|
|
|
local feed = n.feed
|
2021-05-28 12:45:34 -07:00
|
|
|
|
|
|
|
describe(':autocmd', function()
|
2022-04-02 19:55:41 -07:00
|
|
|
before_each(function()
|
|
|
|
clear({ '-u', 'NONE' })
|
|
|
|
end)
|
2021-05-28 12:45:34 -07:00
|
|
|
|
|
|
|
it('should not segfault when you just do autocmd', function()
|
|
|
|
command ':autocmd'
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('should filter based on ++once', function()
|
|
|
|
command 'autocmd! BufEnter'
|
|
|
|
command "autocmd BufEnter * :echo 'Hello'"
|
|
|
|
command [[augroup TestingOne]]
|
|
|
|
command [[ autocmd BufEnter * :echo "Line 1"]]
|
|
|
|
command [[ autocmd BufEnter * :echo "Line 2"]]
|
|
|
|
command [[augroup END]]
|
|
|
|
|
|
|
|
eq(
|
|
|
|
dedent([[
|
|
|
|
|
|
|
|
--- Autocommands ---
|
|
|
|
BufEnter
|
|
|
|
* :echo 'Hello'
|
|
|
|
TestingOne BufEnter
|
|
|
|
* :echo "Line 1"
|
|
|
|
:echo "Line 2"]]),
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.execute('autocmd BufEnter')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2022-04-02 19:55:41 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('should not show group information if interrupted', function()
|
|
|
|
local screen = Screen.new(50, 6)
|
2024-08-14 04:42:05 -07:00
|
|
|
screen:add_extra_attr_ids {
|
|
|
|
[100] = { foreground = Screen.colors.Magenta, bold = true },
|
|
|
|
}
|
2022-04-02 19:55:41 -07:00
|
|
|
screen:attach()
|
|
|
|
exec([[
|
|
|
|
set more
|
|
|
|
autocmd! BufEnter
|
|
|
|
augroup test_1
|
|
|
|
autocmd BufEnter A echo 'A'
|
|
|
|
autocmd BufEnter B echo 'B'
|
|
|
|
autocmd BufEnter C echo 'C'
|
|
|
|
autocmd BufEnter D echo 'D'
|
|
|
|
autocmd BufEnter E echo 'E'
|
|
|
|
autocmd BufEnter F echo 'F'
|
|
|
|
augroup END
|
|
|
|
autocmd! BufLeave
|
|
|
|
augroup test_1
|
|
|
|
autocmd BufLeave A echo 'A'
|
|
|
|
autocmd BufLeave B echo 'B'
|
|
|
|
autocmd BufLeave C echo 'C'
|
|
|
|
autocmd BufLeave D echo 'D'
|
|
|
|
autocmd BufLeave E echo 'E'
|
|
|
|
autocmd BufLeave F echo 'F'
|
|
|
|
augroup END
|
|
|
|
]])
|
|
|
|
feed(':autocmd<CR>')
|
|
|
|
screen:expect([[
|
|
|
|
:autocmd |
|
2024-08-14 04:42:05 -07:00
|
|
|
{100:--- Autocommands ---} |
|
|
|
|
{100:test_1} {100:BufEnter} |
|
2022-04-02 19:55:41 -07:00
|
|
|
A echo 'A' |
|
|
|
|
B echo 'B' |
|
2024-08-14 04:42:05 -07:00
|
|
|
{6:-- More --}^ |
|
2022-04-02 19:55:41 -07:00
|
|
|
]])
|
|
|
|
feed('q')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*4
|
2022-04-02 19:55:41 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('should not show group information for deleted pattern', function()
|
|
|
|
exec([[
|
|
|
|
autocmd! BufEnter
|
|
|
|
augroup test_1
|
|
|
|
autocmd BufEnter A echo 'A'
|
|
|
|
autocmd BufEnter B echo 'B'
|
|
|
|
autocmd BufEnter C echo 'C'
|
|
|
|
augroup END
|
|
|
|
augroup test_2
|
|
|
|
autocmd BufEnter foo echo 'foo'
|
|
|
|
augroup END
|
|
|
|
augroup test_3
|
|
|
|
autocmd BufEnter D echo 'D'
|
|
|
|
autocmd BufEnter E echo 'E'
|
|
|
|
autocmd BufEnter F echo 'F'
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
func Func()
|
|
|
|
autocmd! test_2 BufEnter
|
|
|
|
let g:output = execute('autocmd BufEnter')
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
autocmd User foo call Func()
|
|
|
|
doautocmd User foo
|
|
|
|
]])
|
|
|
|
eq(
|
|
|
|
dedent([[
|
|
|
|
|
|
|
|
--- Autocommands ---
|
|
|
|
test_1 BufEnter
|
|
|
|
A echo 'A'
|
|
|
|
B echo 'B'
|
|
|
|
C echo 'C'
|
|
|
|
test_3 BufEnter
|
|
|
|
D echo 'D'
|
|
|
|
E echo 'E'
|
|
|
|
F echo 'F']]),
|
|
|
|
eval('g:output')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2022-04-02 19:55:41 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('can filter by pattern #17973', function()
|
|
|
|
exec([[
|
|
|
|
autocmd! BufEnter
|
|
|
|
autocmd! User
|
|
|
|
augroup test_1
|
|
|
|
autocmd BufEnter A echo "A1"
|
|
|
|
autocmd BufEnter B echo "B1"
|
|
|
|
autocmd User A echo "A1"
|
|
|
|
autocmd User B echo "B1"
|
|
|
|
augroup END
|
|
|
|
augroup test_2
|
|
|
|
autocmd BufEnter A echo "A2"
|
|
|
|
autocmd BufEnter B echo "B2"
|
|
|
|
autocmd User A echo "A2"
|
|
|
|
autocmd User B echo "B2"
|
|
|
|
augroup END
|
|
|
|
augroup test_3
|
|
|
|
autocmd BufEnter A echo "A3"
|
|
|
|
autocmd BufEnter B echo "B3"
|
|
|
|
autocmd User A echo "A3"
|
|
|
|
autocmd User B echo "B3"
|
|
|
|
augroup END
|
|
|
|
]])
|
|
|
|
eq(
|
|
|
|
dedent([[
|
|
|
|
|
|
|
|
--- Autocommands ---
|
|
|
|
test_1 User
|
|
|
|
A echo "A1"
|
|
|
|
test_2 User
|
|
|
|
A echo "A2"
|
|
|
|
test_3 User
|
|
|
|
A echo "A3"]]),
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.execute('autocmd User A')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2022-04-02 19:55:41 -07:00
|
|
|
eq(
|
|
|
|
dedent([[
|
|
|
|
|
|
|
|
--- Autocommands ---
|
|
|
|
test_1 BufEnter
|
|
|
|
B echo "B1"
|
|
|
|
test_2 BufEnter
|
|
|
|
B echo "B2"
|
|
|
|
test_3 BufEnter
|
|
|
|
B echo "B3"
|
|
|
|
test_1 User
|
|
|
|
B echo "B1"
|
|
|
|
test_2 User
|
|
|
|
B echo "B2"
|
|
|
|
test_3 User
|
|
|
|
B echo "B3"]]),
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.execute('autocmd * B')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2022-04-02 19:55:41 -07:00
|
|
|
eq(
|
|
|
|
dedent([[
|
2021-05-28 12:45:34 -07:00
|
|
|
|
2022-04-02 19:55:41 -07:00
|
|
|
--- Autocommands ---
|
|
|
|
test_3 BufEnter
|
|
|
|
B echo "B3"
|
|
|
|
test_3 User
|
|
|
|
B echo "B3"]]),
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.execute('autocmd test_3 * B')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2021-05-28 12:45:34 -07:00
|
|
|
end)
|
2023-04-27 10:25:08 -07:00
|
|
|
|
|
|
|
it('should skip consecutive patterns', function()
|
|
|
|
exec([[
|
|
|
|
autocmd! BufEnter
|
|
|
|
augroup test_1
|
|
|
|
autocmd BufEnter A echo 'A'
|
|
|
|
autocmd BufEnter A echo 'B'
|
|
|
|
autocmd BufEnter A echo 'C'
|
|
|
|
autocmd BufEnter B echo 'D'
|
|
|
|
autocmd BufEnter B echo 'E'
|
|
|
|
autocmd BufEnter B echo 'F'
|
|
|
|
augroup END
|
|
|
|
augroup test_2
|
|
|
|
autocmd BufEnter C echo 'A'
|
|
|
|
autocmd BufEnter C echo 'B'
|
|
|
|
autocmd BufEnter C echo 'C'
|
|
|
|
autocmd BufEnter D echo 'D'
|
|
|
|
autocmd BufEnter D echo 'E'
|
|
|
|
autocmd BufEnter D echo 'F'
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
let g:output = execute('autocmd BufEnter')
|
|
|
|
]])
|
|
|
|
eq(
|
|
|
|
dedent([[
|
|
|
|
|
|
|
|
--- Autocommands ---
|
|
|
|
test_1 BufEnter
|
|
|
|
A echo 'A'
|
|
|
|
echo 'B'
|
|
|
|
echo 'C'
|
|
|
|
B echo 'D'
|
|
|
|
echo 'E'
|
|
|
|
echo 'F'
|
|
|
|
test_2 BufEnter
|
|
|
|
C echo 'A'
|
|
|
|
echo 'B'
|
|
|
|
echo 'C'
|
|
|
|
D echo 'D'
|
|
|
|
echo 'E'
|
|
|
|
echo 'F']]),
|
|
|
|
eval('g:output')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-04-27 10:25:08 -07:00
|
|
|
end)
|
2021-05-28 12:45:34 -07:00
|
|
|
end)
|