]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/black/tests/data/long_strings.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:

Add '.vim/bundle/black/' from commit '2f3fa1f6d0cbc2a3f31c7440c422da173b068e7b'
[etc/vim.git] / .vim / bundle / black / tests / data / long_strings.py
1 x = "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
2
3 x += "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
4
5 y = (
6     'Short string'
7 )
8
9 print('This is a really long string inside of a print statement with extra arguments attached at the end of it.', x, y, z)
10
11 print("This is a really long string inside of a print statement with no extra arguments attached at the end of it.")
12
13 D1 = {"The First": "This is a really long string that can't possibly be expected to fit all together on one line. Also it is inside a dictionary, so formatting is more difficult.", "The Second": "This is another really really (not really) long string that also can't be expected to fit on one line and is, like the other string, inside a dictionary."}
14
15 D2 = {1.0: "This is a really long string that can't possibly be expected to fit all together on one line. Also it is inside a dictionary, so formatting is more difficult.", 2.0: "This is another really really (not really) long string that also can't be expected to fit on one line and is, like the other string, inside a dictionary."}
16
17 D3 = {x: "This is a really long string that can't possibly be expected to fit all together on one line. Also it is inside a dictionary, so formatting is more difficult.", y: "This is another really really (not really) long string that also can't be expected to fit on one line and is, like the other string, inside a dictionary."}
18
19 D4 = {"A long and ridiculous {}".format(string_key): "This is a really really really long string that has to go i,side of a dictionary. It is soooo bad.", some_func("calling", "some", "stuff"): "This is a really really really long string that has to go inside of a dictionary. It is {soooo} bad (#{x}).".format(sooo="soooo", x=2), "A %s %s" % ("formatted", "string"): "This is a really really really long string that has to go inside of a dictionary. It is %s bad (#%d)." % ("soooo", 2)}
20
21 func_with_keywords(my_arg, my_kwarg="Long keyword strings also need to be wrapped, but they will probably need to be handled a little bit differently.")
22
23 bad_split1 = (
24     'But what should happen when code has already been formatted but in the wrong way? Like'
25     " with a space at the end instead of the beginning. Or what about when it is split too soon?"
26 )
27
28 bad_split2 = "But what should happen when code has already " \
29              "been formatted but in the wrong way? Like " \
30              "with a space at the end instead of the " \
31              "beginning. Or what about when it is split too " \
32              "soon? In the case of a split that is too " \
33              "short, black will try to honer the custom " \
34              "split."
35
36 bad_split3 = (
37     "What if we have inline comments on "  # First Comment
38     "each line of a bad split? In that "  # Second Comment
39     "case, we should just leave it alone."  # Third Comment
40 )
41
42 bad_split_func1(
43     "But what should happen when code has already "
44     "been formatted but in the wrong way? Like "
45     "with a space at the end instead of the "
46     "beginning. Or what about when it is split too "
47     "soon? In the case of a split that is too "
48     "short, black will try to honer the custom "
49     "split.",
50     xxx, yyy, zzz
51 )
52
53 bad_split_func2(
54     xxx, yyy, zzz,
55     long_string_kwarg="But what should happen when code has already been formatted but in the wrong way? Like "
56                       "with a space at the end instead of the beginning. Or what about when it is split too "
57                       "soon?",
58 )
59
60 bad_split_func3(
61     (
62         "But what should happen when code has already "
63         r"been formatted but in the wrong way? Like "
64         "with a space at the end instead of the "
65         r"beginning. Or what about when it is split too "
66         r"soon? In the case of a split that is too "
67         "short, black will try to honer the custom "
68         "split."
69     ),
70     xxx,
71     yyy,
72     zzz,
73 )
74
75 raw_string = r"This is a long raw string. When re-formatting this string, black needs to make sure it prepends the 'r' onto the new string."
76
77 fmt_string1 = "We also need to be sure to preserve any and all {} which may or may not be attached to the string in question.".format("method calls")
78
79 fmt_string2 = "But what about when the string is {} but {}".format("short", "the method call is really really really really really really really really long?")
80
81 old_fmt_string1 = "While we are on the topic of %s, we should also note that old-style formatting must also be preserved, since some %s still uses it." % ("formatting", "code")
82
83 old_fmt_string2 = "This is a %s %s %s %s" % ("really really really really really", "old", "way to format strings!", "Use f-strings instead!")
84
85 old_fmt_string3 = "Whereas only the strings after the percent sign were long in the last example, this example uses a long initial string as well. This is another %s %s %s %s" % ("really really really really really", "old", "way to format strings!", "Use f-strings instead!")
86
87 fstring = f"f-strings definitely make things more {difficult} than they need to be for {{black}}. But boy they sure are handy. The problem is that some lines will need to have the 'f' whereas others do not. This {line}, for example, needs one."
88
89 fstring_with_no_fexprs = f"Some regular string that needs to get split certainly but is NOT an fstring by any means whatsoever."
90
91 comment_string = "Long lines with inline comments should have their comments appended to the reformatted string's enclosing right parentheses."  # This comment gets thrown to the top.
92
93 arg_comment_string = print("Long lines with inline comments which are apart of (and not the only member of) an argument list should have their comments appended to the reformatted string's enclosing left parentheses.",  # This comment stays on the bottom.
94     "Arg #2", "Arg #3", "Arg #4", "Arg #5")
95
96 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone."  # noqa: E501
97
98 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone."  # noqa
99
100 """This is a really really really long triple quote string and it should not be touched."""
101
102 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
103
104 assert some_type_of_boolean_expression, "Followed by a really really really long string that is used to provide context to the AssertionError exception."
105
106 assert some_type_of_boolean_expression, "Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic string {}.".format("formatting")
107
108 assert some_type_of_boolean_expression, "Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic string %s." % "formatting"
109
110 assert some_type_of_boolean_expression, "Followed by a really really really long string that is used to provide context to the AssertionError exception, which uses dynamic %s %s." % ("string", "formatting")
111
112 some_function_call("With a reallly generic name and with a really really long string that is, at some point down the line, " + added + " to a variable and then added to another string.")
113
114 some_function_call("With a reallly generic name and with a really really long string that is, at some point down the line, " + added + " to a variable and then added to another string. But then what happens when the final string is also supppppperrrrr long?! Well then that second (realllllllly long) string should be split too.", "and a second argument", and_a_third)
115
116 return "A really really really really really really really really really really really really really long {} {}".format("return", "value")
117
118 func_with_bad_comma(
119     "This is a really long string argument to a function that has a trailing comma which should NOT be there.",
120 )
121
122 func_with_bad_comma(
123     "This is a really long string argument to a function that has a trailing comma which should NOT be there.", # comment after comma
124 )
125
126 func_with_bad_comma(
127     (
128         "This is a really long string argument to a function that has a trailing comma"
129         " which should NOT be there."
130     ),
131 )
132
133 func_with_bad_comma(
134     (
135         "This is a really long string argument to a function that has a trailing comma"
136         " which should NOT be there."
137     ), # comment after comma
138 )
139
140 func_with_bad_parens_that_wont_fit_in_one_line(
141     ("short string that should have parens stripped"),
142     x,
143     y,
144     z
145 )
146
147 func_with_bad_parens_that_wont_fit_in_one_line(
148     x,
149     y,
150     ("short string that should have parens stripped"),
151     z
152 )
153
154 func_with_bad_parens(
155     ("short string that should have parens stripped"),
156     x,
157     y,
158     z,
159 )
160
161 func_with_bad_parens(
162     x,
163     y,
164     ("short string that should have parens stripped"),
165     z,
166 )
167
168 annotated_variable: Final = "This is a large " + STRING + " that has been " + CONCATENATED + "using the '+' operator."
169 annotated_variable: Final = "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped."
170 annotated_variable: Literal["fakse_literal"] = "This is a large string that has a type annotation attached to it. A type annotation should NOT stop a long string from being wrapped."
171
172 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\"
173 backslashes = "This is a really long string with \"embedded\" double quotes and 'single' quotes that also handles checking for an even number of backslashes \\\\"
174 backslashes = "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes that also handles checking for an odd number of backslashes \\\", like this...\\\\\\"
175
176 short_string = (
177     "Hi"
178     " there."
179 )
180
181 func_call(
182     short_string=(
183         "Hi"
184         " there."
185     )
186 )
187
188 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
189
190 def foo():
191     yield "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
192
193 x = f"This is a {{really}} long string that needs to be split without a doubt (i.e. most definitely). In short, this {string} that can't possibly be {{expected}} to fit all together on one line. In {fact} it may even take up three or more lines... like four or five... but probably just four."
194
195 long_unmergable_string_with_pragma = (
196     "This is a really long string that can't be merged because it has a likely pragma at the end"  # type: ignore
197     " of it."
198 )
199
200 long_unmergable_string_with_pragma = (
201     "This is a really long string that can't be merged because it has a likely pragma at the end"  # noqa
202     " of it."
203 )
204
205 long_unmergable_string_with_pragma = (
206     "This is a really long string that can't be merged because it has a likely pragma at the end"  # pylint: disable=some-pylint-check
207     " of it."
208 )
209
210 string_with_nameescape = (
211     "........................................................................ \N{LAO KO LA}"
212 )
213
214 string_with_nameescape = (
215     "........................................................................... \N{LAO KO LA}"
216 )
217
218 string_with_nameescape = (
219     "............................................................................ \N{LAO KO LA}"
220 )
221
222 string_with_nameescape_and_escaped_backslash = (
223     "...................................................................... \\\N{LAO KO LA}"
224 )
225
226 string_with_nameescape_and_escaped_backslash = (
227     "......................................................................... \\\N{LAO KO LA}"
228 )
229
230 string_with_nameescape_and_escaped_backslash = (
231     ".......................................................................... \\\N{LAO KO LA}"
232 )
233
234 string_with_escaped_nameescape = (
235     "........................................................................ \\N{LAO KO LA}"
236 )
237
238 string_with_escaped_nameescape = (
239     "........................................................................... \\N{LAO KO LA}"
240 )
241
242
243 # output
244
245
246 x = (
247     "This is a really long string that can't possibly be expected to fit all together"
248     " on one line. In fact it may even take up three or more lines... like four or"
249     " five... but probably just three."
250 )
251
252 x += (
253     "This is a really long string that can't possibly be expected to fit all together"
254     " on one line. In fact it may even take up three or more lines... like four or"
255     " five... but probably just three."
256 )
257
258 y = "Short string"
259
260 print(
261     "This is a really long string inside of a print statement with extra arguments"
262     " attached at the end of it.",
263     x,
264     y,
265     z,
266 )
267
268 print(
269     "This is a really long string inside of a print statement with no extra arguments"
270     " attached at the end of it."
271 )
272
273 D1 = {
274     "The First": (
275         "This is a really long string that can't possibly be expected to fit all"
276         " together on one line. Also it is inside a dictionary, so formatting is more"
277         " difficult."
278     ),
279     "The Second": (
280         "This is another really really (not really) long string that also can't be"
281         " expected to fit on one line and is, like the other string, inside a"
282         " dictionary."
283     ),
284 }
285
286 D2 = {
287     1.0: (
288         "This is a really long string that can't possibly be expected to fit all"
289         " together on one line. Also it is inside a dictionary, so formatting is more"
290         " difficult."
291     ),
292     2.0: (
293         "This is another really really (not really) long string that also can't be"
294         " expected to fit on one line and is, like the other string, inside a"
295         " dictionary."
296     ),
297 }
298
299 D3 = {
300     x: (
301         "This is a really long string that can't possibly be expected to fit all"
302         " together on one line. Also it is inside a dictionary, so formatting is more"
303         " difficult."
304     ),
305     y: (
306         "This is another really really (not really) long string that also can't be"
307         " expected to fit on one line and is, like the other string, inside a"
308         " dictionary."
309     ),
310 }
311
312 D4 = {
313     "A long and ridiculous {}".format(string_key): (
314         "This is a really really really long string that has to go i,side of a"
315         " dictionary. It is soooo bad."
316     ),
317     some_func("calling", "some", "stuff"): (
318         "This is a really really really long string that has to go inside of a"
319         " dictionary. It is {soooo} bad (#{x}).".format(sooo="soooo", x=2)
320     ),
321     "A %s %s"
322     % ("formatted", "string"): (
323         "This is a really really really long string that has to go inside of a"
324         " dictionary. It is %s bad (#%d)."
325     )
326     % ("soooo", 2),
327 }
328
329 func_with_keywords(
330     my_arg,
331     my_kwarg=(
332         "Long keyword strings also need to be wrapped, but they will probably need to"
333         " be handled a little bit differently."
334     ),
335 )
336
337 bad_split1 = (
338     "But what should happen when code has already been formatted but in the wrong way?"
339     " Like with a space at the end instead of the beginning. Or what about when it is"
340     " split too soon?"
341 )
342
343 bad_split2 = (
344     "But what should happen when code has already "
345     "been formatted but in the wrong way? Like "
346     "with a space at the end instead of the "
347     "beginning. Or what about when it is split too "
348     "soon? In the case of a split that is too "
349     "short, black will try to honer the custom "
350     "split."
351 )
352
353 bad_split3 = (
354     "What if we have inline comments on "  # First Comment
355     "each line of a bad split? In that "  # Second Comment
356     "case, we should just leave it alone."  # Third Comment
357 )
358
359 bad_split_func1(
360     "But what should happen when code has already "
361     "been formatted but in the wrong way? Like "
362     "with a space at the end instead of the "
363     "beginning. Or what about when it is split too "
364     "soon? In the case of a split that is too "
365     "short, black will try to honer the custom "
366     "split.",
367     xxx,
368     yyy,
369     zzz,
370 )
371
372 bad_split_func2(
373     xxx,
374     yyy,
375     zzz,
376     long_string_kwarg=(
377         "But what should happen when code has already been formatted but in the wrong"
378         " way? Like with a space at the end instead of the beginning. Or what about"
379         " when it is split too soon?"
380     ),
381 )
382
383 bad_split_func3(
384     (
385         "But what should happen when code has already "
386         r"been formatted but in the wrong way? Like "
387         "with a space at the end instead of the "
388         r"beginning. Or what about when it is split too "
389         r"soon? In the case of a split that is too "
390         "short, black will try to honer the custom "
391         "split."
392     ),
393     xxx,
394     yyy,
395     zzz,
396 )
397
398 raw_string = (
399     r"This is a long raw string. When re-formatting this string, black needs to make"
400     r" sure it prepends the 'r' onto the new string."
401 )
402
403 fmt_string1 = (
404     "We also need to be sure to preserve any and all {} which may or may not be"
405     " attached to the string in question.".format("method calls")
406 )
407
408 fmt_string2 = "But what about when the string is {} but {}".format(
409     "short",
410     "the method call is really really really really really really really really long?",
411 )
412
413 old_fmt_string1 = (
414     "While we are on the topic of %s, we should also note that old-style formatting"
415     " must also be preserved, since some %s still uses it." % ("formatting", "code")
416 )
417
418 old_fmt_string2 = "This is a %s %s %s %s" % (
419     "really really really really really",
420     "old",
421     "way to format strings!",
422     "Use f-strings instead!",
423 )
424
425 old_fmt_string3 = (
426     "Whereas only the strings after the percent sign were long in the last example,"
427     " this example uses a long initial string as well. This is another %s %s %s %s"
428     % (
429         "really really really really really",
430         "old",
431         "way to format strings!",
432         "Use f-strings instead!",
433     )
434 )
435
436 fstring = (
437     f"f-strings definitely make things more {difficult} than they need to be for"
438     " {black}. But boy they sure are handy. The problem is that some lines will need"
439     f" to have the 'f' whereas others do not. This {line}, for example, needs one."
440 )
441
442 fstring_with_no_fexprs = (
443     f"Some regular string that needs to get split certainly but is NOT an fstring by"
444     f" any means whatsoever."
445 )
446
447 comment_string = (  # This comment gets thrown to the top.
448     "Long lines with inline comments should have their comments appended to the"
449     " reformatted string's enclosing right parentheses."
450 )
451
452 arg_comment_string = print(
453     "Long lines with inline comments which are apart of (and not the only member of) an"
454     " argument list should have their comments appended to the reformatted string's"
455     " enclosing left parentheses.",  # This comment stays on the bottom.
456     "Arg #2",
457     "Arg #3",
458     "Arg #4",
459     "Arg #5",
460 )
461
462 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone."  # noqa: E501
463
464 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone."  # noqa
465
466 """This is a really really really long triple quote string and it should not be touched."""
467
468 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
469
470 assert some_type_of_boolean_expression, (
471     "Followed by a really really really long string that is used to provide context to"
472     " the AssertionError exception."
473 )
474
475 assert some_type_of_boolean_expression, (
476     "Followed by a really really really long string that is used to provide context to"
477     " the AssertionError exception, which uses dynamic string {}.".format("formatting")
478 )
479
480 assert some_type_of_boolean_expression, (
481     "Followed by a really really really long string that is used to provide context to"
482     " the AssertionError exception, which uses dynamic string %s." % "formatting"
483 )
484
485 assert some_type_of_boolean_expression, (
486     "Followed by a really really really long string that is used to provide context to"
487     " the AssertionError exception, which uses dynamic %s %s."
488     % ("string", "formatting")
489 )
490
491 some_function_call(
492     "With a reallly generic name and with a really really long string that is, at some"
493     " point down the line, "
494     + added
495     + " to a variable and then added to another string."
496 )
497
498 some_function_call(
499     "With a reallly generic name and with a really really long string that is, at some"
500     " point down the line, "
501     + added
502     + " to a variable and then added to another string. But then what happens when the"
503     " final string is also supppppperrrrr long?! Well then that second (realllllllly"
504     " long) string should be split too.",
505     "and a second argument",
506     and_a_third,
507 )
508
509 return (
510     "A really really really really really really really really really really really"
511     " really really long {} {}".format("return", "value")
512 )
513
514 func_with_bad_comma(
515     "This is a really long string argument to a function that has a trailing comma"
516     " which should NOT be there.",
517 )
518
519 func_with_bad_comma(
520     "This is a really long string argument to a function that has a trailing comma"
521     " which should NOT be there.",  # comment after comma
522 )
523
524 func_with_bad_comma(
525     "This is a really long string argument to a function that has a trailing comma"
526     " which should NOT be there.",
527 )
528
529 func_with_bad_comma(
530     "This is a really long string argument to a function that has a trailing comma"
531     " which should NOT be there.",  # comment after comma
532 )
533
534 func_with_bad_parens_that_wont_fit_in_one_line(
535     "short string that should have parens stripped", x, y, z
536 )
537
538 func_with_bad_parens_that_wont_fit_in_one_line(
539     x, y, "short string that should have parens stripped", z
540 )
541
542 func_with_bad_parens(
543     "short string that should have parens stripped",
544     x,
545     y,
546     z,
547 )
548
549 func_with_bad_parens(
550     x,
551     y,
552     "short string that should have parens stripped",
553     z,
554 )
555
556 annotated_variable: Final = (
557     "This is a large "
558     + STRING
559     + " that has been "
560     + CONCATENATED
561     + "using the '+' operator."
562 )
563 annotated_variable: Final = (
564     "This is a large string that has a type annotation attached to it. A type"
565     " annotation should NOT stop a long string from being wrapped."
566 )
567 annotated_variable: Literal["fakse_literal"] = (
568     "This is a large string that has a type annotation attached to it. A type"
569     " annotation should NOT stop a long string from being wrapped."
570 )
571
572 backslashes = (
573     "This is a really long string with \"embedded\" double quotes and 'single' quotes"
574     " that also handles checking for an even number of backslashes \\"
575 )
576 backslashes = (
577     "This is a really long string with \"embedded\" double quotes and 'single' quotes"
578     " that also handles checking for an even number of backslashes \\\\"
579 )
580 backslashes = (
581     "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes"
582     ' that also handles checking for an odd number of backslashes \\", like'
583     " this...\\\\\\"
584 )
585
586 short_string = "Hi there."
587
588 func_call(short_string="Hi there.")
589
590 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
591
592
593 def foo():
594     yield (
595         "This is a really long string that can't possibly be expected to fit all"
596         " together on one line. In fact it may even take up three or more lines... like"
597         " four or five... but probably just three."
598     )
599
600
601 x = (
602     "This is a {really} long string that needs to be split without a doubt (i.e."
603     f" most definitely). In short, this {string} that can't possibly be {{expected}} to"
604     f" fit all together on one line. In {fact} it may even take up three or more"
605     " lines... like four or five... but probably just four."
606 )
607
608 long_unmergable_string_with_pragma = (
609     "This is a really long string that can't be merged because it has a likely pragma at the end"  # type: ignore
610     " of it."
611 )
612
613 long_unmergable_string_with_pragma = (
614     "This is a really long string that can't be merged because it has a likely pragma at the end"  # noqa
615     " of it."
616 )
617
618 long_unmergable_string_with_pragma = (
619     "This is a really long string that can't be merged because it has a likely pragma at the end"  # pylint: disable=some-pylint-check
620     " of it."
621 )
622
623 string_with_nameescape = (
624     "........................................................................"
625     " \N{LAO KO LA}"
626 )
627
628 string_with_nameescape = (
629     "..........................................................................."
630     " \N{LAO KO LA}"
631 )
632
633 string_with_nameescape = (
634     "............................................................................"
635     " \N{LAO KO LA}"
636 )
637
638 string_with_nameescape_and_escaped_backslash = (
639     "......................................................................"
640     " \\\N{LAO KO LA}"
641 )
642
643 string_with_nameescape_and_escaped_backslash = (
644     "........................................................................."
645     " \\\N{LAO KO LA}"
646 )
647
648 string_with_nameescape_and_escaped_backslash = (
649     ".........................................................................."
650     " \\\N{LAO KO LA}"
651 )
652
653 string_with_escaped_nameescape = (
654     "........................................................................ \\N{LAO"
655     " KO LA}"
656 )
657
658 string_with_escaped_nameescape = (
659     "..........................................................................."
660     " \\N{LAO KO LA}"
661 )