@@ -969,6 +969,25 @@ PYSTRING_ADD_TEST(python3_compat, replace_python3)
969969 PYSTRING_CHECK_EQUAL (pystring::replace (" hello" , " hello" , " " , -1 ), " " );
970970}
971971
972+ PYSTRING_ADD_TEST (python3_compat, replace_overlap)
973+ {
974+ PYSTRING_CHECK_EQUAL (pystring::replace (" aaaaa" , " aa" , " b" , -1 ), " bba" );
975+ PYSTRING_CHECK_EQUAL (pystring::replace (" aaaa" , " aa" , " b" , -1 ), " bb" );
976+ PYSTRING_CHECK_EQUAL (pystring::replace (" aaa" , " aa" , " b" , -1 ), " ba" );
977+ PYSTRING_CHECK_EQUAL (pystring::replace (" abababa" , " aba" , " X" , -1 ), " XbX" );
978+ PYSTRING_CHECK_EQUAL (pystring::replace (" aaaaaa" , " aaa" , " x" , -1 ), " xx" );
979+ PYSTRING_CHECK_EQUAL (pystring::replace (" abcabcabc" , " abc" , " x" , 2 ), " xxabc" );
980+ PYSTRING_CHECK_EQUAL (pystring::replace (" abcabcabc" , " abc" , " x" , 1 ), " xabcabc" );
981+ PYSTRING_CHECK_EQUAL (pystring::replace (" aaaa" , " a" , " " , -1 ), " " );
982+ PYSTRING_CHECK_EQUAL (pystring::replace (" aaaa" , " aa" , " " , -1 ), " " );
983+ PYSTRING_CHECK_EQUAL (pystring::replace (" abc" , " d" , " x" , -1 ), " abc" );
984+ PYSTRING_CHECK_EQUAL (pystring::replace (" " , " a" , " x" , -1 ), " " );
985+ PYSTRING_CHECK_EQUAL (pystring::replace (" " , " " , " x" , -1 ), " x" );
986+ PYSTRING_CHECK_EQUAL (pystring::replace (" a" , " " , " -" , -1 ), " -a-" );
987+ PYSTRING_CHECK_EQUAL (pystring::replace (" mississippi" , " issi" , " X" , -1 ), " mXssippi" );
988+ PYSTRING_CHECK_EQUAL (pystring::replace (" 11111" , " 11" , " x" , -1 ), " xx1" );
989+ }
990+
972991PYSTRING_ADD_TEST (python3_compat, rfind_python3)
973992{
974993 PYSTRING_CHECK_EQUAL (pystring::rfind (" hello world" , " world" , 0 ), 6 );
0 commit comments