summaryrefslogtreecommitdiff
path: root/test/test_format_command.vader
blob: 08496c18b1878074290dbc94aa963c18513adfc8 (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
Before:
  silent! cd /testplugin/test
  silent file top/middle/bottom/dummy.txt

After:
  unlet! g:result
  unlet! g:match

Execute(FormatCommand should do nothing to basic command strings):
  AssertEqual ['', 'awesome-linter do something'], ale#engine#FormatCommand(bufnr('%'), 'awesome-linter do something')

Execute(FormatCommand should handle %%, and ignore other percents):
  AssertEqual ['', '% %%d %%f %x %'], ale#engine#FormatCommand(bufnr('%'), '%% %%%d %%%f %x %')

Execute(FormatCommand should convert %s to the current filename):
  AssertEqual ['', 'foo ' . shellescape(expand('%:p')) . ' bar ' . shellescape(expand('%:p'))], ale#engine#FormatCommand(bufnr('%'), 'foo %s bar %s')

Execute(FormatCommand should convert %t to a new temporary filename):
  let g:result = ale#engine#FormatCommand(bufnr('%'), 'foo %t bar %t')
  let g:match = matchlist(g:result[1], '\v^foo (''/tmp/[^'']*/dummy.txt'') bar (''/tmp/[^'']*/dummy.txt'')$')

  Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
  " The first item of the result should be a temporary filename, and it should
  " be the same as the escaped name in the command string.
  AssertEqual shellescape(g:result[0]), g:match[1]
  " The two temporary filenames formatted in should be the same.
  AssertEqual g:match[1], g:match[2]

Execute(FormatCommand should let you combine %s and %t):
  let g:result = ale#engine#FormatCommand(bufnr('%'), 'foo %t bar %s')
  let g:match = matchlist(g:result[1], '\v^foo (''/tmp/.*/dummy.txt'') bar (''.*/dummy.txt'')$')

  Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
  " The first item of the result should be a temporary filename, and it should
  " be the same as the escaped name in the command string.
  AssertEqual shellescape(g:result[0]), g:match[1]
  " The second item should be equal to the original filename.
  AssertEqual shellescape(expand('%:p')), g:match[2]

Execute(EscapeCommandPart should escape all percent signs):
  AssertEqual '%%s %%t %%%% %%s %%t %%%%', ale#engine#EscapeCommandPart('%s %t %% %s %t %%')