This commit is contained in:
@@ -72,9 +72,8 @@ def after_string(source: bytes, position: int) -> int | None:
|
|||||||
|
|
||||||
def after_raw_string(source: bytes, position: int, hashes: bytes) -> int | None:
|
def after_raw_string(source: bytes, position: int, hashes: bytes) -> int | None:
|
||||||
"""The offset after the raw string, opened by `r`, hashes and a quote, that ends at position, None where it is never closed. It has no escapes."""
|
"""The offset after the raw string, opened by `r`, hashes and a quote, that ends at position, None where it is never closed. It has no escapes."""
|
||||||
closing = b'"' + hashes
|
closed = re.compile(b'"' + hashes).search(source, position)
|
||||||
found = source.find(closing, position)
|
return closed.end() if closed else None
|
||||||
return found + len(closing) if found >= 0 else None
|
|
||||||
|
|
||||||
|
|
||||||
def with_tests_of(planted: bytes, copy: bytes) -> bytes:
|
def with_tests_of(planted: bytes, copy: bytes) -> bytes:
|
||||||
|
|||||||
@@ -77,6 +77,10 @@ class ModulesTest(unittest.TestCase):
|
|||||||
source = "#[cfg(test)]\nmod tests {\n const A: &str = r\"\\\";\n}\nfn after() {}\n"
|
source = "#[cfg(test)]\nmod tests {\n const A: &str = r\"\\\";\n}\nfn after() {}\n"
|
||||||
self.assertEqual(list(spelt(source)), ["tests"])
|
self.assertEqual(list(spelt(source)), ["tests"])
|
||||||
|
|
||||||
|
def test_ends_a_raw_string_at_its_first_closing_quote(self):
|
||||||
|
source = "#[cfg(test)]\nmod tests {\n const A: &str = r#\"x\"#;\n}\nconst B: &str = r#\"y\"#;\n"
|
||||||
|
self.assertEqual(list(spelt(source)), ["tests"])
|
||||||
|
|
||||||
def test_reads_a_string_that_ends_in_two_backslashes_or_in_an_escaped_quote(self):
|
def test_reads_a_string_that_ends_in_two_backslashes_or_in_an_escaped_quote(self):
|
||||||
for literal in ('"\\\\"', '"a\\""', '"\\}\\}"'):
|
for literal in ('"\\\\"', '"a\\""', '"\\}\\}"'):
|
||||||
with self.subTest(literal=literal):
|
with self.subTest(literal=literal):
|
||||||
|
|||||||
Reference in New Issue
Block a user