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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
Before:
Save g:ale_buffer_info
Save g:ale_virtualtext_cursor
Save g:ale_virtualtext_delay
Save g:ale_virtualtext_single
Save g:ale_virtualtext_prefix
Save b:ale_virtualtext_prefix
Save g:ale_use_neovim_diagnostics_api
call ale#virtualtext#ResetDataForTests()
let g:setting = ''
let g:ale_virtualtext_prefix = '%comment% %type%: '
let g:ale_virtualtext_delay = 0
let g:ale_virtualtext_single = 0
let g:ale_buffer_info = {
\ bufnr(''): {
\ 'loclist': [
\ {
\ 'bufnr': bufnr(''),
\ 'type': 'E',
\ 'lnum': 1,
\ 'col': 5,
\ 'text': 'Line 1 error',
\ },
\ {
\ 'bufnr': bufnr(''),
\ 'type': 'W',
\ 'lnum': 2,
\ 'col': 1,
\ 'text': 'Line 2 warning 1',
\ },
\ {
\ 'bufnr': bufnr(''),
\ 'type': 'W',
\ 'lnum': 2,
\ 'col': 5,
\ 'text': 'Line 2 warning 2',
\ },
\ {
\ 'bufnr': bufnr(''),
\ 'type': 'W',
\ 'lnum': 3,
\ 'col': 3,
\ 'text': 'Line 3 warning 1',
\ },
\ {
\ 'bufnr': bufnr(''),
\ 'type': 'E',
\ 'lnum': 3,
\ 'col': 5,
\ 'text': 'Line 3 error 1',
\ },
\ {
\ 'bufnr': bufnr(''),
\ 'type': 'E',
\ 'lnum': 3,
\ 'col': 6,
\ 'text': 'Line 3 error 2',
\ },
\ ],
\ },
\}
let g:ale_use_neovim_diagnostics_api = 0
After:
Restore
unlet! g:setting
unlet! g:ns_id
Execute(The correct highlight groups should be loaded for virtual-text):
AssertEqual 'ALEVirtualTextError', ale#virtualtext#GetGroup({})
AssertEqual 'ALEVirtualTextError', ale#virtualtext#GetGroup({'type': 'E'})
AssertEqual 'ALEVirtualTextStyleError',
\ ale#virtualtext#GetGroup({'type': 'E', 'sub_type': 'style'})
AssertEqual 'ALEVirtualTextWarning', ale#virtualtext#GetGroup({'type': 'W'})
AssertEqual 'ALEVirtualTextStyleWarning',
\ ale#virtualtext#GetGroup({'type': 'W', 'sub_type': 'style'})
AssertEqual 'ALEVirtualTextInfo', ale#virtualtext#GetGroup({'type': 'I'})
Given python (An empty Python file):
Execute(Comment text should be detected correctly for Python files):
if has('patch-9.0.0297') || has('nvim-0.8.0')
AssertEqual '#', ale#virtualtext#GetComment(bufnr(''))
endif
Given java (An empty Java file):
Execute(Comment text should be detected correctly for Java files):
if has('patch-9.0.0297') || has('nvim-0.8.0')
AssertEqual '//', ale#virtualtext#GetComment(bufnr(''))
endif
Given html (An empty HTML file):
Execute(Comment text should be detected correctly for HTML files):
if has('patch-9.0.0297') || has('nvim-0.8.0')
AssertEqual "\<!--", ale#virtualtext#GetComment(bufnr(''))
endif
Given python(An example Python file):
# line 1
# line 2
# line 3
Execute(We should not show virtualtext when disabled):
if has('patch-9.0.0297') || has('nvim-0.8.0')
for g:setting in ['disabled', '0', 0]
call ale#virtualtext#ResetDataForTests()
let g:ale_virtualtext_cursor = g:setting
call cursor(1, 1)
call ale#virtualtext#ShowCursorWarningWithDelay()
" Tick the timer.
sleep 1ms
AssertEqual '', ale#virtualtext#GetLastMessageForTests()
endfor
endif
Execute(We should find a virtualtext error on line 1):
if has('patch-9.0.0297') || has('nvim-0.8.0')
for g:setting in ['current', '1', 1]
call ale#virtualtext#ResetDataForTests()
let g:ale_virtualtext_cursor = 'current'
call cursor(1, 1)
call ale#virtualtext#ShowCursorWarningWithDelay()
" Tick the timer.
sleep 1ms
AssertEqual '# E: Line 1 error', ale#virtualtext#GetLastMessageForTests()
if has('patch-9.0.0297')
AssertEqual ['ALEVirtualTextError'], map(prop_list(1), {_, v -> v.type})
AssertEqual [], prop_list(2)
endif
endfor
endif
Execute(We should find a virtualtext error on line 2):
if has('patch-9.0.0297') || has('nvim-0.8.0')
let g:ale_virtualtext_cursor = 'current'
call cursor(2, 5)
call ale#virtualtext#ShowCursorWarningWithDelay()
" Tick the timer.
sleep 1ms
AssertEqual '# W: Line 2 warning 2', ale#virtualtext#GetLastMessageForTests()
if has('patch-9.0.0297')
AssertEqual [], prop_list(1)
AssertEqual ['ALEVirtualTextWarning'], map(prop_list(2), {_, v -> v.type})
endif
endif
Execute(We should be able to change the virtualtext prefix globally):
let g:ale_virtualtext_prefix = '%severity%: '
if has('patch-9.0.0297') || has('nvim-0.8.0')
let g:ale_virtualtext_cursor = 'current'
call cursor(1, 1)
call ale#virtualtext#ShowCursorWarningWithDelay()
" Tick the timer.
sleep 1ms
AssertEqual 'Error: Line 1 error', ale#virtualtext#GetLastMessageForTests()
endif
Execute(We should be able to change the virtualtext prefix per-buffer):
let b:ale_virtualtext_prefix = 'B> '
if has('patch-9.0.0297') || has('nvim-0.8.0')
let g:ale_virtualtext_cursor = 'current'
call cursor(1, 1)
call ale#virtualtext#ShowCursorWarningWithDelay()
" Tick the timer.
sleep 1ms
AssertEqual 'B> Line 1 error', ale#virtualtext#GetLastMessageForTests()
endif
Execute(We should be able to set messages across all lines):
if has('patch-9.0.0297') || has('nvim-0.8.0')
call ale#virtualtext#SetTexts(bufnr(''), g:ale_buffer_info[bufnr('')].loclist)
AssertEqual '# E: Line 3 error 2', ale#virtualtext#GetLastMessageForTests()
if has('patch-9.0.0297')
AssertEqual ['ALEVirtualTextError'], map(prop_list(1), {_, v -> v.type})
AssertEqual ['ALEVirtualTextWarning', 'ALEVirtualTextWarning'],
\ map(prop_list(2), {_, v -> v.type})
endif
endif
Execute(We should be able to limit virtual messages to the first one only):
let g:ale_virtualtext_single = 1
if has('patch-9.0.0297') || has('nvim-0.8.0')
call ale#virtualtext#SetTexts(bufnr(''), g:ale_buffer_info[bufnr('')].loclist)
AssertEqual '# E: Line 3 error 1', ale#virtualtext#GetLastMessageForTests()
if has('patch-9.0.0297')
AssertEqual ['ALEVirtualTextError'], map(prop_list(1), {_, v -> v.type})
AssertEqual ['ALEVirtualTextWarning'], map(prop_list(2), {_, v -> v.type})
AssertEqual ['ALEVirtualTextError'], map(prop_list(3), {_, v -> v.type})
endif
endif
Execute(We should not set cursor messages when Neovim diagnostics are enabled):
let g:ale_use_neovim_diagnostics_api = 1
if has('patch-9.0.0297') || has('nvim-0.8.0')
let g:ale_virtualtext_cursor = 'current'
call cursor(1, 1)
call ale#virtualtext#ShowCursorWarningWithDelay()
" Tick the timer.
sleep 1ms
AssertEqual '', ale#virtualtext#GetLastMessageForTests()
endif
|