summaryrefslogtreecommitdiff
path: root/test/test_lint_on_enter_when_file_changed.vader
blob: 67f43c17378f4b8772a9366c5afe8db6fdd13839 (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
Before:
  Save &filetype
  Save g:ale_buffer_info
  Save g:ale_lint_on_enter
  Save g:ale_set_lists_synchronously

  let g:buf = bufnr('')
  let g:ale_lint_on_enter = 1
  let g:ale_run_synchronously = 1
  let g:ale_set_lists_synchronously = 1

  function! TestCallback(buffer, output)
    return [{
    \ 'lnum': 1,
    \ 'col': 3,
    \ 'text': 'baz boz',
    \}]
  endfunction

  call ale#linter#Define('foobar', {
  \ 'name': 'testlinter',
  \ 'callback': 'TestCallback',
  \ 'executable': has('win32') ? 'cmd' : 'true',
  \ 'command': has('win32') ? 'echo' : 'true',
  \})

After:
  Restore
  unlet! g:buf
  let g:ale_run_synchronously = 0
  delfunction TestCallback
  call ale#linter#Reset()
  call setloclist(0, [])

Execute(The file changed event function should set b:ale_file_changed):
  let g:ale_lint_on_enter = 0

  if has('gui')
    new
  else
    e test
  endif

  call ale#events#FileChangedEvent(g:buf)
  close

  " We should set the flag in the other buffer
  AssertEqual 1, getbufvar(g:buf, 'ale_file_changed')

Execute(The file changed event function should lint the current buffer when it has changed):
  set filetype=foobar
  call ale#events#FileChangedEvent(bufnr(''))

  AssertEqual [{
  \   'bufnr': bufnr(''),
  \   'lnum': 1,
  \   'vcol': 0,
  \   'col': 3,
  \   'text': 'baz boz',
  \   'type': 'E',
  \   'nr': -1,
  \   'pattern': '',
  \   'valid': 1,
  \ }], ale#test#GetLoclistWithoutModule()

Execute(The buffer should be checked after entering it after the file has changed):
  let b:ale_file_changed = 1

  set filetype=foobar
  call ale#events#ReadOrEnterEvent(bufnr(''))

  AssertEqual [{
  \   'bufnr': bufnr(''),
  \   'lnum': 1,
  \   'vcol': 0,
  \   'col': 3,
  \   'text': 'baz boz',
  \   'type': 'E',
  \   'nr': -1,
  \   'pattern': '',
  \   'valid': 1,
  \ }], ale#test#GetLoclistWithoutModule()