]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/fixers/test_prettier_fixer_callback.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 / fixers / test_prettier_fixer_callback.vader
1 Before:
2   call ale#assert#SetUpFixerTest('javascript', 'prettier')
3   Save g:ale_command_wrapper
4
5   let g:ale_command_wrapper = ''
6
7 After:
8   call ale#assert#TearDownFixerTest()
9
10 Execute(The prettier callback should return the correct default values):
11   call ale#test#SetFilename('../test-files/prettier/testfile.js')
12
13   AssertFixer
14   \ {
15   \   'read_temporary_file': 1,
16   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
17   \     . ' %t'
18   \     . ' --write',
19   \ }
20
21 Execute(The --config option should not be set automatically):
22   let g:ale_javascript_prettier_use_local_config = 1
23   call ale#test#SetFilename('../test-files/prettier/with_config/testfile.js')
24
25   AssertFixer
26   \ {
27   \   'read_temporary_file': 1,
28   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
29   \     . ' %t'
30   \     . ' --write',
31   \ }
32
33 Execute(The prettier callback should include custom prettier options):
34   let g:ale_javascript_prettier_options = '--no-semi'
35   call ale#test#SetFilename('../test-files/prettier/with_config/testfile.js')
36
37   AssertFixer
38   \ {
39   \   'read_temporary_file': 1,
40   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
41   \     . ' %t'
42   \     . ' --no-semi'
43   \     . ' --write',
44   \ }
45
46 Execute(The version check should be correct):
47   call ale#test#SetFilename('../test-files/prettier/testfile.js')
48
49   AssertFixer [
50   \ ale#Escape('prettier') . ' --version',
51   \ {'read_temporary_file': 1, 'command': ale#Escape('prettier') . ' %t --write'}
52   \]
53
54 Execute(--stdin-filepath should be used when prettier is new enough):
55   let g:ale_javascript_prettier_options = '--no-semi'
56   call ale#test#SetFilename('../test-files/prettier/with_config/testfile.js')
57
58   GivenCommandOutput ['1.6.0']
59   AssertFixer
60   \ {
61   \   'cwd': '%s:h',
62   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
63   \     . ' --no-semi'
64   \     . ' --stdin-filepath %s --stdin',
65   \ }
66
67 Execute(The version number should be cached):
68   call ale#test#SetFilename('../test-files/prettier/with_config/testfile.js')
69
70   GivenCommandOutput ['1.6.0']
71   AssertFixer
72   \ {
73   \   'cwd': '%s:h',
74   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
75   \     . ' --stdin-filepath %s --stdin',
76   \ }
77
78   GivenCommandOutput []
79   AssertFixer
80   \ {
81   \   'cwd': '%s:h',
82   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
83   \     . ' --stdin-filepath %s --stdin',
84   \ }
85
86 Execute(Should set --parser to `babylon` by default, < 1.16.0):
87   call ale#test#SetFilename('../test-files/prettier/testfile')
88
89   set filetype=javascript
90
91   GivenCommandOutput ['1.6.0']
92   AssertFixer
93   \ {
94   \   'cwd': '%s:h',
95   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
96   \     . ' --parser babylon'
97   \     . ' --stdin-filepath %s --stdin',
98   \ }
99
100 Execute(Should set --parser to `babel` by default, >= 1.16.0):
101   call ale#test#SetFilename('../test-files/prettier/testfile')
102
103   set filetype=javascript
104
105   GivenCommandOutput ['1.16.0']
106   AssertFixer
107   \ {
108   \   'cwd': '%s:h',
109   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
110   \     . ' --parser babel'
111   \     . ' --stdin-filepath %s --stdin',
112   \ }
113
114 Execute(Should set --parser based on filetype, TypeScript):
115   call ale#test#SetFilename('../test-files/prettier/testfile')
116
117   set filetype=typescript
118
119   GivenCommandOutput ['1.6.0']
120   AssertFixer
121   \ {
122   \   'cwd': '%s:h',
123   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
124   \     . ' --parser typescript'
125   \     . ' --stdin-filepath %s --stdin',
126   \ }
127
128 Execute(Should set --parser based on filetype, CSS):
129   call ale#test#SetFilename('../test-files/prettier/testfile')
130
131   set filetype=css
132
133   GivenCommandOutput ['1.6.0']
134   AssertFixer
135   \ {
136   \   'cwd': '%s:h',
137   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
138   \     . ' --parser css'
139   \     . ' --stdin-filepath %s --stdin',
140   \ }
141
142 Execute(Should set --parser based on filetype, LESS):
143   call ale#test#SetFilename('../test-files/prettier/testfile')
144
145   set filetype=less
146
147   GivenCommandOutput ['1.6.0']
148   AssertFixer
149   \ {
150   \   'cwd': '%s:h',
151   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
152   \     . ' --parser less'
153   \     . ' --stdin-filepath %s --stdin',
154   \ }
155
156 Execute(Should set --parser based on filetype, SCSS):
157   call ale#test#SetFilename('../test-files/prettier/testfile')
158
159   set filetype=scss
160
161   GivenCommandOutput ['1.6.0']
162   AssertFixer
163   \ {
164   \   'cwd': '%s:h',
165   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
166   \     . ' --parser scss'
167   \     . ' --stdin-filepath %s --stdin',
168   \ }
169
170 Execute(Should set --parser based on filetype, JSON):
171   call ale#test#SetFilename('../test-files/prettier/testfile')
172
173   set filetype=json
174
175   GivenCommandOutput ['1.6.0']
176   AssertFixer
177   \ {
178   \   'cwd': '%s:h',
179   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
180   \     . ' --parser json'
181   \     . ' --stdin-filepath %s --stdin',
182   \ }
183
184 Execute(Should set --parser based on filetype, JSON5):
185   call ale#test#SetFilename('../test-files/prettier/testfile')
186
187   set filetype=json5
188
189   GivenCommandOutput ['1.6.0']
190   AssertFixer
191   \ {
192   \   'cwd': '%s:h',
193   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
194   \     . ' --parser json5'
195   \     . ' --stdin-filepath %s --stdin',
196   \ }
197
198 Execute(Should set --parser based on filetype, GraphQL):
199   call ale#test#SetFilename('../test-files/prettier/testfile')
200
201   set filetype=graphql
202
203   GivenCommandOutput ['1.6.0']
204   AssertFixer
205   \ {
206   \   'cwd': '%s:h',
207   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
208   \     . ' --parser graphql'
209   \     . ' --stdin-filepath %s --stdin',
210   \ }
211
212 Execute(Should set --parser based on filetype, Markdown):
213   call ale#test#SetFilename('../test-files/prettier/testfile')
214
215   set filetype=markdown
216
217   GivenCommandOutput ['1.6.0']
218   AssertFixer
219   \ {
220   \   'cwd': '%s:h',
221   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
222   \     . ' --parser markdown'
223   \     . ' --stdin-filepath %s --stdin',
224   \ }
225
226 Execute(Should set --parser based on filetype, Vue):
227   call ale#test#SetFilename('../test-files/prettier/testfile')
228
229   set filetype=vue
230
231   GivenCommandOutput ['1.6.0']
232   AssertFixer
233   \ {
234   \   'cwd': '%s:h',
235   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
236   \     . ' --parser vue'
237   \     . ' --stdin-filepath %s --stdin',
238   \ }
239
240 Execute(Should set --parser based on filetype, YAML):
241   call ale#test#SetFilename('../test-files/prettier/testfile')
242
243   set filetype=yaml
244
245   GivenCommandOutput ['1.6.0']
246   AssertFixer
247   \ {
248   \   'cwd': '%s:h',
249   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
250   \     . ' --parser yaml'
251   \     . ' --stdin-filepath %s --stdin',
252   \ }
253
254 Execute(Should set --parser based on filetype, HTML):
255   call ale#test#SetFilename('../test-files/prettier/testfile')
256
257   set filetype=html
258
259   GivenCommandOutput ['1.6.0']
260   AssertFixer
261   \ {
262   \   'cwd': '%s:h',
263   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
264   \     . ' --parser html'
265   \     . ' --stdin-filepath %s --stdin',
266   \ }
267
268 Execute(Should set --parser based on filetype, Ruby):
269   call ale#test#SetFilename('../test-files/prettier/testfile')
270
271   set filetype=ruby
272
273   GivenCommandOutput ['1.6.0']
274   AssertFixer
275   \ {
276   \   'cwd': '%s:h',
277   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
278   \     . ' --parser ruby'
279   \     . ' --stdin-filepath %s --stdin',
280   \ }
281
282 Execute(Should set --parser based on first filetype of multiple filetypes):
283   call ale#test#SetFilename('../test-files/prettier/testfile')
284
285   set filetype=css.scss
286
287   GivenCommandOutput ['1.6.0']
288   AssertFixer
289   \ {
290   \   'cwd': '%s:h',
291   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
292   \     . ' --parser css'
293   \     . ' --stdin-filepath %s --stdin',
294   \ }
295
296 Execute(Should set --parser based on first filetype of multiple filetypes):
297   call ale#test#SetFilename('../test-files/prettier/testfile')
298
299   set filetype=astro
300
301   GivenCommandOutput ['1.6.0']
302   AssertFixer
303   \ {
304   \   'cwd': '%s:h',
305   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
306   \     . ' --parser astro'
307   \     . ' --stdin-filepath %s --stdin',
308   \ }
309
310 Execute(Should set --parser for experimental language, Handlebars):
311   call ale#test#SetFilename('../test-files/prettier/testfile.hbs')
312
313   set filetype=html.handlebars
314
315   GivenCommandOutput ['1.6.0']
316   AssertFixer
317   \ {
318   \   'cwd': '%s:h',
319   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
320   \     . ' --parser glimmer'
321   \     . ' --stdin-filepath %s --stdin',
322   \ }
323
324 Execute(Changes to directory where .prettierignore is found):
325   call ale#test#SetFilename('../test-files/prettier/with_prettierignore/src/testfile.js')
326
327   GivenCommandOutput ['1.6.0']
328   AssertFixer
329   \ {
330   \   'cwd': expand('%:p:h:h'),
331   \   'command': ale#Escape(g:ale_javascript_prettier_executable)
332   \     . ' --stdin-filepath %s --stdin',
333   \ }
334
335 Execute(The prettier_d post-processor should permit regular JavaScript content):
336   AssertEqual
337   \ [
338   \   'const x = ''Error: foo''',
339   \   'const y = 3',
340   \ ],
341   \ ale#fixers#prettier#ProcessPrettierDOutput(bufnr(''), [
342   \   'const x = ''Error: foo''',
343   \   'const y = 3',
344   \ ])
345
346 Execute(The prettier_d post-processor should handle error messages correctly):
347   AssertEqual
348   \ [],
349   \ ale#fixers#prettier#ProcessPrettierDOutput(bufnr(''), [
350   \   'SyntaxError: Unexpected token, expected "," (36:28)',
351   \ ])