Skip to content

Commit 477a465

Browse files
committed
gh-160501: Cover the UCS4 adaptive search path in test_str
1 parent 7715c92 commit 477a465

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎Lib/test/test_str.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,22 @@ class MyStr(str):
267267
pass
268268
self.checkequal(3, MyStr('aaa'), 'count', 'a')
269269

270+
def test_find_adaptive_nonbmp(self):
271+
# The adaptive path in Objects/stringlib/fastsearch.h needs a haystack
272+
# of at least 2500 characters and a needle of at least 100, with the
273+
# needle at least a third of the haystack. test_adaptive_find only
274+
# uses ASCII, so the UCS4 variant of adaptive_find never ran.
275+
a, b = '\U0001d11e', '\U0001d11f'
276+
for N in 1000, 10_000:
277+
A, B = a * N, b * N
278+
haystack = A + A + B + A + A
279+
needle = A + B + B + A
280+
self.assertEqual(haystack.find(needle), -1)
281+
self.assertEqual(haystack.count(needle), 0)
282+
combined = haystack + needle
283+
self.assertEqual(combined.find(needle), len(haystack))
284+
self.assertEqual(combined.count(needle), 1)
285+
270286
def test_find(self):
271287
string_tests.StringLikeTest.test_find(self)
272288
# test implementation details of the memchr fast path

0 commit comments

Comments
 (0)