]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/test_statusline.vader

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / test / test_statusline.vader
1 Before:
2   Save g:ale_buffer_info
3
4   let g:ale_buffer_info = {}
5
6   " A function for conveniently creating expected count objects.
7   function! Counts(data) abort
8     let l:res = {
9     \   '0': 0,
10     \   '1': 0,
11     \   'error': 0,
12     \   'warning': 0,
13     \   'info': 0,
14     \   'style_error': 0,
15     \   'style_warning': 0,
16     \   'total': 0,
17     \}
18
19     for l:key in keys(a:data)
20       let l:res[l:key] = a:data[l:key]
21     endfor
22
23     let l:res[0] = l:res.error + l:res.style_error
24     let l:res[1] = l:res.warning + l:res.style_warning + l:res.info
25     let l:res.total = l:res[0] + l:res[1]
26
27     return l:res
28   endfunction
29
30   " A test simplified loclist that will be used for some of the
31   " tests in this module.
32   let g:test_buffer_info = {
33   \ bufnr(''): {
34   \   'loclist': [
35   \     {'bufnr': bufnr('') - 1, 'type': 'E'},
36   \     {'bufnr': bufnr('') - 1, 'type': 'E', 'sub_type': 'style'},
37   \     {'bufnr': bufnr('') - 1, 'type': 'W'},
38   \     {'bufnr': bufnr('') - 1, 'type': 'W', 'sub_type': 'style'},
39   \     {'bufnr': bufnr('') - 1, 'type': 'I'},
40   \     {'bufnr': bufnr(''), 'type': 'E'},
41   \     {'bufnr': bufnr(''), 'type': 'E', 'sub_type': 'style'},
42   \     {'bufnr': bufnr(''), 'type': 'E', 'sub_type': 'style'},
43   \     {'bufnr': bufnr(''), 'type': 'W'},
44   \     {'bufnr': bufnr(''), 'type': 'W'},
45   \     {'bufnr': bufnr(''), 'type': 'W'},
46   \     {'bufnr': bufnr(''), 'type': 'W', 'sub_type': 'style'},
47   \     {'bufnr': bufnr(''), 'type': 'W', 'sub_type': 'style'},
48   \     {'bufnr': bufnr(''), 'type': 'W', 'sub_type': 'style'},
49   \     {'bufnr': bufnr(''), 'type': 'W', 'sub_type': 'style'},
50   \     {'bufnr': bufnr(''), 'type': 'I'},
51   \     {'bufnr': bufnr(''), 'type': 'I'},
52   \     {'bufnr': bufnr(''), 'type': 'I'},
53   \     {'bufnr': bufnr(''), 'type': 'I'},
54   \     {'bufnr': bufnr(''), 'type': 'I'},
55   \     {'bufnr': bufnr('') + 1, 'type': 'E'},
56   \     {'bufnr': bufnr('') + 1, 'type': 'E', 'sub_type': 'style'},
57   \     {'bufnr': bufnr('') + 1, 'type': 'W'},
58   \     {'bufnr': bufnr('') + 1, 'type': 'W', 'sub_type': 'style'},
59   \     {'bufnr': bufnr('') + 1, 'type': 'I'},
60   \   ],
61   \ },
62   \}
63 After:
64   Restore
65
66   delfunction Counts
67   unlet g:test_buffer_info
68
69 Execute (Count should be 0 when data is empty):
70   AssertEqual Counts({}), ale#statusline#Count(bufnr(''))
71
72 Execute (FirstProblem should be 0 when data is empty):
73   AssertEqual {}, ale#statusline#FirstProblem(bufnr(''), 'error')
74   AssertEqual {}, ale#statusline#FirstProblem(bufnr(''), 'warning')
75   AssertEqual {}, ale#statusline#FirstProblem(bufnr(''), 'style_error')
76   AssertEqual {}, ale#statusline#FirstProblem(bufnr(''), 'style_warning')
77   AssertEqual {}, ale#statusline#FirstProblem(bufnr(''), 'info')
78
79 Execute (Count should read data from the cache):
80   let g:ale_buffer_info = {'44': {'count': Counts({'error': 1, 'warning': 2})}}
81   AssertEqual Counts({'error': 1, 'warning': 2}), ale#statusline#Count(44)
82
83 Execute (FirstProblem should read data from the cache):
84   let g:ale_buffer_info =
85     \{"44":
86         \{'count': 0,
87          \'first_problems':
88               \{'error': {'lnum': 3},
89               \'warning': {'lnum': 44},
90               \'style_error': {'lnum': 22},
91               \'style_warning': {'lnum': 223},
92               \'info': {'lnum': 2}
93            \}
94         \}
95     \}
96   AssertEqual {'lnum': 3}, ale#statusline#FirstProblem(44, 'error')
97   AssertEqual {'lnum': 44}, ale#statusline#FirstProblem(44, 'warning')
98   AssertEqual {'lnum': 223}, ale#statusline#FirstProblem(44, 'style_warning')
99   AssertEqual {'lnum': 22}, ale#statusline#FirstProblem(44, 'style_error')
100   AssertEqual {'lnum': 2}, ale#statusline#FirstProblem(44, 'info')
101
102 Execute (The count should be correct after an update):
103   let g:ale_buffer_info = {'44': {}}
104   call ale#statusline#Update(44, [])
105   AssertEqual Counts({}), ale#statusline#Count(44)
106
107 Execute (FirstProblem should be correct after an update):
108   let g:ale_buffer_info = {'44': {}}
109   call ale#statusline#Update(44, [])
110   AssertEqual {}, ale#statusline#FirstProblem(bufnr(''), 'error')
111   AssertEqual {}, ale#statusline#FirstProblem(bufnr(''), 'warning')
112   AssertEqual {}, ale#statusline#FirstProblem(bufnr(''), 'style_error')
113   AssertEqual {}, ale#statusline#FirstProblem(bufnr(''), 'style_warning')
114   AssertEqual {}, ale#statusline#FirstProblem(bufnr(''), 'info')
115
116 Execute (Count should match the loclist):
117   let g:ale_buffer_info = g:test_buffer_info
118   AssertEqual {
119   \ 'error': 1,
120   \ 'style_error': 2,
121   \ 'warning': 3,
122   \ 'style_warning': 4,
123   \ 'info': 5,
124   \ '0': 3,
125   \ '1': 12,
126   \ 'total': 15,
127   \}, ale#statusline#Count(bufnr(''))
128
129 Execute (FirstProblem should pull the first matching value from the loclist):
130   let g:ale_buffer_info = g:test_buffer_info
131   AssertEqual {'bufnr': bufnr(''), 'type': 'E'}, ale#statusline#FirstProblem(bufnr(''), 'error')
132   AssertEqual {'bufnr': bufnr(''), 'type': 'W'}, ale#statusline#FirstProblem(bufnr(''), 'warning')
133   AssertEqual {'bufnr': bufnr(''), 'type': 'E', 'sub_type': 'style'}, ale#statusline#FirstProblem(bufnr(''), 'style_error')
134   AssertEqual {'bufnr': bufnr(''), 'type': 'W', 'sub_type': 'style'}, ale#statusline#FirstProblem(bufnr(''), 'style_warning')
135   AssertEqual {'bufnr': bufnr(''), 'type': 'I'}, ale#statusline#FirstProblem(bufnr(''), 'info')
136
137 Execute (Output should be empty for non-existent buffer):
138   let g:ale_buffer_info = g:test_buffer_info
139   AssertEqual Counts({}), ale#statusline#Count(9001)
140   AssertEqual {}, ale#statusline#FirstProblem(9001, 'error')
141   AssertEqual {}, ale#statusline#FirstProblem(9001, 'warning')
142   AssertEqual {}, ale#statusline#FirstProblem(9001, 'style_error')
143   AssertEqual {}, ale#statusline#FirstProblem(9001, 'style_warning')
144   AssertEqual {}, ale#statusline#FirstProblem(9001, 'info')