summaryrefslogtreecommitdiff
path: root/test/test_pattern_options.vader
blob: f439afbd3e327c7db326d1c4526d64f46728bd7c (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Before:
  Save g:ale_pattern_options
  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',
  \ },
  \}

  call ale#test#SetFilename('foobar.js')
  call ale#pattern_options#SetOptions(bufnr(''))

  AssertEqual 0, b:ale_enabled
  AssertEqual 0, b:some_option

  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

" 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 = {}

  call ale#pattern_options#SetOptions(bufnr(''))

  AssertEqual 0, b:some_option

  let g:ale_pattern_options['foo'] = {'some_option': 666}

  call ale#pattern_options#SetOptions(bufnr(''))

  AssertEqual 666, b:some_option

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

  call ale#pattern_options#SetOptions(bufnr(''))

  let g:ale_pattern_options_enabled = 1

  call ale#pattern_options#SetOptions(bufnr(''))