Files
vim-lsp-mirror/test/lsp/utils.vimspec
Prabir Shrestha 3aba91cf71 remove lsp#utils#to_col in favor of lsp#utils#position#_lsp_to_vim (#645)
* refactor to use lsp#utils#position#_lsp_to_vim
* remove lsp#utils#to_col in favor of lsp#utils#position#_lsp_to_vim
* fix doc
2020-01-01 13:33:36 -08:00

135 lines
6.8 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#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