From 7481facd7373dda4667c401695e6d8000ef52362 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 23 Oct 2016 22:41:00 +0100 Subject: #107 Stop jobs when buffers close --- test/test_cleanup.vader | 23 +++++------------ test/test_linting_sets_signs.vader | 40 +++++++++++++++++++++++++++++ test/test_statusline.vader | 52 +++++++++++++++++++++++--------------- 3 files changed, 77 insertions(+), 38 deletions(-) create mode 100644 test/test_linting_sets_signs.vader (limited to 'test') diff --git a/test/test_cleanup.vader b/test/test_cleanup.vader index 4f6827f4..a700d6b5 100644 --- a/test/test_cleanup.vader +++ b/test/test_cleanup.vader @@ -1,32 +1,21 @@ Before: let g:buffer = bufnr('%') - let g:ale_buffer_count_map = { - \ g:buffer: [1, 1], - \ 10347: [1, 1], - \} let g:ale_buffer_loclist_map = { \ g:buffer : [], \ 10347: [], \} - let g:ale_buffer_should_reset_map = { - \ g:buffer : 1, - \ 10347: 1, - \} - let g:ale_buffer_sign_dummy_map = { - \ g:buffer : 1, - \ 10347: 1, + + let g:ale_buffer_info = { + \ g:buffer : {}, + \ 10347: {}, \} After: unlet! g:buffer - let g:ale_buffer_count_map = {} let g:ale_buffer_loclist_map = {} - let g:ale_buffer_should_reset_map = {} - let g:ale_buffer_sign_dummy_map = {} + let g:ale_buffer_info = {} Execute('ALE globals should be cleared when the buffer is closed.'): :q! - AssertEqual {10347: [1, 1]}, g:ale_buffer_count_map AssertEqual {10347: []}, g:ale_buffer_loclist_map - AssertEqual {10347: 1}, g:ale_buffer_should_reset_map - AssertEqual {10347: 1}, g:ale_buffer_sign_dummy_map + AssertEqual {10347: {}}, g:ale_buffer_info diff --git a/test/test_linting_sets_signs.vader b/test/test_linting_sets_signs.vader new file mode 100644 index 00000000..1f323fe8 --- /dev/null +++ b/test/test_linting_sets_signs.vader @@ -0,0 +1,40 @@ +Given javascript (Some JavaScript with problems): + var y = 3+3; + var y = 3 + +Before: + sign unplace * + let g:actual_sign_list = [] + let g:expected_sign_list = [ + \ ['1', 'ALEWarningSign'], + \ ['2', 'ALEErrorSign'], + \] + + function! g:CollectSigns() + redir => l:output + silent exec 'sign place' + redir END + + for l:line in split(l:output, "\n") + let l:match = matchlist(l:line, 'line=\(\d\+\).*name=\(ALE[a-zA-Z]\+\)') + + if len(l:match) > 0 + call add(g:actual_sign_list, [l:match[1], l:match[2]]) + endif + endfor + endfunction + +After: + sign unplace * + let g:ale_buffer_loclist_map = {} + let g:ale_buffer_info = {} + delfunction g:CollectSigns + unlet g:actual_sign_list + unlet g:expected_sign_list + +Execute(The signs should be updated after linting is done): + call ale#Lint() + call ale#engine#WaitForJobs(2000) + call g:CollectSigns() + + AssertEqual g:expected_sign_list, g:actual_sign_list diff --git a/test/test_statusline.vader b/test/test_statusline.vader index da4c693f..43245e97 100644 --- a/test/test_statusline.vader +++ b/test/test_statusline.vader @@ -1,49 +1,59 @@ Before: let g:ale_buffer_loclist_map = {} + let g:ale_statusline_format = ['%sE', '%sW', 'OKIE'] + +After: + let g:ale_buffer_loclist_map = {} + let g:ale_buffer_info = {} Execute (Count should be 0 when data is empty): + let g:ale_buffer_info = {} AssertEqual [0, 0], ale#statusline#Count(bufnr('%')) -Before: - let g:ale_buffer_count_map = {'44': [1, 2]} - Execute (Count should read data from the cache): + let g:ale_buffer_info = {'44': {'count': [1, 2]}} AssertEqual [1, 2], ale#statusline#Count(44) -Execute (Update the cache with new data): +Execute (The count should be correct after an update): + let g:ale_buffer_info = {'44': {}} call ale#statusline#Update(44, []) - -Then (The cache should reflect the new data): AssertEqual [0, 0], ale#statusline#Count(44) -Before: - let g:ale_buffer_loclist_map = {'1': [{'lnum': 1, 'bufnr': 1, 'vcol': 0, 'linter_name': 'testlinter', 'nr': -1, 'type': 'E', 'col': 1, 'text': 'Test Error'}]} - Execute (Count should be match the loclist): - AssertEqual [1, 0], ale#statusline#Count(1) + let g:ale_buffer_info = {bufnr('%'): {}} + let g:ale_buffer_loclist_map = {bufnr('%'): [ + \ { + \ 'lnum': 1, + \ 'bufnr': 1, + \ 'vcol': 0, + \ 'linter_name': 'testlinter', + \ 'nr': -1, + \ 'type': 'E', + \ 'col': 1, + \ 'text': 'Test Error', + \ }, + \]} + AssertEqual [1, 0], ale#statusline#Count(bufnr('%')) Execute (Output should be empty for non-existant buffer): AssertEqual [0, 0], ale#statusline#Count(9001) -Before: - let g:ale_statusline_format = ['%sE', '%sW', 'OKIE'] - -Execute (Given some errors): +Execute (Statusline is formatted to the users preference for just errors): + let g:ale_buffer_info = {bufnr('%'): {}} call ale#statusline#Update(bufnr('%'), [{'type': 'E'}, {'type': 'E'}]) -Then (Statusline is formatted to the users preference): AssertEqual '2E', ale#statusline#Status() -Execute (Given some warnings): +Execute (Statusline is formatted to the users preference for just warnings): + let g:ale_buffer_info = {bufnr('%'): {}} call ale#statusline#Update(bufnr('%'), [{'type': 'W'}, {'type': 'W'}, {'type': 'W'}]) -Then (Statusline is formatted to the users preference): AssertEqual '3W', ale#statusline#Status() -Execute (Given some warnings, and errors): +Execute (Statusline is formatted to the users preference for errors and warnings): + let g:ale_buffer_info = {bufnr('%'): {}} call ale#statusline#Update(bufnr('%'), [{'type': 'E'}, {'type': 'W'}, {'type': 'W'}]) -Then (Statusline is formatted to the users preference): AssertEqual '1E 2W', ale#statusline#Status() -Execute (Given a lack of data): +Execute (Statusline is formatted to the users preference for no errors or warnings): + let g:ale_buffer_info = {bufnr('%'): {}} call ale#statusline#Update(bufnr('%'), []) -Then (Statusline is formatted to the users preference): AssertEqual 'OKIE', ale#statusline#Status() -- cgit v1.2.3 From c546f47cc0c003053fb157b0ca2cced46b5429bc Mon Sep 17 00:00:00 2001 From: w0rp Date: Mon, 24 Oct 2016 20:21:32 +0100 Subject: Merge everything into the one global map. --- test/test_alelint_autocmd.vader | 3 +++ test/test_cleanup.vader | 6 ------ test/test_cursor_warnings.vader | 38 +++++++++++++++++---------------- test/test_get_loclist.vader | 31 +++++++++++++++++++++++++++ test/test_linting_sets_signs.vader | 1 - test/test_linting_updates_loclist.vader | 28 ++++++++++++++++++++---- test/test_statusline.vader | 31 ++++++++++++++------------- 7 files changed, 94 insertions(+), 44 deletions(-) create mode 100644 test/test_get_loclist.vader (limited to 'test') diff --git a/test/test_alelint_autocmd.vader b/test/test_alelint_autocmd.vader index 86772b61..22fe1935 100644 --- a/test/test_alelint_autocmd.vader +++ b/test/test_alelint_autocmd.vader @@ -7,11 +7,14 @@ Before: After: augroup! VaderTest + let g:ale_buffer_info = {} Given vim (Some vimscript): set nocompatible + Execute (Lint it): call ale#Lint() call ale#engine#WaitForJobs(2000) + Then (Autocommands should have run): AssertEqual g:success, 1 diff --git a/test/test_cleanup.vader b/test/test_cleanup.vader index a700d6b5..ec2b38aa 100644 --- a/test/test_cleanup.vader +++ b/test/test_cleanup.vader @@ -1,9 +1,5 @@ Before: let g:buffer = bufnr('%') - let g:ale_buffer_loclist_map = { - \ g:buffer : [], - \ 10347: [], - \} let g:ale_buffer_info = { \ g:buffer : {}, @@ -12,10 +8,8 @@ Before: After: unlet! g:buffer - let g:ale_buffer_loclist_map = {} let g:ale_buffer_info = {} Execute('ALE globals should be cleared when the buffer is closed.'): :q! - AssertEqual {10347: []}, g:ale_buffer_loclist_map AssertEqual {10347: {}}, g:ale_buffer_info diff --git a/test/test_cursor_warnings.vader b/test/test_cursor_warnings.vader index 364db4bc..b12f2451 100644 --- a/test/test_cursor_warnings.vader +++ b/test/test_cursor_warnings.vader @@ -1,17 +1,18 @@ Before: - let g:ale_buffer_loclist_map = { - \ bufnr('%'): [ - \ { - \ 'lnum': 1, - \ 'bufnr': bufnr('%'), - \ 'vcol': 0, - \ 'linter_name': 'eslint', - \ 'nr': -1, - \ 'type': 'E', - \ 'col': 10, - \ 'text': 'Missing semicolon. (semi)' - \ }, - \ { + let g:ale_buffer_info = { + \ bufnr('%'): { + \ 'loclist': [ + \ { + \ 'lnum': 1, + \ 'bufnr': bufnr('%'), + \ 'vcol': 0, + \ 'linter_name': 'eslint', + \ 'nr': -1, + \ 'type': 'E', + \ 'col': 10, + \ 'text': 'Missing semicolon. (semi)' + \ }, + \ { \ 'lnum': 2, \ 'bufnr': bufnr('%'), \ 'vcol': 0, @@ -20,8 +21,8 @@ Before: \ 'type': 'W', \ 'col': 10, \ 'text': 'Infix operators must be spaced. (space-infix-ops)' - \ }, - \ { + \ }, + \ { \ 'lnum': 2, \ 'bufnr': bufnr('%'), \ 'vcol': 0, @@ -30,14 +31,15 @@ Before: \ 'type': 'E', \ 'col': 15, \ 'text': 'Missing radix parameter (radix)' - \ } - \ ], + \ } + \ ], + \ }, \} After: unlet! g:output unlet! g:lines - let g:ale_buffer_loclist_map = {} + let g:ale_buffer_info = {} Given javascript(A Javscript file with warnings/errors): var x = 3 diff --git a/test/test_get_loclist.vader b/test/test_get_loclist.vader new file mode 100644 index 00000000..14696998 --- /dev/null +++ b/test/test_get_loclist.vader @@ -0,0 +1,31 @@ +Before: + let g:loclist = [ + \ { + \ 'lnum': 1, + \ 'bufnr': bufnr('%'), + \ 'vcol': 0, + \ 'linter_name': 'eslint', + \ 'nr': -1, + \ 'type': 'E', + \ 'col': 10, + \ 'text': 'Missing semicolon. (semi)' + \ }, + \ { + \ 'lnum': 2, + \ 'bufnr': bufnr('%'), + \ 'vcol': 0, + \ 'linter_name': 'eslint', + \ 'nr': -1, + \ 'type': 'W', + \ 'col': 10, + \ 'text': 'Infix operators must be spaced. (space-infix-ops)' + \ }, + \] + let g:ale_buffer_info = {'1': {'loclist': g:loclist}} + +After: + unlet g:loclist + let g:ale_buffer_info = {} + +Execute(GetLoclist should return the loclist): + AssertEqual g:loclist, ale#engine#GetLoclist(1) diff --git a/test/test_linting_sets_signs.vader b/test/test_linting_sets_signs.vader index 1f323fe8..e96e490b 100644 --- a/test/test_linting_sets_signs.vader +++ b/test/test_linting_sets_signs.vader @@ -26,7 +26,6 @@ Before: After: sign unplace * - let g:ale_buffer_loclist_map = {} let g:ale_buffer_info = {} delfunction g:CollectSigns unlet g:actual_sign_list diff --git a/test/test_linting_updates_loclist.vader b/test/test_linting_updates_loclist.vader index 920a4e46..06f11d8b 100644 --- a/test/test_linting_updates_loclist.vader +++ b/test/test_linting_updates_loclist.vader @@ -3,15 +3,35 @@ Given javascript (Some JavaScript with problems): var y = 3 Before: - let g:ale_buffer_loclist_map = {} - let g:expected_data = {bufnr('%'): [{'lnum': 1, 'bufnr': bufnr('%'), 'vcol': 0, 'linter_name': 'eslint', 'nr': -1, 'type': 'W', 'col': 10, 'text': 'Infix operators must be spaced. [Warning/space-infix-ops]'}, {'lnum': 2, 'bufnr': bufnr('%'), 'vcol': 0, 'linter_name': 'eslint', 'nr': -1, 'type': 'E', 'col': 10, 'text': 'Missing semicolon. [Error/semi]'}]} + let g:expected_data = [ + \ { + \ 'lnum': 1, + \ 'bufnr': bufnr('%'), + \ 'vcol': 0, + \ 'linter_name': 'eslint', + \ 'nr': -1, + \ 'type': 'W', + \ 'col': 10, + \ 'text': 'Infix operators must be spaced. [Warning/space-infix-ops]', + \ }, + \ { + \ 'lnum': 2, + \ 'bufnr': bufnr('%'), + \ 'vcol': 0, + \ 'linter_name': 'eslint', + \ 'nr': -1, + \ 'type': 'E', + \ 'col': 10, + \ 'text': 'Missing semicolon. [Error/semi]', + \ } + \] After: - let g:ale_buffer_loclist_map = {} unlet g:expected_data Execute(The loclist should be updated after linting is done): call ale#Lint() call ale#engine#WaitForJobs(2000) - AssertEqual g:expected_data, g:ale_buffer_loclist_map + AssertEqual ['' . bufnr('%')], keys(g:ale_buffer_info) + AssertEqual g:expected_data, g:ale_buffer_info[bufnr('%')].loclist diff --git a/test/test_statusline.vader b/test/test_statusline.vader index 43245e97..05e60479 100644 --- a/test/test_statusline.vader +++ b/test/test_statusline.vader @@ -1,9 +1,7 @@ Before: - let g:ale_buffer_loclist_map = {} let g:ale_statusline_format = ['%sE', '%sW', 'OKIE'] After: - let g:ale_buffer_loclist_map = {} let g:ale_buffer_info = {} Execute (Count should be 0 when data is empty): @@ -20,19 +18,22 @@ Execute (The count should be correct after an update): AssertEqual [0, 0], ale#statusline#Count(44) Execute (Count should be match the loclist): - let g:ale_buffer_info = {bufnr('%'): {}} - let g:ale_buffer_loclist_map = {bufnr('%'): [ - \ { - \ 'lnum': 1, - \ 'bufnr': 1, - \ 'vcol': 0, - \ 'linter_name': 'testlinter', - \ 'nr': -1, - \ 'type': 'E', - \ 'col': 1, - \ 'text': 'Test Error', - \ }, - \]} + let g:ale_buffer_info = { + \ bufnr('%'): { + \ 'loclist': [ + \ { + \ 'lnum': 1, + \ 'bufnr': 1, + \ 'vcol': 0, + \ 'linter_name': 'testlinter', + \ 'nr': -1, + \ 'type': 'E', + \ 'col': 1, + \ 'text': 'Test Error', + \ }, + \ ], + \ }, + \} AssertEqual [1, 0], ale#statusline#Count(bufnr('%')) Execute (Output should be empty for non-existant buffer): -- cgit v1.2.3