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
|
Before:
Save &filetype
Save g:ale_lint_on_filetype_changed
let g:ale_lint_on_filetype_changed = 1
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#ReadOrEnterEvent(bufnr(''))
AssertEqual 'foobar', b:ale_original_filetype
let &filetype = 'bazboz'
call ale#events#ReadOrEnterEvent(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
" The original filetype should be updated, so we don't trigger linting
" by setting a filetype equal to what it already is.
AssertEqual 'bazboz', b:ale_original_filetype
Execute(Linting should be done when the original filetype was blank):
let b:ale_original_filetype = ''
call ale#events#FileTypeEvent(bufnr(''), 'bazboz')
AssertEqual [[300, 'lint_file', bufnr('')]], g:queue_calls
AssertEqual 'bazboz', b:ale_original_filetype
Execute(Linting should not be done when the setting is off):
let b:ale_original_filetype = 'foobar'
let g:ale_lint_on_filetype_changed = 0
call ale#events#FileTypeEvent(bufnr(''), 'bazboz')
AssertEqual [], g:queue_calls
" We should still update the old filetype
AssertEqual 'bazboz', b:ale_original_filetype
Execute(Linting should be done when the original filetype was not set):
unlet! b:ale_original_filetype
call ale#events#FileTypeEvent(bufnr(''), 'bazboz')
AssertEqual [], g:queue_calls
|