Merge PR #4388 'Clean up tests'

This commit is contained in:
Marco Hinz 2016-03-02 12:37:58 +01:00
commit 9d1e076056
3 changed files with 56 additions and 23 deletions

View File

@ -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)

View File

@ -1,22 +1,28 @@
local helpers = require('test.functional.helpers') local helpers = require('test.functional.helpers')
local clear, nvim, eq = helpers.clear, helpers.nvim, helpers.eq
describe('TabNew', function() local clear = helpers.clear
setup(clear) local command = helpers.command
describe('au TabNew', function() local eq = helpers.eq
describe('with * as <afile>', function() local eval = helpers.eval
it('matches when opening any new tab', function()
nvim('command', 'au! TabNew * echom "tabnew:".tabpagenr().":".bufnr("")') describe('autocmd TabNew', function()
eq("\ntabnew:2:1", nvim('command_output', 'tabnew')) before_each(clear)
eq("\ntabnew:3:2\n\"test.x\" [New File]", nvim('command_output', 'tabnew test.x'))
end) it('matches when opening any new tab', function()
end) command('autocmd! TabNew * let g:test = "tabnew:".tabpagenr().":".bufnr("")')
describe('with FILE as <afile>', function() command('tabnew')
it('matches when opening a new tab for FILE', function() eq('tabnew:2:1', eval('g:test'))
local tmp_path = nvim('eval', 'tempname()') command('tabnew test.x')
nvim('command', 'au! TabNew '..tmp_path..' echom "tabnew:match"') eq('tabnew:3:2', eval('g:test'))
eq("\ntabnew:4:3\ntabnew:match\n\""..tmp_path.."\" [New File]", nvim('command_output', 'tabnew '..tmp_path)) end)
end)
end) it('matches when opening a new tab for FILE', function()
end) 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) end)

View File

@ -139,7 +139,6 @@ describe('tab pages', function()
autocmd TabLeave * :call add(g:r, 'TabLeave') autocmd TabLeave * :call add(g:r, 'TabLeave')
autocmd WinLeave * :call add(g:r, 'WinLeave') autocmd WinLeave * :call add(g:r, 'WinLeave')
autocmd BufLeave * :call add(g:r, 'BufLeave') autocmd BufLeave * :call add(g:r, 'BufLeave')
autocmd TabNew * :call add(g:r, 'TabNew')
let t:a='a' let t:a='a'
C tab split C tab split
let t:a='b' let t:a='b'
@ -186,13 +185,11 @@ describe('tab pages', function()
=== tab split === === tab split ===
WinLeave WinLeave
TabLeave TabLeave
TabNew
WinEnter WinEnter
TabEnter TabEnter
=== tabnew === === tabnew ===
WinLeave WinLeave
TabLeave TabLeave
TabNew
WinEnter WinEnter
TabEnter TabEnter
BufLeave BufLeave
@ -225,7 +222,6 @@ describe('tab pages', function()
=== tabnew === === tabnew ===
WinLeave WinLeave
TabLeave TabLeave
TabNew
WinEnter WinEnter
TabEnter TabEnter
BufLeave BufLeave