]> git.madduck.net Git - etc/vim.git/blob - 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:

Make sure to split lines that start with a string operator (#2286)
[etc/vim.git] / 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
211 # output
212
213
214 x = (
215     "This is a really long string that can't possibly be expected to fit all together"
216     " on one line. In fact it may even take up three or more lines... like four or"
217     " five... but probably just three."
218 )
219
220 x += (
221     "This is a really long string that can't possibly be expected to fit all together"
222     " on one line. In fact it may even take up three or more lines... like four or"
223     " five... but probably just three."
224 )
225
226 y = "Short string"
227
228 print(
229     "This is a really long string inside of a print statement with extra arguments"
230     " attached at the end of it.",
231     x,
232     y,
233     z,
234 )
235
236 print(
237     "This is a really long string inside of a print statement with no extra arguments"
238     " attached at the end of it."
239 )
240
241 D1 = {
242     "The First": (
243         "This is a really long string that can't possibly be expected to fit all"
244         " together on one line. Also it is inside a dictionary, so formatting is more"
245         " difficult."
246     ),
247     "The Second": (
248         "This is another really really (not really) long string that also can't be"
249         " expected to fit on one line and is, like the other string, inside a"
250         " dictionary."
251     ),
252 }
253
254 D2 = {
255     1.0: (
256         "This is a really long string that can't possibly be expected to fit all"
257         " together on one line. Also it is inside a dictionary, so formatting is more"
258         " difficult."
259     ),
260     2.0: (
261         "This is another really really (not really) long string that also can't be"
262         " expected to fit on one line and is, like the other string, inside a"
263         " dictionary."
264     ),
265 }
266
267 D3 = {
268     x: (
269         "This is a really long string that can't possibly be expected to fit all"
270         " together on one line. Also it is inside a dictionary, so formatting is more"
271         " difficult."
272     ),
273     y: (
274         "This is another really really (not really) long string that also can't be"
275         " expected to fit on one line and is, like the other string, inside a"
276         " dictionary."
277     ),
278 }
279
280 D4 = {
281     "A long and ridiculous {}".format(string_key): (
282         "This is a really really really long string that has to go i,side of a"
283         " dictionary. It is soooo bad."
284     ),
285     some_func("calling", "some", "stuff"): (
286         "This is a really really really long string that has to go inside of a"
287         " dictionary. It is {soooo} bad (#{x}).".format(sooo="soooo", x=2)
288     ),
289     "A %s %s"
290     % ("formatted", "string"): (
291         "This is a really really really long string that has to go inside of a"
292         " dictionary. It is %s bad (#%d)."
293     )
294     % ("soooo", 2),
295 }
296
297 func_with_keywords(
298     my_arg,
299     my_kwarg=(
300         "Long keyword strings also need to be wrapped, but they will probably need to"
301         " be handled a little bit differently."
302     ),
303 )
304
305 bad_split1 = (
306     "But what should happen when code has already been formatted but in the wrong way?"
307     " Like with a space at the end instead of the beginning. Or what about when it is"
308     " split too soon?"
309 )
310
311 bad_split2 = (
312     "But what should happen when code has already "
313     "been formatted but in the wrong way? Like "
314     "with a space at the end instead of the "
315     "beginning. Or what about when it is split too "
316     "soon? In the case of a split that is too "
317     "short, black will try to honer the custom "
318     "split."
319 )
320
321 bad_split3 = (
322     "What if we have inline comments on "  # First Comment
323     "each line of a bad split? In that "  # Second Comment
324     "case, we should just leave it alone."  # Third Comment
325 )
326
327 bad_split_func1(
328     "But what should happen when code has already "
329     "been formatted but in the wrong way? Like "
330     "with a space at the end instead of the "
331     "beginning. Or what about when it is split too "
332     "soon? In the case of a split that is too "
333     "short, black will try to honer the custom "
334     "split.",
335     xxx,
336     yyy,
337     zzz,
338 )
339
340 bad_split_func2(
341     xxx,
342     yyy,
343     zzz,
344     long_string_kwarg=(
345         "But what should happen when code has already been formatted but in the wrong"
346         " way? Like with a space at the end instead of the beginning. Or what about"
347         " when it is split too soon?"
348     ),
349 )
350
351 bad_split_func3(
352     (
353         "But what should happen when code has already "
354         r"been formatted but in the wrong way? Like "
355         "with a space at the end instead of the "
356         r"beginning. Or what about when it is split too "
357         r"soon? In the case of a split that is too "
358         "short, black will try to honer the custom "
359         "split."
360     ),
361     xxx,
362     yyy,
363     zzz,
364 )
365
366 raw_string = (
367     r"This is a long raw string. When re-formatting this string, black needs to make"
368     r" sure it prepends the 'r' onto the new string."
369 )
370
371 fmt_string1 = (
372     "We also need to be sure to preserve any and all {} which may or may not be"
373     " attached to the string in question.".format("method calls")
374 )
375
376 fmt_string2 = "But what about when the string is {} but {}".format(
377     "short",
378     "the method call is really really really really really really really really long?",
379 )
380
381 old_fmt_string1 = (
382     "While we are on the topic of %s, we should also note that old-style formatting"
383     " must also be preserved, since some %s still uses it." % ("formatting", "code")
384 )
385
386 old_fmt_string2 = "This is a %s %s %s %s" % (
387     "really really really really really",
388     "old",
389     "way to format strings!",
390     "Use f-strings instead!",
391 )
392
393 old_fmt_string3 = (
394     "Whereas only the strings after the percent sign were long in the last example,"
395     " this example uses a long initial string as well. This is another %s %s %s %s"
396     % (
397         "really really really really really",
398         "old",
399         "way to format strings!",
400         "Use f-strings instead!",
401     )
402 )
403
404 fstring = (
405     f"f-strings definitely make things more {difficult} than they need to be for"
406     " {black}. But boy they sure are handy. The problem is that some lines will need"
407     f" to have the 'f' whereas others do not. This {line}, for example, needs one."
408 )
409
410 fstring_with_no_fexprs = (
411     f"Some regular string that needs to get split certainly but is NOT an fstring by"
412     f" any means whatsoever."
413 )
414
415 comment_string = (  # This comment gets thrown to the top.
416     "Long lines with inline comments should have their comments appended to the"
417     " reformatted string's enclosing right parentheses."
418 )
419
420 arg_comment_string = print(
421     "Long lines with inline comments which are apart of (and not the only member of) an"
422     " argument list should have their comments appended to the reformatted string's"
423     " enclosing left parentheses.",  # This comment stays on the bottom.
424     "Arg #2",
425     "Arg #3",
426     "Arg #4",
427     "Arg #5",
428 )
429
430 pragma_comment_string1 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone."  # noqa: E501
431
432 pragma_comment_string2 = "Lines which end with an inline pragma comment of the form `# <pragma>: <...>` should be left alone."  # noqa
433
434 """This is a really really really long triple quote string and it should not be touched."""
435
436 triple_quote_string = """This is a really really really long triple quote string assignment and it should not be touched."""
437
438 assert some_type_of_boolean_expression, (
439     "Followed by a really really really long string that is used to provide context to"
440     " the AssertionError exception."
441 )
442
443 assert some_type_of_boolean_expression, (
444     "Followed by a really really really long string that is used to provide context to"
445     " the AssertionError exception, which uses dynamic string {}.".format("formatting")
446 )
447
448 assert some_type_of_boolean_expression, (
449     "Followed by a really really really long string that is used to provide context to"
450     " the AssertionError exception, which uses dynamic string %s." % "formatting"
451 )
452
453 assert some_type_of_boolean_expression, (
454     "Followed by a really really really long string that is used to provide context to"
455     " the AssertionError exception, which uses dynamic %s %s."
456     % ("string", "formatting")
457 )
458
459 some_function_call(
460     "With a reallly generic name and with a really really long string that is, at some"
461     " point down the line, "
462     + added
463     + " to a variable and then added to another string."
464 )
465
466 some_function_call(
467     "With a reallly generic name and with a really really long string that is, at some"
468     " point down the line, "
469     + added
470     + " to a variable and then added to another string. But then what happens when the"
471     " final string is also supppppperrrrr long?! Well then that second (realllllllly"
472     " long) string should be split too.",
473     "and a second argument",
474     and_a_third,
475 )
476
477 return (
478     "A really really really really really really really really really really really"
479     " really really long {} {}".format("return", "value")
480 )
481
482 func_with_bad_comma(
483     "This is a really long string argument to a function that has a trailing comma"
484     " which should NOT be there.",
485 )
486
487 func_with_bad_comma(
488     "This is a really long string argument to a function that has a trailing comma"
489     " which should NOT be there.",  # comment after comma
490 )
491
492 func_with_bad_comma(
493     "This is a really long string argument to a function that has a trailing comma"
494     " which should NOT be there.",
495 )
496
497 func_with_bad_comma(
498     "This is a really long string argument to a function that has a trailing comma"
499     " which should NOT be there.",  # comment after comma
500 )
501
502 func_with_bad_parens_that_wont_fit_in_one_line(
503     "short string that should have parens stripped", x, y, z
504 )
505
506 func_with_bad_parens_that_wont_fit_in_one_line(
507     x, y, "short string that should have parens stripped", z
508 )
509
510 func_with_bad_parens(
511     "short string that should have parens stripped",
512     x,
513     y,
514     z,
515 )
516
517 func_with_bad_parens(
518     x,
519     y,
520     "short string that should have parens stripped",
521     z,
522 )
523
524 annotated_variable: Final = (
525     "This is a large "
526     + STRING
527     + " that has been "
528     + CONCATENATED
529     + "using the '+' operator."
530 )
531 annotated_variable: Final = (
532     "This is a large string that has a type annotation attached to it. A type"
533     " annotation should NOT stop a long string from being wrapped."
534 )
535 annotated_variable: Literal["fakse_literal"] = (
536     "This is a large string that has a type annotation attached to it. A type"
537     " annotation should NOT stop a long string from being wrapped."
538 )
539
540 backslashes = (
541     "This is a really long string with \"embedded\" double quotes and 'single' quotes"
542     " that also handles checking for an even number of backslashes \\"
543 )
544 backslashes = (
545     "This is a really long string with \"embedded\" double quotes and 'single' quotes"
546     " that also handles checking for an even number of backslashes \\\\"
547 )
548 backslashes = (
549     "This is a really 'long' string with \"embedded double quotes\" and 'single' quotes"
550     ' that also handles checking for an odd number of backslashes \\", like'
551     " this...\\\\\\"
552 )
553
554 short_string = "Hi there."
555
556 func_call(short_string="Hi there.")
557
558 raw_strings = r"Don't" " get" r" merged" " unless they are all raw."
559
560
561 def foo():
562     yield (
563         "This is a really long string that can't possibly be expected to fit all"
564         " together on one line. In fact it may even take up three or more lines... like"
565         " four or five... but probably just three."
566     )
567
568
569 x = (
570     "This is a {really} long string that needs to be split without a doubt (i.e."
571     f" most definitely). In short, this {string} that can't possibly be {{expected}} to"
572     f" fit all together on one line. In {fact} it may even take up three or more"
573     " lines... like four or five... but probably just four."
574 )
575
576 long_unmergable_string_with_pragma = (
577     "This is a really long string that can't be merged because it has a likely pragma at the end"  # type: ignore
578     " of it."
579 )
580
581 long_unmergable_string_with_pragma = (
582     "This is a really long string that can't be merged because it has a likely pragma at the end"  # noqa
583     " of it."
584 )
585
586 long_unmergable_string_with_pragma = (
587     "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
588     " of it."
589 )