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.lua101
-rw-r--r--test/functional/autocmd/cmdline_spec.lua2
-rw-r--r--test/functional/autocmd/tabclose_spec.lua18
-rw-r--r--test/functional/autocmd/tabnewentered_spec.lua563
-rw-r--r--test/functional/autocmd/textyankpost_spec.lua48
5 files changed, 681 insertions, 51 deletions
diff --git a/test/functional/autocmd/autocmd_spec.lua b/test/functional/autocmd/autocmd_spec.lua
index 805db9dd78..e62d3bb66b 100644
--- a/test/functional/autocmd/autocmd_spec.lua
+++ b/test/functional/autocmd/autocmd_spec.lua
@@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
+local assert_visible = helpers.assert_visible
local dedent = helpers.dedent
local eq = helpers.eq
local eval = helpers.eval
@@ -18,26 +19,86 @@ local source = helpers.source
describe('autocmd', function()
before_each(clear)
- it(':tabnew triggers events in the correct order', function()
+ it(':tabnew, :split, :close events order, <afile>', function()
local expected = {
- 'WinLeave',
- 'TabLeave',
- 'WinEnter',
- 'TabNew',
- 'TabEnter',
- 'BufLeave',
- 'BufEnter'
+ {'WinLeave', ''},
+ {'TabLeave', ''},
+ {'WinEnter', ''},
+ {'TabNew', 'testfile1'}, -- :tabnew
+ {'TabEnter', ''},
+ {'BufLeave', ''},
+ {'BufEnter', 'testfile1'}, -- :split
+ {'WinLeave', 'testfile1'},
+ {'WinEnter', 'testfile1'},
+ {'WinLeave', 'testfile1'},
+ {'WinClosed', '1002'}, -- :close, WinClosed <afile> = window-id
+ {'WinEnter', 'testfile1'},
+ {'WinLeave', 'testfile1'}, -- :bdelete
+ {'WinEnter', 'testfile1'},
+ {'BufLeave', 'testfile1'},
+ {'BufEnter', 'testfile2'},
+ {'WinClosed', '1000'},
}
- 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'))
+ command('let g:evs = []')
+ command('autocmd BufEnter * :call add(g:evs, ["BufEnter", expand("<afile>")])')
+ command('autocmd BufLeave * :call add(g:evs, ["BufLeave", expand("<afile>")])')
+ command('autocmd TabEnter * :call add(g:evs, ["TabEnter", expand("<afile>")])')
+ command('autocmd TabLeave * :call add(g:evs, ["TabLeave", expand("<afile>")])')
+ command('autocmd TabNew * :call add(g:evs, ["TabNew", expand("<afile>")])')
+ command('autocmd WinEnter * :call add(g:evs, ["WinEnter", expand("<afile>")])')
+ command('autocmd WinLeave * :call add(g:evs, ["WinLeave", expand("<afile>")])')
+ command('autocmd WinClosed * :call add(g:evs, ["WinClosed", expand("<afile>")])')
+ command('tabnew testfile1')
+ command('split')
+ command('close')
+ command('new testfile2')
+ command('bdelete 1')
+ eq(expected, eval('g:evs'))
+ end)
+
+ it('WinClosed is non-recursive', function()
+ command('let g:triggered = 0')
+ command('autocmd WinClosed * :let g:triggered+=1 | :bdelete 2')
+ command('new testfile2')
+ command('new testfile3')
+
+ -- All 3 buffers are visible.
+ assert_visible(1, true)
+ assert_visible(2, true)
+ assert_visible(3, true)
+
+ -- Trigger WinClosed, which also deletes buffer/window 2.
+ command('bdelete 1')
+
+ -- Buffers 1 and 2 were closed but WinClosed was triggered only once.
+ eq(1, eval('g:triggered'))
+ assert_visible(1, false)
+ assert_visible(2, false)
+ assert_visible(3, true)
+ end)
+
+ it('WinClosed from a different tabpage', function()
+ command('let g:evs = []')
+ command('edit tesfile1')
+ command('autocmd WinClosed <buffer> :call add(g:evs, ["WinClosed", expand("<abuf>")])')
+ local buf1 = eval("bufnr('%')")
+ command('new')
+ local buf2 = eval("bufnr('%')")
+ command('autocmd WinClosed <buffer> :call add(g:evs, ["WinClosed", expand("<abuf>")])'
+ -- Attempt recursion.
+ ..' | bdelete '..buf2)
+ command('tabedit testfile2')
+ command('tabedit testfile3')
+ command('bdelete '..buf2)
+ -- Non-recursive: only triggered once.
+ eq({
+ {'WinClosed', '2'},
+ }, eval('g:evs'))
+ command('bdelete '..buf1)
+ eq({
+ {'WinClosed', '2'},
+ {'WinClosed', '1'},
+ }, eval('g:evs'))
end)
it('v:vim_did_enter is 1 after VimEnter', function()
@@ -219,7 +280,7 @@ describe('autocmd', function()
eq(7, eval('g:test'))
-- API calls are blocked when aucmd_win is not in scope
- eq('Vim(call):E5555: API call: Invalid window id',
+ eq('Vim(call):E5555: API call: Invalid window id: 1001',
pcall_err(command, "call nvim_set_current_win(g:winid)"))
-- second time aucmd_win is needed, a different code path is invoked
@@ -257,7 +318,7 @@ describe('autocmd', function()
eq(0, eval('g:had_value'))
eq(7, eval('g:test'))
- eq('Vim(call):E5555: API call: Invalid window id',
+ eq('Vim(call):E5555: API call: Invalid window id: 1001',
pcall_err(command, "call nvim_set_current_win(g:winid)"))
end)
diff --git a/test/functional/autocmd/cmdline_spec.lua b/test/functional/autocmd/cmdline_spec.lua
index 51b7b819e9..8ec06dc148 100644
--- a/test/functional/autocmd/cmdline_spec.lua
+++ b/test/functional/autocmd/cmdline_spec.lua
@@ -33,7 +33,7 @@ describe('cmdline autocommands', function()
eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg())
-- note: feed('bork<c-c>') might not consume 'bork'
- -- due to out-of-band interupt handling
+ -- due to out-of-band interrupt handling
feed('bork<esc>')
eq({'notification', 'CmdlineLeave',
{{cmdtype=':', cmdlevel=1, abort=true}}}, next_msg())
diff --git a/test/functional/autocmd/tabclose_spec.lua b/test/functional/autocmd/tabclose_spec.lua
index b7c33dc3d8..92d860c628 100644
--- a/test/functional/autocmd/tabclose_spec.lua
+++ b/test/functional/autocmd/tabclose_spec.lua
@@ -11,10 +11,10 @@ describe('TabClosed', function()
repeat
nvim('command', 'tabnew')
until nvim('eval', 'tabpagenr()') == 6 -- current tab is now 6
- eq("tabclosed:6:6:5", nvim('command_output', 'tabclose')) -- close last 6, current tab is now 5
- eq("tabclosed:5:5:4", nvim('command_output', 'close')) -- close last window on tab, closes tab
- eq("tabclosed:2:2:3", nvim('command_output', '2tabclose')) -- close tab 2, current tab is now 3
- eq("tabclosed:1:1:2\ntabclosed:1:1:1", nvim('command_output', 'tabonly')) -- close tabs 1 and 2
+ eq("tabclosed:6:6:5", nvim('exec', 'tabclose', true)) -- close last 6, current tab is now 5
+ eq("tabclosed:5:5:4", nvim('exec', 'close', true)) -- close last window on tab, closes tab
+ eq("tabclosed:2:2:3", nvim('exec', '2tabclose', true)) -- close tab 2, current tab is now 3
+ eq("tabclosed:1:1:2\ntabclosed:1:1:1", nvim('exec', 'tabonly', true)) -- close tabs 1 and 2
end)
it('is triggered when closing a window via bdelete from another tab', function()
@@ -23,7 +23,7 @@ describe('TabClosed', function()
nvim('command', '1tabedit Xtestfile')
nvim('command', 'normal! 1gt')
eq({1, 3}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
- eq("tabclosed:2:2:1\ntabclosed:2:2:1", nvim('command_output', 'bdelete Xtestfile'))
+ eq("tabclosed:2:2:1\ntabclosed:2:2:1", nvim('exec', 'bdelete Xtestfile', true))
eq({1, 1}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
end)
@@ -35,7 +35,7 @@ describe('TabClosed', function()
-- Only one tab is closed, and the alternate file is used for the other.
eq({2, 3}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
- eq("tabclosed:2:2:2", nvim('command_output', 'bdelete Xtestfile2'))
+ eq("tabclosed:2:2:2", nvim('exec', 'bdelete Xtestfile2', true))
eq('Xtestfile1', nvim('eval', 'bufname("")'))
end)
end)
@@ -48,9 +48,9 @@ describe('TabClosed', function()
nvim('command', 'tabnew')
until nvim('eval', 'tabpagenr()') == 7 -- current tab is now 7
-- sanity check, we shouldn't match on tabs with numbers other than 2
- eq("tabclosed:7:7:6", nvim('command_output', 'tabclose'))
+ eq("tabclosed:7:7:6", nvim('exec', 'tabclose', true))
-- close tab page 2, current tab is now 5
- eq("tabclosed:2:2:5\ntabclosed:match", nvim('command_output', '2tabclose'))
+ eq("tabclosed:2:2:5\ntabclosed:match", nvim('exec', '2tabclose', true))
end)
end)
@@ -59,7 +59,7 @@ describe('TabClosed', function()
nvim('command', 'au! TabClosed * echom "tabclosed:".expand("<afile>").":".expand("<amatch>").":".tabpagenr()')
nvim('command', 'tabedit Xtestfile')
eq({2, 2}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
- eq("tabclosed:2:2:1", nvim('command_output', 'close'))
+ eq("tabclosed:2:2:1", nvim('exec', 'close', true))
eq({1, 1}, nvim('eval', '[tabpagenr(), tabpagenr("$")]'))
end)
end)
diff --git a/test/functional/autocmd/tabnewentered_spec.lua b/test/functional/autocmd/tabnewentered_spec.lua
index 59cac07b34..dc2fd3e97d 100644
--- a/test/functional/autocmd/tabnewentered_spec.lua
+++ b/test/functional/autocmd/tabnewentered_spec.lua
@@ -1,5 +1,13 @@
local helpers = require('test.functional.helpers')(after_each)
-local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq
+
+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 nvim = helpers.nvim
+local redir_exec = helpers.redir_exec
describe('TabNewEntered', function()
describe('au TabNewEntered', function()
@@ -7,15 +15,15 @@ describe('TabNewEntered', function()
it('matches when entering any new tab', function()
clear()
nvim('command', 'au! TabNewEntered * echom "tabnewentered:".tabpagenr().":".bufnr("")')
- eq("tabnewentered:2:2", nvim('command_output', 'tabnew'))
- eq("tabnewentered:3:3", nvim('command_output', 'tabnew test.x2'))
+ eq("tabnewentered:2:2", nvim('exec', 'tabnew', true))
+ eq("tabnewentered:3:3", nvim('exec', 'tabnew test.x2', true))
end)
end)
describe('with FILE as <afile>', function()
it('matches when opening a new tab for FILE', function()
nvim('command', 'au! TabNewEntered Xtest-tabnewentered echom "tabnewentered:match"')
eq('tabnewentered:4:4\ntabnewentered:match',
- nvim('command_output', 'tabnew Xtest-tabnewentered'))
+ nvim('exec', 'tabnew Xtest-tabnewentered', true))
end)
end)
describe('with CTRL-W T', function()
@@ -24,8 +32,553 @@ describe('TabNewEntered', function()
nvim('command', 'au! TabNewEntered * echom "entered"')
nvim('command', 'tabnew test.x2')
nvim('command', 'split')
- eq('entered', nvim('command_output', 'execute "normal \\<C-W>T"'))
+ eq('entered', nvim('exec', 'execute "normal \\<C-W>T"', true))
end)
end)
end)
end)
+
+describe('TabEnter', function()
+ before_each(clear)
+ it('has correct previous tab when entering any new tab', function()
+ command('augroup TEMP')
+ nvim('command', 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')')
+ command('augroup END')
+ eq("tabenter:2:1", nvim('exec', 'tabnew', true))
+ eq("tabenter:3:2", nvim('exec', 'tabnew test.x2', true))
+ command('augroup! TEMP')
+ end)
+ it('has correct previous tab when entering any preexisting tab', function()
+ command('tabnew')
+ command('tabnew')
+ command('augroup TEMP')
+ nvim('command', 'au! TabEnter * echom "tabenter:".tabpagenr().":".tabpagenr(\'#\')')
+ command('augroup END')
+ eq("tabenter:1:3", nvim('exec', 'tabnext', true))
+ eq("tabenter:2:1", nvim('exec', 'tabnext', true))
+ command('augroup! TEMP')
+ end)
+end)
+
+describe('tabpage/previous', function()
+ before_each(clear)
+ local function switches_to_previous_after_new_tab_creation_at_end(characters)
+ return function()
+ -- Add three tabs for a total of four
+ command('tabnew')
+ command('tabnew')
+ command('tabnew')
+
+ -- The previous tab is now the third.
+ eq(3, eval('tabpagenr(\'#\')'))
+
+ -- Switch to the previous (third) tab
+ feed(characters)
+
+ eq(dedent([=[
+
+
+ Tab page 1
+ [No Name]
+ Tab page 2
+ [No Name]
+ Tab page 3
+ > [No Name]
+ Tab page 4
+ # [No Name]]=]),
+ redir_exec('tabs')
+ )
+
+ -- The previous tab is now the fourth.
+ eq(4, eval('tabpagenr(\'#\')'))
+ end
+ end
+ it('switches to previous via g<Tab> after new tab creation at end',
+ switches_to_previous_after_new_tab_creation_at_end('g<Tab>'))
+ it('switches to previous via <C-W>g<Tab>. after new tab creation at end', switches_to_previous_after_new_tab_creation_at_end('<C-W>g<Tab>'))
+ it('switches to previous via <C-Tab>. after new tab creation at end', switches_to_previous_after_new_tab_creation_at_end('<C-Tab>'))
+ it('switches to previous via :tabn #<CR>. after new tab creation at end', switches_to_previous_after_new_tab_creation_at_end(':tabn #<CR>'))
+
+ local function switches_to_previous_after_new_tab_creation_in_middle(characters)
+ return function()
+ -- Add three tabs for a total of four
+ command('tabnew')
+ command('tabnew')
+ command('tabnew')
+ -- Switch to the second tab
+ command('tabnext 2')
+ -- Add a new tab after the second tab
+ command('tabnew')
+
+ -- The previous tab is now the second.
+ eq(2, eval('tabpagenr(\'#\')'))
+
+ -- Switch to the previous (second) tab
+ feed(characters)
+ eq(dedent([=[
+
+
+ Tab page 1
+ [No Name]
+ Tab page 2
+ > [No Name]
+ Tab page 3
+ # [No Name]
+ Tab page 4
+ [No Name]
+ Tab page 5
+ [No Name]]=]),
+ redir_exec('tabs')
+ )
+
+ -- The previous tab is now the third.
+ eq(3, eval('tabpagenr(\'#\')'))
+ end
+ end
+ it('switches to previous via g<Tab> after new tab creation in middle',
+ switches_to_previous_after_new_tab_creation_in_middle('g<Tab>'))
+ it('switches to previous via <C-W>g<Tab> after new tab creation in middle',
+ switches_to_previous_after_new_tab_creation_in_middle('<C-W>g<Tab>'))
+ it('switches to previous via <C-Tab> after new tab creation in middle',
+ switches_to_previous_after_new_tab_creation_in_middle('<C-Tab>'))
+ it('switches to previous via :tabn #<CR> after new tab creation in middle',
+ switches_to_previous_after_new_tab_creation_in_middle(':tabn #<CR>'))
+
+ local function switches_to_previous_after_switching_to_next_tab(characters)
+ return function()
+ -- Add three tabs for a total of four
+ command('tabnew')
+ command('tabnew')
+ command('tabnew')
+ -- Switch to the next (first) tab
+ command('tabnext')
+
+ -- The previous tab is now the fourth.
+ eq(4, eval('tabpagenr(\'#\')'))
+
+ -- Switch to the previous (fourth) tab
+ feed(characters)
+
+ eq(dedent([=[
+
+
+ Tab page 1
+ # [No Name]
+ Tab page 2
+ [No Name]
+ Tab page 3
+ [No Name]
+ Tab page 4
+ > [No Name]]=]),
+ redir_exec('tabs')
+ )
+
+ -- The previous tab is now the first.
+ eq(1, eval('tabpagenr(\'#\')'))
+ end
+ end
+ it('switches to previous via g<Tab> after switching to next tab',
+ switches_to_previous_after_switching_to_next_tab('g<Tab>'))
+ it('switches to previous via <C-W>g<Tab> after switching to next tab',
+ switches_to_previous_after_switching_to_next_tab('<C-W>g<Tab>'))
+ it('switches to previous via <C-Tab> after switching to next tab',
+ switches_to_previous_after_switching_to_next_tab('<C-Tab>'))
+ it('switches to previous via :tabn #<CR> after switching to next tab',
+ switches_to_previous_after_switching_to_next_tab(':tabn #<CR>'))
+
+ local function switches_to_previous_after_switching_to_last_tab(characters)
+ return function()
+ -- Add three tabs for a total of four
+ command('tabnew')
+ command('tabnew')
+ command('tabnew')
+ -- Switch to the next (first) tab
+ command('tabnext')
+ -- Switch to the last (fourth) tab.
+ command('tablast')
+
+ -- The previous tab is now the second.
+ eq(1, eval('tabpagenr(\'#\')'))
+
+ -- Switch to the previous (second) tab
+ feed(characters)
+
+ eq(dedent([=[
+
+
+ Tab page 1
+ > [No Name]
+ Tab page 2
+ [No Name]
+ Tab page 3
+ [No Name]
+ Tab page 4
+ # [No Name]]=]),
+ redir_exec('tabs')
+ )
+
+ -- The previous tab is now the fourth.
+ eq(4, eval('tabpagenr(\'#\')'))
+ end
+ end
+ it('switches to previous after switching to last tab',
+ switches_to_previous_after_switching_to_last_tab('g<Tab>'))
+ it('switches to previous after switching to last tab',
+ switches_to_previous_after_switching_to_last_tab('<C-W>g<Tab>'))
+ it('switches to previous after switching to last tab',
+ switches_to_previous_after_switching_to_last_tab('<C-Tab>'))
+ it('switches to previous after switching to last tab',
+ switches_to_previous_after_switching_to_last_tab(':tabn #<CR>'))
+
+ local function switches_to_previous_after_switching_to_previous_tab(characters)
+ return function()
+ -- Add three tabs for a total of four
+ command('tabnew')
+ command('tabnew')
+ command('tabnew')
+ -- Switch to the previous (third) tab
+ command('tabprevious')
+
+ -- The previous tab is now the fourth.
+ eq(4, eval('tabpagenr(\'#\')'))
+
+ -- Switch to the previous (fourth) tab
+ feed(characters)
+
+ eq(dedent([=[
+
+
+ Tab page 1
+ [No Name]
+ Tab page 2
+ [No Name]
+ Tab page 3
+ # [No Name]
+ Tab page 4
+ > [No Name]]=]),
+ redir_exec('tabs')
+ )
+
+ -- The previous tab is now the third.
+ eq(3, eval('tabpagenr(\'#\')'))
+ end
+ end
+ it('switches to previous via g<Tab> after switching to previous tab',
+ switches_to_previous_after_switching_to_previous_tab('g<Tab>'))
+ it('switches to previous via <C-W>g<Tab> after switching to previous tab',
+ switches_to_previous_after_switching_to_previous_tab('<C-W>g<Tab>'))
+ it('switches to previous via <C-Tab> after switching to previous tab',
+ switches_to_previous_after_switching_to_previous_tab('<C-Tab>'))
+ it('switches to previous via :tabn #<CR> after switching to previous tab',
+ switches_to_previous_after_switching_to_previous_tab(':tabn #<CR>'))
+
+ local function switches_to_previous_after_switching_to_first_tab(characters)
+ return function()
+ -- Add three tabs for a total of four
+ command('tabnew')
+ command('tabnew')
+ command('tabnew')
+ -- Switch to the previous (third) tab
+ command('tabprevious')
+ -- Switch to the first tab
+ command('tabfirst')
+
+ -- The previous tab is now the third.
+ eq(3, eval('tabpagenr(\'#\')'))
+
+ -- Switch to the previous (third) tab
+ feed(characters)
+
+ eq(dedent([=[
+
+
+ Tab page 1
+ # [No Name]
+ Tab page 2
+ [No Name]
+ Tab page 3
+ > [No Name]
+ Tab page 4
+ [No Name]]=]),
+ redir_exec('tabs')
+ )
+
+ -- The previous tab is now the first.
+ eq(1, eval('tabpagenr(\'#\')'))
+ end
+ end
+ it('switches to previous via g<Tab> after switching to first tab',
+ switches_to_previous_after_switching_to_first_tab('g<Tab>'))
+ it('switches to previous via <C-W>g<Tab> after switching to first tab',
+ switches_to_previous_after_switching_to_first_tab('<C-W>g<Tab>'))
+ it('switches to previous via <C-Tab> after switching to first tab',
+ switches_to_previous_after_switching_to_first_tab('<C-Tab>'))
+ it('switches to previous via :tabn #<CR> after switching to first tab',
+ switches_to_previous_after_switching_to_first_tab(':tabn #<CR>'))
+
+ local function switches_to_previous_after_numbered_tab_switch(characters)
+ return function()
+ -- Add three tabs for a total of four
+ command('tabnew')
+ command('tabnew')
+ command('tabnew')
+ -- Switch to the second tab
+ command('tabnext 2')
+
+ -- The previous tab is now the fourth.
+ eq(4, eval('tabpagenr(\'#\')'))
+
+ -- Switch to the previous (fourth) tab
+ feed(characters)
+
+ eq(dedent([=[
+
+
+ Tab page 1
+ [No Name]
+ Tab page 2
+ # [No Name]
+ Tab page 3
+ [No Name]
+ Tab page 4
+ > [No Name]]=]),
+ redir_exec('tabs')
+ )
+
+ -- The previous tab is now the second.
+ eq(2, eval('tabpagenr(\'#\')'))
+ end
+ end
+ it('switches to previous via g<Tab> after numbered tab switch',
+ switches_to_previous_after_numbered_tab_switch('g<Tab>'))
+ it('switches to previous via <C-W>g<Tab> after numbered tab switch',
+ switches_to_previous_after_numbered_tab_switch('<C-W>g<Tab>'))
+ it('switches to previous via <C-Tab> after numbered tab switch',
+ switches_to_previous_after_numbered_tab_switch('<C-Tab>'))
+ it('switches to previous via :tabn #<CR> after numbered tab switch',
+ switches_to_previous_after_numbered_tab_switch(':tabn #<CR>'))
+
+ local function switches_to_previous_after_switching_to_previous(characters1, characters2)
+ return function()
+ -- Add three tabs for a total of four
+ command('tabnew')
+ command('tabnew')
+ command('tabnew')
+ -- Switch to the second tab
+ command('tabnext 2')
+ -- Switch to the previous (fourth) tab
+ feed(characters1)
+
+ -- The previous tab is now the second.
+ eq(2, eval('tabpagenr(\'#\')'))
+
+ -- Switch to the previous (second) tab
+ feed(characters2)
+
+ eq(dedent([=[
+
+
+ Tab page 1
+ [No Name]
+ Tab page 2
+ > [No Name]
+ Tab page 3
+ [No Name]
+ Tab page 4
+ # [No Name]]=]),
+ redir_exec('tabs')
+ )
+
+ -- The previous tab is now the fourth.
+ eq(4, eval('tabpagenr(\'#\')'))
+ end
+ end
+ it('switches to previous via g<Tab> after switching to previous via g<Tab>',
+ switches_to_previous_after_switching_to_previous('g<Tab>', 'g<Tab>'))
+ it('switches to previous via <C-W>g<Tab> after switching to previous via g<Tab>',
+ switches_to_previous_after_switching_to_previous('g<Tab>', '<C-W>g<Tab>'))
+ it('switches to previous via <C-Tab> after switching to previous via g<Tab>',
+ switches_to_previous_after_switching_to_previous('g<Tab>', '<C-Tab>'))
+ it('switches to previous via :tabn #<CR> after switching to previous via g<Tab>',
+ switches_to_previous_after_switching_to_previous('g<Tab>', ':tabn #<CR>'))
+ it('switches to previous via g<Tab> after switching to previous via <C-W>g<Tab>',
+ switches_to_previous_after_switching_to_previous('<C-W>g<Tab>', 'g<Tab>'))
+ it('switches to previous via <C-W>g<Tab> after switching to previous via <C-W>g<Tab>',
+ switches_to_previous_after_switching_to_previous('<C-W>g<Tab>', '<C-W>g<Tab>'))
+ it('switches to previous via <C-Tab> after switching to previous via <C-W>g<Tab>',
+ switches_to_previous_after_switching_to_previous('<C-W>g<Tab>', '<C-Tab>'))
+ it('switches to previous via :tabn #<CR> after switching to previous via <C-W>g<Tab>',
+ switches_to_previous_after_switching_to_previous('<C-W>g<Tab>', ':tabn #<CR>'))
+ it('switches to previous via g<Tab> after switching to previous via <C-Tab>',
+ switches_to_previous_after_switching_to_previous('<C-Tab>', 'g<Tab>'))
+ it('switches to previous via <C-W>g<Tab> after switching to previous via <C-Tab>',
+ switches_to_previous_after_switching_to_previous('<C-Tab>', '<C-W>g<Tab>'))
+ it('switches to previous via <C-Tab> after switching to previous via <C-Tab>',
+ switches_to_previous_after_switching_to_previous('<C-Tab>', '<C-Tab>'))
+ it('switches to previous via :tabn #<CR> after switching to previous via <C-Tab>',
+ switches_to_previous_after_switching_to_previous('<C-Tab>', ':tabn #<CR>'))
+ it('switches to previous via g<Tab> after switching to previous via :tabn #<CR>',
+ switches_to_previous_after_switching_to_previous(':tabn #<CR>', 'g<Tab>'))
+ it('switches to previous via <C-W>g<Tab> after switching to previous via :tabn #<CR>',
+ switches_to_previous_after_switching_to_previous(':tabn #<CR>', '<C-W>g<Tab>'))
+ it('switches to previous via <C-Tab> after switching to previous via <C-Tab>',
+ switches_to_previous_after_switching_to_previous(':tabn #<CR>', '<C-Tab>'))
+ it('switches to previous via :tabn #<CR> after switching to previous via :tabn #<CR>',
+ switches_to_previous_after_switching_to_previous(':tabn #<CR>', ':tabn #<CR>'))
+
+ local function does_not_switch_to_previous_after_closing_current_tab(characters)
+ return function()
+ -- Add three tabs for a total of four
+ command('tabnew')
+ command('tabnew')
+ command('tabnew')
+ -- Close the current (fourth tab)
+ command('wincmd c')
+
+ -- The previous tab is now the "zeroth" -- there isn't one.
+ eq(0, eval('tabpagenr(\'#\')'))
+
+ -- At this point, switching to the "previous" (i.e. fourth) tab would mean
+ -- switching to either a dangling or a null pointer.
+ feed(characters)
+
+ eq(dedent([=[
+
+
+ Tab page 1
+ [No Name]
+ Tab page 2
+ [No Name]
+ Tab page 3
+ > [No Name]]=]),
+ redir_exec('tabs')
+ )
+
+ -- The previous tab is now the "zero".
+ eq(0, eval('tabpagenr(\'#\')'))
+ end
+ end
+ it('does not switch to previous via g<Tab> after closing current tab',
+ does_not_switch_to_previous_after_closing_current_tab('g<Tab>'))
+ it('does not switch to previous via <C-W>g<Tab> after closing current tab',
+ does_not_switch_to_previous_after_closing_current_tab('<C-W>g<Tab>'))
+ it('does not switch to previous via <C-Tab> after closing current tab',
+ does_not_switch_to_previous_after_closing_current_tab('<C-Tab>'))
+ it('does not switch to previous via :tabn #<CR> after closing current tab',
+ does_not_switch_to_previous_after_closing_current_tab(':tabn #<CR>'))
+
+ local function does_not_switch_to_previous_after_entering_operator_pending(characters)
+ return function()
+ -- Add three tabs for a total of four
+ command('tabnew')
+ command('tabnew')
+ command('tabnew')
+
+ -- The previous tab is now the third.
+ eq(3, eval('tabpagenr(\'#\')'))
+
+ -- Enter operator pending mode.
+ feed('d')
+ eq('no', eval('mode(1)'))
+
+ -- At this point switching to the previous tab should have no effect
+ -- other than leaving operator pending mode.
+ feed(characters)
+
+ -- Attempting to switch tabs returns us to normal mode.
+ eq('n', eval('mode()'))
+
+ -- The current tab is still the fourth.
+ eq(4, eval('tabpagenr()'))
+
+ -- The previous tab is still the third.
+ eq(3, eval('tabpagenr(\'#\')'))
+ end
+ end
+ it('does not switch to previous via g<Tab> after entering operator pending',
+ does_not_switch_to_previous_after_entering_operator_pending('g<Tab>'))
+ -- NOTE: When in operator pending mode, attempting to switch to previous has
+ -- the following effect:
+ -- - Ctrl-W exits operator pending mode
+ -- - g<Tab> switches to the previous tab
+ -- In other words, the effect of "<C-W>g<Tab>" is to switch to the
+ -- previous tab even from operator pending mode, but only thanks to the
+ -- fact that the suffix after "<C-W>" in "<C-W>g<Tab>" just happens to
+ -- be the same as the normal mode command to switch to the previous tab.
+ -- it('does not switch to previous via <C-W>g<Tab> after entering operator pending',
+ -- does_not_switch_to_previous_after_entering_operator_pending('<C-W>g<Tab>'))
+ it('does not switch to previous via <C-Tab> after entering operator pending',
+ does_not_switch_to_previous_after_entering_operator_pending('<C-Tab>'))
+ -- NOTE: When in operator pending mode, pressing : leaves operator pending
+ -- mode and enters command mode, so :tabn #<CR> does in fact switch
+ -- tabs.
+ -- it('does not switch to previous via :tabn #<CR> after entering operator pending',
+ -- does_not_switch_to_previous_after_entering_operator_pending(':tabn #<CR>'))
+
+ local function cmdline_win_prevents_tab_switch(characters, completion_visible)
+ return function()
+ -- Add three tabs for a total of four
+ command('tabnew')
+ command('tabnew')
+ command('tabnew')
+
+ -- The previous tab is now the third.
+ eq(3, eval('tabpagenr(\'#\')'))
+
+ -- Edit : command line in command-line window
+ feed('q:')
+
+ local cmdline_win_id = eval('win_getid()')
+
+ -- At this point switching to the previous tab should have no effect.
+ feed(characters)
+
+ -- Attempting to switch tabs maintains the current window.
+ eq(cmdline_win_id, eval('win_getid()'))
+ eq(completion_visible, eval('complete_info().pum_visible'))
+
+ -- The current tab is still the fourth.
+ eq(4, eval('tabpagenr()'))
+
+ -- The previous tab is still the third.
+ eq(3, eval('tabpagenr(\'#\')'))
+ end
+ end
+ it('cmdline-win prevents tab switch via g<Tab>',
+ cmdline_win_prevents_tab_switch('g<Tab>', 0))
+ it('cmdline-win prevents tab switch via <C-W>g<Tab>',
+ cmdline_win_prevents_tab_switch('<C-W>g<Tab>', 1))
+ it('cmdline-win prevents tab switch via <C-Tab>',
+ cmdline_win_prevents_tab_switch('<C-Tab>', 0))
+ it('cmdline-win prevents tab switch via :tabn #<CR>',
+ cmdline_win_prevents_tab_switch(':tabn #<CR>', 0))
+
+ it(':tabs indicates correct prevtab curwin', function()
+ -- Add three tabs for a total of four
+ command('tabnew')
+ command('tabnew')
+ command('split')
+ command('vsplit')
+ feed('<C-w>p')
+ command('tabnew')
+
+ -- The previous tab is now the three.
+ eq(3, eval('tabpagenr(\'#\')'))
+
+ eq(dedent([=[
+
+
+ Tab page 1
+ [No Name]
+ Tab page 2
+ [No Name]
+ Tab page 3
+ [No Name]
+ # [No Name]
+ [No Name]
+ Tab page 4
+ > [No Name]]=]),
+ redir_exec('tabs')
+ )
+ end)
+end)
diff --git a/test/functional/autocmd/textyankpost_spec.lua b/test/functional/autocmd/textyankpost_spec.lua
index 8c23b72cff..3898d59e58 100644
--- a/test/functional/autocmd/textyankpost_spec.lua
+++ b/test/functional/autocmd/textyankpost_spec.lua
@@ -27,7 +27,8 @@ describe('TextYankPost', function()
operator = 'y',
regcontents = { 'foo\nbar' },
regname = '',
- regtype = 'V'
+ regtype = 'V',
+ visual = false
}, eval('g:event'))
eq(1, eval('g:count'))
@@ -40,7 +41,8 @@ describe('TextYankPost', function()
operator = 'y',
regcontents = { 'baz ' },
regname = '',
- regtype = 'v'
+ regtype = 'v',
+ visual = false
}, eval('g:event'))
eq(2, eval('g:count'))
@@ -50,7 +52,8 @@ describe('TextYankPost', function()
operator = 'y',
regcontents = { 'foo', 'baz' },
regname = '',
- regtype = "\0223" -- ^V + block width
+ regtype = "\0223", -- ^V + block width
+ visual = true
}, eval('g:event'))
eq(3, eval('g:count'))
end)
@@ -62,7 +65,8 @@ describe('TextYankPost', function()
operator = 'y',
regcontents = { 'foo\nbar' },
regname = '',
- regtype = 'V'
+ regtype = 'V',
+ visual = false
}, eval('g:event'))
command('set debug=msg')
@@ -92,7 +96,8 @@ describe('TextYankPost', function()
operator = 'y',
regcontents = { 'foo\nbar' },
regname = '',
- regtype = 'V'
+ regtype = 'V',
+ visual = false
}, eval('g:event'))
eq(1, eval('g:count'))
eq({ 'foo\nbar' }, funcs.getreg('+',1,1))
@@ -105,7 +110,8 @@ describe('TextYankPost', function()
operator = 'd',
regcontents = { 'foo' },
regname = '',
- regtype = 'v'
+ regtype = 'v',
+ visual = false
}, eval('g:event'))
eq(1, eval('g:count'))
@@ -115,7 +121,8 @@ describe('TextYankPost', function()
operator = 'd',
regcontents = { '\nbar' },
regname = '',
- regtype = 'V'
+ regtype = 'V',
+ visual = false
}, eval('g:event'))
eq(2, eval('g:count'))
@@ -125,7 +132,8 @@ describe('TextYankPost', function()
operator = 'c',
regcontents = { 'baz' },
regname = '',
- regtype = 'v'
+ regtype = 'v',
+ visual = false
}, eval('g:event'))
eq(3, eval('g:count'))
end)
@@ -153,7 +161,8 @@ describe('TextYankPost', function()
operator = 'y',
regcontents = { 'bar' },
regname = 'b',
- regtype = 'v'
+ regtype = 'v',
+ visual = false
}, eval('g:event'))
feed('"*yy')
@@ -162,7 +171,8 @@ describe('TextYankPost', function()
operator = 'y',
regcontents = { 'foo\nbar' },
regname = '*',
- regtype = 'V'
+ regtype = 'V',
+ visual = false
}, eval('g:event'))
command("set clipboard=unnamed")
@@ -174,7 +184,8 @@ describe('TextYankPost', function()
operator = 'y',
regcontents = { 'foo\nbar' },
regname = '',
- regtype = 'V'
+ regtype = 'V',
+ visual = false
}, eval('g:event'))
feed('"*yy')
@@ -183,7 +194,8 @@ describe('TextYankPost', function()
operator = 'y',
regcontents = { 'foo\nbar' },
regname = '*',
- regtype = 'V'
+ regtype = 'V',
+ visual = false
}, eval('g:event'))
end)
@@ -194,7 +206,8 @@ describe('TextYankPost', function()
operator = 'd',
regcontents = { 'foo\nbar' },
regname = '+',
- regtype = 'V'
+ regtype = 'V',
+ visual = false
}, eval('g:event'))
eq(1, eval('g:count'))
@@ -204,7 +217,8 @@ describe('TextYankPost', function()
operator = 'y',
regcontents = { 'baz text' },
regname = '',
- regtype = 'V'
+ regtype = 'V',
+ visual = false
}, eval('g:event'))
eq(2, eval('g:count'))
@@ -214,7 +228,8 @@ describe('TextYankPost', function()
operator = 'y',
regcontents = { 'baz ' },
regname = '',
- regtype = 'v'
+ regtype = 'v',
+ visual = false
}, eval('g:event'))
eq(3, eval('g:count'))
@@ -224,7 +239,8 @@ describe('TextYankPost', function()
operator = 'd',
regcontents = { 'baz text' },
regname = '',
- regtype = 'V'
+ regtype = 'V',
+ visual = false
}, eval('g:event'))
eq(4, eval('g:count'))
end)