@@ -36,11 +36,19 @@ PYSTRING_ADD_TEST(pystring, find)
3636 PYSTRING_CHECK_EQUAL (pystring::find (" " , " a" ), -1 );
3737 PYSTRING_CHECK_EQUAL (pystring::find (" a" , " " ), 0 );
3838 PYSTRING_CHECK_EQUAL (pystring::find (" a" , " a" ), 0 );
39+ PYSTRING_CHECK_EQUAL (pystring::find (" abcdef" , " " ), 0 );
40+ PYSTRING_CHECK_EQUAL (pystring::find (" abcdef" , " " , -1 ), 5 );
41+ PYSTRING_CHECK_EQUAL (pystring::find (" abcdef" , " " , -2 ), 4 );
42+ PYSTRING_CHECK_EQUAL (pystring::find (" abcdef" , " " , -5 ), 1 );
43+ PYSTRING_CHECK_EQUAL (pystring::find (" abcdef" , " " , -6 ), 0 );
44+ PYSTRING_CHECK_EQUAL (pystring::find (" abcdef" , " " , -7 ), 0 );
45+
3946 PYSTRING_CHECK_EQUAL (pystring::find (" abcdef" , " def" ), 3 );
4047 PYSTRING_CHECK_EQUAL (pystring::find (" abcdef" , " def" , 3 ), 3 );
4148 PYSTRING_CHECK_EQUAL (pystring::find (" abcdef" , " def" , 4 ), -1 );
4249 PYSTRING_CHECK_EQUAL (pystring::find (" abcdef" , " def" , -5 ), 3 );
4350 PYSTRING_CHECK_EQUAL (pystring::find (" abcdef" , " def" , -1 ), -1 );
51+
4452 PYSTRING_CHECK_EQUAL (pystring::find (" abcabcabc" , " bc" , -2 ), 7 );
4553 PYSTRING_CHECK_EQUAL (pystring::find (" abcabcabc" , " bc" , -1 ), -1 );
4654 PYSTRING_CHECK_EQUAL (pystring::find (" abcabcabc" , " bc" , 0 ), 1 );
@@ -55,6 +63,66 @@ PYSTRING_ADD_TEST(pystring, find)
5563 PYSTRING_CHECK_EQUAL (pystring::find (" abcabcabc" , " bc" , 4 , 6 ), 4 );
5664}
5765
66+ PYSTRING_ADD_TEST (pystring, rfind)
67+ {
68+ PYSTRING_CHECK_EQUAL (pystring::rfind (" " , " " ), 0 );
69+ PYSTRING_CHECK_EQUAL (pystring::rfind (" " , " a" ), -1 );
70+ PYSTRING_CHECK_EQUAL (pystring::rfind (" a" , " " ), 1 );
71+ PYSTRING_CHECK_EQUAL (pystring::rfind (" a" , " a" ), 0 );
72+
73+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcdef" , " " ), 6 );
74+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcdef" , " " , 0 , 1 ), 1 );
75+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcdef" , " " , 0 , 5 ), 5 );
76+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcdef" , " " , 0 ,-1 ), 5 );
77+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcdef" , " " , 0 ,-3 ), 3 );
78+
79+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcdef" , " def" ), 3 );
80+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcdef" , " def" , 3 ), 3 );
81+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcdef" , " def" , 4 ), -1 );
82+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcdef" , " def" , -5 ), 3 );
83+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcdef" , " def" , -1 ), -1 );
84+
85+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcabcabc" , " bc" , -2 ), 7 );
86+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcabcabc" , " bc" , -1 ), -1 );
87+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcabcabc" , " bc" , 0 ), 7 );
88+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcabcabc" , " bc" , 1 ), 7 );
89+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcabcabc" , " bc" , 4 ), 7 );
90+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcabcabc" , " bc" , 7 ), 7 );
91+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcabcabc" , " bc" , 4 , -5 ), -1 );
92+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcabcabc" , " bc" , 4 , -10 ), -1 );
93+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcabcabc" , " bc" , 4 , 20 ), 7 );
94+
95+ PYSTRING_CHECK_EQUAL (pystring::rfind (" abcabcabc" , " abc" , 6 , 8 ), -1 );
96+ }
97+
98+ PYSTRING_ADD_TEST (pystring, slice)
99+ {
100+ PYSTRING_CHECK_EQUAL (pystring::slice (" " ), " " );
101+ PYSTRING_CHECK_EQUAL (pystring::slice (" " , 1 ), " " );
102+ PYSTRING_CHECK_EQUAL (pystring::slice (" " , -1 ), " " );
103+ PYSTRING_CHECK_EQUAL (pystring::slice (" " , -1 ,2 ), " " );
104+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ), " abcdef" );
105+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,0 ), " abcdef" );
106+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,1 ), " bcdef" );
107+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,2 ), " cdef" );
108+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,2 ,2 ), " " );
109+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,2 ,3 ), " c" );
110+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,2 ,1 ), " " );
111+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,2 ,-1 ), " cde" );
112+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,2 ,-2 ), " cd" );
113+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,2 ,-3 ), " c" );
114+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,2 ,-4 ), " " );
115+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,2 ,-5 ), " " );
116+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,-1 ), " f" );
117+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,-2 ), " ef" );
118+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,-99 ), " abcdef" );
119+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,-99 ,-98 ), " " );
120+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,-2 , 3 ), " " );
121+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,-2 , 10 ), " ef" );
122+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,-1 ), " f" );
123+ PYSTRING_CHECK_EQUAL (pystring::slice (" abcdef" ,0 ,-1 ), " abcde" );
124+ }
125+
58126PYSTRING_ADD_TEST (pystring, startswith)
59127{
60128 PYSTRING_CHECK_EQUAL (pystring::startswith (" " , " " ), true );
0 commit comments