summaryrefslogtreecommitdiff
path: root/test/fix/test_ale_fix_ignore.vader
blob: 5eb9b9ab7d7cc51eef73dc196e29238c7b586918 (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
104
105
106
107
108
109
110
Before:
  Save g:ale_fixers
  Save g:ale_fix_on_save
  Save g:ale_fix_on_save_ignore

  let g:ale_fix_on_save = 1
  let g:ale_fixers = {'abc': ['a', 'b'], 'xyz': ['c', 'd']}
  unlet! b:ale_fixers
  unlet! b:ale_fix_on_save_ignore

  function FixerA(buffer, lines) abort
    return a:lines + ['a']
  endfunction

  function FixerB(buffer, lines) abort
    return a:lines + ['b']
  endfunction

  function FixerC(buffer, lines) abort
    return a:lines + ['c']
  endfunction

  function FixerD(buffer, lines) abort
    return a:lines + ['d']
  endfunction

  set filetype=abc.xyz
  let g:test_filename = tempname()
  execute 'noautocmd silent file ' . fnameescape(g:test_filename)

  call ale#fix#registry#Add('a', 'FixerA', ['abc'], '')
  call ale#fix#registry#Add('b', 'FixerB', ['abc'], '')
  call ale#fix#registry#Add('c', 'FixerC', ['xyz'], '')
  call ale#fix#registry#Add('d', 'FixerD', ['xyz'], '')

After:
  Restore

  if exists('g:test_filename') && filereadable(g:test_filename)
    call delete(g:test_filename)
  endif

  unlet! b:ale_fixers
  unlet! b:ale_fix_on_save_ignore
  unlet! g:test_filename

  delfunction FixerA
  delfunction FixerB
  delfunction FixerC
  delfunction FixerD

  call ale#fix#registry#ResetToDefaults()

Given abc.xyz (An empty file):
Execute(Ignoring with a filetype in a global Dictionary should work):
  let g:ale_fix_on_save_ignore = {'abc': ['b'], 'xyz': ['c']}

  call ale#events#SaveEvent(bufnr(''))

  AssertEqual ['', 'a', 'd'], getline(1, '$')

Execute(Ignoring with a filetype in a global List should work):
  let g:ale_fix_on_save_ignore = ['b', 'c']

  call ale#events#SaveEvent(bufnr(''))

  AssertEqual ['', 'a', 'd'], getline(1, '$')

Execute(Ignoring with a filetype in a local Dictionary should work):
  let g:ale_fix_on_save_ignore = {'abc': ['b'], 'xyz': ['c']}
  " The local Dictionary should entirely replace the global one.
  let b:ale_fix_on_save_ignore = {'abc': ['b']}

  call ale#events#SaveEvent(bufnr(''))

  AssertEqual ['', 'a', 'c', 'd'], getline(1, '$')

Execute(Ignoring with a filetype in a local List should work):
  let g:ale_fix_on_save_ignore = {'abc': ['b'], 'xyz': ['c']}
  " The local List should entirely replace the global Dictionary.
  let b:ale_fix_on_save_ignore = ['b']

  call ale#events#SaveEvent(bufnr(''))

  AssertEqual ['', 'a', 'c', 'd'], getline(1, '$')

Execute(Ignoring functions by reference with a Dictionary should work):
  let g:ale_fixers = {
  \ 'abc': [function('FixerA'), function('FixerB')],
  \ 'xyz': [function('FixerC'), function('FixerD')],
  \}
  let b:ale_fix_on_save_ignore = {
  \ 'abc': [function('FixerB')],
  \ 'xyz': [function('FixerC')],
  \}

  call ale#events#SaveEvent(bufnr(''))

  AssertEqual ['', 'a', 'd'], getline(1, '$')

Execute(Ignoring functions by reference with a List should work):
  let g:ale_fixers = {
  \ 'abc': [function('FixerA'), function('FixerB')],
  \ 'xyz': [function('FixerC'), function('FixerD')],
  \}
  let b:ale_fix_on_save_ignore = [function('FixerB'), function('FixerC')]

  call ale#events#SaveEvent(bufnr(''))

  AssertEqual ['', 'a', 'd'], getline(1, '$')