Files
ale/test/test_find_nearest_file_or_directory.vader
Ben Boeckel 528e25954b
Some checks failed
CI / build_image (push) Has been cancelled
CI / test_ale (--linters-only) (push) Has been cancelled
CI / test_ale (--lua-only) (push) Has been cancelled
CI / test_ale (--neovim-07-only) (push) Has been cancelled
CI / test_ale (--neovim-08-only) (push) Has been cancelled
CI / test_ale (--vim-80-only) (push) Has been cancelled
CI / test_ale (--vim-90-only) (push) Has been cancelled
ale: add FindNearestFileOrDirectory function (#5033)
* test: rename `FindNearestFile` test file

It matches the API name better and now lives beside the test file for
`FindNearestDirectory`.

* ale: add `FindNearestFileOrDirectory` function

Some anchor paths can be files or directories (e.g., `.git` is a
directory normally, but a file for worktrees). Add a function that finds
either type of path and returns the nearest.
2025-08-21 12:59:18 +01:00

23 lines
892 B
Plaintext

Before:
call ale#test#SetDirectory('/testplugin/test')
After:
call ale#test#RestoreDirectory()
Execute(We should find a directory when searching and it is closer):
call ale#test#SetFilename('test-files/top/needle_dir/target/query/buffer.txt')
AssertEqual
\ ale#path#Simplify(expand('%:p:h:h:h:h:h:h') . '/test-files/top/needle_dir/target/needle/'),
\ ale#path#FindNearestFileOrDirectory(bufnr('%'), 'needle')
Execute(We should find a file when searching and it is closer):
call ale#test#SetFilename('test-files/top/needle_file/target/query/buffer.txt')
AssertEqual
\ ale#path#Simplify(expand('%:p:h:h:h:h:h:h') . '/test-files/top/needle_file/target/needle'),
\ ale#path#FindNearestFileOrDirectory(bufnr('%'), 'needle')
Execute(We shouldn't find anything for files which don't match):
AssertEqual '', ale#path#FindNearestFileOrDirectory(bufnr('%'), 'cantfindthis')