Make the nearest file search result absolute paths, and add tests to cover it.
This commit is contained in:
parent
7c2a16e149
commit
654a172473
4 changed files with 20 additions and 1 deletions
|
@ -33,7 +33,15 @@ endfunction
|
||||||
" Given a buffer and a filename, find the nearest file by searching upwards
|
" Given a buffer and a filename, find the nearest file by searching upwards
|
||||||
" through the paths relative to the given buffer.
|
" through the paths relative to the given buffer.
|
||||||
function! ale#util#FindNearestFile(buffer, filename) abort
|
function! ale#util#FindNearestFile(buffer, filename) abort
|
||||||
return findfile(a:filename, fnamemodify(bufname(a:buffer), ':p') . ';')
|
let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p')
|
||||||
|
|
||||||
|
let l:relative_path = findfile(a:filename, l:buffer_filename . ';')
|
||||||
|
|
||||||
|
if !empty(l:relative_path)
|
||||||
|
return fnamemodify(l:relative_path, ':p')
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#util#GetFunction(string_or_ref) abort
|
function! ale#util#GetFunction(string_or_ref) abort
|
||||||
|
|
11
test/test_nearest_file_search.vader
Normal file
11
test/test_nearest_file_search.vader
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
Execute(Open a file some directory down):
|
||||||
|
silent! cd /testplugin/test
|
||||||
|
:e! top/middle/bottom/dummy.txt
|
||||||
|
|
||||||
|
Then(We should be able to find a configuration file further up):
|
||||||
|
AssertEqual expand('%:p:h:h:h:h') . '/top/example.ini', ale#util#FindNearestFile(bufnr('%'), 'example.ini')
|
||||||
|
|
||||||
|
Execute(Do nothing):
|
||||||
|
|
||||||
|
Then(We shouldn't find anything for files which don't match):
|
||||||
|
AssertEqual '', ale#util#FindNearestFile(bufnr('%'), 'cantfindthis')
|
0
test/top/example.ini
Normal file
0
test/top/example.ini
Normal file
0
test/top/middle/bottom/dummy.txt
Normal file
0
test/top/middle/bottom/dummy.txt
Normal file
Reference in a new issue