2017-05-26 14:59:43 +00:00
|
|
|
Before:
|
2017-07-08 23:10:28 +00:00
|
|
|
Save g:ale_pattern_options
|
|
|
|
Save g:ale_pattern_options_enabled
|
2018-07-16 23:18:20 +00:00
|
|
|
Save b:ale_quitting
|
|
|
|
Save b:ale_original_filetype
|
2017-07-08 23:10:28 +00:00
|
|
|
Save &filetype
|
2017-05-26 14:59:43 +00:00
|
|
|
|
2018-07-16 23:18:20 +00:00
|
|
|
unlet! b:ale_file_changed
|
|
|
|
|
2017-11-11 13:44:05 +00:00
|
|
|
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')
|
|
|
|
|
2017-05-26 14:59:43 +00:00
|
|
|
After:
|
|
|
|
Restore
|
|
|
|
|
|
|
|
unlet! b:ale_enabled
|
|
|
|
unlet! b:some_option
|
|
|
|
|
2017-11-11 13:44:05 +00:00
|
|
|
call ale#test#RestoreDirectory()
|
2017-05-26 14:59:43 +00:00
|
|
|
|
2017-11-11 13:44:05 +00:00
|
|
|
Execute(The pattern options function should work when there are no patterns):
|
|
|
|
call ale#test#SetFilename('foobar.js')
|
2018-07-16 23:18:20 +00:00
|
|
|
call ale#events#ReadOrEnterEvent(bufnr(''))
|
2017-05-26 14:59:43 +00:00
|
|
|
|
2017-11-11 13:44:05 +00:00
|
|
|
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',
|
|
|
|
\ },
|
|
|
|
\}
|
2017-05-26 14:59:43 +00:00
|
|
|
|
2017-11-11 13:44:05 +00:00
|
|
|
call ale#test#SetFilename('foobar.js')
|
2018-07-16 23:18:20 +00:00
|
|
|
call ale#events#ReadOrEnterEvent(bufnr(''))
|
2017-05-26 14:59:43 +00:00
|
|
|
|
2017-11-11 13:44:05 +00:00
|
|
|
AssertEqual 0, b:ale_enabled
|
|
|
|
AssertEqual 0, b:some_option
|
2017-05-26 14:59:43 +00:00
|
|
|
|
2017-11-11 13:44:05 +00:00
|
|
|
call ale#test#SetFilename('bazboz.js')
|
2018-07-16 23:18:20 +00:00
|
|
|
call ale#events#ReadOrEnterEvent(bufnr(''))
|
2017-05-26 14:59:43 +00:00
|
|
|
|
|
|
|
AssertEqual 1, b:ale_enabled
|
|
|
|
AssertEqual 347, b:some_option
|
2017-07-08 23:10:28 +00:00
|
|
|
AssertEqual 'pattern_option_set_filetype', &filetype
|
2017-11-11 13:44:05 +00:00
|
|
|
|
|
|
|
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')
|
2018-07-16 23:18:20 +00:00
|
|
|
call ale#events#ReadOrEnterEvent(bufnr(''))
|
2017-11-11 13:44:05 +00:00
|
|
|
|
|
|
|
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')
|
2018-07-16 23:18:20 +00:00
|
|
|
call ale#events#ReadOrEnterEvent(bufnr(''))
|
2017-11-11 13:44:05 +00:00
|
|
|
|
|
|
|
AssertEqual 0, b:some_option
|
2017-11-11 14:26:54 +00:00
|
|
|
|
|
|
|
" This test is important for making sure we update the sorted items.
|
|
|
|
Execute(Patterns should be applied after the Dictionary changes):
|
|
|
|
call ale#test#SetFilename('foobar.js')
|
|
|
|
|
|
|
|
let g:ale_pattern_options = {}
|
|
|
|
|
2018-07-16 23:18:20 +00:00
|
|
|
call ale#events#ReadOrEnterEvent(bufnr(''))
|
2017-11-11 14:26:54 +00:00
|
|
|
|
|
|
|
AssertEqual 0, b:some_option
|
|
|
|
|
|
|
|
let g:ale_pattern_options['foo'] = {'some_option': 666}
|
|
|
|
|
2018-07-16 23:18:20 +00:00
|
|
|
call ale#events#ReadOrEnterEvent(bufnr(''))
|
2017-11-11 14:26:54 +00:00
|
|
|
|
|
|
|
AssertEqual 666, b:some_option
|
2018-06-01 20:03:22 +00:00
|
|
|
|
|
|
|
Execute(SetOptions should tolerate settings being unset):
|
|
|
|
" This might happen if ALE is loaded in a weird way, so tolerate it.
|
|
|
|
unlet! g:ale_pattern_options
|
|
|
|
unlet! g:ale_pattern_options_enabled
|
|
|
|
|
2018-07-16 23:18:20 +00:00
|
|
|
call ale#events#ReadOrEnterEvent(bufnr(''))
|
2018-06-01 20:03:22 +00:00
|
|
|
|
|
|
|
let g:ale_pattern_options_enabled = 1
|
|
|
|
|
2018-07-16 23:18:20 +00:00
|
|
|
call ale#events#ReadOrEnterEvent(bufnr(''))
|