summaryrefslogtreecommitdiff
path: root/test/test_ale_fix.vader
blob: 8ec7896deb1363f4921badca537b5e079358cd1c (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
Before:
  Save g:ale_fixers, &shell
  let g:ale_run_synchronously = 1
  let g:ale_fixers = {
  \ 'testft': [],
  \}
  let &shell = '/bin/bash'

  function AddCarets(buffer, lines) abort
    " map() is applied to the original lines here.
    " This way, we can ensure that defensive copies are made.
    return map(a:lines, '''^'' . v:val')
  endfunction

  function AddDollars(buffer, lines) abort
    return map(a:lines, '''$'' . v:val')
  endfunction

  function DoNothing(buffer, lines) abort
    return 0
  endfunction

  function CatLine(buffer, lines) abort
    return {'command': 'cat - <(echo d)'}
  endfunction

  function ReplaceWithTempFile(buffer, lines) abort
    return {'command': 'echo x > %t', 'read_temporary_file': 1}
  endfunction

After:
  Restore
  unlet! g:ale_run_synchronously
  unlet! g:ale_emulate_job_failure
  delfunction AddCarets
  delfunction AddDollars
  delfunction DoNothing
  delfunction CatLine
  delfunction ReplaceWithTempFile

Given testft (A file with three lines):
  a
  b
  c

Execute(ALEFix should complain when there are no functions to call):
  AssertThrows ALEFix
  AssertEqual 'Vim(echoerr):No fixers have been defined for filetype: testft', g:vader_exception

Execute(ALEFix should apply simple functions):
  let g:ale_fixers.testft = ['AddCarets']
  ALEFix

Expect(The first function should be used):
  ^a
  ^b
  ^c

Execute(ALEFix should apply simple functions in a chain):
  let g:ale_fixers.testft = ['AddCarets', 'AddDollars']
  ALEFix

Expect(Both functions should be used):
  $^a
  $^b
  $^c

Execute(ALEFix should allow 0 to be returned to skip functions):
  let g:ale_fixers.testft = ['DoNothing', 'AddDollars']
  ALEFix

Expect(Only the second function should be applied):
  $a
  $b
  $c

Execute(ALEFix should allow commands to be run):
  let g:ale_fixers.testft = ['CatLine']
  ALEFix

Expect(An extra line should be added):
  a
  b
  c
  d

Execute(ALEFix should allow temporary files to be read):
  let g:ale_fixers.testft = ['ReplaceWithTempFile']
  ALEFix

Expect(The line we wrote to the temporary file should be used here):
  x

Execute(ALEFix should allow jobs and simple functions to be combined):
  let g:ale_fixers.testft = ['ReplaceWithTempFile', 'AddDollars']
  ALEFix

Expect(The lines from the temporary file should be modified):
  $x

Execute(ALEFix should send lines modified by functions to jobs):
  let g:ale_fixers.testft = ['AddDollars', 'CatLine']
  ALEFix

Expect(The lines should first be modified by the function, then the job):
  $a
  $b
  $c
  d

Execute(ALEFix should skip commands when jobs fail to run):
  let g:ale_emulate_job_failure = 1
  let g:ale_fixers.testft = ['CatLine', 'AddDollars']
  ALEFix

Expect(Only the second function should be applied):
  $a
  $b
  $c

Execute(ALEFix should handle strings for selecting a single function):
  let g:ale_fixers.testft = 'AddCarets'
  ALEFix

Expect(The first function should be used):
  ^a
  ^b
  ^c