test: avoid extra clear() calls

also: various other cleanup
This commit is contained in:
Justin M. Keyes
2017-10-02 00:24:19 +02:00
parent e9dba214ea
commit 6f7754dfa0
3 changed files with 29 additions and 40 deletions

View File

@@ -2,60 +2,55 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear local clear = helpers.clear
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local get_pathsep = helpers.get_pathsep
local command = helpers.command local command = helpers.command
local iswin = helpers.iswin
describe("'%:p' expanding", function() describe('path collapse', function()
local pathsep
local targetdir local targetdir
local expected_path local expected_path
local function get_full_path()
return eval('expand("%:p")')
end
local function join_path(...) local function join_path(...)
local pathsep = (iswin() and '\\' or '/')
return table.concat({...}, pathsep) return table.concat({...}, pathsep)
end end
before_each(function() before_each(function()
clear()
pathsep = get_pathsep()
targetdir = join_path('test', 'functional', 'fixtures') targetdir = join_path('test', 'functional', 'fixtures')
clear(join_path(targetdir, 'tty-test.c')) clear()
expected_path = get_full_path() command('edit '..join_path(targetdir, 'tty-test.c'))
expected_path = eval('expand("%:p")')
end) end)
it('given a relative path with current directory in the middle #7117', function() it('with /./ segment #7117', function()
clear(join_path(targetdir, '.', 'tty-test.c')) command('edit '..join_path(targetdir, '.', 'tty-test.c'))
eq(expected_path, get_full_path()) eq(expected_path, eval('expand("%:p")'))
end) end)
it('given a relative path with current directory #7117', function() it('with ./ prefix #7117', function()
clear(join_path('.', targetdir, 'tty-test.c')) command('edit '..join_path('.', targetdir, 'tty-test.c'))
eq(expected_path, get_full_path()) eq(expected_path, eval('expand("%:p")'))
end) end)
it('given a relative path with current directory to a file when changing directory #7117', function() it('with ./ prefix, after directory change #7117', function()
clear(join_path('.', targetdir, 'tty-test.c')) command('edit '..join_path('.', targetdir, 'tty-test.c'))
command('cd test') command('cd test')
eq(expected_path, get_full_path()) eq(expected_path, eval('expand("%:p")'))
end) end)
it('given a relative path with directory up the tree to a file #7117', function() it('with /../ segment #7117', function()
clear(join_path(targetdir, '..', 'fixtures', 'tty-test.c')) command('edit '..join_path(targetdir, '..', 'fixtures', 'tty-test.c'))
eq(expected_path, get_full_path()) eq(expected_path, eval('expand("%:p")'))
end) end)
it('given a different starting directory and a relative path with directory up the tree #7117', function() it('with ../ and different starting directory #7117', function()
command('cd test') command('cd test')
command('e ' .. join_path('..', targetdir, 'tty-test.c')) command('edit '..join_path('..', targetdir, 'tty-test.c'))
eq(expected_path, get_full_path()) eq(expected_path, eval('expand("%:p")'))
end) end)
it('given a different starting directory and a relative path with current directory and up the tree #7117', function() it('with ./../ and different starting directory #7117', function()
command('cd test') command('cd test')
command('e ' .. join_path('.', '..', targetdir, 'tty-test.c')) command('edit '..join_path('.', '..', targetdir, 'tty-test.c'))
eq(expected_path, get_full_path()) eq(expected_path, eval('expand("%:p")'))
end) end)
end) end)

View File

@@ -120,16 +120,10 @@ describe('Screen', function()
end) end)
it('has correct default title with named file', function() it('has correct default title with named file', function()
local expected = 'myfile (/mydir) - NVIM' local expected = (iswin() and 'myfile (C:\\mydir) - NVIM'
if iswin() then or 'myfile (/mydir) - NVIM')
expected = 'myfile (C:\\mydir) - NVIM'
end
command('set title') command('set title')
if iswin() then command(iswin() and 'file C:\\mydir\\myfile' or 'file /mydir/myfile')
command('file C:\\mydir\\myfile')
else
command('file /mydir/myfile')
end
screen:expect(function() screen:expect(function()
eq(expected, screen.title) eq(expected, screen.title)
end) end)

View File

@@ -482,14 +482,14 @@ describe('path.c', function()
eq(OK, result) eq(OK, result)
end) end)
itp('works with a relative path with the current directory prefix #7117', function() itp('expands "./" to the current directory #7117', function()
local force_expansion = 1 local force_expansion = 1
local result = vim_FullName('./unit-test-directory/test.file', buffer, length, force_expansion) local result = vim_FullName('./unit-test-directory/test.file', buffer, length, force_expansion)
eq(OK, result) eq(OK, result)
eq(lfs.currentdir() .. '/unit-test-directory/test.file', (ffi.string(buffer))) eq(lfs.currentdir() .. '/unit-test-directory/test.file', (ffi.string(buffer)))
end) end)
itp('works with a relative path with the directory name mentioned twice #7117', function() itp('collapses "foo/../foo" to "foo" #7117', function()
local force_expansion = 1 local force_expansion = 1
local result = vim_FullName('unit-test-directory/../unit-test-directory/test.file', buffer, length, force_expansion) local result = vim_FullName('unit-test-directory/../unit-test-directory/test.file', buffer, length, force_expansion)
eq(OK, result) eq(OK, result)