]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/handler/test_tslint_handler.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:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / test / handler / test_tslint_handler.vader
1 Before:
2   Save g:ale_typescript_tslint_ignore_empty_files
3
4   unlet! g:ale_typescript_tslint_ignore_empty_files
5   unlet! b:ale_typescript_tslint_ignore_empty_files
6
7   runtime ale_linters/typescript/tslint.vim
8
9   call ale#test#SetDirectory('/testplugin/test/handler')
10
11 After:
12   Restore
13
14   unlet! b:ale_typescript_tslint_ignore_empty_files
15   unlet! b:relative_to_root
16   unlet! b:tempname_suffix
17   unlet! b:relative_tempname
18
19   call ale#test#RestoreDirectory()
20   call ale#linter#Reset()
21
22 Execute(The tslint handler should parse lines correctly):
23   call ale#test#SetFilename('app/test.ts')
24
25   AssertEqual
26   \ [
27   \   {
28   \     'lnum': 1,
29   \     'col': 15,
30   \     'filename': ale#path#Simplify(expand('%:p:h') . '/test.ts'),
31   \     'end_lnum': 1,
32   \     'type': 'E',
33   \     'end_col': 15,
34   \     'text': 'Missing semicolon',
35   \     'code': 'semicolon',
36   \   },
37   \   {
38   \     'lnum': 2,
39   \     'col': 8,
40   \     'filename': ale#path#Simplify(expand('%:p:h') . '/test.ts'),
41   \     'end_lnum': 3,
42   \     'type': 'W',
43   \     'end_col': 12,
44   \     'text': 'Something else',
45   \   },
46   \   {
47   \     'lnum': 2,
48   \     'col': 8,
49   \     'filename': ale#path#Simplify(expand('%:p:h') . '/something-else.ts'),
50   \     'end_lnum': 3,
51   \     'type': 'W',
52   \     'end_col': 12,
53   \     'text': 'Something else',
54   \     'code': 'something',
55   \   },
56   \   {
57   \     'lnum': 31,
58   \     'col': 9,
59   \     'filename': ale#path#Simplify(expand('%:p:h') . '/test.ts'),
60   \     'end_lnum': 31,
61   \     'type': 'E',
62   \     'end_col': 20,
63   \     'text': 'Calls to console.log are not allowed.',
64   \     'code': 'no-console',
65   \   },
66   \ ] ,
67   \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([
68   \   {
69   \     'endPosition': {
70   \       'character': 14,
71   \       'line': 0,
72   \       'position': 1000
73   \     },
74   \     'failure': 'Missing semicolon',
75   \     'fix': {
76   \       'innerLength': 0,
77   \       'innerStart': 14,
78   \       'innerText': ';'
79   \     },
80   \     'name': 'test.ts',
81   \     'ruleName': 'semicolon',
82   \     'ruleSeverity': 'ERROR',
83   \     'startPosition': {
84   \       'character': 14,
85   \       'line': 0,
86   \       'position': 1000
87   \     }
88   \   },
89   \   {
90   \     'endPosition': {
91   \       'character': 11,
92   \       'line': 2,
93   \       'position': 1000
94   \     },
95   \     'failure': 'Something else',
96   \     'fix': {
97   \       'innerLength': 0,
98   \       'innerStart': 14,
99   \       'innerText': ';'
100   \     },
101   \     'name': 'test.ts',
102   \     'ruleSeverity': 'WARNING',
103   \     'startPosition': {
104   \       'character': 7,
105   \       'line': 1,
106   \       'position': 1000
107   \     }
108   \   },
109   \   {
110   \     'endPosition': {
111   \       'character': 11,
112   \       'line': 2,
113   \       'position': 22
114   \     },
115   \     'failure': 'Something else',
116   \     'fix': {
117   \       'innerLength': 0,
118   \       'innerStart': 14,
119   \       'innerText': ';'
120   \     },
121   \     'name': 'something-else.ts',
122   \     'ruleName': 'something',
123   \     'ruleSeverity': 'WARNING',
124   \     'startPosition': {
125   \       'character': 7,
126   \       'line': 1,
127   \       'position': 14
128   \     }
129   \   },
130   \   {
131   \     "endPosition": {
132   \       "character": 19,
133   \       "line": 30,
134   \       "position": 14590
135   \     },
136   \     "failure": "Calls to console.log are not allowed.",
137   \     'name': 'test.ts',
138   \     "ruleName": "no-console",
139   \     "startPosition": {
140   \       "character": 8,
141   \       "line": 30,
142   \       "position": 14579
143   \     }
144   \   },
145   \])])
146
147 Execute(The tslint handler should handle empty output):
148   AssertEqual
149   \ [],
150   \ ale_linters#typescript#tslint#Handle(bufnr(''), [])
151
152 Execute(The tslint handler report errors for empty files by default):
153   call ale#test#SetFilename('app/test.ts')
154
155   AssertEqual
156   \ [
157   \   {
158   \     'lnum': 2,
159   \     'col': 1,
160   \     'filename': ale#path#Simplify(expand('%:p:h') . '/test.ts'),
161   \     'end_lnum': 2,
162   \     'type': 'E',
163   \     'end_col': 1,
164   \     'text': 'Consecutive blank lines are forbidden',
165   \     'code': 'no-consecutive-blank-lines',
166   \   },
167   \ ],
168   \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([{
169   \   'endPosition': {
170   \     'character': 0,
171   \     'line': 1,
172   \     'position': 1
173   \   },
174   \   'failure': 'Consecutive blank lines are forbidden',
175   \   'fix': [{
176   \     'innerStart': 0,
177   \     'innerLength': 1,
178   \     'innerText': ''
179   \   }],
180   \   'name': 'test.ts',
181   \   'ruleName': 'no-consecutive-blank-lines',
182   \   'ruleSeverity': 'ERROR',
183   \   'startPosition': {
184   \     'character': 0,
185   \     'line': 1,
186   \     'position': 1
187   \   }
188   \ }])])
189
190 Execute(The tslint handler should not report errors for empty files when the ignore option is on):
191   let b:ale_typescript_tslint_ignore_empty_files = 1
192   call ale#test#SetFilename('app/test.ts')
193
194   AssertEqual
195   \ [
196   \ ],
197   \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([{
198   \   'endPosition': {
199   \     'character': 0,
200   \     'line': 1,
201   \     'position': 1
202   \   },
203   \   'failure': 'Consecutive blank lines are forbidden',
204   \   'fix': [{
205   \     'innerStart': 0,
206   \     'innerLength': 1,
207   \     'innerText': ''
208   \   }],
209   \   'name': 'test.ts',
210   \   'ruleName': 'no-consecutive-blank-lines',
211   \   'ruleSeverity': 'ERROR',
212   \   'startPosition': {
213   \     'character': 0,
214   \     'line': 1,
215   \     'position': 1
216   \   }
217   \ }])])
218
219 Given typescript(A file with extra blank lines):
220   const x = 3
221
222
223   const y = 4
224
225 Execute(The tslint handler should report errors when the ignore option is on, but the file is not empty):
226   let b:ale_typescript_tslint_ignore_empty_files = 1
227   call ale#test#SetFilename('app/test.ts')
228
229   AssertEqual
230   \ [
231   \   {
232   \     'lnum': 2,
233   \     'col': 1,
234   \     'filename': ale#path#Simplify(expand('%:p:h') . '/test.ts'),
235   \     'end_lnum': 2,
236   \     'type': 'E',
237   \     'end_col': 1,
238   \     'text': 'Consecutive blank lines are forbidden',
239   \     'code': 'no-consecutive-blank-lines',
240   \   },
241   \ ],
242   \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([{
243   \   'endPosition': {
244   \     'character': 0,
245   \     'line': 1,
246   \     'position': 1
247   \   },
248   \   'failure': 'Consecutive blank lines are forbidden',
249   \   'fix': [{
250   \     'innerStart': 0,
251   \     'innerLength': 1,
252   \     'innerText': ''
253   \   }],
254   \   'name': 'test.ts',
255   \   'ruleName': 'no-consecutive-blank-lines',
256   \   'ruleSeverity': 'ERROR',
257   \   'startPosition': {
258   \     'character': 0,
259   \     'line': 1,
260   \     'position': 1
261   \   }
262   \ }])])
263
264 Execute(The tslint handler should not report no-implicit-dependencies errors):
265   call ale#test#SetFilename('app/test.ts')
266
267   AssertEqual
268   \ [
269   \ ],
270   \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([{
271   \   'endPosition': {
272   \     'character': 0,
273   \     'line': 1,
274   \     'position': 1
275   \   },
276   \   'failure': 'this is ignored',
277   \   'name': 'test.ts',
278   \   'ruleName': 'no-implicit-dependencies',
279   \   'ruleSeverity': 'ERROR',
280   \   'startPosition': {
281   \     'character': 0,
282   \     'line': 1,
283   \     'position': 1
284   \   },
285   \ }])])
286
287 Execute(The tslint handler should set filename keys for temporary files):
288   " The temporary filename below is hacked into being a relative path so we can
289   " test that we resolve the temporary filename first.
290   let b:relative_to_root = substitute(expand('%:p'), '\v[^/\\]*([/\\])[^/\\]*', '../', 'g')
291   let b:tempname_suffix = substitute(tempname(), '^\v([A-Z]:)?[/\\]', '', '')
292   let b:relative_tempname = substitute(b:relative_to_root . b:tempname_suffix, '\\', '/', 'g')
293
294   AssertEqual
295   \ [
296   \   {'lnum': 47, 'col': 1, 'code': 'curly', 'end_lnum': 47, 'type': 'E', 'end_col': 26, 'text': 'if statements must be braced'},
297   \ ],
298   \ ale_linters#typescript#tslint#Handle(bufnr(''), [json_encode([
299   \   {
300   \     'endPosition': {
301   \       'character':25,
302   \       'line':46,
303   \       'position':1383,
304   \     },
305   \     'failure': 'if statements must be braced',
306   \     'name': b:relative_tempname,
307   \     'ruleName': 'curly',
308   \     'ruleSeverity':'ERROR',
309   \     'startPosition': {
310   \       'character':0,
311   \       'line':46,
312   \       'position':1358,
313   \     }
314   \   },
315   \ ])])