summaryrefslogtreecommitdiff
path: root/test/test_loclist_jumping.vader
blob: 5e18499ed16a22443269e9982413776075bd1a15 (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
Before:
  let g:ale_buffer_info = {
  \ bufnr(''): {
  \   'loclist': [
  \     {'bufnr': bufnr('') - 1, 'lnum': 3, 'col': 2},
  \     {'bufnr': bufnr(''), 'lnum': 1, 'col': 2},
  \     {'bufnr': bufnr(''), 'lnum': 1, 'col': 3},
  \     {'bufnr': bufnr(''), 'lnum': 2, 'col': 1},
  \     {'bufnr': bufnr(''), 'lnum': 2, 'col': 2},
  \     {'bufnr': bufnr(''), 'lnum': 2, 'col': 3},
  \     {'bufnr': bufnr(''), 'lnum': 2, 'col': 6},
  \     {'bufnr': bufnr(''), 'lnum': 2, 'col': 700},
  \     {'bufnr': bufnr('') + 1, 'lnum': 3, 'col': 2},
  \   ],
  \ },
  \}

  function! TestJump(position, wrap, pos)
    call cursor(a:pos)

    if type(a:position) == type(0)
      call ale#loclist_jumping#JumpToIndex(a:position)
    else
      call ale#loclist_jumping#Jump(a:position, a:wrap)
    endif

    return getcurpos()[1:2]
  endfunction

After:
  let g:ale_buffer_info = {}
  delfunction TestJump

Given foobar (Some imaginary filetype):
  12345678
  12345678

Execute(loclist jumping should jump correctly when not wrapping):
  AssertEqual [2, 1], TestJump('before', 0, [2, 2])
  AssertEqual [1, 3], TestJump('before', 0, [2, 1])
  AssertEqual [2, 3], TestJump('after', 0, [2, 2])
  AssertEqual [2, 1], TestJump('after', 0, [1, 3])
  AssertEqual [2, 6], TestJump('after', 0, [2, 4])
  AssertEqual [2, 8], TestJump('after', 0, [2, 6])

Execute(loclist jumping should jump correctly when wrapping):
  AssertEqual [2, 1], TestJump('before', 1, [2, 2])
  AssertEqual [1, 3], TestJump('before', 1, [2, 1])
  AssertEqual [2, 3], TestJump('after', 1, [2, 2])
  AssertEqual [2, 1], TestJump('after', 1, [1, 3])
  AssertEqual [2, 6], TestJump('after', 1, [2, 4])

  AssertEqual [1, 2], TestJump('after', 1, [2, 8])
  AssertEqual [2, 8], TestJump('before', 1, [1, 2])

Execute(loclist jumping not jump when the loclist is empty):
  let g:ale_buffer_info[bufnr('%')].loclist = []

  AssertEqual [1, 6], TestJump('before', 0, [1, 6])
  AssertEqual [1, 6], TestJump('before', 1, [1, 6])
  AssertEqual [1, 6], TestJump('after', 0, [1, 6])
  AssertEqual [1, 6], TestJump('after', 1, [1, 6])

Execute(We should be able to jump to the last item):
  AssertEqual [2, 8], TestJump(-1, 0, [1, 6])

Execute(We shouldn't move when jumping to the last item where there are none):
  let g:ale_buffer_info[bufnr('%')].loclist = []

  AssertEqual [1, 6], TestJump(-1, 0, [1, 6])

Execute(We should be able to jump to the first item):
  AssertEqual [1, 2], TestJump(0, 0, [1, 6])

Execute(We shouldn't move when jumping to the first item where there are none):
  let g:ale_buffer_info[bufnr('%')].loclist = []

  AssertEqual [1, 6], TestJump(0, 0, [1, 6])

Execute(We should be able to jump when the error line is blank):
  " Add a blank line at the end.
  call setline(1, getline('.', '$') + [''])
  " Add a problem on the blank line.
  call add(g:ale_buffer_info[bufnr('%')].loclist, {'bufnr': bufnr(''), 'lnum': 3, 'col': 1})

  AssertEqual 0, len(getline(3))
  AssertEqual [2, 8], TestJump('before', 0, [3, 1])
  AssertEqual [2, 8], TestJump('before', 1, [3, 1])
  AssertEqual [3, 1], TestJump('after', 0, [3, 1])
  AssertEqual [1, 2], TestJump('after', 1, [3, 1])