aboutsummaryrefslogtreecommitdiff
path: root/test/functional/autocmd
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-05-24 19:18:11 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-05-24 19:18:11 +0000
commitff7ed8f586589d620a806c3758fac4a47a8e7e15 (patch)
tree729bbcb92231538fa61dab6c3d890b025484b7f5 /test/functional/autocmd
parent376914f419eb08fdf4c1a63a77e1f035898a0f10 (diff)
parent28c04948a1c887a1cc0cb64de79fa32631700466 (diff)
downloadrneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.gz
rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.bz2
rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'test/functional/autocmd')
-rw-r--r--test/functional/autocmd/autocmd_oldtest_spec.lua30
-rw-r--r--test/functional/autocmd/autocmd_spec.lua120
-rw-r--r--test/functional/autocmd/bufenter_spec.lua17
-rw-r--r--test/functional/autocmd/bufmodifiedset_spec.lua13
-rw-r--r--test/functional/autocmd/cmdline_spec.lua19
-rw-r--r--test/functional/autocmd/completedone_spec.lua41
-rw-r--r--test/functional/autocmd/cursorhold_spec.lua15
-rw-r--r--test/functional/autocmd/cursormoved_spec.lua15
-rw-r--r--test/functional/autocmd/dirchanged_spec.lua19
-rw-r--r--test/functional/autocmd/filetype_spec.lua10
-rw-r--r--test/functional/autocmd/focus_spec.lua20
-rw-r--r--test/functional/autocmd/modechanged_spec.lua10
-rw-r--r--test/functional/autocmd/recording_spec.lua11
-rw-r--r--test/functional/autocmd/safestate_spec.lua14
-rw-r--r--test/functional/autocmd/searchwrapped_spec.lua17
-rw-r--r--test/functional/autocmd/show_spec.lua19
-rw-r--r--test/functional/autocmd/signal_spec.lua19
-rw-r--r--test/functional/autocmd/tabclose_spec.lua10
-rw-r--r--test/functional/autocmd/tabnew_spec.lua11
-rw-r--r--test/functional/autocmd/tabnewentered_spec.lua21
-rw-r--r--test/functional/autocmd/termxx_spec.lua33
-rw-r--r--test/functional/autocmd/textchanged_spec.lua142
-rw-r--r--test/functional/autocmd/textyankpost_spec.lua16
-rw-r--r--test/functional/autocmd/win_scrolled_resized_spec.lua19
24 files changed, 394 insertions, 267 deletions
diff --git a/test/functional/autocmd/autocmd_oldtest_spec.lua b/test/functional/autocmd/autocmd_oldtest_spec.lua
index 0243674f2d..1a3b723ac2 100644
--- a/test/functional/autocmd/autocmd_oldtest_spec.lua
+++ b/test/functional/autocmd/autocmd_oldtest_spec.lua
@@ -1,16 +1,27 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
-local clear = helpers.clear
-local eq = helpers.eq
-local api = helpers.api
-local fn = helpers.fn
-local exec = helpers.exec
-local feed = helpers.feed
+local clear = n.clear
+local eq = t.eq
+local api = n.api
+local fn = n.fn
+local exec = n.exec
+local feed = n.feed
+local assert_log = t.assert_log
+local check_close = n.check_close
+local is_os = t.is_os
+
+local testlog = 'Xtest_autocmd_oldtest_log'
describe('oldtests', function()
before_each(clear)
+ after_each(function()
+ check_close()
+ os.remove(testlog)
+ end)
+
local exec_lines = function(str)
return fn.split(fn.execute(str), '\n')
end
@@ -49,6 +60,7 @@ describe('oldtests', function()
end)
it('should fire on unload buf', function()
+ clear({ env = { NVIM_LOG_FILE = testlog } })
fn.writefile({ 'Test file Xxx1' }, 'Xxx1')
fn.writefile({ 'Test file Xxx2' }, 'Xxx2')
local fname = 'Xtest_functional_autocmd_unload'
@@ -81,6 +93,10 @@ describe('oldtests', function()
fn.delete('Xxx2')
fn.delete(fname)
fn.delete('Xout')
+
+ if is_os('win') then
+ assert_log('stream write failed. RPC canceled; closing channel', testlog)
+ end
end)
-- oldtest: Test_delete_ml_get_errors()
diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua
index 5fffb70095..5e407a9986 100644
--- a/test/functional/autocmd/autocmd_spec.lua
+++ b/test/functional/autocmd/autocmd_spec.lua
@@ -1,24 +1,25 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
-local assert_visible = helpers.assert_visible
-local assert_alive = helpers.assert_alive
-local dedent = helpers.dedent
-local eq = helpers.eq
-local neq = helpers.neq
-local eval = helpers.eval
-local feed = helpers.feed
-local clear = helpers.clear
-local matches = helpers.matches
-local api = helpers.api
-local pcall_err = helpers.pcall_err
-local fn = helpers.fn
-local expect = helpers.expect
-local command = helpers.command
-local exc_exec = helpers.exc_exec
-local exec_lua = helpers.exec_lua
-local retry = helpers.retry
-local source = helpers.source
+local assert_visible = n.assert_visible
+local assert_alive = n.assert_alive
+local dedent = t.dedent
+local eq = t.eq
+local neq = t.neq
+local eval = n.eval
+local feed = n.feed
+local clear = n.clear
+local matches = t.matches
+local api = n.api
+local pcall_err = t.pcall_err
+local fn = n.fn
+local expect = n.expect
+local command = n.command
+local exc_exec = n.exc_exec
+local exec_lua = n.exec_lua
+local retry = t.retry
+local source = n.source
describe('autocmd', function()
before_each(clear)
@@ -371,6 +372,31 @@ describe('autocmd', function()
assert_alive()
screen:expect_unchanged()
+ -- Also check with win_splitmove().
+ exec_lua [[
+ vim.api.nvim_buf_call(_G.buf, function()
+ vim.fn.win_splitmove(vim.fn.winnr(), vim.fn.win_getid(1))
+ end)
+ ]]
+ screen:expect_unchanged()
+
+ -- Also check with nvim_win_set_config().
+ matches(
+ ': Failed to move window %d+ into split$',
+ pcall_err(
+ exec_lua,
+ [[
+ vim.api.nvim_buf_call(_G.buf, function()
+ vim.api.nvim_win_set_config(0, {
+ vertical = true,
+ win = vim.fn.win_getid(1)
+ })
+ end)
+ ]]
+ )
+ )
+ screen:expect_unchanged()
+
-- Ensure splitting still works from inside the aucmd_win.
exec_lua [[vim.api.nvim_buf_call(_G.buf, function() vim.cmd "split" end)]]
screen:expect [[
@@ -391,12 +417,12 @@ describe('autocmd', function()
eq(
'editor',
exec_lua [[
- vim.cmd "only"
- vim.api.nvim_buf_call(_G.buf, function()
- _G.config = vim.api.nvim_win_get_config(0)
- end)
- return _G.config.relative
- ]]
+ vim.cmd "only"
+ vim.api.nvim_buf_call(_G.buf, function()
+ _G.config = vim.api.nvim_win_get_config(0)
+ end)
+ return _G.config.relative
+ ]]
)
end)
@@ -437,11 +463,11 @@ describe('autocmd', function()
pcall_err(
exec_lua,
[[
- vim.api.nvim_buf_call(_G.buf, function()
- local win = vim.api.nvim_get_current_win()
- vim.api.nvim_win_close(win, true)
- end)
- ]]
+ vim.api.nvim_buf_call(_G.buf, function()
+ local win = vim.api.nvim_get_current_win()
+ vim.api.nvim_win_close(win, true)
+ end)
+ ]]
)
)
matches(
@@ -449,12 +475,12 @@ describe('autocmd', function()
pcall_err(
exec_lua,
[[
- vim.api.nvim_buf_call(_G.buf, function()
- local win = vim.api.nvim_get_current_win()
- vim.cmd('tabnext')
- vim.api.nvim_win_close(win, true)
- end)
- ]]
+ vim.api.nvim_buf_call(_G.buf, function()
+ local win = vim.api.nvim_get_current_win()
+ vim.cmd('tabnext')
+ vim.api.nvim_win_close(win, true)
+ end)
+ ]]
)
)
matches(
@@ -462,11 +488,11 @@ describe('autocmd', function()
pcall_err(
exec_lua,
[[
- vim.api.nvim_buf_call(_G.buf, function()
- local win = vim.api.nvim_get_current_win()
- vim.api.nvim_win_hide(win)
- end)
- ]]
+ vim.api.nvim_buf_call(_G.buf, function()
+ local win = vim.api.nvim_get_current_win()
+ vim.api.nvim_win_hide(win)
+ end)
+ ]]
)
)
matches(
@@ -474,12 +500,12 @@ describe('autocmd', function()
pcall_err(
exec_lua,
[[
- vim.api.nvim_buf_call(_G.buf, function()
- local win = vim.api.nvim_get_current_win()
- vim.cmd('tabnext')
- vim.api.nvim_win_hide(win)
- end)
- ]]
+ vim.api.nvim_buf_call(_G.buf, function()
+ local win = vim.api.nvim_get_current_win()
+ vim.cmd('tabnext')
+ vim.api.nvim_win_hide(win)
+ end)
+ ]]
)
)
end)
diff --git a/test/functional/autocmd/bufenter_spec.lua b/test/functional/autocmd/bufenter_spec.lua
index af0dd887fa..72e650cae4 100644
--- a/test/functional/autocmd/bufenter_spec.lua
+++ b/test/functional/autocmd/bufenter_spec.lua
@@ -1,11 +1,12 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
-local clear = helpers.clear
-local command = helpers.command
-local eq = helpers.eq
-local eval = helpers.eval
-local request = helpers.request
-local source = helpers.source
+local clear = n.clear
+local command = n.command
+local eq = t.eq
+local eval = n.eval
+local request = n.request
+local source = n.source
describe('autocmd BufEnter', function()
before_each(clear)
@@ -33,7 +34,7 @@ describe('autocmd BufEnter', function()
end)
it('triggered by ":split normal|:help|:bw"', function()
- helpers.add_builddir_to_rtp()
+ n.add_builddir_to_rtp()
command('split normal')
command('wincmd j')
command('help')
diff --git a/test/functional/autocmd/bufmodifiedset_spec.lua b/test/functional/autocmd/bufmodifiedset_spec.lua
index 27fe9fcc94..fb8f160b05 100644
--- a/test/functional/autocmd/bufmodifiedset_spec.lua
+++ b/test/functional/autocmd/bufmodifiedset_spec.lua
@@ -1,10 +1,11 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
-local clear = helpers.clear
-local eq = helpers.eq
-local eval = helpers.eval
-local source = helpers.source
-local request = helpers.request
+local clear = n.clear
+local eq = t.eq
+local eval = n.eval
+local source = n.source
+local request = n.request
describe('BufModified', function()
before_each(clear)
diff --git a/test/functional/autocmd/cmdline_spec.lua b/test/functional/autocmd/cmdline_spec.lua
index 7428456656..ad3bc3576f 100644
--- a/test/functional/autocmd/cmdline_spec.lua
+++ b/test/functional/autocmd/cmdline_spec.lua
@@ -1,14 +1,15 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
-local clear = helpers.clear
-local command = helpers.command
-local eq = helpers.eq
-local expect = helpers.expect
-local eval = helpers.eval
-local next_msg = helpers.next_msg
-local feed = helpers.feed
-local api = helpers.api
+local clear = n.clear
+local command = n.command
+local eq = t.eq
+local expect = n.expect
+local eval = n.eval
+local next_msg = n.next_msg
+local feed = n.feed
+local api = n.api
describe('cmdline autocommands', function()
local channel
diff --git a/test/functional/autocmd/completedone_spec.lua b/test/functional/autocmd/completedone_spec.lua
new file mode 100644
index 0000000000..33beb16db2
--- /dev/null
+++ b/test/functional/autocmd/completedone_spec.lua
@@ -0,0 +1,41 @@
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local clear = n.clear
+local command = n.command
+local call = n.call
+local feed = n.feed
+local eval = n.eval
+local eq = t.eq
+
+describe('CompleteDone', function()
+ before_each(clear)
+
+ describe('sets v:event.reason', function()
+ before_each(function()
+ clear()
+ command('autocmd CompleteDone * let g:donereason = v:event.reason')
+ feed('i')
+ call('complete', call('col', '.'), { 'foo', 'bar' })
+ end)
+
+ it('accept', function()
+ feed('<C-y>')
+ eq('accept', eval('g:donereason'))
+ end)
+ describe('cancel', function()
+ it('on <C-e>', function()
+ feed('<C-e>')
+ eq('cancel', eval('g:donereason'))
+ end)
+ it('on non-keyword character', function()
+ feed('<Esc>')
+ eq('cancel', eval('g:donereason'))
+ end)
+ it('when overriden by another complete()', function()
+ call('complete', call('col', '.'), { 'bar', 'baz' })
+ eq('cancel', eval('g:donereason'))
+ end)
+ end)
+ end)
+end)
diff --git a/test/functional/autocmd/cursorhold_spec.lua b/test/functional/autocmd/cursorhold_spec.lua
index fc2b65f53a..c2815be5c6 100644
--- a/test/functional/autocmd/cursorhold_spec.lua
+++ b/test/functional/autocmd/cursorhold_spec.lua
@@ -1,12 +1,13 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
-local clear = helpers.clear
-local eq = helpers.eq
-local feed = helpers.feed
-local retry = helpers.retry
-local exec = helpers.source
+local clear = n.clear
+local eq = t.eq
+local feed = n.feed
+local retry = t.retry
+local exec = n.source
local sleep = vim.uv.sleep
-local api = helpers.api
+local api = n.api
before_each(clear)
diff --git a/test/functional/autocmd/cursormoved_spec.lua b/test/functional/autocmd/cursormoved_spec.lua
index 302afe87b8..2cf02e00f3 100644
--- a/test/functional/autocmd/cursormoved_spec.lua
+++ b/test/functional/autocmd/cursormoved_spec.lua
@@ -1,11 +1,12 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
-local clear = helpers.clear
-local eq = helpers.eq
-local eval = helpers.eval
-local api = helpers.api
-local source = helpers.source
-local command = helpers.command
+local clear = n.clear
+local eq = t.eq
+local eval = n.eval
+local api = n.api
+local source = n.source
+local command = n.command
describe('CursorMoved', function()
before_each(clear)
diff --git a/test/functional/autocmd/dirchanged_spec.lua b/test/functional/autocmd/dirchanged_spec.lua
index 7ad529891f..24ac737b5b 100644
--- a/test/functional/autocmd/dirchanged_spec.lua
+++ b/test/functional/autocmd/dirchanged_spec.lua
@@ -1,11 +1,12 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
-local clear = helpers.clear
-local command = helpers.command
-local eq = helpers.eq
-local eval = helpers.eval
-local request = helpers.request
-local is_os = helpers.is_os
+local clear = n.clear
+local command = n.command
+local eq = t.eq
+local eval = n.eval
+local request = n.request
+local is_os = t.is_os
describe('autocmd DirChanged and DirChangedPre', function()
local curdir = vim.uv.cwd():gsub('\\', '/')
@@ -22,12 +23,12 @@ describe('autocmd DirChanged and DirChangedPre', function()
setup(function()
for _, dir in pairs(dirs) do
- helpers.mkdir(dir)
+ t.mkdir(dir)
end
end)
teardown(function()
for _, dir in pairs(dirs) do
- helpers.rmdir(dir)
+ n.rmdir(dir)
end
end)
diff --git a/test/functional/autocmd/filetype_spec.lua b/test/functional/autocmd/filetype_spec.lua
index 648f830f27..91843c7910 100644
--- a/test/functional/autocmd/filetype_spec.lua
+++ b/test/functional/autocmd/filetype_spec.lua
@@ -1,14 +1,14 @@
-local helpers = require('test.functional.helpers')(after_each)
+local n = require('test.functional.testnvim')()
-local eval = helpers.eval
-local clear = helpers.clear
-local command = helpers.command
+local eval = n.eval
+local clear = n.clear
+local command = n.command
describe('autocmd FileType', function()
before_each(clear)
it('is triggered by :help only once', function()
- helpers.add_builddir_to_rtp()
+ n.add_builddir_to_rtp()
command('let g:foo = 0')
command('autocmd FileType help let g:foo = g:foo + 1')
command('help help')
diff --git a/test/functional/autocmd/focus_spec.lua b/test/functional/autocmd/focus_spec.lua
index 4f4a036ba8..5163b576db 100644
--- a/test/functional/autocmd/focus_spec.lua
+++ b/test/functional/autocmd/focus_spec.lua
@@ -1,10 +1,12 @@
-local helpers = require('test.functional.helpers')(after_each)
-local thelpers = require('test.functional.terminal.helpers')
-local clear = helpers.clear
-local feed_command = helpers.feed_command
-local feed_data = thelpers.feed_data
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+local tt = require('test.functional.terminal.testutil')
-if helpers.skip(helpers.is_os('win')) then
+local clear = n.clear
+local feed_command = n.feed_command
+local feed_data = tt.feed_data
+
+if t.skip(t.is_os('win')) then
return
end
@@ -14,7 +16,7 @@ describe('autoread TUI FocusGained/FocusLost', function()
before_each(function()
clear()
- screen = thelpers.setup_child_nvim({
+ screen = tt.setup_child_nvim({
'-u',
'NONE',
'-i',
@@ -39,7 +41,7 @@ describe('autoread TUI FocusGained/FocusLost', function()
line 4
]]
- helpers.write_file(path, '')
+ t.write_file(path, '')
local atime = os.time() - 10
vim.uv.fs_utime(path, atime, atime)
@@ -75,7 +77,7 @@ describe('autoread TUI FocusGained/FocusLost', function()
unchanged = true,
}
- helpers.write_file(path, expected_addition)
+ t.write_file(path, expected_addition)
feed_data('\027[I')
diff --git a/test/functional/autocmd/modechanged_spec.lua b/test/functional/autocmd/modechanged_spec.lua
index 8ad914a597..61ce15d91d 100644
--- a/test/functional/autocmd/modechanged_spec.lua
+++ b/test/functional/autocmd/modechanged_spec.lua
@@ -1,7 +1,9 @@
-local helpers = require('test.functional.helpers')(after_each)
-local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq
-local feed, command = helpers.feed, helpers.command
-local exec_lua = helpers.exec_lua
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local clear, eval, eq = n.clear, n.eval, t.eq
+local feed, command = n.feed, n.command
+local exec_lua = n.exec_lua
describe('ModeChanged', function()
before_each(function()
diff --git a/test/functional/autocmd/recording_spec.lua b/test/functional/autocmd/recording_spec.lua
index b9aec774f1..6ee61c5676 100644
--- a/test/functional/autocmd/recording_spec.lua
+++ b/test/functional/autocmd/recording_spec.lua
@@ -1,9 +1,10 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
-local clear = helpers.clear
-local eq = helpers.eq
-local eval = helpers.eval
-local source_vim = helpers.source
+local clear = n.clear
+local eq = t.eq
+local eval = n.eval
+local source_vim = n.source
describe('RecordingEnter', function()
before_each(clear)
diff --git a/test/functional/autocmd/safestate_spec.lua b/test/functional/autocmd/safestate_spec.lua
index b5b7ab2f95..c45a64e373 100644
--- a/test/functional/autocmd/safestate_spec.lua
+++ b/test/functional/autocmd/safestate_spec.lua
@@ -1,9 +1,11 @@
-local helpers = require('test.functional.helpers')(after_each)
-local clear = helpers.clear
-local eq = helpers.eq
-local exec = helpers.exec
-local feed = helpers.feed
-local api = helpers.api
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local clear = n.clear
+local eq = t.eq
+local exec = n.exec
+local feed = n.feed
+local api = n.api
before_each(clear)
diff --git a/test/functional/autocmd/searchwrapped_spec.lua b/test/functional/autocmd/searchwrapped_spec.lua
index 0705b2d5de..0c0b3595ca 100644
--- a/test/functional/autocmd/searchwrapped_spec.lua
+++ b/test/functional/autocmd/searchwrapped_spec.lua
@@ -1,11 +1,12 @@
-local helpers = require('test.functional.helpers')(after_each)
-
-local clear = helpers.clear
-local command = helpers.command
-local api = helpers.api
-local eq = helpers.eq
-local eval = helpers.eval
-local feed = helpers.feed
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local clear = n.clear
+local command = n.command
+local api = n.api
+local eq = t.eq
+local eval = n.eval
+local feed = n.feed
describe('autocmd SearchWrapped', function()
before_each(function()
diff --git a/test/functional/autocmd/show_spec.lua b/test/functional/autocmd/show_spec.lua
index 1a9dc8a337..7e1818c4fd 100644
--- a/test/functional/autocmd/show_spec.lua
+++ b/test/functional/autocmd/show_spec.lua
@@ -1,14 +1,15 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
-local clear = helpers.clear
-local command = helpers.command
-local dedent = helpers.dedent
-local eq = helpers.eq
-local fn = helpers.fn
-local eval = helpers.eval
-local exec = helpers.exec
-local feed = helpers.feed
+local clear = n.clear
+local command = n.command
+local dedent = t.dedent
+local eq = t.eq
+local fn = n.fn
+local eval = n.eval
+local exec = n.exec
+local feed = n.feed
describe(':autocmd', function()
before_each(function()
diff --git a/test/functional/autocmd/signal_spec.lua b/test/functional/autocmd/signal_spec.lua
index c7087254e7..4416afb3ba 100644
--- a/test/functional/autocmd/signal_spec.lua
+++ b/test/functional/autocmd/signal_spec.lua
@@ -1,12 +1,13 @@
-local helpers = require('test.functional.helpers')(after_each)
-
-local clear = helpers.clear
-local command = helpers.command
-local eq = helpers.eq
-local fn = helpers.fn
-local next_msg = helpers.next_msg
-local is_os = helpers.is_os
-local skip = helpers.skip
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local clear = n.clear
+local command = n.command
+local eq = t.eq
+local fn = n.fn
+local next_msg = n.next_msg
+local is_os = t.is_os
+local skip = t.skip
if skip(is_os('win'), 'Only applies to POSIX systems') then
return
diff --git a/test/functional/autocmd/tabclose_spec.lua b/test/functional/autocmd/tabclose_spec.lua
index d0b2ac6a8d..fde72cf4d7 100644
--- a/test/functional/autocmd/tabclose_spec.lua
+++ b/test/functional/autocmd/tabclose_spec.lua
@@ -1,7 +1,9 @@
-local helpers = require('test.functional.helpers')(after_each)
-local clear, eq = helpers.clear, helpers.eq
-local api = helpers.api
-local command = helpers.command
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local clear, eq = n.clear, t.eq
+local api = n.api
+local command = n.command
describe('TabClosed', function()
before_each(clear)
diff --git a/test/functional/autocmd/tabnew_spec.lua b/test/functional/autocmd/tabnew_spec.lua
index ad40954f76..80ab5a1944 100644
--- a/test/functional/autocmd/tabnew_spec.lua
+++ b/test/functional/autocmd/tabnew_spec.lua
@@ -1,9 +1,10 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
-local clear = helpers.clear
-local command = helpers.command
-local eq = helpers.eq
-local eval = helpers.eval
+local clear = n.clear
+local command = n.command
+local eq = t.eq
+local eval = n.eval
describe('autocmd TabNew', function()
before_each(clear)
diff --git a/test/functional/autocmd/tabnewentered_spec.lua b/test/functional/autocmd/tabnewentered_spec.lua
index b888845e3b..fcfebd7af5 100644
--- a/test/functional/autocmd/tabnewentered_spec.lua
+++ b/test/functional/autocmd/tabnewentered_spec.lua
@@ -1,13 +1,14 @@
-local helpers = require('test.functional.helpers')(after_each)
-
-local clear = helpers.clear
-local command = helpers.command
-local dedent = helpers.dedent
-local eval = helpers.eval
-local eq = helpers.eq
-local feed = helpers.feed
-local api = helpers.api
-local exec_capture = helpers.exec_capture
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local clear = n.clear
+local command = n.command
+local dedent = t.dedent
+local eval = n.eval
+local eq = t.eq
+local feed = n.feed
+local api = n.api
+local exec_capture = n.exec_capture
describe('TabNewEntered', function()
describe('au TabNewEntered', function()
diff --git a/test/functional/autocmd/termxx_spec.lua b/test/functional/autocmd/termxx_spec.lua
index 982edfa06a..a63996ae36 100644
--- a/test/functional/autocmd/termxx_spec.lua
+++ b/test/functional/autocmd/termxx_spec.lua
@@ -1,17 +1,18 @@
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+local tt = require('test.functional.terminal.testutil')
local uv = vim.uv
-local helpers = require('test.functional.helpers')(after_each)
-local thelpers = require('test.functional.terminal.helpers')
-
-local clear, command, testprg = helpers.clear, helpers.command, helpers.testprg
-local eval, eq, neq, retry = helpers.eval, helpers.eq, helpers.neq, helpers.retry
-local matches = helpers.matches
-local ok = helpers.ok
-local feed = helpers.feed
-local api = helpers.api
-local pcall_err = helpers.pcall_err
-local assert_alive = helpers.assert_alive
-local skip = helpers.skip
-local is_os = helpers.is_os
+
+local clear, command, testprg = n.clear, n.command, n.testprg
+local eval, eq, neq, retry = n.eval, t.eq, t.neq, t.retry
+local matches = t.matches
+local ok = t.ok
+local feed = n.feed
+local api = n.api
+local pcall_err = t.pcall_err
+local assert_alive = n.assert_alive
+local skip = t.skip
+local is_os = t.is_os
describe('autocmd TermClose', function()
before_each(function()
@@ -198,11 +199,11 @@ end)
describe('autocmd TextChangedT', function()
clear()
- local screen = thelpers.screen_setup()
+ local screen = tt.screen_setup()
it('works', function()
command('autocmd TextChangedT * ++once let g:called = 1')
- thelpers.feed_data('a')
+ tt.feed_data('a')
retry(nil, nil, function()
eq(1, api.nvim_get_var('called'))
end)
@@ -210,7 +211,7 @@ describe('autocmd TextChangedT', function()
it('cannot delete terminal buffer', function()
command([[autocmd TextChangedT * call nvim_input('<CR>') | bwipe!]])
- thelpers.feed_data('a')
+ tt.feed_data('a')
screen:expect({ any = 'E937: ' })
matches(
'^E937: Attempt to delete a buffer that is in use: term://',
diff --git a/test/functional/autocmd/textchanged_spec.lua b/test/functional/autocmd/textchanged_spec.lua
index d501560dc1..7c679cd4c0 100644
--- a/test/functional/autocmd/textchanged_spec.lua
+++ b/test/functional/autocmd/textchanged_spec.lua
@@ -1,17 +1,19 @@
-local helpers = require('test.functional.helpers')(after_each)
-local clear = helpers.clear
-local exec = helpers.exec
-local command = helpers.command
-local feed = helpers.feed
-local eq = helpers.eq
-local neq = helpers.neq
-local eval = helpers.eval
-local poke_eventloop = helpers.poke_eventloop
-
-before_each(clear)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local clear = n.clear
+local exec = n.exec
+local command = n.command
+local feed = n.feed
+local eq = t.eq
+local neq = t.neq
+local eval = n.eval
+local poke_eventloop = n.poke_eventloop
+local write_file = t.write_file
-- oldtest: Test_ChangedP()
it('TextChangedI and TextChangedP autocommands', function()
+ clear()
-- The oldtest uses feedkeys() with 'x' flag, which never triggers TextChanged.
-- So don't add TextChanged autocommand here.
exec([[
@@ -93,6 +95,7 @@ end)
-- oldtest: Test_TextChangedI_with_setline()
it('TextChangedI with setline()', function()
+ clear()
exec([[
let g:setline_handled = v:false
func SetLineOne()
@@ -118,76 +121,93 @@ it('TextChangedI with setline()', function()
eq('', eval('getline(2)'))
end)
+-- oldtest: Test_TextChanged_with_norm()
+it('TextChanged is triggered after :norm that enters Insert mode', function()
+ clear()
+ exec([[
+ let g:a = 0
+ au TextChanged * let g:a += 1
+ ]])
+ eq(0, eval('g:a'))
+ feed(':norm! ia<CR>')
+ eq(1, eval('g:a'))
+end)
+
-- oldtest: Test_Changed_ChangedI()
it('TextChangedI and TextChanged', function()
+ write_file('XTextChangedI2', 'one\ntwo\nthree')
+ finally(function()
+ os.remove('XTextChangedI2')
+ end)
+ clear('XTextChangedI2')
+
exec([[
- let [g:autocmd_i, g:autocmd_n] = ['','']
+ let [g:autocmd_n, g:autocmd_i] = ['','']
- func! TextChangedAutocmdI(char)
+ func TextChangedAutocmd(char)
let g:autocmd_{tolower(a:char)} = a:char .. b:changedtick
endfunc
- augroup Test_TextChanged
- au!
- au TextChanged <buffer> :call TextChangedAutocmdI('N')
- au TextChangedI <buffer> :call TextChangedAutocmdI('I')
- augroup END
+ au TextChanged <buffer> :call TextChangedAutocmd('N')
+ au TextChangedI <buffer> :call TextChangedAutocmd('I')
+
+ nnoremap <CR> o<Esc>
]])
+ -- TextChanged should trigger if a mapping enters and leaves Insert mode.
+ feed('<CR>')
+ eq('N4', eval('g:autocmd_n'))
+ eq('', eval('g:autocmd_i'))
+
feed('i')
- poke_eventloop()
+ eq('N4', eval('g:autocmd_n'))
+ eq('', eval('g:autocmd_i'))
+ -- TextChangedI should trigger if change is done in Insert mode.
feed('f')
- poke_eventloop()
+ eq('N4', eval('g:autocmd_n'))
+ eq('I5', eval('g:autocmd_i'))
feed('o')
- poke_eventloop()
+ eq('N4', eval('g:autocmd_n'))
+ eq('I6', eval('g:autocmd_i'))
feed('o')
- poke_eventloop()
- feed('<esc>')
- eq('', eval('g:autocmd_n'))
- eq('I5', eval('g:autocmd_i'))
+ eq('N4', eval('g:autocmd_n'))
+ eq('I7', eval('g:autocmd_i'))
+ -- TextChanged shouldn't trigger when leaving Insert mode and TextChangedI
+ -- has been triggered.
+ feed('<Esc>')
+ eq('N4', eval('g:autocmd_n'))
+ eq('I7', eval('g:autocmd_i'))
+ -- TextChanged should trigger if change is done in Normal mode.
feed('yyp')
- eq('N6', eval('g:autocmd_n'))
- eq('I5', eval('g:autocmd_i'))
-
- -- TextChangedI should only trigger if change was done in Insert mode
- command([[let g:autocmd_i = '']])
- feed('yypi<esc>')
- eq('', eval('g:autocmd_i'))
+ eq('N8', eval('g:autocmd_n'))
+ eq('I7', eval('g:autocmd_i'))
- -- TextChanged should only trigger if change was done in Normal mode
- command([[let g:autocmd_n = '']])
- feed('ibar<esc>')
- eq('', eval('g:autocmd_n'))
+ -- TextChangedI shouldn't trigger if change isn't done in Insert mode.
+ feed('i')
+ eq('N8', eval('g:autocmd_n'))
+ eq('I7', eval('g:autocmd_i'))
+ feed('<Esc>')
+ eq('N8', eval('g:autocmd_n'))
+ eq('I7', eval('g:autocmd_i'))
+ -- TextChangedI should trigger if change is a mix of Normal and Insert modes.
local function validate_mixed_textchangedi(keys)
- feed('ifoo<esc>')
- command([[let g:autocmd_i = '']])
- command([[let g:autocmd_n = '']])
- for _, s in ipairs(keys) do
- feed(s)
- poke_eventloop()
- end
+ feed('ifoo<Esc>')
+ command(":let [g:autocmd_n, g:autocmd_i] = ['', '']")
+ feed(keys)
+ eq('', eval('g:autocmd_n'))
neq('', eval('g:autocmd_i'))
+ feed('<Esc>')
eq('', eval('g:autocmd_n'))
+ neq('', eval('g:autocmd_i'))
end
- validate_mixed_textchangedi({ 'o', '<esc>' })
- validate_mixed_textchangedi({ 'O', '<esc>' })
- validate_mixed_textchangedi({ 'ciw', '<esc>' })
- validate_mixed_textchangedi({ 'cc', '<esc>' })
- validate_mixed_textchangedi({ 'C', '<esc>' })
- validate_mixed_textchangedi({ 's', '<esc>' })
- validate_mixed_textchangedi({ 'S', '<esc>' })
-end)
-
--- oldtest: Test_TextChanged_with_norm()
-it('TextChanged is triggered after :norm that enters Insert mode', function()
- exec([[
- let g:a = 0
- au TextChanged * let g:a += 1
- ]])
- eq(0, eval('g:a'))
- feed(':norm! ia<CR>')
- eq(1, eval('g:a'))
+ validate_mixed_textchangedi('o')
+ validate_mixed_textchangedi('O')
+ validate_mixed_textchangedi('ciw')
+ validate_mixed_textchangedi('cc')
+ validate_mixed_textchangedi('C')
+ validate_mixed_textchangedi('s')
+ validate_mixed_textchangedi('S')
end)
diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua
index 29cd62f586..cf8cbe25c1 100644
--- a/test/functional/autocmd/textyankpost_spec.lua
+++ b/test/functional/autocmd/textyankpost_spec.lua
@@ -1,7 +1,9 @@
-local helpers = require('test.functional.helpers')(after_each)
-local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq
-local feed, command, expect = helpers.feed, helpers.command, helpers.expect
-local api, fn, neq = helpers.api, helpers.fn, helpers.neq
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+
+local clear, eval, eq = n.clear, n.eval, t.eq
+local feed, command, expect = n.feed, n.command, n.expect
+local api, fn, neq = n.api, n.fn, t.neq
describe('TextYankPost', function()
before_each(function()
@@ -72,19 +74,19 @@ describe('TextYankPost', function()
command('set debug=msg')
-- the regcontents should not be changed without copy.
local status, err = pcall(command, 'call extend(g:event.regcontents, ["more text"])')
- eq(status, false)
+ eq(false, status)
neq(nil, string.find(err, ':E742:'))
-- can't mutate keys inside the autocommand
command('autocmd! TextYankPost * let v:event.regcontents = 0')
status, err = pcall(command, 'normal yy')
- eq(status, false)
+ eq(false, status)
neq(nil, string.find(err, ':E46:'))
-- can't add keys inside the autocommand
command('autocmd! TextYankPost * let v:event.mykey = 0')
status, err = pcall(command, 'normal yy')
- eq(status, false)
+ eq(false, status)
neq(nil, string.find(err, ':E742:'))
end)
diff --git a/test/functional/autocmd/win_scrolled_resized_spec.lua b/test/functional/autocmd/win_scrolled_resized_spec.lua
index d40dc37103..72bbc1e469 100644
--- a/test/functional/autocmd/win_scrolled_resized_spec.lua
+++ b/test/functional/autocmd/win_scrolled_resized_spec.lua
@@ -1,14 +1,15 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
-local clear = helpers.clear
-local eq = helpers.eq
-local eval = helpers.eval
-local exec = helpers.exec
-local command = helpers.command
-local feed = helpers.feed
-local api = helpers.api
-local assert_alive = helpers.assert_alive
+local clear = n.clear
+local eq = t.eq
+local eval = n.eval
+local exec = n.exec
+local command = n.command
+local feed = n.feed
+local api = n.api
+local assert_alive = n.assert_alive
before_each(clear)