You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

140 lines
7.5 KiB

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_col
It should return the byte-index from the given character-index on a buffer
call setline(1, ['a β c', 'δ', ''])
Assert lsp#utils#to_col('%', 1, 0) == 1
Assert lsp#utils#to_col('%', 1, 1) == 2
Assert lsp#utils#to_col('%', 1, 2) == 3
Assert lsp#utils#to_col('%', 1, 3) == 5
Assert lsp#utils#to_col('%', 1, 4) == 6
Assert lsp#utils#to_col('%', 1, 5) == 7
Assert lsp#utils#to_col('%', 2, 0) == 1
Assert lsp#utils#to_col('%', 2, 1) == 3
Assert lsp#utils#to_col('%', 3, 0) == 1
%delete
End
It should return the byte-index from the given character-index in an unloaded file
Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 1, 0) == 1
Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 1, 1) == 2
Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 1, 2) == 3
Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 1, 3) == 5
Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 1, 4) == 6
Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 1, 5) == 7
Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 2, 0) == 1
Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 2, 1) == 3
Assert lsp#utils#to_col('./test/testfiles/multibyte.txt', 3, 0) == 1
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
End