]> 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:

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