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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
Before:
Save g:ale_buffer_info
function! CreateError(type, message) abort
let l:diagnostics = []
if !empty(a:message)
let l:diagnostics = [{
\ 'start': {'line': 1, 'offset': 1},
\ 'end': {'line': 1, 'offset':1},
\ 'text': a:message,
\ 'code': 1005,
\}]
endif
return {
\ 'seq': 0,
\ 'type': 'event',
\ 'event': a:type,
\ 'body': {'file': expand('%:p'), 'diagnostics': l:diagnostics},
\}
endfunction
function! CreateLoclist(message) abort
let l:list = []
if !empty(a:message)
let l:list = [{
\ 'lnum': 1,
\ 'col': 1,
\ 'end_lnum': 1,
\ 'end_col': 1,
\ 'text': a:message,
\}]
endif
return l:list
endfunction
call ale#test#SetDirectory('/testplugin/test')
call ale#test#SetFilename('filename.ts')
runtime autoload/ale/engine.vim
let g:ale_buffer_info = {bufnr(''): {'loclist': []}}
let g:ale_handle_loclist_called = 0
function! ale#engine#HandleLoclist(linter_name, buffer, loclist, from_other_source) abort
let g:ale_handle_loclist_called = 1
endfunction
After:
Restore
delfunction CreateError
delfunction CreateLoclist
call ale#test#RestoreDirectory()
runtime autoload/ale/engine.vim
Execute(An initial empty list of syntax errors should be ignored):
call ale#lsp_linter#HandleLSPResponse(1, CreateError('syntaxDiag', ''))
Assert !g:ale_handle_loclist_called
Execute(An initial list of syntax errors should be handled):
call ale#lsp_linter#HandleLSPResponse(1, CreateError('syntaxDiag', 'x'))
Assert g:ale_handle_loclist_called
Execute(Subsequent empty lists should be ignored):
let g:ale_buffer_info[bufnr('')].syntax_loclist = []
call ale#lsp_linter#HandleLSPResponse(1, CreateError('syntaxDiag', ''))
Assert !g:ale_handle_loclist_called
Execute(Empty then non-empty syntax errors should be handled):
let g:ale_buffer_info[bufnr('')].syntax_loclist = []
call ale#lsp_linter#HandleLSPResponse(1, CreateError('syntaxDiag', 'x'))
Assert g:ale_handle_loclist_called
Execute(Non-empty then empty syntax errors should be handled):
let g:ale_buffer_info[bufnr('')].syntax_loclist = CreateLoclist('x')
call ale#lsp_linter#HandleLSPResponse(1, CreateError('syntaxDiag', ''))
Assert g:ale_handle_loclist_called
Execute(Non-empty then non-empty syntax errors should be handled):
let g:ale_buffer_info[bufnr('')].syntax_loclist = CreateLoclist('x')
call ale#lsp_linter#HandleLSPResponse(1, CreateError('syntaxDiag', 'x'))
Assert g:ale_handle_loclist_called
Execute(An initial empty list of semantic errors should be ignored):
call ale#lsp_linter#HandleLSPResponse(1, CreateError('semanticDiag', ''))
Assert !g:ale_handle_loclist_called
Execute(An initial list of semantic errors should be handled):
call ale#lsp_linter#HandleLSPResponse(1, CreateError('semanticDiag', 'x'))
Assert g:ale_handle_loclist_called
Execute(Subsequent empty lists should be ignored):
let g:ale_buffer_info[bufnr('')].semantic_loclist = []
call ale#lsp_linter#HandleLSPResponse(1, CreateError('semanticDiag', ''))
Assert !g:ale_handle_loclist_called
Execute(Empty then non-empty semantic errors should be handled):
let g:ale_buffer_info[bufnr('')].semantic_loclist = []
call ale#lsp_linter#HandleLSPResponse(1, CreateError('semanticDiag', 'x'))
Assert g:ale_handle_loclist_called
Execute(Non-empty then empty semantic errors should be handled):
let g:ale_buffer_info[bufnr('')].semantic_loclist = CreateLoclist('x')
call ale#lsp_linter#HandleLSPResponse(1, CreateError('semanticDiag', ''))
Assert g:ale_handle_loclist_called
Execute(Non-empty then non-empty semantic errors should be handled):
let g:ale_buffer_info[bufnr('')].semantic_loclist = CreateLoclist('x')
call ale#lsp_linter#HandleLSPResponse(1, CreateError('semanticDiag', 'x'))
Assert g:ale_handle_loclist_called
|