summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-08-14 23:31:46 +0100
committerw0rp <devw0rp@gmail.com>2017-08-14 23:31:54 +0100
commit5af82312fbdec54af41fb60daae6aa59b3ee7379 (patch)
tree00b3cb21e54a3ebf206f7184b72d72f815c74b77 /test
parent1680f7af630da107bd0124adb434e27eef3e2371 (diff)
downloadale-5af82312fbdec54af41fb60daae6aa59b3ee7379.zip
Set up one BufEnter event used for everything, and add tests for linting when the filetype changes
Diffstat (limited to 'test')
-rw-r--r--test/test_ale_init_au_groups.vader25
-rw-r--r--test/test_lint_on_filetype_changed.vader47
-rw-r--r--test/test_results_not_cleared_when_opening_loclist.vader3
-rw-r--r--test/test_setting_loclist_from_another_buffer.vader8
4 files changed, 70 insertions, 13 deletions
diff --git a/test/test_ale_init_au_groups.vader b/test/test_ale_init_au_groups.vader
index c7f56469..da77ccee 100644
--- a/test/test_ale_init_au_groups.vader
+++ b/test/test_ale_init_au_groups.vader
@@ -107,10 +107,12 @@ Execute (g:ale_pattern_options_enabled = 1 should bind BufReadPost and BufEnter)
\ 'BufReadPost * call ale#pattern_options#SetOptions()',
\], CheckAutocmd('ALEPatternOptionsGroup')
-Execute (g:ale_lint_on_enter = 0 should bind no events):
+Execute (g:ale_lint_on_enter = 0 should bind only the BufEnter event):
let g:ale_lint_on_enter = 0
- AssertEqual [], CheckAutocmd('ALERunOnEnterGroup')
+ AssertEqual
+ \ ['BufEnter * call ale#events#EnterEvent(str2nr(expand(''<abuf>'')))'],
+ \ CheckAutocmd('ALERunOnEnterGroup')
Execute (g:ale_lint_on_enter = 1 should bind the required events):
let g:ale_lint_on_enter = 1
@@ -127,18 +129,17 @@ Execute (g:ale_lint_on_filetype_changed = 0 should bind no events):
AssertEqual [], CheckAutocmd('ALERunOnFiletypeChangeGroup')
-Execute (g:ale_lint_on_filetype_changed = 1 should bind FileType, and required buffer events):
+Execute (g:ale_lint_on_filetype_changed = 1 should bind the FileType event):
let g:ale_lint_on_filetype_changed = 1
- AssertEqual [
- \ 'BufEnter * let b:ale_original_filetype = &filetype',
- \ 'BufReadPost * let b:ale_original_filetype = &filetype',
- \ 'FileType * '
- \ . 'if has_key(b:, ''ale_original_filetype'') '
- \ . '&& b:ale_original_filetype isnot# expand(''<amatch>'')'
- \ . '| call ale#Queue(300, ''lint_file'')'
- \ . '| endif',
- \], CheckAutocmd('ALERunOnFiletypeChangeGroup')
+ AssertEqual
+ \ [
+ \ 'FileType * call ale#events#FileTypeEvent( '
+ \ . 'str2nr(expand(''<abuf>'')), '
+ \ . 'expand(''<amatch>'')'
+ \ . ')',
+ \ ],
+ \ CheckAutocmd('ALERunOnFiletypeChangeGroup')
Execute (g:ale_lint_on_save = 0 should bind no events):
let g:ale_lint_on_save = 0
diff --git a/test/test_lint_on_filetype_changed.vader b/test/test_lint_on_filetype_changed.vader
new file mode 100644
index 00000000..44446ef0
--- /dev/null
+++ b/test/test_lint_on_filetype_changed.vader
@@ -0,0 +1,47 @@
+Before:
+ Save &filetype
+
+ let g:queue_calls = []
+
+ function! ale#Queue(...)
+ call add(g:queue_calls, a:000)
+ endfunction
+
+After:
+ Restore
+
+ unlet! g:queue_calls
+
+ " Reload the ALE code to load the real function again.
+ runtime autoload/ale.vim
+
+ unlet! b:ale_original_filetype
+
+Execute(The original filetype should be set on BufEnter):
+ let &filetype = 'foobar'
+
+ call ale#events#EnterEvent(bufnr(''))
+
+ AssertEqual 'foobar', b:ale_original_filetype
+
+ let &filetype = 'bazboz'
+
+ call ale#events#EnterEvent(bufnr(''))
+
+ AssertEqual 'bazboz', b:ale_original_filetype
+
+Execute(Linting should not be queued when the filetype is the same):
+ let b:ale_original_filetype = 'foobar'
+ let g:queue_calls = []
+
+ call ale#events#FileTypeEvent(bufnr(''), 'foobar')
+
+ AssertEqual [], g:queue_calls
+
+Execute(Linting should be queued when the filetype changes):
+ let b:ale_original_filetype = 'foobar'
+ let g:queue_calls = []
+
+ call ale#events#FileTypeEvent(bufnr(''), 'bazboz')
+
+ AssertEqual [[300, 'lint_file', bufnr('')]], g:queue_calls
diff --git a/test/test_results_not_cleared_when_opening_loclist.vader b/test/test_results_not_cleared_when_opening_loclist.vader
index 07d3d303..0c053b85 100644
--- a/test/test_results_not_cleared_when_opening_loclist.vader
+++ b/test/test_results_not_cleared_when_opening_loclist.vader
@@ -26,6 +26,9 @@ After:
delfunction TestCallback
let g:ale_buffer_info = {}
call ale#linter#Reset()
+ call setloclist(0, [])
+ call clearmatches()
+ sign unplace *
Given foobar (Some file):
abc
diff --git a/test/test_setting_loclist_from_another_buffer.vader b/test/test_setting_loclist_from_another_buffer.vader
index 4b757c61..ae53de1f 100644
--- a/test/test_setting_loclist_from_another_buffer.vader
+++ b/test/test_setting_loclist_from_another_buffer.vader
@@ -1,8 +1,14 @@
Before:
+ Save g:ale_buffer_info
+
+ let g:ale_buffer_info = {}
+
let g:original_buffer = bufnr('%')
- new
+ noautocmd new
After:
+ Restore
+
unlet! g:original_buffer
Execute(Errors should be set in the loclist for the original buffer, not the new one):