fix strutils.split_special_areas

This commit is contained in:
Maximilian Hils 2017-08-26 17:04:56 +02:00
parent 1000efb671
commit e1af76e71f
2 changed files with 10 additions and 2 deletions

View File

@ -172,14 +172,14 @@ def split_special_areas(
"".join(split_special_areas(x, ...)) == x always holds true.
"""
patterns = "|".join(
r"{lchar}.*?{rchar}".format(
r"{lchar}[\s\S]*?{rchar}".format(
lchar=a,
rchar=b,
) for (a, b) in area_delimiter)
return re.split(
"({})".format(patterns),
data,
re.MULTILINE
flags=re.MULTILINE
)

View File

@ -111,6 +111,14 @@ def test_split_special_areas():
"""foo 'b\\'a"r' baz""",
ESCAPE_QUOTES
) == ["foo ", "'b\\'a\"r'", " baz"]
assert strutils.split_special_areas(
"foo\n/*bar\nbaz*/\nqux",
[(r'/\*', r'\*/')]
) == ["foo\n", "/*bar\nbaz*/", "\nqux"]
assert strutils.split_special_areas(
"foo\n//bar\nbaz",
[(r'//', r'$')]
) == ["foo\n", "//bar", "\nbaz"]
def test_escape_special_areas():