aboutsummaryrefslogtreecommitdiff
path: root/test/lsp_settings.vimspec
blob: 529187e20aff82cef11251ee15e32d296833fe55 (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
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
End