2016-10-14 19:29:31 +00:00
|
|
|
Before:
|
2017-11-12 23:19:26 +00:00
|
|
|
Save g:ale_echo_msg_format
|
2017-12-19 14:43:18 +00:00
|
|
|
Save g:ale_echo_cursor
|
2019-06-10 19:54:38 +00:00
|
|
|
Save b:ale_lint_on_insert_leave
|
|
|
|
|
|
|
|
let g:ale_echo_msg_format = '%code: %%s'
|
|
|
|
let b:ale_lint_on_insert_leave = 0
|
2017-11-12 23:19:26 +00:00
|
|
|
|
2018-04-10 20:05:22 +00:00
|
|
|
" We should prefer the error message at column 10 instead of the warning.
|
2016-10-24 19:21:32 +00:00
|
|
|
let g:ale_buffer_info = {
|
|
|
|
\ bufnr('%'): {
|
|
|
|
\ 'loclist': [
|
|
|
|
\ {
|
|
|
|
\ 'lnum': 1,
|
2017-03-03 20:14:03 +00:00
|
|
|
\ 'col': 10,
|
2016-10-24 19:21:32 +00:00
|
|
|
\ 'bufnr': bufnr('%'),
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'linter_name': 'eslint',
|
|
|
|
\ 'nr': -1,
|
2018-04-10 20:05:22 +00:00
|
|
|
\ 'type': 'W',
|
|
|
|
\ 'code': 'semi',
|
|
|
|
\ 'text': 'Ignore me.',
|
|
|
|
\ },
|
|
|
|
\ {
|
|
|
|
\ 'lnum': 1,
|
|
|
|
\ 'col': 10,
|
|
|
|
\ 'bufnr': bufnr('%'),
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'linter_name': 'eslint',
|
|
|
|
\ 'nr': -1,
|
2016-10-24 19:21:32 +00:00
|
|
|
\ 'type': 'E',
|
2017-11-13 00:47:34 +00:00
|
|
|
\ 'code': 'semi',
|
|
|
|
\ 'text': 'Missing semicolon.',
|
|
|
|
\ 'detail': "Every statement should end with a semicolon\nsecond line",
|
2016-10-24 19:21:32 +00:00
|
|
|
\ },
|
|
|
|
\ {
|
2017-11-12 23:19:26 +00:00
|
|
|
\ 'lnum': 1,
|
|
|
|
\ 'col': 14,
|
|
|
|
\ 'bufnr': bufnr('%'),
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'linter_name': 'eslint',
|
|
|
|
\ 'nr': -1,
|
|
|
|
\ 'type': 'I',
|
|
|
|
\ 'text': 'Some information',
|
|
|
|
\ },
|
|
|
|
\ {
|
2016-10-14 19:29:31 +00:00
|
|
|
\ 'lnum': 2,
|
2017-03-03 20:14:03 +00:00
|
|
|
\ 'col': 10,
|
2016-10-14 19:29:31 +00:00
|
|
|
\ 'bufnr': bufnr('%'),
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'linter_name': 'eslint',
|
|
|
|
\ 'nr': -1,
|
|
|
|
\ 'type': 'W',
|
2017-11-13 00:47:34 +00:00
|
|
|
\ 'code': 'space-infix-ops',
|
|
|
|
\ 'text': 'Infix operators must be spaced.',
|
2016-10-24 19:21:32 +00:00
|
|
|
\ },
|
|
|
|
\ {
|
2016-10-14 19:29:31 +00:00
|
|
|
\ 'lnum': 2,
|
2017-03-03 20:14:03 +00:00
|
|
|
\ 'col': 15,
|
2016-10-14 19:29:31 +00:00
|
|
|
\ 'bufnr': bufnr('%'),
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'linter_name': 'eslint',
|
|
|
|
\ 'nr': -1,
|
|
|
|
\ 'type': 'E',
|
2017-11-13 00:47:34 +00:00
|
|
|
\ 'code': 'radix',
|
|
|
|
\ 'text': 'Missing radix parameter',
|
2017-05-21 18:51:34 +00:00
|
|
|
\ },
|
|
|
|
\ {
|
|
|
|
\ 'lnum': 3,
|
|
|
|
\ 'col': 1,
|
|
|
|
\ 'bufnr': bufnr('%'),
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'linter_name': 'eslint',
|
|
|
|
\ 'nr': -1,
|
|
|
|
\ 'type': 'E',
|
2017-11-13 00:47:34 +00:00
|
|
|
\ 'text': 'lowercase error',
|
2017-05-21 18:51:34 +00:00
|
|
|
\ },
|
2016-10-24 19:21:32 +00:00
|
|
|
\ ],
|
|
|
|
\ },
|
2016-10-14 19:29:31 +00:00
|
|
|
\}
|
|
|
|
|
2017-03-02 23:36:31 +00:00
|
|
|
" Turn off other features, we only care about this one feature in this test.
|
|
|
|
let g:ale_set_loclist = 0
|
|
|
|
let g:ale_set_signs = 0
|
|
|
|
let g:ale_set_highlights = 0
|
2017-12-19 14:43:18 +00:00
|
|
|
let g:ale_echo_cursor = 1
|
2017-03-02 23:36:31 +00:00
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
function GetLastMessage()
|
|
|
|
redir => l:output
|
|
|
|
silent mess
|
|
|
|
redir END
|
|
|
|
|
|
|
|
let l:lines = split(l:output, "\n")
|
|
|
|
|
|
|
|
return empty(l:lines) ? '' : l:lines[-1]
|
|
|
|
endfunction
|
|
|
|
|
2019-06-10 19:54:38 +00:00
|
|
|
call ale#linter#Reset()
|
|
|
|
call ale#linter#PreventLoading('javascript')
|
|
|
|
|
2016-10-14 19:29:31 +00:00
|
|
|
After:
|
2017-11-12 23:19:26 +00:00
|
|
|
Restore
|
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
call cursor(1, 1)
|
|
|
|
|
2017-03-02 23:36:31 +00:00
|
|
|
let g:ale_set_loclist = 1
|
|
|
|
let g:ale_set_signs = 1
|
|
|
|
let g:ale_set_highlights = 1
|
|
|
|
|
2016-10-24 19:21:32 +00:00
|
|
|
let g:ale_buffer_info = {}
|
2016-10-14 19:29:31 +00:00
|
|
|
|
2017-03-04 23:55:12 +00:00
|
|
|
unlet! g:output
|
2017-11-19 23:44:02 +00:00
|
|
|
unlet! b:ale_loclist_msg_format
|
2017-03-04 23:55:12 +00:00
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
delfunction GetLastMessage
|
|
|
|
|
2017-05-12 19:38:52 +00:00
|
|
|
" Clearing the messages breaks tests on NeoVim for some reason, but all
|
|
|
|
" we need to do for these tests is just make it so the last message isn't
|
|
|
|
" carried over between test cases.
|
|
|
|
echomsg ''
|
2017-03-03 20:14:03 +00:00
|
|
|
|
2017-11-14 23:25:01 +00:00
|
|
|
" Close the preview window if it's open.
|
|
|
|
if &filetype is# 'ale-preview'
|
|
|
|
noautocmd :q!
|
|
|
|
endif
|
|
|
|
|
2019-06-10 19:54:38 +00:00
|
|
|
call ale#linter#Reset()
|
|
|
|
|
2016-10-14 19:29:31 +00:00
|
|
|
Given javascript(A Javscript file with warnings/errors):
|
2017-11-12 23:19:26 +00:00
|
|
|
var x = 3 + 12345678
|
2016-10-14 19:29:31 +00:00
|
|
|
var x = 5*2 + parseInt("10");
|
2017-05-21 18:51:34 +00:00
|
|
|
// comment
|
2016-10-14 19:29:31 +00:00
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
Execute(Messages should be shown for the correct lines):
|
|
|
|
call cursor(1, 1)
|
2016-10-14 19:29:31 +00:00
|
|
|
call ale#cursor#EchoCursorWarning()
|
|
|
|
|
2017-11-13 00:47:34 +00:00
|
|
|
AssertEqual 'semi: Missing semicolon.', GetLastMessage()
|
2016-10-14 19:29:31 +00:00
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
Execute(Messages should be shown for earlier columns):
|
|
|
|
call cursor(2, 1)
|
2016-10-14 19:29:31 +00:00
|
|
|
call ale#cursor#EchoCursorWarning()
|
|
|
|
|
2017-11-13 00:47:34 +00:00
|
|
|
AssertEqual 'space-infix-ops: Infix operators must be spaced.', GetLastMessage()
|
2016-10-14 19:29:31 +00:00
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
Execute(Messages should be shown for later columns):
|
|
|
|
call cursor(2, 16)
|
2016-10-14 19:29:31 +00:00
|
|
|
call ale#cursor#EchoCursorWarning()
|
|
|
|
|
2017-11-13 00:47:34 +00:00
|
|
|
AssertEqual 'radix: Missing radix parameter', GetLastMessage()
|
2017-03-02 07:14:30 +00:00
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
Execute(The message at the cursor should be shown when linting ends):
|
|
|
|
call cursor(1, 1)
|
2017-03-02 23:36:31 +00:00
|
|
|
call ale#engine#SetResults(
|
|
|
|
\ bufnr('%'),
|
|
|
|
\ g:ale_buffer_info[bufnr('%')].loclist,
|
|
|
|
\)
|
|
|
|
|
2017-11-13 00:47:34 +00:00
|
|
|
AssertEqual 'semi: Missing semicolon.', GetLastMessage()
|
2017-03-02 23:36:31 +00:00
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
Execute(The message at the cursor should be shown on InsertLeave):
|
|
|
|
call cursor(2, 9)
|
2017-03-02 23:36:31 +00:00
|
|
|
doautocmd InsertLeave
|
|
|
|
|
2017-11-13 00:47:34 +00:00
|
|
|
AssertEqual 'space-infix-ops: Infix operators must be spaced.', GetLastMessage()
|
2017-03-02 07:14:30 +00:00
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
Execute(ALEDetail should print 'detail' attributes):
|
|
|
|
call cursor(1, 1)
|
2017-03-03 02:40:07 +00:00
|
|
|
|
2017-11-14 23:25:01 +00:00
|
|
|
ALEDetail
|
2017-03-04 23:55:12 +00:00
|
|
|
|
2017-11-14 23:25:01 +00:00
|
|
|
AssertEqual
|
|
|
|
\ ['Every statement should end with a semicolon', 'second line'],
|
|
|
|
\ getline(1, '$')
|
2017-03-03 02:40:07 +00:00
|
|
|
|
2017-03-03 20:14:03 +00:00
|
|
|
Execute(ALEDetail should print regular 'text' attributes):
|
|
|
|
call cursor(2, 10)
|
2017-03-03 02:40:07 +00:00
|
|
|
|
2017-11-14 23:25:01 +00:00
|
|
|
ALEDetail
|
2017-03-04 23:55:12 +00:00
|
|
|
|
2017-11-14 23:25:01 +00:00
|
|
|
" ALEDetail opens a window, so check the text in it.
|
|
|
|
AssertEqual
|
|
|
|
\ ['Infix operators must be spaced.'],
|
|
|
|
\ getline(1, '$')
|
2017-05-21 18:51:34 +00:00
|
|
|
|
|
|
|
Execute(ALEDetail should not capitlise cursor messages):
|
|
|
|
call cursor(3, 1)
|
|
|
|
call ale#cursor#EchoCursorWarning()
|
|
|
|
|
|
|
|
AssertEqual 'lowercase error', GetLastMessage()
|
2017-11-12 23:19:26 +00:00
|
|
|
|
|
|
|
Execute(The linter name should be formatted into the message correctly):
|
|
|
|
let g:ale_echo_msg_format = '%linter%: %s'
|
|
|
|
|
|
|
|
call cursor(2, 9)
|
|
|
|
call ale#cursor#EchoCursorWarning()
|
|
|
|
|
|
|
|
AssertEqual
|
2017-11-13 00:47:34 +00:00
|
|
|
\ 'eslint: Infix operators must be spaced.',
|
2017-11-12 23:19:26 +00:00
|
|
|
\ GetLastMessage()
|
|
|
|
|
|
|
|
Execute(The severity should be formatted into the message correctly):
|
|
|
|
let g:ale_echo_msg_format = '%severity%: %s'
|
|
|
|
|
|
|
|
call cursor(2, 9)
|
|
|
|
call ale#cursor#EchoCursorWarning()
|
|
|
|
|
|
|
|
AssertEqual
|
2017-11-13 00:47:34 +00:00
|
|
|
\ 'Warning: Infix operators must be spaced.',
|
2017-11-12 23:19:26 +00:00
|
|
|
\ GetLastMessage()
|
|
|
|
|
|
|
|
call cursor(1, 10)
|
|
|
|
call ale#cursor#EchoCursorWarning()
|
|
|
|
|
2017-11-13 00:47:34 +00:00
|
|
|
AssertEqual 'Error: Missing semicolon.', GetLastMessage()
|
2017-11-12 23:19:26 +00:00
|
|
|
|
|
|
|
call cursor(1, 14)
|
|
|
|
call ale#cursor#EchoCursorWarning()
|
|
|
|
|
|
|
|
AssertEqual 'Info: Some information', GetLastMessage()
|
2017-11-13 00:47:34 +00:00
|
|
|
|
|
|
|
Execute(The %code% and %ifcode% should show the code and some text):
|
|
|
|
let g:ale_echo_msg_format = '%(code) %%s'
|
|
|
|
|
|
|
|
call cursor(2, 9)
|
|
|
|
call ale#cursor#EchoCursorWarning()
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ '(space-infix-ops) Infix operators must be spaced.',
|
|
|
|
\ GetLastMessage()
|
|
|
|
|
|
|
|
Execute(The %code% and %ifcode% should be removed when there's no code):
|
|
|
|
let g:ale_echo_msg_format = '%(code) %%s'
|
|
|
|
|
|
|
|
call cursor(1, 14)
|
|
|
|
call ale#cursor#EchoCursorWarning()
|
|
|
|
|
|
|
|
AssertEqual 'Some information', GetLastMessage()
|
2017-11-19 23:44:02 +00:00
|
|
|
|
|
|
|
Execute(The buffer message format option should take precedence):
|
|
|
|
let g:ale_echo_msg_format = '%(code) %%s'
|
|
|
|
let b:ale_echo_msg_format = 'FOO %s'
|
|
|
|
|
|
|
|
call cursor(1, 14)
|
|
|
|
call ale#cursor#EchoCursorWarning()
|
|
|
|
|
|
|
|
AssertEqual 'FOO Some information', GetLastMessage()
|
2017-12-19 14:43:18 +00:00
|
|
|
|
|
|
|
Execute(The cursor message shouldn't be echoed if the option is off):
|
|
|
|
let g:ale_echo_cursor = 0
|
|
|
|
echom 'foo'
|
|
|
|
|
|
|
|
call cursor(1, 1)
|
|
|
|
call ale#cursor#EchoCursorWarning()
|
|
|
|
|
|
|
|
AssertEqual 'foo', GetLastMessage()
|