summaryrefslogtreecommitdiff
path: root/test/command_callback/test_thrift_command_callback.vader
blob: 670089196ef908ff78b8ef57c5a24dfa768141f1 (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
Before:
  Save g:ale_thrift_thrift_executable
  Save g:ale_thrift_thrift_generators
  Save g:ale_thrift_thrift_includes
  Save g:ale_thrift_thrift_options

  unlet! b:ale_thrift_thrift_executable
  unlet! b:ale_thrift_thrift_generators
  unlet! b:ale_thrift_thrift_includes
  unlet! b:ale_thrift_thrift_options

  function! GetCommand(buffer) abort
    call ale#engine#InitBufferInfo(a:buffer)
    let l:command = ale_linters#thrift#thrift#GetCommand(a:buffer)
    call ale#engine#Cleanup(a:buffer)

    let l:split_command = split(l:command)
    let l:index = index(l:split_command, '-out')

    if l:index >= 0
      let l:split_command[l:index + 1] = 'TEMP'
    endif

    return join(l:split_command)
  endfunction

  runtime ale_linters/thrift/thrift.vim

After:
  Restore
  delfunction GetCommand
  unlet! b:ale_thrift_thrift_executable
  unlet! b:ale_thrift_thrift_generators
  unlet! b:ale_thrift_thrift_includes
  unlet! b:ale_thrift_thrift_options
  call ale#linter#Reset()

Execute(The executable should be configurable):
  AssertEqual 'thrift', ale_linters#thrift#thrift#GetExecutable(bufnr(''))

  let b:ale_thrift_thrift_executable = 'foobar'
  AssertEqual 'foobar', ale_linters#thrift#thrift#GetExecutable(bufnr(''))

Execute(The executable should be used in the command):
  AssertEqual
  \ ale#Escape('thrift') . ' --gen cpp -strict -out TEMP %t',
  \ GetCommand(bufnr('%'))

  let b:ale_thrift_thrift_executable = 'foobar'
  AssertEqual
  \ ale#Escape('foobar') . ' --gen cpp -strict -out TEMP %t',
  \ GetCommand(bufnr('%'))

Execute(The list of generators should be configurable):
  let b:ale_thrift_thrift_generators = ['java', 'py:dynamic']

  AssertEqual
  \ ale#Escape('thrift') . ' --gen java --gen py:dynamic -strict -out TEMP %t',
  \ GetCommand(bufnr('%'))

  let b:ale_thrift_thrift_generators = []

  AssertEqual
  \ ale#Escape('thrift') . ' --gen cpp -strict -out TEMP %t',
  \ GetCommand(bufnr('%'))

Execute(The list of include paths should be configurable):
  let b:ale_thrift_thrift_includes = ['included/path']

  AssertEqual
  \ ale#Escape('thrift')
  \   . ' --gen cpp'
  \   . ' -I included/path'
  \   . ' -strict -out TEMP %t',
  \ GetCommand(bufnr('%'))

Execute(The string of compiler options should be configurable):
  let b:ale_thrift_thrift_options = '-strict --allow-64bit-consts'

  AssertEqual
  \ ale#Escape('thrift')
  \   . ' --gen cpp -strict --allow-64bit-consts'
  \   . ' -out TEMP %t',
  \ GetCommand(bufnr('%'))