aboutsummaryrefslogtreecommitdiff
path: root/test/functional/autocmd
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/autocmd')
-rw-r--r--test/functional/autocmd/autocmd_spec.lua31
-rw-r--r--test/functional/autocmd/tabclose_spec.lua5
-rw-r--r--test/functional/autocmd/tabnew_spec.lua46
-rw-r--r--test/functional/autocmd/tabnewentered_spec.lua6
-rw-r--r--test/functional/autocmd/termclose_spec.lua44
-rw-r--r--test/functional/autocmd/textyankpost_spec.lua216
6 files changed, 319 insertions, 29 deletions
diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua
new file mode 100644
index 0000000000..3c813abc2e
--- /dev/null
+++ b/test/functional/autocmd/autocmd_spec.lua
@@ -0,0 +1,31 @@
+local helpers = require('test.functional.helpers')
+
+local clear = helpers.clear
+local command = helpers.command
+local eval = helpers.eval
+
+describe('autocmds:', function()
+ before_each(clear)
+
+ it(':tabnew triggers events in the correct order', function()
+ local expected = {
+ 'WinLeave',
+ 'TabLeave',
+ 'TabNew',
+ 'WinEnter',
+ 'TabEnter',
+ 'BufLeave',
+ 'BufEnter'
+ }
+ command('let g:foo = []')
+ command('autocmd BufEnter * :call add(g:foo, "BufEnter")')
+ command('autocmd BufLeave * :call add(g:foo, "BufLeave")')
+ command('autocmd TabEnter * :call add(g:foo, "TabEnter")')
+ command('autocmd TabLeave * :call add(g:foo, "TabLeave")')
+ command('autocmd TabNew * :call add(g:foo, "TabNew")')
+ command('autocmd WinEnter * :call add(g:foo, "WinEnter")')
+ command('autocmd WinLeave * :call add(g:foo, "WinLeave")')
+ command('tabnew')
+ assert.same(expected, eval('g:foo'))
+ end)
+end)
diff --git a/test/functional/autocmd/tabclose_spec.lua b/test/functional/autocmd/tabclose_spec.lua
index 847362e3de..bf609d1846 100644
--- a/test/functional/autocmd/tabclose_spec.lua
+++ b/test/functional/autocmd/tabclose_spec.lua
@@ -1,7 +1,5 @@
local helpers = require('test.functional.helpers')
-local clear, nvim, buffer, curbuf, curwin, eq, neq, ok =
- helpers.clear, helpers.nvim, helpers.buffer, helpers.curbuf, helpers.curwin,
- helpers.eq, helpers.neq, helpers.ok
+local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq
describe('TabClosed', function()
describe('au TabClosed', function()
@@ -20,7 +18,6 @@ describe('TabClosed', function()
end)
describe('with NR as <afile>', function()
it('matches when closing a tab whose index is NR', function()
- tmp_path = nvim('eval', 'tempname()')
nvim('command', 'au! TabClosed 2 echom "tabclosed:match"')
repeat
nvim('command', 'tabnew')
diff --git a/test/functional/autocmd/tabnew_spec.lua b/test/functional/autocmd/tabnew_spec.lua
index d80644cd92..aaf9db0a99 100644
--- a/test/functional/autocmd/tabnew_spec.lua
+++ b/test/functional/autocmd/tabnew_spec.lua
@@ -1,24 +1,28 @@
local helpers = require('test.functional.helpers')
-local clear, nvim, buffer, curbuf, curwin, eq, neq, ok =
- helpers.clear, helpers.nvim, helpers.buffer, helpers.curbuf, helpers.curwin,
- helpers.eq, helpers.neq, helpers.ok
-describe('TabNew', function()
- setup(clear)
- describe('au TabNew', function()
- describe('with * as <afile>', function()
- it('matches when opening any new tab', function()
- nvim('command', 'au! TabNew * echom "tabnew:".tabpagenr().":".bufnr("")')
- eq("\ntabnew:2:1", nvim('command_output', 'tabnew'))
- eq("\ntabnew:3:2\n\"test.x\" [New File]", nvim('command_output', 'tabnew test.x'))
- end)
- end)
- describe('with FILE as <afile>', function()
- it('matches when opening a new tab for FILE', function()
- tmp_path = nvim('eval', 'tempname()')
- nvim('command', 'au! TabNew '..tmp_path..' echom "tabnew:match"')
- eq("\ntabnew:4:3\ntabnew:match\n\""..tmp_path.."\" [New File]", nvim('command_output', 'tabnew '..tmp_path))
- end)
- end)
- end)
+local clear = helpers.clear
+local command = helpers.command
+local eq = helpers.eq
+local eval = helpers.eval
+
+describe('autocmd TabNew', function()
+ before_each(clear)
+
+ it('matches when opening any new tab', function()
+ command('autocmd! TabNew * let g:test = "tabnew:".tabpagenr().":".bufnr("")')
+ command('tabnew')
+ eq('tabnew:2:1', eval('g:test'))
+ command('tabnew test.x')
+ eq('tabnew:3:2', eval('g:test'))
+ end)
+
+ it('matches when opening a new tab for FILE', function()
+ local tmp_path = helpers.funcs.tempname()
+ command('let g:test = "foo"')
+ command('autocmd! TabNew ' .. tmp_path .. ' let g:test = "bar"')
+ command('tabnew ' .. tmp_path ..'X')
+ eq('foo', eval('g:test'))
+ command('tabnew ' .. tmp_path)
+ eq('bar', eval('g:test'))
+ end)
end)
diff --git a/test/functional/autocmd/tabnewentered_spec.lua b/test/functional/autocmd/tabnewentered_spec.lua
index f220c15ef7..64b9a22f41 100644
--- a/test/functional/autocmd/tabnewentered_spec.lua
+++ b/test/functional/autocmd/tabnewentered_spec.lua
@@ -1,7 +1,5 @@
local helpers = require('test.functional.helpers')
-local clear, nvim, buffer, curbuf, curwin, eq, neq, ok =
- helpers.clear, helpers.nvim, helpers.buffer, helpers.curbuf, helpers.curwin,
- helpers.eq, helpers.neq, helpers.ok
+local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq
describe('TabNewEntered', function()
describe('au TabNewEntered', function()
@@ -15,7 +13,7 @@ describe('TabNewEntered', function()
end)
describe('with FILE as <afile>', function()
it('matches when opening a new tab for FILE', function()
- tmp_path = nvim('eval', 'tempname()')
+ local tmp_path = nvim('eval', 'tempname()')
nvim('command', 'au! TabNewEntered '..tmp_path..' echom "tabnewentered:match"')
eq("\n\""..tmp_path.."\" [New File]\ntabnewentered:4:4\ntabnewentered:match", nvim('command_output', 'tabnew '..tmp_path))
end)
diff --git a/test/functional/autocmd/termclose_spec.lua b/test/functional/autocmd/termclose_spec.lua
new file mode 100644
index 0000000000..4de3f039c1
--- /dev/null
+++ b/test/functional/autocmd/termclose_spec.lua
@@ -0,0 +1,44 @@
+local helpers = require('test.functional.helpers')
+local Screen = require('test.functional.ui.screen')
+
+local clear, execute, feed, nvim, nvim_dir = helpers.clear,
+helpers.execute, helpers.feed, helpers.nvim, helpers.nvim_dir
+local eval, eq = helpers.eval, helpers.eq
+
+describe('TermClose event', function()
+ local screen
+ before_each(function()
+ clear()
+ nvim('set_option', 'shell', nvim_dir .. '/shell-test')
+ nvim('set_option', 'shellcmdflag', 'EXE')
+ screen = Screen.new(20, 4)
+ screen:attach(false)
+ end)
+
+ it('works as expected', function()
+ execute('autocmd TermClose * echomsg "TermClose works!"')
+ execute('terminal')
+ feed('<c-\\><c-n>')
+ screen:expect([[
+ ready $ |
+ [Process exited 0] |
+ ^ |
+ TermClose works! |
+ ]])
+ end)
+
+ it('reports the correct <abuf>', function()
+ execute('set hidden')
+ execute('autocmd TermClose * let g:abuf = expand("<abuf>")')
+ execute('edit foo')
+ execute('edit bar')
+ eq(2, eval('bufnr("%")'))
+ execute('terminal')
+ feed('<c-\\><c-n>')
+ eq(3, eval('bufnr("%")'))
+ execute('buffer 1')
+ eq(1, eval('bufnr("%")'))
+ execute('3bdelete!')
+ eq('3', eval('g:abuf'))
+ end)
+end)
diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua
new file mode 100644
index 0000000000..c26ceeaedc
--- /dev/null
+++ b/test/functional/autocmd/textyankpost_spec.lua
@@ -0,0 +1,216 @@
+local helpers = require('test.functional.helpers')
+local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq
+local feed, execute, expect, command = helpers.feed, helpers.execute, helpers.expect, helpers.command
+local curbufmeths, funcs, neq = helpers.curbufmeths, helpers.funcs, helpers.neq
+
+describe('TextYankPost', function()
+ before_each(function()
+ clear()
+
+ -- emulate the clipboard so system clipboard isn't affected
+ execute('let &rtp = "test/functional/fixtures,".&rtp')
+
+ execute('let g:count = 0')
+ execute('autocmd TextYankPost * let g:event = copy(v:event)')
+ execute('autocmd TextYankPost * let g:count += 1')
+
+ curbufmeths.set_lines(0, -1, true, {
+ 'foo\0bar',
+ 'baz text',
+ })
+ end)
+
+ it('is executed after yank and handles register types', function()
+ feed('yy')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo\nbar' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+ eq(1, eval('g:count'))
+
+ -- v:event is cleared after the autocommand is done
+ eq({}, eval('v:event'))
+
+ feed('+yw')
+ eq({
+ operator = 'y',
+ regcontents = { 'baz ' },
+ regname = '',
+ regtype = 'v'
+ }, eval('g:event'))
+ eq(2, eval('g:count'))
+
+ feed('<c-v>eky')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo', 'baz' },
+ regname = '',
+ regtype = "\0223" -- ^V + block width
+ }, eval('g:event'))
+ eq(3, eval('g:count'))
+ end)
+
+ it('makes v:event immutable', function()
+ feed('yy')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo\nbar' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+
+ execute('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)
+ neq(nil, string.find(err, ':E742:'))
+
+ -- can't mutate keys inside the autocommand
+ execute('autocmd! TextYankPost * let v:event.regcontents = 0')
+ status, err = pcall(command,'normal yy')
+ eq(status,false)
+ neq(nil, string.find(err, ':E46:'))
+
+ -- can't add keys inside the autocommand
+ execute('autocmd! TextYankPost * let v:event.mykey = 0')
+ status, err = pcall(command,'normal yy')
+ eq(status,false)
+ neq(nil, string.find(err, ':E742:'))
+ end)
+
+ it('is not invoked recursively', function()
+ execute('autocmd TextYankPost * normal "+yy')
+ feed('yy')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo\nbar' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+ eq(1, eval('g:count'))
+ eq({ 'foo\nbar' }, funcs.getreg('+',1,1))
+ end)
+
+ it('is executed after delete and change', function()
+ feed('dw')
+ eq({
+ operator = 'd',
+ regcontents = { 'foo' },
+ regname = '',
+ regtype = 'v'
+ }, eval('g:event'))
+ eq(1, eval('g:count'))
+
+ feed('dd')
+ eq({
+ operator = 'd',
+ regcontents = { '\nbar' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+ eq(2, eval('g:count'))
+
+ feed('cwspam<esc>')
+ eq({
+ operator = 'c',
+ regcontents = { 'baz' },
+ regname = '',
+ regtype = 'v'
+ }, eval('g:event'))
+ eq(3, eval('g:count'))
+ end)
+
+ it('is not executed after black-hole operation', function()
+ feed('"_dd')
+ eq(0, eval('g:count'))
+
+ feed('"_cwgood<esc>')
+ eq(0, eval('g:count'))
+
+ expect([[
+ good text]])
+ feed('"_yy')
+ eq(0, eval('g:count'))
+
+ execute('delete _')
+ eq(0, eval('g:count'))
+ end)
+
+ it('gives the correct register name', function()
+ feed('$"byiw')
+ eq({
+ operator = 'y',
+ regcontents = { 'bar' },
+ regname = 'b',
+ regtype = 'v'
+ }, eval('g:event'))
+
+ feed('"*yy')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo\nbar' },
+ regname = '*',
+ regtype = 'V'
+ }, eval('g:event'))
+
+ execute("set clipboard=unnamed")
+
+ -- regname still shows the name the user requested
+ feed('yy')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo\nbar' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+
+ feed('"*yy')
+ eq({
+ operator = 'y',
+ regcontents = { 'foo\nbar' },
+ regname = '*',
+ regtype = 'V'
+ }, eval('g:event'))
+ end)
+
+ it('works with Ex commands', function()
+ execute('1delete +')
+ eq({
+ operator = 'd',
+ regcontents = { 'foo\nbar' },
+ regname = '+',
+ regtype = 'V'
+ }, eval('g:event'))
+ eq(1, eval('g:count'))
+
+ execute('yank')
+ eq({
+ operator = 'y',
+ regcontents = { 'baz text' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+ eq(2, eval('g:count'))
+
+ execute('normal yw')
+ eq({
+ operator = 'y',
+ regcontents = { 'baz ' },
+ regname = '',
+ regtype = 'v'
+ }, eval('g:event'))
+ eq(3, eval('g:count'))
+
+ execute('normal! dd')
+ eq({
+ operator = 'd',
+ regcontents = { 'baz text' },
+ regname = '',
+ regtype = 'V'
+ }, eval('g:event'))
+ eq(4, eval('g:count'))
+ end)
+
+end)