Repository: psf/black
File: tests/data/cases/preview_long_strings.py (Python)

Code before:
code = (
    ("    return [\n")
    + (
        ", \n".join(
            "        (%r, self.%s, visitor.%s)"
            % (attrname, attrname, visit_name)
            for attrname, visit_name in names
        )
    )
    + ("\n    ]\n")
)


# Test case of an outer string' parens enclose an inner string's parens.
call(body=("%s %s" % ((",".join(items)), suffix)))

log.info(f'Skipping: {desc["db_id"]=} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]=} {desc["exposure_max"]=}')

log.info(f"Skipping: {desc['db_id']=} {desc['ms_name']} {money=} {dte=} {pos_share=} {desc['status']=} {desc['exposure_max']=}")

log.info(f'Skipping: {desc["db_id"]} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}')

log.info(f'Skipping: {foo("asdf")=} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}')

log.info(f'Skipping: {  longer_longer_longer_longer_longer_longer_name   [ "db_id" ]      [ "another_key" ]   =  :  .3f }')

# output


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."
)

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."
)

y = "Short string"

print(
    "This is a really long string inside of a print statement with extra arguments"
    " attached at the end of it.",
    x,
    y,
    z,
)


Review comment (suggestion):
Add some test cases involving triple quotes, e.g.

```
% black --line-length=20 --preview -c "log.info(f'''{\"a\" == 'b'} aaaaaa aa aa aa aa aa aa aa''')"
log.info(
    f"""{"a" == 'b'} aaaaaa aa aa aa aa aa aa aa"""
)
```


Code after:
code = (
    ("    return [\n")
    + (
        ", \n".join(
            "        (%r, self.%s, visitor.%s)"
            % (attrname, attrname, visit_name)
            for attrname, visit_name in names
        )
    )
    + ("\n    ]\n")
)


# Test case of an outer string' parens enclose an inner string's parens.
call(body=("%s %s" % ((",".join(items)), suffix)))

log.info(f'Skipping: {desc["db_id"]=} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]=} {desc["exposure_max"]=}')

log.info(f"Skipping: {desc['db_id']=} {desc['ms_name']} {money=} {dte=} {pos_share=} {desc['status']=} {desc['exposure_max']=}")

log.info(f'Skipping: {desc["db_id"]} {foo("bar",x=123)} {"foo" != "bar"} {(x := "abc=")} {pos_share=} {desc["status"]} {desc["exposure_max"]}')

log.info(f'Skipping: {desc["db_id"]} {desc["ms_name"]} {money=} {(x := "abc=")=} {pos_share=} {desc["status"]} {desc["exposure_max"]}')

log.info(f'Skipping: {desc["db_id"]} {foo("bar",x=123)=} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}')

log.info(f'Skipping: {foo("asdf")=} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}')

log.info(f'Skipping: {"a" == "b" == "c" == "d"} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}')

log.info(f'Skipping: {"a" == "b" == "c" == "d"=} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}')

log.info(f'Skipping: {  longer_longer_longer_longer_longer_longer_name   [ "db_id" ]      [ "another_key" ]   =  :  .3f }')

log.info(f'''Skipping: {"a" == 'b'} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}''')

log.info(f'''Skipping: {'a' == "b"=} {desc["ms_name"]} {money=} {dte=} {pos_share=} {desc["status"]} {desc["exposure_max"]}''')

log.info(f"""Skipping: {'a' == 'b'} {desc['ms_name']} {money=} {dte=} {pos_share=} {desc['status']} {desc['exposure_max']}""")

# output


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."
)

x += (
    "This is a really long string that can't possibly be expected to fit all together"