Fix some path issues, and get lsp dir tests passing on Windows

This commit is contained in:
w0rp 2017-09-09 18:39:56 +01:00
parent 8055a03067
commit b3a9a0e3e8
3 changed files with 25 additions and 15 deletions

View File

@ -7,6 +7,18 @@ function! ale#path#Simplify(path) abort
return substitute(simplify(a:path), '^//\+', '/', 'g') " no-custom-checks return substitute(simplify(a:path), '^//\+', '/', 'g') " no-custom-checks
endfunction endfunction
" This function is mainly used for testing.
" Simplify() a path, and change forward slashes to back slashes on Windows.
function! ale#path#Winify(path) abort
let l:simplified_path = ale#path#Simplify(a:path)
if has('win32')
return substitute(l:simplified_path, '/', '\\', 'g')
endif
return l:simplified_path
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#path#FindNearestFile(buffer, filename) abort function! ale#path#FindNearestFile(buffer, filename) abort

View File

@ -50,5 +50,5 @@ function! ale#test#SetFilename(path) abort
\ ? a:path \ ? a:path
\ : l:dir . '/' . a:path \ : l:dir . '/' . a:path
silent noautocmd execute 'file ' . fnameescape(ale#path#Simplify(l:full_path)) silent noautocmd execute 'file ' . fnameescape(ale#path#Winify(l:full_path))
endfunction endfunction

View File

@ -1,13 +1,11 @@
Before: Before:
silent! cd /testplugin/test/lsp
let g:dir = getcwd()
let g:ale_lsp_next_version_id = 1 let g:ale_lsp_next_version_id = 1
call ale#test#SetDirectory('/testplugin/test/lsp')
call ale#test#SetFilename('foo/bar.ts') call ale#test#SetFilename('foo/bar.ts')
After: After:
silent execute 'cd ' . fnameescape(g:dir) call ale#test#RestoreDirectory()
unlet! g:dir
Execute(ale#lsp#message#Initialize() should return correct messages): Execute(ale#lsp#message#Initialize() should return correct messages):
AssertEqual AssertEqual
@ -44,7 +42,7 @@ Execute(ale#lsp#message#DidOpen() should return correct messages):
\ 'textDocument/didOpen', \ 'textDocument/didOpen',
\ { \ {
\ 'textDocument': { \ 'textDocument': {
\ 'uri': 'file://' . g:dir . '/foo/bar.ts', \ 'uri': ale#path#ToURI(g:dir . '/foo/bar.ts'),
\ 'languageId': 'typescript', \ 'languageId': 'typescript',
\ 'version': 12, \ 'version': 12,
\ 'text': "foo()\nbar()\nbaz()", \ 'text': "foo()\nbar()\nbaz()",
@ -62,7 +60,7 @@ Execute(ale#lsp#message#DidChange() should return correct messages):
\ 'textDocument/didChange', \ 'textDocument/didChange',
\ { \ {
\ 'textDocument': { \ 'textDocument': {
\ 'uri': 'file://' . g:dir . '/foo/bar.ts', \ 'uri': ale#path#ToURI(g:dir . '/foo/bar.ts'),
\ 'version': 34, \ 'version': 34,
\ }, \ },
\ 'contentChanges': [{'text': "foo()\nbar()\nbaz()"}], \ 'contentChanges': [{'text': "foo()\nbar()\nbaz()"}],
@ -84,7 +82,7 @@ Execute(ale#lsp#message#DidSave() should return correct messages):
\ 'textDocument/didSave', \ 'textDocument/didSave',
\ { \ {
\ 'textDocument': { \ 'textDocument': {
\ 'uri': 'file://' . g:dir . '/foo/bar.ts', \ 'uri': ale#path#ToURI(g:dir . '/foo/bar.ts'),
\ }, \ },
\ } \ }
\ ], \ ],
@ -97,7 +95,7 @@ Execute(ale#lsp#message#DidClose() should return correct messages):
\ 'textDocument/didClose', \ 'textDocument/didClose',
\ { \ {
\ 'textDocument': { \ 'textDocument': {
\ 'uri': 'file://' . g:dir . '/foo/bar.ts', \ 'uri': ale#path#ToURI(g:dir . '/foo/bar.ts'),
\ }, \ },
\ } \ }
\ ], \ ],
@ -109,7 +107,7 @@ Execute(ale#lsp#tsserver_message#Open() should return correct messages):
\ 1, \ 1,
\ 'ts@open', \ 'ts@open',
\ { \ {
\ 'file': g:dir . '/foo/bar.ts', \ 'file': ale#path#Winify(g:dir . '/foo/bar.ts'),
\ } \ }
\ ], \ ],
\ ale#lsp#tsserver_message#Open(bufnr('')) \ ale#lsp#tsserver_message#Open(bufnr(''))
@ -120,7 +118,7 @@ Execute(ale#lsp#tsserver_message#Close() should return correct messages):
\ 1, \ 1,
\ 'ts@close', \ 'ts@close',
\ { \ {
\ 'file': g:dir . '/foo/bar.ts', \ 'file': ale#path#Winify(g:dir . '/foo/bar.ts'),
\ } \ }
\ ], \ ],
\ ale#lsp#tsserver_message#Close(bufnr('')) \ ale#lsp#tsserver_message#Close(bufnr(''))
@ -131,7 +129,7 @@ Execute(ale#lsp#tsserver_message#Change() should return correct messages):
\ 1, \ 1,
\ 'ts@change', \ 'ts@change',
\ { \ {
\ 'file': g:dir . '/foo/bar.ts', \ 'file': ale#path#Winify(g:dir . '/foo/bar.ts'),
\ 'line': 1, \ 'line': 1,
\ 'offset': 1, \ 'offset': 1,
\ 'endLine': 1073741824, \ 'endLine': 1073741824,
@ -147,7 +145,7 @@ Execute(ale#lsp#tsserver_message#Geterr() should return correct messages):
\ 1, \ 1,
\ 'ts@geterr', \ 'ts@geterr',
\ { \ {
\ 'files': [g:dir . '/foo/bar.ts'], \ 'files': [ale#path#Winify(g:dir . '/foo/bar.ts')],
\ } \ }
\ ], \ ],
\ ale#lsp#tsserver_message#Geterr(bufnr('')) \ ale#lsp#tsserver_message#Geterr(bufnr(''))
@ -158,7 +156,7 @@ Execute(ale#lsp#tsserver_message#Completions() should return correct messages):
\ 0, \ 0,
\ 'ts@completions', \ 'ts@completions',
\ { \ {
\ 'file': g:dir . '/foo/bar.ts', \ 'file': ale#path#Winify(g:dir . '/foo/bar.ts'),
\ 'line': 347, \ 'line': 347,
\ 'offset': 12, \ 'offset': 12,
\ 'prefix': 'abc', \ 'prefix': 'abc',
@ -172,7 +170,7 @@ Execute(ale#lsp#tsserver_message#CompletionEntryDetails() should return correct
\ 0, \ 0,
\ 'ts@completionEntryDetails', \ 'ts@completionEntryDetails',
\ { \ {
\ 'file': g:dir . '/foo/bar.ts', \ 'file': ale#path#Winify(g:dir . '/foo/bar.ts'),
\ 'line': 347, \ 'line': 347,
\ 'offset': 12, \ 'offset': 12,
\ 'entryNames': ['foo', 'bar'], \ 'entryNames': ['foo', 'bar'],