]> git.madduck.net Git - etc/vim.git/blob - tests/data/fmtonoff.py

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:

Refactor docs / Maintenance of docs (#1456)
[etc/vim.git] / tests / data / fmtonoff.py
1 #!/usr/bin/env python3
2 import asyncio
3 import sys
4
5 from third_party import X, Y, Z
6
7 from library import some_connection, \
8                     some_decorator
9 # fmt: off
10 from third_party import (X,
11                          Y, Z)
12 # fmt: on
13 f'trigger 3.6 mode'
14 # Comment 1
15
16 # Comment 2
17
18 # fmt: off
19 def func_no_args():
20   a; b; c
21   if True: raise RuntimeError
22   if False: ...
23   for i in range(10):
24     print(i)
25     continue
26   exec('new-style exec', {}, {})
27   return None
28 async def coroutine(arg, exec=False):
29  'Single-line docstring. Multiline is harder to reformat.'
30  async with some_connection() as conn:
31      await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
32  await asyncio.sleep(1)
33 @asyncio.coroutine
34 @some_decorator(
35 with_args=True,
36 many_args=[1,2,3]
37 )
38 def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
39  return text[number:-1]
40 # fmt: on
41 def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r''):
42  offset = attr.ib(default=attr.Factory( lambda: _r.uniform(1, 2)))
43  assert task._cancel_stack[:len(old_stack)] == old_stack
44 def spaces_types(a: int = 1, b: tuple = (), c: list = [], d: dict = {}, e: bool = True, f: int = -1, g: int = 1 if False else 2, h: str = "", i: str = r''): ...
45 def spaces2(result= _core.Value(None)):
46  ...
47 something = {
48     # fmt: off
49     key: 'value',
50 }
51
52 def subscriptlist():
53     atom[
54         # fmt: off
55         'some big and',
56         'complex subscript',
57         # fmt: on
58         goes + here, andhere,
59        ]
60
61 def import_as_names():
62     # fmt: off
63     from hello import a,        b
64     'unformatted'
65     # fmt: on
66
67 def testlist_star_expr():
68     # fmt: off
69     a , b = *hello
70     'unformatted'
71     # fmt: on
72
73 def yield_expr():
74     # fmt: off
75     yield hello
76     'unformatted'
77     # fmt: on
78     'formatted'
79     # fmt: off
80     ( yield hello )
81     'unformatted'
82     # fmt: on
83
84 def example(session):
85     # fmt: off
86     result = session\
87         .query(models.Customer.id)\
88         .filter(models.Customer.account_id == account_id,
89                 models.Customer.email == email_address)\
90         .order_by(models.Customer.id.asc())\
91         .all()
92     # fmt: on
93 def off_and_on_without_data():
94     """All comments here are technically on the same prefix.
95
96     The comments between will be formatted. This is a known limitation.
97     """
98     # fmt: off
99
100
101         #hey, that won't work
102
103
104     # fmt: on
105     pass
106 def on_and_off_broken():
107     """Another known limitation."""
108     # fmt: on
109     # fmt: off
110     this=should.not_be.formatted()
111     and_=indeed . it  is  not  formatted
112     because . the . handling . inside . generate_ignored_nodes()
113     now . considers . multiple . fmt . directives . within . one . prefix
114     # fmt: on
115     # fmt: off
116         # ...but comments still get reformatted even though they should not be
117     # fmt: on
118 def long_lines():
119     if True:
120         typedargslist.extend(
121             gen_annotated_params(ast_args.kwonlyargs, ast_args.kw_defaults, parameters, implicit_default=True)
122         )
123         # fmt: off
124         a = (
125             unnecessary_bracket()
126         )
127         # fmt: on
128     _type_comment_re = re.compile(
129         r"""
130         ^
131         [\t ]*
132         \#[ ]type:[ ]*
133         (?P<type>
134             [^#\t\n]+?
135         )
136         (?<!ignore)     # note: this will force the non-greedy + in <type> to match
137                         # a trailing space which is why we need the silliness below
138         (?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
139         (?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
140         (?<!ignore[ ]{9})(?<!ignore[ ]{10})
141         [\t ]*
142         (?P<nl>
143             (?:\#[^\n]*)?
144             \n?
145         )
146         $
147         """,
148         # fmt: off
149         re.MULTILINE|re.VERBOSE
150         # fmt: on
151     )
152 def single_literal_yapf_disable():
153     """Black does not support this."""
154     BAZ = {
155         (1, 2, 3, 4),
156         (5, 6, 7, 8),
157         (9, 10, 11, 12)
158     }  # yapf: disable
159 cfg.rule(
160     "Default", "address",
161     xxxx_xxxx=["xxx-xxxxxx-xxxxxxxxxx"],
162     xxxxxx="xx_xxxxx", xxxxxxx="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
163     xxxxxxxxx_xxxx=True, xxxxxxxx_xxxxxxxxxx=False,
164     xxxxxx_xxxxxx=2, xxxxxx_xxxxx_xxxxxxxx=70, xxxxxx_xxxxxx_xxxxx=True,
165     # fmt: off
166     xxxxxxx_xxxxxxxxxxxx={
167         "xxxxxxxx": {
168             "xxxxxx": False,
169             "xxxxxxx": False,
170             "xxxx_xxxxxx": "xxxxx",
171         },
172         "xxxxxxxx-xxxxx": {
173             "xxxxxx": False,
174             "xxxxxxx": True,
175             "xxxx_xxxxxx": "xxxxxx",
176         },
177     },
178     # fmt: on
179     xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5
180 )
181 # fmt: off
182 yield  'hello'
183 # No formatting to the end of the file
184 l=[1,2,3]
185 d={'a':1,
186    'b':2}
187
188 # output
189
190
191 #!/usr/bin/env python3
192 import asyncio
193 import sys
194
195 from third_party import X, Y, Z
196
197 from library import some_connection, some_decorator
198
199 # fmt: off
200 from third_party import (X,
201                          Y, Z)
202 # fmt: on
203 f"trigger 3.6 mode"
204 # Comment 1
205
206 # Comment 2
207
208 # fmt: off
209 def func_no_args():
210   a; b; c
211   if True: raise RuntimeError
212   if False: ...
213   for i in range(10):
214     print(i)
215     continue
216   exec('new-style exec', {}, {})
217   return None
218 async def coroutine(arg, exec=False):
219  'Single-line docstring. Multiline is harder to reformat.'
220  async with some_connection() as conn:
221      await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
222  await asyncio.sleep(1)
223 @asyncio.coroutine
224 @some_decorator(
225 with_args=True,
226 many_args=[1,2,3]
227 )
228 def function_signature_stress_test(number:int,no_annotation=None,text:str='default',* ,debug:bool=False,**kwargs) -> str:
229  return text[number:-1]
230 # fmt: on
231 def spaces(a=1, b=(), c=[], d={}, e=True, f=-1, g=1 if False else 2, h="", i=r""):
232     offset = attr.ib(default=attr.Factory(lambda: _r.uniform(1, 2)))
233     assert task._cancel_stack[: len(old_stack)] == old_stack
234
235
236 def spaces_types(
237     a: int = 1,
238     b: tuple = (),
239     c: list = [],
240     d: dict = {},
241     e: bool = True,
242     f: int = -1,
243     g: int = 1 if False else 2,
244     h: str = "",
245     i: str = r"",
246 ):
247     ...
248
249
250 def spaces2(result=_core.Value(None)):
251     ...
252
253
254 something = {
255     # fmt: off
256     key: 'value',
257 }
258
259
260 def subscriptlist():
261     atom[
262         # fmt: off
263         'some big and',
264         'complex subscript',
265         # fmt: on
266         goes + here,
267         andhere,
268     ]
269
270
271 def import_as_names():
272     # fmt: off
273     from hello import a,        b
274     'unformatted'
275     # fmt: on
276
277
278 def testlist_star_expr():
279     # fmt: off
280     a , b = *hello
281     'unformatted'
282     # fmt: on
283
284
285 def yield_expr():
286     # fmt: off
287     yield hello
288     'unformatted'
289     # fmt: on
290     "formatted"
291     # fmt: off
292     ( yield hello )
293     'unformatted'
294     # fmt: on
295
296
297 def example(session):
298     # fmt: off
299     result = session\
300         .query(models.Customer.id)\
301         .filter(models.Customer.account_id == account_id,
302                 models.Customer.email == email_address)\
303         .order_by(models.Customer.id.asc())\
304         .all()
305     # fmt: on
306
307
308 def off_and_on_without_data():
309     """All comments here are technically on the same prefix.
310
311     The comments between will be formatted. This is a known limitation.
312     """
313     # fmt: off
314
315     # hey, that won't work
316
317     # fmt: on
318     pass
319
320
321 def on_and_off_broken():
322     """Another known limitation."""
323     # fmt: on
324     # fmt: off
325     this=should.not_be.formatted()
326     and_=indeed . it  is  not  formatted
327     because . the . handling . inside . generate_ignored_nodes()
328     now . considers . multiple . fmt . directives . within . one . prefix
329     # fmt: on
330     # fmt: off
331     # ...but comments still get reformatted even though they should not be
332     # fmt: on
333
334
335 def long_lines():
336     if True:
337         typedargslist.extend(
338             gen_annotated_params(
339                 ast_args.kwonlyargs,
340                 ast_args.kw_defaults,
341                 parameters,
342                 implicit_default=True,
343             )
344         )
345         # fmt: off
346         a = (
347             unnecessary_bracket()
348         )
349         # fmt: on
350     _type_comment_re = re.compile(
351         r"""
352         ^
353         [\t ]*
354         \#[ ]type:[ ]*
355         (?P<type>
356             [^#\t\n]+?
357         )
358         (?<!ignore)     # note: this will force the non-greedy + in <type> to match
359                         # a trailing space which is why we need the silliness below
360         (?<!ignore[ ]{1})(?<!ignore[ ]{2})(?<!ignore[ ]{3})(?<!ignore[ ]{4})
361         (?<!ignore[ ]{5})(?<!ignore[ ]{6})(?<!ignore[ ]{7})(?<!ignore[ ]{8})
362         (?<!ignore[ ]{9})(?<!ignore[ ]{10})
363         [\t ]*
364         (?P<nl>
365             (?:\#[^\n]*)?
366             \n?
367         )
368         $
369         """,
370         # fmt: off
371         re.MULTILINE|re.VERBOSE
372         # fmt: on
373     )
374
375
376 def single_literal_yapf_disable():
377     """Black does not support this."""
378     BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)}  # yapf: disable
379
380
381 cfg.rule(
382     "Default",
383     "address",
384     xxxx_xxxx=["xxx-xxxxxx-xxxxxxxxxx"],
385     xxxxxx="xx_xxxxx",
386     xxxxxxx="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
387     xxxxxxxxx_xxxx=True,
388     xxxxxxxx_xxxxxxxxxx=False,
389     xxxxxx_xxxxxx=2,
390     xxxxxx_xxxxx_xxxxxxxx=70,
391     xxxxxx_xxxxxx_xxxxx=True,
392     # fmt: off
393     xxxxxxx_xxxxxxxxxxxx={
394         "xxxxxxxx": {
395             "xxxxxx": False,
396             "xxxxxxx": False,
397             "xxxx_xxxxxx": "xxxxx",
398         },
399         "xxxxxxxx-xxxxx": {
400             "xxxxxx": False,
401             "xxxxxxx": True,
402             "xxxx_xxxxxx": "xxxxxx",
403         },
404     },
405     # fmt: on
406     xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
407 )
408 # fmt: off
409 yield  'hello'
410 # No formatting to the end of the file
411 l=[1,2,3]
412 d={'a':1,
413    'b':2}