Skip to content

Commit

Permalink
Merge pull request #638 from tsuyoshicho/fix/filepath-dir
Browse files Browse the repository at this point in the history
Filepath.abspath are directory' path resolving fail fix
  • Loading branch information
tyru authored Jul 23, 2019
2 parents 2036821 + dd21137 commit 923927e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions autoload/vital/__vital__/System/Filepath.vim
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ function! s:abspath(path) abort
return a:path
endif
" Note:
" the behavior of ':p' for non existing file path is not defined
return filereadable(a:path)
" the behavior of ':p' for non existing file path/directory is not defined
return (filereadable(a:path) || isdirectory(a:path))
\ ? fnamemodify(a:path, ':p')
\ : s:join(fnamemodify(getcwd(), ':p'), a:path)
endfunction
Expand Down
13 changes: 12 additions & 1 deletion test/System/Filepath.vimspec
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Describe System.Filepath
Assert Same(ret, abspath)
End

It should return an absolute path of {path} which exists
It should return an absolute path of {path} which exists file
let relpath = 'foo.txt'
call writefile(['foo'], relpath)
let ret = FP.abspath(relpath)
Expand All @@ -72,6 +72,17 @@ Describe System.Filepath
call delete(relpath)
End

It should return an absolute path of {path} which exists dir
let relpath = 'foo'
call mkdir(relpath, "")
let ret = FP.abspath(relpath)
let exp = FP.join(getcwd(), relpath) . FP.separator()
Assert NotSame(ret, relpath)
Assert NotEquals(ret, relpath)
Assert Equals(ret, exp)
call delete(relpath, 'd')
End

It should return an absolute path of {path} which does not exist
let relpath = FP.join('hoge', 'bar.txt')
let ret = FP.abspath(relpath)
Expand Down

0 comments on commit 923927e

Please sign in to comment.