#1095 Apply all patterns for g:ale_pattern_options, instead of just the first match
This commit is contained in:
parent
6c60ca24c1
commit
8cd1ccff84
5 changed files with 111 additions and 43 deletions
|
@ -108,17 +108,28 @@ Execute (g:ale_lint_on_insert_leave = 0 should bind no events):
|
|||
|
||||
AssertEqual [], CheckAutocmd('ALERunOnInsertLeave')
|
||||
|
||||
Execute (g:ale_pattern_options_enabled = 0 should bind no events):
|
||||
let g:ale_pattern_options_enabled = 0
|
||||
|
||||
AssertEqual [], CheckAutocmd('ALEPatternOptionsGroup')
|
||||
|
||||
Execute (g:ale_pattern_options_enabled = 1 should bind BufReadPost and BufEnter):
|
||||
let g:ale_pattern_options_enabled = 1
|
||||
|
||||
AssertEqual [
|
||||
\ 'BufEnter * call ale#pattern_options#SetOptions()',
|
||||
\ 'BufReadPost * call ale#pattern_options#SetOptions()',
|
||||
\ 'BufEnter * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufReadPost * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\], CheckAutocmd('ALEPatternOptionsGroup')
|
||||
|
||||
Execute (g:ale_pattern_options_enabled = 0 should still bind events):
|
||||
let g:ale_pattern_options_enabled = 0
|
||||
|
||||
AssertEqual [
|
||||
\ 'BufEnter * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufReadPost * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\], CheckAutocmd('ALEPatternOptionsGroup')
|
||||
|
||||
Execute (g:ale_enabled = 0 should still bind pattern events):
|
||||
let g:ale_enabled = 0
|
||||
|
||||
AssertEqual [
|
||||
\ 'BufEnter * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufReadPost * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\], CheckAutocmd('ALEPatternOptionsGroup')
|
||||
|
||||
Execute (g:ale_lint_on_enter = 0 should bind only the BufEnter event):
|
||||
|
|
|
@ -3,30 +3,74 @@ Before:
|
|||
Save g:ale_pattern_options_enabled
|
||||
Save &filetype
|
||||
|
||||
let g:ale_pattern_options_enabled = 1
|
||||
let g:ale_pattern_options = {}
|
||||
|
||||
let b:ale_enabled = 0
|
||||
let b:some_option = 0
|
||||
|
||||
call ale#test#SetDirectory('/testplugin/test')
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
unlet! b:ale_enabled
|
||||
unlet! b:some_option
|
||||
|
||||
call ale#test#RestoreDirectory()
|
||||
|
||||
Execute(The pattern options function should work when there are no patterns):
|
||||
call ale#test#SetFilename('foobar.js')
|
||||
call ale#pattern_options#SetOptions(bufnr(''))
|
||||
|
||||
Execute(Buffer variables should be set when filename patterns match):
|
||||
let g:ale_pattern_options = {'baz.*\.js': {
|
||||
\ 'ale_enabled': 1,
|
||||
\ 'some_option': 347,
|
||||
\ '&filetype': 'pattern_option_set_filetype',
|
||||
\}}
|
||||
let g:ale_pattern_options = {
|
||||
\ 'baz.*\.js': {
|
||||
\ 'ale_enabled': 1,
|
||||
\ 'some_option': 347,
|
||||
\ '&filetype': 'pattern_option_set_filetype',
|
||||
\ },
|
||||
\}
|
||||
|
||||
silent! file foobar.js
|
||||
call ale#test#SetFilename('foobar.js')
|
||||
call ale#pattern_options#SetOptions(bufnr(''))
|
||||
|
||||
call ale#pattern_options#SetOptions()
|
||||
AssertEqual 0, b:ale_enabled
|
||||
AssertEqual 0, b:some_option
|
||||
|
||||
Assert !exists('b:ale_enabled')
|
||||
Assert !exists('b:some_option')
|
||||
|
||||
silent! file bazboz.js
|
||||
|
||||
call ale#pattern_options#SetOptions()
|
||||
call ale#test#SetFilename('bazboz.js')
|
||||
call ale#pattern_options#SetOptions(bufnr(''))
|
||||
|
||||
AssertEqual 1, b:ale_enabled
|
||||
AssertEqual 347, b:some_option
|
||||
AssertEqual 'pattern_option_set_filetype', &filetype
|
||||
|
||||
Execute(Multiple pattern matches should be applied):
|
||||
let g:ale_pattern_options = {
|
||||
\ 'foo': {
|
||||
\ 'some_option': 666,
|
||||
\ },
|
||||
\ 'bar': {
|
||||
\ 'ale_enabled': 1,
|
||||
\ 'some_option': 123,
|
||||
\ },
|
||||
\ 'notmatched': {
|
||||
\ 'some_option': 489,
|
||||
\ 'ale_enabled': 0,
|
||||
\ },
|
||||
\}
|
||||
|
||||
call ale#test#SetFilename('foobar.js')
|
||||
call ale#pattern_options#SetOptions(bufnr(''))
|
||||
|
||||
AssertEqual 1, b:ale_enabled
|
||||
AssertEqual 666, b:some_option
|
||||
|
||||
Execute(Patterns should not be applied when the setting is disabled):
|
||||
let g:ale_pattern_options_enabled = 0
|
||||
let g:ale_pattern_options = {'foo': {'some_option': 666}}
|
||||
|
||||
call ale#test#SetFilename('foobar.js')
|
||||
call ale#pattern_options#SetOptions(bufnr(''))
|
||||
|
||||
AssertEqual 0, b:some_option
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue