summaryrefslogtreecommitdiff
path: root/test/test_engine_invocation.vader
blob: c56895d35cee0785222d9275985d3a0a54687e98 (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
129
130
131
132
133
134
135
136
137
138
139
Before:
  function! CollectResults(buffer, output)
    return []
  endfunction

  function! FirstChainFunction(buffer)
    return 'first'
  endfunction

  function! SecondChainFunction(buffer, output)
    " We'll skip this command
    return ''
  endfunction

  function! ThirdChainFunction(buffer, output)
    return 'third'
  endfunction

  function! FourthChainFunction(buffer, output)
    return 'fourth'
  endfunction

  let g:linter = {
  \ 'name': 'testlinter',
  \ 'callback': 'CollectResults',
  \ 'executable': 'echo',
  \ 'command_chain': [
  \   {'callback': 'FirstChainFunction'},
  \   {'callback': 'SecondChainFunction'},
  \   {'callback': 'ThirdChainFunction'},
  \   {'callback': 'FourthChainFunction'},
  \ ],
  \ 'read_buffer': 1,
  \}

  function! ProcessIndex(chain_index)
    return ale#engine#ProcessChain(347, g:linter, a:chain_index, [])
  endfunction

After:
  delfunction CollectResults
  delfunction FirstChainFunction
  delfunction SecondChainFunction
  delfunction ThirdChainFunction
  delfunction ProcessIndex
  unlet! g:linter
  unlet! g:result

Execute(Engine invocation should return the command for the first item correctly):
  let g:result = ProcessIndex(0)

  AssertEqual 'first', g:result.command
  AssertEqual 1, g:result.next_chain_index

Execute(Engine invocation should return the command for the second item correctly):
  let g:result = ProcessIndex(1)

  AssertEqual 'third', g:result.command
  AssertEqual 3, g:result.next_chain_index

Execute(Engine invocation should return the command for the fourth item correctly):
  let g:result = ProcessIndex(3)

  AssertEqual 'fourth', g:result.command
  AssertEqual 4, g:result.next_chain_index

Execute(Engine invocation should return the command for a single callback correctly):
  unlet g:linter.command_chain
  let g:linter.command_callback = 'FirstChainFunction'

  let g:result = ProcessIndex(0)

  AssertEqual 'first', g:result.command

Execute(Engine invocation should return the command for a command string correctly):
  unlet g:linter.command_chain
  let g:linter.command = 'foo bar'

  let g:result = ProcessIndex(0)

  AssertEqual 'foo bar', g:result.command

Execute(Engine invocation should process read_buffer correctly for simple commands):
  unlet g:linter.command_chain
  let g:linter.command = 'foo bar'
  let g:linter.read_buffer = 0

  let g:result = ProcessIndex(0)

  AssertEqual 'foo bar', g:result.command
  AssertEqual 0, g:result.read_buffer

  let g:linter.command_callback = 'FirstChainFunction'
  unlet g:linter.command

  let g:result = ProcessIndex(0)

  AssertEqual 'first', g:result.command
  AssertEqual 0, g:result.read_buffer

Execute(Engine invocation should allow read_buffer to be enabled for a command in the middle of a chain):
  let g:linter.command_chain[2].read_buffer = 1

  let g:result = ProcessIndex(2)

  AssertEqual g:result.command, 'third'
  AssertEqual g:result.read_buffer, 1

Execute(Engine invocation should allow read_buffer to be disabled for the end of a chain):
  let g:linter.command_chain[3].read_buffer = 0

  let g:result = ProcessIndex(3)

  AssertEqual g:result.command, 'fourth'
  AssertEqual g:result.read_buffer, 0

Execute(Engine invocation should not use read_buffer from earlier items in a chain):
  let g:linter.command_chain[1].read_buffer = 1

  let g:result = ProcessIndex(1)

  AssertEqual g:result.command, 'third'
  AssertEqual g:result.read_buffer, 0

Execute(Engine invocation should allow the output_stream setting to be changed in the middle of a chain):
  let g:linter.command_chain[2].output_stream = 'both'

  let g:result = ProcessIndex(2)

  AssertEqual g:result.command, 'third'
  AssertEqual g:result.output_stream, 'both'

Execute(Engine invocation should not use output_stream from earlier items in a chain):
  let g:linter.command_chain[1].output_stream = 'both'

  let g:result = ProcessIndex(1)

  AssertEqual g:result.command, 'third'
  AssertEqual g:result.output_stream, 'stdout'