aboutsummaryrefslogtreecommitdiff
path: root/test/functional/vimscript/fnamemodify_spec.lua
Commit message (Collapse)AuthorAge
* refactor(path): pathcmp() #41035tao2026-08-07
| | | | | | | | | | | | | | | | | | | | | | Problem: Redudant code Solution: Add `path_fold_char()` to normalize path sep. Refactor `pathcmp()` and `path_fnamencmp()` into `path_cmp`. | feature | pathcmp | path_fnamencmp | path_cmp(now) | | ------------------------ | -------------- | -------------- | ------------- | | case folding | `mb_toupper()` | `utf_fold()` | `utf_fold()` | | consults fileignorecase | ✅ | ✅ | `ic` param | | `maxlen` | ✅ | ✅ | ✅ | | `/` == `\` | ✅ | ✅ | ✅ | | MSWIN drive letter | ❌ | ✅ | ✅ | | sep affects sorting | ✅ | ❌ | ✅ | | ignores a trailing slash | ✅ | ❌ | ✅ | Refactor `path_fnamecmp` and `path_full_compare` into `path_equal`, with flags controlling "no filesystem" comparison (i.e. `path_cmp`), env variables expansion, absolute path resolution and filesystem access.
* fix(path): DOS device path check #40976Dominic Della Valle2026-07-26
| | | | | | | | | | | Problem: The current check is intended to match DOS device paths starting with `\\?` or `\\.` but will match any path starting with `?` or `.`, including relative paths such as `.\`. This is because the leading slashes are removed before the comparison. Solution: Changes the check to include the path's prefix, assuring the path has the correct amount of separators for a DOS device path.
* test(harness): migrate away from magic globalsJustin M. Keyes2026-07-21
| | | | | | | | | | | | | | | | | | | | | Problem: The magic globals `it`, `describe`, etc., are more trouble than they are worth. - Hooking into `after_each` requires `getfenv()` hacks. - They confuse luals/emmylua, because the top-level `.luarc.json` isn't merged with `test/.luarc.json` (apparently a luals limitation?) - They totally defeat discoverability because the user just has to "know" about the various magic symbols. So they harm DX, which means they serve no purpose at all. Solution: - Expose the test API from `testutil`, so tests can call `t.it()`, `t.describe()`, etc., in the conventional way. - Drop `getfenv()` hacks. - Drop the `setfenv()` injection in `load_chunk`. - Drop `test/_meta.lua`.
* docs: misc, remove some old help tags #40214Justin M. Keyes2026-07-18
| | | | | | | | | | - Remove old help tags: they add noise to cmdline completion. Co-authored-by: acehinnnqru <acehinnnqru@gmail.com> Co-authored-by: KangaZero <samuelyongw@gmail.com> Co-authored-by: Simone Ragusa <hi@interrato.dev> Co-authored-by: Chinmay Dalal <~chinmay/public-inbox@lists.sr.ht> Co-authored-by: coyaSONG <66289470+coyaSONG@users.noreply.github.com> Co-authored-by: Olivia Kinnear <git@superatomic.dev>
* fix(path): avoid shell fallback for unknown users #40757MAAZIZ Adel Ayoub2026-07-17
| | | | | | | | Problem: Expanding an unknown ~user path falls back to the shell. In a fast event, this re-enters the event loop and aborts Nvim. Solution: Leave unknown users unexpanded when the system account lookup fails.
* fix(coverity): RESOURCE_LEAK, USE_AFTER_FREEJustin M. Keyes2026-07-13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | /src/nvim/ex_docmd.c: 5033 in ex_restart() 5027 // The address after --listen may be in use by the current server. 5028 if (i > 0 && strequal(arg, "--listen")) { 5029 const listitem_T *next_li = li->li_next; 5030 if (next_li != NULL) { 5031 const char *addr = tv_get_string(TV_LIST_ITEM_TV(next_li)); 5032 if (strstr(addr, ":") || strstr(addr, "/") || strstr(addr, "\\")) { >>> CID 649201: Resource leaks (RESOURCE_LEAK) >>> Overwriting "listen_arg" in "listen_arg = xstrdup(addr)" leaks the storage that "listen_arg" points to. 5033 listen_arg = TO_SLASH_SAVE(addr); 5034 #ifdef MSWIN 5035 // On Windows, don't pass --listen to new server (named pipe can't be reused immediately). 5036 // Instead pass the address via RPC; new server rebinds after startup. 5037 li = next_li; 5038 continue; *** CID 649200: Memory - illegal accesses (USE_AFTER_FREE) /src/nvim/eval/fs.c: 228 in modify_fname() 222 223 // ":h" - head, remove "/file_name", can be repeated 224 // Don't remove the logical root, see `FileInfo`. 225 while (src[*usedlen] == ':' && src[*usedlen + 1] == 'h') { 226 valid |= VALID_HEAD; 227 *usedlen += 2; >>> CID 649200: Memory - illegal accesses (USE_AFTER_FREE) >>> Using freed pointer "s". 228 while (tail > s && after_pathsep(s, tail)) { 229 MB_PTR_BACK(*fnamep, tail); 230 } 231 *fnamelen = tail <= s ? (size_t)(s - *fnamep) : (size_t)(tail - *fnamep); 232 if (*fnamelen == 0) { 233 // Result is empty. Turn it into "." to make ":cd %:h" work.
* fix(path): normalize separators (slashes) #39155tao2026-07-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Continue separators normalization, and try to keep it at the nvim <-> external boundary, e.g., `fn.xxx`, `api.xxx`, `:xxx` Solution: some key changes - normalize `$HOME-windows` - normalize entry points of changing directory - `nvim_set_current_dir()`, `chdir()` - normalize the named pipe - `--listen` arg, `--server` arg, `:restart` - `serverstart()`, `sockconnect()`, `serverstop()` - make `expand()` respect 'shellslash' again - clean up `did_set_shellslash` - replace `forward_slash` with `TO_SLASH` - remove obsolete `TMP_PATHSEPSTR` - remove `slash_adjust` in `do_autocmd_dirchanged`? - make `fnamemodify()` always return `/` (except when substituting separators via `:s`, `:gs` ?) Note: - these funcs still apply `slash_adjust` on return, as before: `:pwd`, `chdir()`, `exepath()`, `getcwd()` - these funcs alwarys return `/`, unlike before the normalization PRs - `getcompletion()`, `finddir()`, `findfile()` Also - clean up code, comments, formatting and tests - move `TO_SLASH` from `f_chdir` to `changedir_func` - move `TO_SLASH` from `f_bufadd` to `buflist_new` Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
* feat(path): fnamemodify(':h') preserves logical root #40447tao2026-07-01
| | | | | | | | | | | | | | | | | | | | | | Problem: On Windows, `fnamemodify('//foo/C$', ':h')` incorrectly removes `C$` as a regular file name and returns `//foo`. However, this is a valid UNC path, `foo` is a server name and `C$` is a share name. The correct result should be `//foo/C$`. Solution: Extend `os_fileinfo2` and `FileInfo` with `prefix_off`, `rest_off` to identify path types and logical root boundaries. ':h' can use this info to prevent traversing past the logical root. Examples: /foo => / //foo => // (POSIX) //foo/bar => //foo (POSIX) //server/share/foo => //server/share/ (Windows) C:/foo => C:/ //?/C:/foo => //?/C:/ Co-authored-by: Barrett Ruth <br@barrettruth.com>
* fix(vimscript): normalize multi-slash heads in fnamemodify() #39805Barrett Ruth2026-05-17
| | | | | Problem: `fnamemodify(..., ':h')` mishandles POSIX leading slash runs longer than `//`. Solution: Collapse those slash runs to `/` before computing the head.
* fix(path): normalize path slashes on Windows #37729tao2026-04-24
| | | | | | | | | | | | | | | | | | | | Problem: On Windows, path separators may become inconsistent for various reasons, which makes normalization quite painful. Solution: Normalize paths to `/` at the entry boundaries and always use it internally, converting back only in rare cases where `\` is really needed (e.g. cmd.exe/bat scripts?). This is the first commit in a series of incremental steps. Note: * some funcs won't respect shellslash. e.g. `expand/fnamemodify` * some funcs still respect shellslash, but will be updated in a follow PR. e.g. `ex_pwd/f_chdir/f_getcwd` * uv's built-in funcs always return `\`. e.g. `uv.cwd/uv.exepath` Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
* fix(fs): expand drive-relative paths on Windows #37084tao2026-03-18
| | | | | | | | | | | Problem: On windows, if a drive-relative path doesn't contain a slash, `path_to_absolute` can't split out the relative component, causing expansion to fails. e.g., `c:` `c:.` `c:..` `c:foo.md` Solution: For these cases, we can pass letter and colon to `path_full_dir_name`. Notably, `..` is included as well. if that relative path exists, it can be expanded correctly.
* test: start test runners in Xtest_xdg dir (#37964)zeertzjq2026-02-20
| | | | | | | | | | | | | | This is a better way to prevent parallel tests from interfering with each other, as there are many ways files can be created and deleted in tests, so enforcing different file names is hard. Using $TMPDIR can also work in most cases, but 'backipskip' etc. have special defaults for $TMPDIR. Symlink runtime/, src/, test/ and README.md to Xtest_xdg dir to make tests more convenient (and symlinking test/ is required for busted). Also, use README.md instead of test/README.md in the Ex mode inccommand test, as test/README.md no longer contains 'N' char.
* refactor(test): rename alter_slashes, invert its behaviorJustin M. Keyes2024-09-09
| | | | | | | - `alter_slashes` belongs in `testutil.lua`, not `testnvim.lua`. - `alter_slashes` is an unusual name. Rename it to `fix_slashes`. - invert its behavior, to emphasize that `/` slashes are the preferred, pervasive convention, not `\` slashes.
* test: improve test conventionsdundargoc2024-04-23
| | | | | | | | | Specifically, functions that are run in the context of the test runner are put in module `test/testutil.lua` while the functions that are run in the context of the test session are put in `test/functional/testnvim.lua`. Closes https://github.com/neovim/neovim/issues/27004.
* refactor(test): inject after_each differentlyLewis Russell2024-04-10
|
* test: improve test conventionsdundargoc2024-04-08
| | | | Work on https://github.com/neovim/neovim/issues/27004.
* test: rename (meths, funcs) -> (api, fn)Lewis Russell2024-01-12
|
* refactor: format test/*Justin M. Keyes2024-01-03
|
* test: simplify platform detection (#21020)dundargoc2022-11-22
| | | | | Extend the capabilities of is_os to detect more platforms such as freebsd and openbsd. Also remove `iswin()` helper function as it can be replaced by `is_os("win")`.
* test: reorg #15698Justin M. Keyes2021-09-17
Problem: Subdirectories like "visual", "insert", "normal" encourage people to separate *related* tests for no good reason. Typically the _mode_ is not the relevant topic of a test (and when it is, _then_ create an appropriate describe() or it()). Solution: - Delete the various `test/functional/<mode>/` subdirectories, move their tests to more meaningful topics. - Rename `…/normal/` to `…/editor/`. - Move or merge `…/visual/*` and `…/insert/*` tests into here where appropriate. - Rename `…/eval/` to `…/vimscript/`. - Move `…/viml/*` into here also. * test(reorg): insert/* => editor/mode_insert_spec.lua * test(reorg): cmdline/* => editor/mode_cmdline_spec.lua * test(reorg): eval core tests => eval_spec.lua