From 39f86f253866adfa930082c9dd96055a3516f2f7 Mon Sep 17 00:00:00 2001 From: Adam Walker <86650480+wlkr73@users.noreply.github.com> Date: Fri, 23 Oct 2026 20:47:33 +0000 Subject: [PATCH] gh-160501: Cover the UCS4 adaptive search path in test_str --- Lib/test/test_str.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Lib/test/test_str.py b/Lib/test/test_str.py index bef0e62fb42bccc..faee0e826ad0aaf 100644 --- a/Lib/test/test_str.py +++ b/Lib/test/test_str.py @@ -267,6 +267,22 @@ class MyStr(str): pass self.checkequal(3, MyStr('aaa'), 'count', 'a') + def test_find_adaptive_nonbmp(self): + # The adaptive path in Objects/stringlib/fastsearch.h needs a haystack + # of at least 2500 characters and a needle of at least 100, with the + # needle at least a third of the haystack. test_adaptive_find only + # uses ASCII, so the UCS4 variant of adaptive_find never ran. + a, b = '\U0001d11e', '\U0001d11f' + for N in 1000, 10_000: + A, B = a * N, b * N + haystack = A + A + B + A + A + needle = A + B + B + A + self.assertEqual(haystack.find(needle), -1) + self.assertEqual(haystack.count(needle), 0) + combined = haystack + needle + self.assertEqual(combined.find(needle), len(haystack)) + self.assertEqual(combined.count(needle), 1) + def test_find(self): string_tests.StringLikeTest.test_find(self) # test implementation details of the memchr fast path