]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/vim-lsp/test/lsp/utils.vimspec

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / vim-lsp / test / lsp / utils.vimspec
1 Describe lsp#utils
2
3     Describe lsp#utils#empty_complete
4         It should return empty complete
5             let items = lsp#utils#empty_complete()
6             Assert type(items) == type([])
7             Assert len(items) == 0
8         End
9     End
10
11     Describe lsp#utils#uri_to_path
12         It should return path from uri (Windows)
13             if !has('win32')
14               Skip This tests is not for UNIX
15             endif
16             let tests = [
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'},
23             \]
24             for test in tests
25                 let path = lsp#utils#uri_to_path(test.uri)
26                 Assert Equals(path, test.path)
27             endfor
28         End
29
30         It should return path from uri (UNIX)
31             if has('win32')
32               Skip This tests is not for Windows
33             endif
34             let tests = [
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'},
41             \]
42             for test in tests
43                 let path = lsp#utils#uri_to_path(test.uri)
44                 Assert Equals(path, test.path)
45             endfor
46         End
47     End
48
49     Describe lsp#utils#path_to_uri
50         It should return uri from path (Windows)
51             if !has('win32')
52               Skip This tests is not for UNIX
53             endif
54             let tests = [
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'},
59             \]
60             for test in tests
61                 let uri = lsp#utils#path_to_uri(test.path)
62                 Assert Equals(uri, test.uri)
63             endfor
64         End
65
66         It should return uri from path (UNIX)
67             if has('win32')
68               Skip This tests is not for Windows
69             endif
70             let tests = [
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'},
75             \]
76             for test in tests
77                 let uri = lsp#utils#path_to_uri(test.path)
78                 Assert Equals(uri, test.uri)
79             endfor
80         End
81     End
82
83     Describe lsp#utils#normalize_uri
84         It should return normalized uri (Windows)
85             if !has('win32')
86               Skip This tests is not for UNIX
87             endif
88             let tests = [
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'},
94             \]
95             for test in tests
96                 let uri = lsp#utils#normalize_uri(test.path)
97                 Assert Equals(uri, test.uri)
98             endfor
99         End
100
101         It should return normalized uri (UNIX)
102             if has('win32')
103               Skip This tests is not for Windows
104             endif
105             let tests = [
106             \  {'path': 'file:///path/to/the/file.txt', 'uri': 'file:///path/to/the/file.txt'},
107             \]
108             for test in tests
109                 let uri = lsp#utils#normalize_uri(test.path)
110                 Assert Equals(uri, test.uri)
111             endfor
112         End
113     End
114
115     Describe lsp#utils#find_nearest_parent_file_directory
116         It should return the root directory if it is found
117             let tests = [
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'},
128             \]
129             for test in tests
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'))
132             endfor
133         End
134
135         It should return an empty string if not target has been found
136             let tests = [
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'},
143             \]
144             for test in tests
145                 let path = lsp#utils#find_nearest_parent_file_directory(fnamemodify(test.from, ':p:h'), test.target)
146                 Assert Empty(path)
147             endfor
148         End
149     End
150
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
163             %delete
164         End
165
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
176         End
177     End
178
179     Describe lsp#utils#_get_before_line
180         It should return line before cursor on col=1
181             enew!
182             call setline(1, ['123456789'])
183             call cursor(1, 1)
184             Assert Equals(lsp#utils#_get_before_line(), '')
185         End
186
187         It should return line before cursor on col=$
188             let l:saved_virtualedit = &virtualedit
189             let &virtualedit = 'all'
190             enew!
191             call setline(1, ['123456789'])
192             call cursor(1, 10)
193             Assert Equals(lsp#utils#_get_before_line(), '123456789')
194             let &virtualedit = l:saved_virtualedit
195         End
196
197         It should return line before cursor with multibyte
198             enew!
199             call setline(1, ['あいうえおabc'])
200             call cursor(1, 18)
201             Assert Equals(lsp#utils#_get_before_line(), 'あいうえおab')
202         End
203     End
204
205     Describe lsp#utils#_get_before_char_skip_white
206         It should return before char in above of line
207             enew!
208             call setline(1, ['(', ''])
209             call cursor(2, 1)
210             Assert Equals(lsp#utils#_get_before_char_skip_white(), '(')
211         End
212         It should return before char with multibyte
213             enew!
214             call setline(1, ['あいうえお(    '])
215             call cursor(1, 21)
216             Assert Equals(lsp#utils#_get_before_char_skip_white(), '(')
217         End
218     End
219
220     Describe lsp#utils#base64_decode
221         It should decode basic string correctly
222             Assert Equals(lsp#utils#base64_decode('TWFu'), [77, 97, 110])
223         End
224
225         It should decode multiple groups correctly
226             Assert Equals(lsp#utils#base64_decode('TWFuIHRlc3R4'), [77, 97, 110, 32, 116, 101, 115, 116, 120])
227         End
228
229         It should handle padding (one octet)
230             Assert Equals(lsp#utils#base64_decode('TQ=='), [77])
231         End
232
233         It should handle padding (two octets)
234             Assert Equals(lsp#utils#base64_decode('TWE='), [77, 97])
235         End
236
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])
239         End
240     End
241
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')
259         End
260     End
261
262     Describe lsp#utils#_split_by_eol
263
264         It should split text by \r\n
265           Assert Equals(lsp#utils#_split_by_eol("あいうえお\r\nかきくけこ"), ['あいうえお', 'かきくけこ'])
266         End
267
268         It should split text by \r
269           Assert Equals(lsp#utils#_split_by_eol("あいうえお\rかきくけこ"), ['あいうえお', 'かきくけこ'])
270         End
271
272         It should split text by \r\n\r
273           Assert Equals(lsp#utils#_split_by_eol("あいうえお\r\n\rかきくけこ"), ['あいうえお', '', 'かきくけこ'])
274         End
275
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かきくけこ"), ['あいうえお', '', '', '', 'かきくけこ'])
278         End
279
280     End
281
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')
287         End
288
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')
293         End
294
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')
299         End
300     End
301
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({}), [])
310         End
311
312         It should return the list it self if list is given
313             Assert Equals(lsp#utils#iteratable([1,2,3]), [1,2,3])
314         End
315     End
316 End