]> git.madduck.net Git - etc/vim.git/blobdiff - .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:

Merge commit 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / vim-lsp / test / lsp / utils.vimspec
diff --git a/.vim/bundle/vim-lsp/test/lsp/utils.vimspec b/.vim/bundle/vim-lsp/test/lsp/utils.vimspec
new file mode 100644 (file)
index 0000000..0425e9f
--- /dev/null
@@ -0,0 +1,316 @@
+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#path_to_uri
+        It should return uri from path (Windows)
+            if !has('win32')
+              Skip This tests is not for UNIX
+            endif
+            let tests = [
+            \  {'path': 'C:\path\to\the\file.txt', 'uri': 'file:///C:/path/to/the/file.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': 'http://foo/bar.txt', 'uri': 'http://foo/bar.txt'},
+            \]
+            for test in tests
+                let uri = lsp#utils#path_to_uri(test.path)
+                Assert Equals(uri, test.uri)
+            endfor
+        End
+
+        It should return uri from path (UNIX)
+            if has('win32')
+              Skip This tests is not for Windows
+            endif
+            let tests = [
+            \  {'path': '/path/to/the/file.txt', 'uri': 'file:///path/to/the/file.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': 'http://foo/bar.txt', 'uri': 'http://foo/bar.txt'},
+            \]
+            for test in tests
+                let uri = lsp#utils#path_to_uri(test.path)
+                Assert Equals(uri, test.uri)
+            endfor
+        End
+    End
+
+    Describe lsp#utils#normalize_uri
+        It should return normalized uri (Windows)
+            if !has('win32')
+              Skip This tests is not for UNIX
+            endif
+            let tests = [
+            \  {'path': 'file:///C:\path\to\the\file.txt', 'uri': 'file:///c:\path\to\the\file.txt'},
+            \  {'path': 'file:///c:\path\to\the\file.txt', 'uri': 'file:///c:\path\to\the\file.txt'},
+            \  {'path': 'file:///C%3A\path\to\the\file.txt', 'uri': 'file:///c:\path\to\the\file.txt'},
+            \  {'path': 'file:///c%3a\path\to\the\file.txt', 'uri': 'file:///c:\path\to\the\file.txt'},
+            \  {'path': 'http://foo/bar.txt', 'uri': 'http://foo/bar.txt'},
+            \]
+            for test in tests
+                let uri = lsp#utils#normalize_uri(test.path)
+                Assert Equals(uri, test.uri)
+            endfor
+        End
+
+        It should return normalized uri (UNIX)
+            if has('win32')
+              Skip This tests is not for Windows
+            endif
+            let tests = [
+            \  {'path': 'file:///path/to/the/file.txt', 'uri': 'file:///path/to/the/file.txt'},
+            \]
+            for test in tests
+                let uri = lsp#utils#normalize_uri(test.path)
+                Assert Equals(uri, test.uri)
+            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/src'},
+            \  {'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
+
+    Describe lsp#utils#make_valid_word
+        It should make valid word
+            Assert Equals(lsp#utils#make_valid_word('my-word'), 'my-word')
+            Assert Equals(lsp#utils#make_valid_word("my\nword"), 'my')
+            Assert Equals(lsp#utils#make_valid_word('my-word: description'), 'my-word')
+            Assert Equals(lsp#utils#make_valid_word('my-word : description'), 'my-word')
+            Assert Equals(lsp#utils#make_valid_word('my-word is word'), 'my-word')
+            Assert Equals(lsp#utils#make_valid_word('my-func()'), 'my-func')
+            Assert Equals(lsp#utils#make_valid_word('my-name::space'), 'my-name::space')
+            Assert Equals(lsp#utils#make_valid_word('my-name#space'), 'my-name#space')
+            Assert Equals(lsp#utils#make_valid_word('my-name.space'), 'my-name.space')
+            Assert Equals(lsp#utils#make_valid_word('my-name.space: foo'), 'my-name.space')
+            Assert Equals(lsp#utils#make_valid_word('my-name%space: foo'), 'my-name%space')
+            Assert Equals(lsp#utils#make_valid_word('my-name&space: foo'), 'my-name&space')
+            Assert Equals(lsp#utils#make_valid_word('my-array[0]'), 'my-array')
+            Assert Equals(lsp#utils#make_valid_word('my-array<string>'), 'my-array')
+            Assert Equals(lsp#utils#make_valid_word("my-name\tdescription"), 'my-name')
+        End
+    End
+
+    Describe lsp#utils#_split_by_eol
+
+        It should split text by \r\n
+          Assert Equals(lsp#utils#_split_by_eol("あいうえお\r\nかきくけこ"), ['あいうえお', 'かきくけこ'])
+        End
+
+        It should split text by \r
+          Assert Equals(lsp#utils#_split_by_eol("あいうえお\rかきくけこ"), ['あいうえお', 'かきくけこ'])
+        End
+
+        It should split text by \r\n\r
+          Assert Equals(lsp#utils#_split_by_eol("あいうえお\r\n\rかきくけこ"), ['あいうえお', '', 'かきくけこ'])
+        End
+
+        It should split text by \r\n\n\r\r\n
+          Assert Equals(lsp#utils#_split_by_eol("あいうえお\r\n\n\r\r\nかきくけこ"), ['あいうえお', '', '', '', 'かきくけこ'])
+        End
+
+    End
+
+    Describe lsp#utils#_compare_nearest_path
+        It should return looong since it is longest
+          Assert Equals(lsp#utils#_nearest_path(
+          \  {'/path/to/looong': 1, '/path/to/short': 1,}
+          \), '/path/to/looong')
+        End
+
+        It should return loong since they are both longest but loong matches mostly
+          Assert Equals(lsp#utils#_nearest_path(
+          \  {'/path/to/loong': 2, '/path/to/short': 1,}
+          \), '/path/to/loong')
+        End
+
+        It should return not long since it is not longest
+          Assert Equals(lsp#utils#_nearest_path(
+          \  {'/path/to/long': 2, '/path/to/short': 1,}
+          \), '/path/to/short')
+        End
+    End
+
+    Describe lsp#utils#iteratable
+        It should return empty list if non-list is given
+            Assert Equals(lsp#utils#iteratable(''), [])
+            Assert Equals(lsp#utils#iteratable(1), [])
+            Assert Equals(lsp#utils#iteratable(2.3), [])
+            Assert Equals(lsp#utils#iteratable(v:false), [])
+            Assert Equals(lsp#utils#iteratable(v:true), [])
+            Assert Equals(lsp#utils#iteratable({}), [])
+        End
+
+        It should return the list it self if list is given
+            Assert Equals(lsp#utils#iteratable([1,2,3]), [1,2,3])
+        End
+    End
+End