black/tests
Richard Si 8c04847aa2
Improve f-string expression detection regex so ... (#2437)
we don't accidentally add backslashes to them when normalizing quotes
because that's invalid syntax!

The problem this commit fixes is that matches would eat too much
blocking important matches to occur. For example, here's one f-string
body:

    {a}{b}{c}

I know there's no risk of introducing backslashes here, but the regex
already goes sideways with this. Throwing this example at regex101
I get:

    {a}{b}{c}   # The As and Bs are the two matches, and the upper
    ---- ----   # case letters are the groups with those matches.
    aAaa bbBb

... we've missed the middle expression (so if any backslashes in a
more complex example were introduced there we wouldn't bail out
even though we should -- hence the bug). As it stands the regex
needs somesort of extra character (or the start/end of the body)
around the expressions but that isn't always the case as shown
above.

The fix implemented here is to turn the "eat a surrounding non-curly
bracket character" groups ie. `(?:[^{]|^)` and `(?:[^}]|$)` into
negative lookaheads and lookbehinds. This still guarantees the
already specified rules but without problematically eating extra
characters ^^
2021-08-22 19:52:19 -07:00
..
data Improve f-string expression detection regex so ... (#2437) 2021-08-22 19:52:19 -07:00
__init__.py Remove deprecated use of 'setup.py test' (#1275) 2020-05-08 06:23:50 -07:00
conftest.py Use optional tests for "no_python2" to simplify local testing (#2203) 2021-05-07 15:03:13 +02:00
empty.toml Add --target-version option to allow users to choose targeted Python versions (#618) 2019-02-06 18:43:50 -08:00
optional.py Use optional tests for "no_python2" to simplify local testing (#2203) 2021-05-07 15:03:13 +02:00
test_black.py Present a more user-friendly error if .gitignore is invalid (#2414) 2021-08-20 19:54:53 -04:00
test_blackd.py Mark blackd tests with the blackd optional marker (#2204) 2021-05-07 16:33:36 +02:00
test_format.py Possible fix for issue with indentation and fmt: skip (#2281) 2021-06-08 14:37:34 -07:00
test_ipynb.py Jupyter notebook support (#2357) 2021-08-06 16:57:46 -04:00
test_no_ipynb.py Jupyter notebook support (#2357) 2021-08-06 16:57:46 -04:00
test_primer.py Use setuptools.find_packages in setup (#2363) 2021-07-09 17:09:29 -07:00
test.toml Switch toml TOML library for tomli (#2301) 2021-07-12 16:01:38 -04:00
util.py add context manager to temporarily change the cwd (#2377) 2021-07-16 22:21:34 -04:00