All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
3 Describe lsp#utils#empty_complete
4 It should return empty complete
5 let items = lsp#utils#empty_complete()
6 Assert type(items) == type([])
11 Describe lsp#utils#uri_to_path
12 It should return path from uri (Windows)
14 Skip This tests is not for UNIX
17 \ {'uri': 'file:///C:/path/to/the/file.txt', 'path': 'C:\path\to\the\file.txt'},
18 \ {'uri': 'file:///C:/path/to/the/file+name.txt', 'path': 'C:\path\to\the\file+name.txt'},
19 \ {'uri': 'file:///C:/path/to/the/file%2Bname.txt', 'path': 'C:\path\to\the\file+name.txt'},
20 \ {'uri': 'file:///C:/path/to/the/file%20name.txt', 'path': 'C:\path\to\the\file name.txt'},
21 \ {'uri': 'file:///C:/path+name?query=your+value', 'path': 'C:\path+name'},
22 \ {'uri': 'file:///C:/path+name#hash', 'path': 'C:\path+name'},
25 let path = lsp#utils#uri_to_path(test.uri)
26 Assert Equals(path, test.path)
30 It should return path from uri (UNIX)
32 Skip This tests is not for Windows
35 \ {'uri': 'file:///path/to/the/file.txt', 'path': '/path/to/the/file.txt'},
36 \ {'uri': 'file:///path/to/the/file+name.txt', 'path': '/path/to/the/file+name.txt'},
37 \ {'uri': 'file:///path/to/the/file%2Bname.txt', 'path': '/path/to/the/file+name.txt'},
38 \ {'uri': 'file:///path/to/the/file%20name.txt', 'path': '/path/to/the/file name.txt'},
39 \ {'uri': 'file:///path+name?query=your+value', 'path': '/path+name'},
40 \ {'uri': 'file:///path+name#hash', 'path': '/path+name'},
43 let path = lsp#utils#uri_to_path(test.uri)
44 Assert Equals(path, test.path)
49 Describe lsp#utils#path_to_uri
50 It should return uri from path (Windows)
52 Skip This tests is not for UNIX
55 \ {'path': 'C:\path\to\the\file.txt', 'uri': 'file:///C:/path/to/the/file.txt'},
56 \ {'path': 'C:\path\to\the\file+name.txt', 'uri': 'file:///C:/path/to/the/file%2Bname.txt'},
57 \ {'path': 'C:\path\to\the\file name.txt', 'uri': 'file:///C:/path/to/the/file%20name.txt'},
58 \ {'path': 'http://foo/bar.txt', 'uri': 'http://foo/bar.txt'},
61 let uri = lsp#utils#path_to_uri(test.path)
62 Assert Equals(uri, test.uri)
66 It should return uri from path (UNIX)
68 Skip This tests is not for Windows
71 \ {'path': '/path/to/the/file.txt', 'uri': 'file:///path/to/the/file.txt'},
72 \ {'path': '/path/to/the/file+name.txt', 'uri': 'file:///path/to/the/file%2Bname.txt'},
73 \ {'path': '/path/to/the/file name.txt', 'uri': 'file:///path/to/the/file%20name.txt'},
74 \ {'path': 'http://foo/bar.txt', 'uri': 'http://foo/bar.txt'},
77 let uri = lsp#utils#path_to_uri(test.path)
78 Assert Equals(uri, test.uri)
83 Describe lsp#utils#normalize_uri
84 It should return normalized uri (Windows)
86 Skip This tests is not for UNIX
89 \ {'path': 'file:///C:\path\to\the\file.txt', 'uri': 'file:///c:\path\to\the\file.txt'},
90 \ {'path': 'file:///c:\path\to\the\file.txt', 'uri': 'file:///c:\path\to\the\file.txt'},
91 \ {'path': 'file:///C%3A\path\to\the\file.txt', 'uri': 'file:///c:\path\to\the\file.txt'},
92 \ {'path': 'file:///c%3a\path\to\the\file.txt', 'uri': 'file:///c:\path\to\the\file.txt'},
93 \ {'path': 'http://foo/bar.txt', 'uri': 'http://foo/bar.txt'},
96 let uri = lsp#utils#normalize_uri(test.path)
97 Assert Equals(uri, test.uri)
101 It should return normalized uri (UNIX)
103 Skip This tests is not for Windows
106 \ {'path': 'file:///path/to/the/file.txt', 'uri': 'file:///path/to/the/file.txt'},
109 let uri = lsp#utils#normalize_uri(test.path)
110 Assert Equals(uri, test.uri)
115 Describe lsp#utils#find_nearest_parent_file_directory
116 It should return the root directory if it is found
118 \ {'from': './test/testproject/src/main.cpp', 'target': ['.ccls', 'compile_commands.json', 'README.md', 'git/'], 'root': './test/testproject'},
119 \ {'from': './test/testproject/src/main.cpp', 'target': ['.ccls', 'build/', 'CMakeLists.txt', 'git/'], 'root': './test/testproject/src'},
120 \ {'from': './test/testproject/src/main.cpp', 'target': '.ccls', 'root': './test/testproject'},
121 \ {'from': './test/testproject/src/main.cpp', 'target': 'git/', 'root': './test/testproject'},
122 \ {'from': './test/testproject/src/main.cpp', 'target': 'CMakeLists.txt', 'root': './test/testproject/src'},
123 \ {'from': './test/testproject/README.md', 'target': ['.ccls', 'compile_commands.json', 'README.md', 'git/'], 'root': './test/testproject'},
124 \ {'from': './test/testproject/README.md', 'target': ['.ccls', 'build/', 'CMakeLists.txt', 'git/'], 'root': './test/testproject'},
125 \ {'from': './test/testproject/README.md', 'target': '.ccls', 'root': './test/testproject'},
126 \ {'from': './test/testproject/README.md', 'target': 'git/', 'root': './test/testproject'},
127 \ {'from': './test/testproject/README.md', 'target': 'CMakeLists.txt', 'root': './test/testproject'},
130 let path = lsp#utils#find_nearest_parent_file_directory(fnamemodify(test.from, ':p:h'), test.target)
131 Assert Equals(path, fnamemodify(test.root, ':p:h'))
135 It should return an empty string if not target has been found
137 \ {'from': './test/testproject/src/main.cpp', 'target': ['fdrvbws/', 'asbr/', 'bgdf/', 'abfrb.txt', 'ngo.c']},
138 \ {'from': './test/testproject/src/main.cpp', 'target': 'asbr/'},
139 \ {'from': './test/testproject/src/main.cpp', 'target': 'btr.c'},
140 \ {'from': './test/testproject/.gitignore', 'target': ['fdrvbws/', 'asbr/', 'bgdf/', 'abfrb.txt', 'ngo.c']},
141 \ {'from': './test/testproject/.gitignore', 'target': 'asbr/'},
142 \ {'from': './test/testproject/.gitignore', 'target': 'btr.c'},
145 let path = lsp#utils#find_nearest_parent_file_directory(fnamemodify(test.from, ':p:h'), test.target)
151 Describe lsp#utils#to_char
152 It should return the character-index from the given byte-index on a buffer
153 call setline(1, ['a β c', 'δ', ''])
154 Assert lsp#utils#to_char('%', 1, 1) == 0
155 Assert lsp#utils#to_char('%', 1, 2) == 1
156 Assert lsp#utils#to_char('%', 1, 3) == 2
157 Assert lsp#utils#to_char('%', 1, 5) == 3
158 Assert lsp#utils#to_char('%', 1, 6) == 4
159 Assert lsp#utils#to_char('%', 1, 7) == 5
160 Assert lsp#utils#to_char('%', 2, 1) == 0
161 Assert lsp#utils#to_char('%', 2, 3) == 1
162 Assert lsp#utils#to_char('%', 3, 1) == 0
166 It should return the character-index from the given byte-index in an unloaded file
167 Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 1) == 0
168 Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 2) == 1
169 Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 3) == 2
170 Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 5) == 3
171 Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 6) == 4
172 Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 1, 7) == 5
173 Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 2, 1) == 0
174 Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 2, 3) == 1
175 Assert lsp#utils#to_char('./test/testfiles/multibyte.txt', 3, 1) == 0
179 Describe lsp#utils#_get_before_line
180 It should return line before cursor on col=1
182 call setline(1, ['123456789'])
184 Assert Equals(lsp#utils#_get_before_line(), '')
187 It should return line before cursor on col=$
188 let l:saved_virtualedit = &virtualedit
189 let &virtualedit = 'all'
191 call setline(1, ['123456789'])
193 Assert Equals(lsp#utils#_get_before_line(), '123456789')
194 let &virtualedit = l:saved_virtualedit
197 It should return line before cursor with multibyte
199 call setline(1, ['あいうえおabc'])
201 Assert Equals(lsp#utils#_get_before_line(), 'あいうえおab')
205 Describe lsp#utils#_get_before_char_skip_white
206 It should return before char in above of line
208 call setline(1, ['(', ''])
210 Assert Equals(lsp#utils#_get_before_char_skip_white(), '(')
212 It should return before char with multibyte
214 call setline(1, ['あいうえお( '])
216 Assert Equals(lsp#utils#_get_before_char_skip_white(), '(')
220 Describe lsp#utils#base64_decode
221 It should decode basic string correctly
222 Assert Equals(lsp#utils#base64_decode('TWFu'), [77, 97, 110])
225 It should decode multiple groups correctly
226 Assert Equals(lsp#utils#base64_decode('TWFuIHRlc3R4'), [77, 97, 110, 32, 116, 101, 115, 116, 120])
229 It should handle padding (one octet)
230 Assert Equals(lsp#utils#base64_decode('TQ=='), [77])
233 It should handle padding (two octets)
234 Assert Equals(lsp#utils#base64_decode('TWE='), [77, 97])
237 It should handle more complex string
238 Assert Equals(lsp#utils#base64_decode('AAAAEgAJABYAAAAIAAQAFw=='), [0, 0, 0, 18, 0, 9, 0, 22, 0, 0, 0, 8, 0, 4, 0, 23])
242 Describe lsp#utils#make_valid_word
243 It should make valid word
244 Assert Equals(lsp#utils#make_valid_word('my-word'), 'my-word')
245 Assert Equals(lsp#utils#make_valid_word("my\nword"), 'my')
246 Assert Equals(lsp#utils#make_valid_word('my-word: description'), 'my-word')
247 Assert Equals(lsp#utils#make_valid_word('my-word : description'), 'my-word')
248 Assert Equals(lsp#utils#make_valid_word('my-word is word'), 'my-word')
249 Assert Equals(lsp#utils#make_valid_word('my-func()'), 'my-func')
250 Assert Equals(lsp#utils#make_valid_word('my-name::space'), 'my-name::space')
251 Assert Equals(lsp#utils#make_valid_word('my-name#space'), 'my-name#space')
252 Assert Equals(lsp#utils#make_valid_word('my-name.space'), 'my-name.space')
253 Assert Equals(lsp#utils#make_valid_word('my-name.space: foo'), 'my-name.space')
254 Assert Equals(lsp#utils#make_valid_word('my-name%space: foo'), 'my-name%space')
255 Assert Equals(lsp#utils#make_valid_word('my-name&space: foo'), 'my-name&space')
256 Assert Equals(lsp#utils#make_valid_word('my-array[0]'), 'my-array')
257 Assert Equals(lsp#utils#make_valid_word('my-array<string>'), 'my-array')
258 Assert Equals(lsp#utils#make_valid_word("my-name\tdescription"), 'my-name')
262 Describe lsp#utils#_split_by_eol
264 It should split text by \r\n
265 Assert Equals(lsp#utils#_split_by_eol("あいうえお\r\nかきくけこ"), ['あいうえお', 'かきくけこ'])
268 It should split text by \r
269 Assert Equals(lsp#utils#_split_by_eol("あいうえお\rかきくけこ"), ['あいうえお', 'かきくけこ'])
272 It should split text by \r\n\r
273 Assert Equals(lsp#utils#_split_by_eol("あいうえお\r\n\rかきくけこ"), ['あいうえお', '', 'かきくけこ'])
276 It should split text by \r\n\n\r\r\n
277 Assert Equals(lsp#utils#_split_by_eol("あいうえお\r\n\n\r\r\nかきくけこ"), ['あいうえお', '', '', '', 'かきくけこ'])
282 Describe lsp#utils#_compare_nearest_path
283 It should return looong since it is longest
284 Assert Equals(lsp#utils#_nearest_path(
285 \ {'/path/to/looong': 1, '/path/to/short': 1,}
286 \), '/path/to/looong')
289 It should return loong since they are both longest but loong matches mostly
290 Assert Equals(lsp#utils#_nearest_path(
291 \ {'/path/to/loong': 2, '/path/to/short': 1,}
292 \), '/path/to/loong')
295 It should return not long since it is not longest
296 Assert Equals(lsp#utils#_nearest_path(
297 \ {'/path/to/long': 2, '/path/to/short': 1,}
298 \), '/path/to/short')
302 Describe lsp#utils#iteratable
303 It should return empty list if non-list is given
304 Assert Equals(lsp#utils#iteratable(''), [])
305 Assert Equals(lsp#utils#iteratable(1), [])
306 Assert Equals(lsp#utils#iteratable(2.3), [])
307 Assert Equals(lsp#utils#iteratable(v:false), [])
308 Assert Equals(lsp#utils#iteratable(v:true), [])
309 Assert Equals(lsp#utils#iteratable({}), [])
312 It should return the list it self if list is given
313 Assert Equals(lsp#utils#iteratable([1,2,3]), [1,2,3])