diff options
author | Ignas Anikevicius <anikevicius@gmail.com> | 2017-09-18 21:06:55 +0300 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-10-02 00:48:30 +0200 |
commit | 2b133101cf67b523c2503ef715dfb9ebfa732da2 (patch) | |
tree | 3955290491608369498a6821d070d6d711248da2 | |
parent | 981387b7c83026c1446cdddf6b374f63973a2b86 (diff) | |
download | rneovim-2b133101cf67b523c2503ef715dfb9ebfa732da2.tar.gz rneovim-2b133101cf67b523c2503ef715dfb9ebfa732da2.tar.bz2 rneovim-2b133101cf67b523c2503ef715dfb9ebfa732da2.zip |
win: vim_FullName(): force backslashes #7287
- Replace obvious cases of '/' literal with PATHSEP. (There are still
some remaining cases that need closer inspection.)
- Fixup tests: ui/screen_basic
closes #7117
ref https://github.com/neovim/neovim/issues/2471#issuecomment-271193714
-rw-r--r-- | src/nvim/path.c | 10 | ||||
-rw-r--r-- | test/functional/core/path_spec.lua | 61 | ||||
-rw-r--r-- | test/functional/ui/screen_basic_spec.lua | 10 | ||||
-rw-r--r-- | test/unit/path_spec.lua | 14 |
4 files changed, 92 insertions, 3 deletions
diff --git a/src/nvim/path.c b/src/nvim/path.c index f2339c8046..51adcfb135 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1690,6 +1690,9 @@ int vim_FullName(const char *fname, char *buf, size_t len, bool force) if (strlen(fname) > (len - 1)) { xstrlcpy(buf, fname, len); // truncate +#ifdef WIN32 + slash_adjust(buf); +#endif return FAIL; } @@ -1702,6 +1705,9 @@ int vim_FullName(const char *fname, char *buf, size_t len, bool force) if (rv == FAIL) { xstrlcpy(buf, fname, len); // something failed; use the filename } +#ifdef WIN32 + slash_adjust(buf); +#endif return rv; } @@ -2196,11 +2202,11 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf, // expand it if forced or not an absolute path if (force || !path_is_absolute_path(fname)) { - if ((p = vim_strrchr(fname, '/')) != NULL) { + if ((p = vim_strrchr(fname, PATHSEP)) != NULL) { // relative to root if (p == fname) { // only one path component - relative_directory[0] = '/'; + relative_directory[0] = PATHSEP; relative_directory[1] = NUL; } else { assert(p >= fname); diff --git a/test/functional/core/path_spec.lua b/test/functional/core/path_spec.lua new file mode 100644 index 0000000000..44e69fff7b --- /dev/null +++ b/test/functional/core/path_spec.lua @@ -0,0 +1,61 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear +local eq = helpers.eq +local eval = helpers.eval +local get_pathsep = helpers.get_pathsep +local command = helpers.command + +describe("'%:p' expanding", function() + local pathsep + local targetdir + local expected_path + + local function get_full_path() + return eval('expand("%:p")') + end + + local function join_path(...) + return table.concat({...}, pathsep) + end + + before_each(function() + clear() + pathsep = get_pathsep() + targetdir = join_path('test', 'functional', 'fixtures') + clear(join_path(targetdir, 'tty-test.c')) + expected_path = get_full_path() + end) + + it('given a relative path with current directory in the middle #7117', function() + clear(join_path(targetdir, '.', 'tty-test.c')) + eq(expected_path, get_full_path()) + end) + + it('given a relative path with current directory #7117', function() + clear(join_path('.', targetdir, 'tty-test.c')) + eq(expected_path, get_full_path()) + end) + + it('given a relative path with current directory to a file when changing directory #7117', function() + clear(join_path('.', targetdir, 'tty-test.c')) + command('cd test') + eq(expected_path, get_full_path()) + end) + + it('given a relative path with directory up the tree to a file #7117', function() + clear(join_path(targetdir, '..', 'fixtures', 'tty-test.c')) + eq(expected_path, get_full_path()) + end) + + it('given a different starting directory and a relative path with directory up the tree #7117', function() + command('cd test') + command('e ' .. join_path('..', targetdir, 'tty-test.c')) + eq(expected_path, get_full_path()) + end) + + it('given a different starting directory and a relative path with current directory and up the tree #7117', function() + command('cd test') + command('e ' .. join_path('.', '..', targetdir, 'tty-test.c')) + eq(expected_path, get_full_path()) + end) +end) diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index bfcdc7f652..9032239b31 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -5,6 +5,7 @@ local feed, command = helpers.feed, helpers.command local insert = helpers.insert local eq = helpers.eq local eval = helpers.eval +local iswin = helpers.iswin describe('screen', function() local screen @@ -120,8 +121,15 @@ describe('Screen', function() it('has correct default title with named file', function() local expected = 'myfile (/mydir) - NVIM' + if iswin() then + expected = 'myfile (C:\\mydir) - NVIM' + end command('set title') - command('file /mydir/myfile') + if iswin() then + command('file C:\\mydir\\myfile') + else + command('file /mydir/myfile') + end screen:expect(function() eq(expected, screen.title) end) diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index a9cba7df84..0400747e72 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -481,6 +481,20 @@ describe('path.c', function() eq('/tmp', ffi.string(buffer)) eq(OK, result) end) + + itp('works with a relative path with the current directory prefix #7117', function() + local force_expansion = 1 + local result = vim_FullName('./unit-test-directory/test.file', buffer, length, force_expansion) + eq(OK, result) + eq(lfs.currentdir() .. '/unit-test-directory/test.file', (ffi.string(buffer))) + end) + + itp('works with a relative path with the directory name mentioned twice #7117', function() + local force_expansion = 1 + local result = vim_FullName('unit-test-directory/../unit-test-directory/test.file', buffer, length, force_expansion) + eq(OK, result) + eq(lfs.currentdir() .. '/unit-test-directory/test.file', (ffi.string(buffer))) + end) end) describe('path_fix_case', function() |