aboutsummaryrefslogtreecommitdiff
path: root/test/lsp_settings.vimspec
blob: 36db445b536e9a7cbf2ff36fdeb35ff91e38de01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Describe lsp_settings
    Describe lsp_settings#get
        It should return configuration value from key and name
            Assert Equals(lsp_settings#get('pyls', 'cmd', 'bad'), 'bad')
            let g:lsp_settings = {'pyls': {'cmd': 'good'}}
            Assert Equals(lsp_settings#get('pyls', 'cmd', 'bad'), 'good')
            let g:lsp_settings = {'pyls': {'cmd': {key,name->'good'}}}
            Assert Equals(lsp_settings#get('pyls', 'cmd', 'bad'), 'good')
            unlet g:lsp_settings
        End

        It should return default value with lambda
            Assert Equals(lsp_settings#get('pyls', 'cmd', {key, name-> 'good'}), 'good')
        End
    End

    Describe lsp_settings#executable
        It should return command is executable in $PATH
            if has('win32')
                Assert Equals(lsp_settings#executable('cmd'), 1)
            else
                Assert Equals(lsp_settings#executable('sh'), 1)
            endif
            Assert Equals(lsp_settings#executable('unknown-command'), 0)
        End

        It should return 0 when command is not in server/foo-bar/foo-bar
            let l:servers_dir = lsp_settings#servers_dir()

            try
                call delete(l:servers_dir . '/foo-bar', 'rf')
                call mkdir(l:servers_dir . '/foo-bar', 'p')
                Assert Equals(lsp_settings#executable('foo-bar'), 0)
            finally
                call delete(l:servers_dir . '/foo-bar', 'rf')
            endtry
        End

        It should return 1 when command is executable in server/foo-bar/foo-bar
            let l:servers_dir = lsp_settings#servers_dir()

            try
                call delete(l:servers_dir . '/foo-bar', 'rf')
                call mkdir(l:servers_dir . '/foo-bar', 'p')
                if has('win32')
                    call writefile(['@echo off', 'echo foo-bar'], l:servers_dir . '/foo-bar/foo-bar.cmd')
                else
                    call writefile(['#!/bin/sh', 'echo foo-bar'], l:servers_dir . '/foo-bar/foo-bar')
                    call setfperm(l:servers_dir . '/foo-bar/foo-bar', 'rwxr-xr-x')
                endif
                Assert Equals(lsp_settings#executable('foo-bar'), 1)
            finally
                call delete(l:servers_dir . '/foo-bar', 'rf')
            endtry
        End
    End

    Describe lsp_settings#exec_path
        It should return full-path to the command
            if has('win32')
                Assert Equals(empty(lsp_settings#exec_path('cmd')), 0)
            else
                Assert Equals(empty(lsp_settings#exec_path('sh')), 0)
            endif
        End

        It should return 1 when command is executable in server/foo-bar/foo-bar
            let l:servers_dir = lsp_settings#servers_dir()

            try
                call delete(l:servers_dir . '/foo-bar', 'rf')
                call mkdir(l:servers_dir . '/foo-bar', 'p')
                if has('win32')
                    call writefile(['@echo off', 'echo foo-bar'], l:servers_dir . '/foo-bar/foo-bar.cmd')
                    Assert Equals(lsp_settings#exec_path('foo-bar'), l:servers_dir . '\foo-bar\foo-bar.cmd')
                else
                    call writefile(['#!/bin/sh', 'echo foo-bar'], l:servers_dir . '/foo-bar/foo-bar')
                    call setfperm(l:servers_dir . '/foo-bar/foo-bar', 'rwxr-xr-x')
                    Assert Equals(lsp_settings#exec_path('foo-bar'), l:servers_dir . '/foo-bar/foo-bar')
                endif
            finally
                call delete(l:servers_dir . '/foo-bar', 'rf')
            endtry
        End
    End

    Describe lsp_settings#init
        It should setup commands and autocmds.
            call lsp_settings#clear()
            call lsp_settings#init()
            autocmd vim_lsp_suggest_python
            Assert exists(':LspInstallServer')
            delcommand LspInstallServer
            Assert !exists('#vim_lsp_suggest_efm_langserver')
            for v in filter(split(execute('augroup'), '\s\+'), 'v:val=~"^vim_lsp_"')
                exe 'augroup ' . v
                  autocmd!
                augroup END
                exe 'augroup! ' . v
            endfor
            bw!
        End

        It should setup commands and autocmds with python.
            call lsp_settings#clear()
            call lsp_settings#init()
            new
            let g:lsp_settings = {'pyls': {'cmd': ['foo', 'bar']}}
            Throw /E117/ :setfiletype python
            bw!
            for v in filter(split(execute('augroup'), '\s\+'), 'v:val=~"^vim_lsp_suggest"')
                exe 'augroup ' . v
                  autocmd!
                augroup END
                exe 'augroup! ' . v
            endfor
            unlet g:lsp_settings
        End
    End
End