Files
vim-lsp-mirror/test/lsp/utils.vimspec
T
hrsh7th fef60795ec Improve signature help with lexima.vim (#638)
* Improve signature help with lexima.vim

* Fix buffer change problem

* Display signature help after cursor jumped

* Fix event

* Add _ prefix for inner functions
2020-01-04 09:17:03 -08:00

176 lines
8.2 KiB
Plaintext

Describe lsp#utils
Describe lsp#utils#empty_complete
It should return empty complete
let items = lsp#utils#empty_complete()
Assert type(items) == type([])
Assert len(items) == 0
End
End
Describe lsp#utils#uri_to_path
It should return path from uri (Windows)
if !has('win32')
Skip This tests is not for UNIX
endif
let tests = [
\ {'uri': 'file:///C:/path/to/the/file.txt', 'path': 'C:\path\to\the\file.txt'},
\ {'uri': 'file:///C:/path/to/the/file+name.txt', 'path': 'C:\path\to\the\file+name.txt'},
\ {'uri': 'file:///C:/path/to/the/file%2Bname.txt', 'path': 'C:\path\to\the\file+name.txt'},
\ {'uri': 'file:///C:/path/to/the/file%20name.txt', 'path': 'C:\path\to\the\file name.txt'},
\ {'uri': 'file:///C:/path+name?query=your+value', 'path': 'C:\path+name'},
\ {'uri': 'file:///C:/path+name#hash', 'path': 'C:\path+name'},
\]
for test in tests
let path = lsp#utils#uri_to_path(test.uri)
Assert Equals(path, test.path)
endfor
End
It should return path from uri (UNIX)
if has('win32')
Skip This tests is not for Windows
endif
let tests = [
\ {'uri': 'file:///path/to/the/file.txt', 'path': '/path/to/the/file.txt'},
\ {'uri': 'file:///path/to/the/file+name.txt', 'path': '/path/to/the/file+name.txt'},
\ {'uri': 'file:///path/to/the/file%2Bname.txt', 'path': '/path/to/the/file+name.txt'},
\ {'uri': 'file:///path/to/the/file%20name.txt', 'path': '/path/to/the/file name.txt'},
\ {'uri': 'file:///path+name?query=your+value', 'path': '/path+name'},
\ {'uri': 'file:///path+name#hash', 'path': '/path+name'},
\]
for test in tests
let path = lsp#utils#uri_to_path(test.uri)
Assert Equals(path, test.path)
endfor
End
End
Describe lsp#utils#find_nearest_parent_file_directory
It should return the root directory if it is found
let tests = [
\ {'from': './test/testproject/src/main.cpp', 'target': ['.ccls', 'compile_commands.json', 'README.md', 'git/'], 'root': './test/testproject'},
\ {'from': './test/testproject/src/main.cpp', 'target': ['.ccls', 'build/', 'CMakeLists.txt', 'git/'], 'root': './test/testproject'},
\ {'from': './test/testproject/src/main.cpp', 'target': '.ccls', 'root': './test/testproject'},
\ {'from': './test/testproject/src/main.cpp', 'target': 'git/', 'root': './test/testproject'},
\ {'from': './test/testproject/src/main.cpp', 'target': 'CMakeLists.txt', 'root': './test/testproject/src'},
\ {'from': './test/testproject/README.md', 'target': ['.ccls', 'compile_commands.json', 'README.md', 'git/'], 'root': './test/testproject'},
\ {'from': './test/testproject/README.md', 'target': ['.ccls', 'build/', 'CMakeLists.txt', 'git/'], 'root': './test/testproject'},
\ {'from': './test/testproject/README.md', 'target': '.ccls', 'root': './test/testproject'},
\ {'from': './test/testproject/README.md', 'target': 'git/', 'root': './test/testproject'},
\ {'from': './test/testproject/README.md', 'target': 'CMakeLists.txt', 'root': './test/testproject'},
\]
for test in tests
let path = lsp#utils#find_nearest_parent_file_directory(fnamemodify(test.from, ':p:h'), test.target)
Assert Equals(path, fnamemodify(test.root, ':p:h'))
endfor
End
It should return an empty string if not target has been found
let tests = [
\ {'from': './test/testproject/src/main.cpp', 'target': ['fdrvbws/', 'asbr/', 'bgdf/', 'abfrb.txt', 'ngo.c']},
\ {'from': './test/testproject/src/main.cpp', 'target': 'asbr/'},
\ {'from': './test/testproject/src/main.cpp', 'target': 'btr.c'},
\ {'from': './test/testproject/.gitignore', 'target': ['fdrvbws/', 'asbr/', 'bgdf/', 'abfrb.txt', 'ngo.c']},
\ {'from': './test/testproject/.gitignore', 'target': 'asbr/'},
\ {'from': './test/testproject/.gitignore', 'target': 'btr.c'},
\]
for test in tests
let path = lsp#utils#find_nearest_parent_file_directory(fnamemodify(test.from, ':p:h'), test.target)
Assert Empty(path)
endfor
End
End
Describe lsp#utils#to_char
It should return the character-index from the given byte-index on a buffer
call setline(1, ['a β c', 'δ', ''])
Assert lsp#utils#to_char('%', 1, 1) == 0
Assert lsp#utils#to_char('%', 1, 2) == 1
Assert lsp#utils#to_char('%', 1, 3) == 2
Assert lsp#utils#to_char('%', 1, 5) == 3
Assert lsp#utils#to_char('%', 1, 6) == 4
Assert lsp#utils#to_char('%', 1, 7) == 5
Assert lsp#utils#to_char('%', 2, 1) == 0
Assert lsp#utils#to_char('%', 2, 3) == 1
Assert lsp#utils#to_char('%', 3, 1) == 0
%delete
End
It should return the character-index from the given byte-index in an unloaded file
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 1) == 0
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 2) == 1
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 3) == 2
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 5) == 3
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 6) == 4
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 7) == 5
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 2, 1) == 0
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 2, 3) == 1
Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 3, 1) == 0
End
End
Describe lsp#utils#_get_before_line
It should return line before cursor on col=1
enew!
call setline(1, ['123456789'])
call cursor(1, 1)
Assert Equals(lsp#utils#_get_before_line(), '')
End
It should return line before cursor on col=$
let l:saved_virtualedit = &virtualedit
let &virtualedit = 'all'
enew!
call setline(1, ['123456789'])
call cursor(1, 10)
Assert Equals(lsp#utils#_get_before_line(), '123456789')
let &virtualedit = l:saved_virtualedit
End
It should return line before cursor with multibyte
enew!
call setline(1, ['あいうえおabc'])
call cursor(1, 18)
Assert Equals(lsp#utils#_get_before_line(), 'あいうえおab')
End
End
Describe lsp#utils#_get_before_char_skip_white
It should return before char in above of line
enew!
call setline(1, ['(', ''])
call cursor(2, 1)
Assert Equals(lsp#utils#_get_before_char_skip_white(), '(')
End
It should return before char with multibyte
enew!
call setline(1, ['あいうえお( '])
call cursor(1, 21)
Assert Equals(lsp#utils#_get_before_char_skip_white(), '(')
End
End
Describe lsp#utils#base64_decode
It should decode basic string correctly
Assert Equals(lsp#utils#base64_decode('TWFu'), [77, 97, 110])
End
It should decode multiple groups correctly
Assert Equals(lsp#utils#base64_decode('TWFuIHRlc3R4'), [77, 97, 110, 32, 116, 101, 115, 116, 120])
End
It should handle padding (one octet)
Assert Equals(lsp#utils#base64_decode('TQ=='), [77])
End
It should handle padding (two octets)
Assert Equals(lsp#utils#base64_decode('TWE='), [77, 97])
End
It should handle more complex string
Assert Equals(lsp#utils#base64_decode('AAAAEgAJABYAAAAIAAQAFw=='), [0, 0, 0, 18, 0, 9, 0, 22, 0, 0, 0, 8, 0, 4, 0, 23])
End
End
End