File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,26 @@ fn test_find_str() {
115
115
assert_eq ! ( data[ 43 ..86 ] . find( "ย中" ) , Some ( 67 - 43 ) ) ;
116
116
assert_eq ! ( data[ 43 ..86 ] . find( "iệt" ) , Some ( 77 - 43 ) ) ;
117
117
assert_eq ! ( data[ 43 ..86 ] . find( "Nam" ) , Some ( 83 - 43 ) ) ;
118
+
119
+ // find every substring -- assert that it finds it, or an earlier occurence.
120
+ let string = "Việt Namacbaabcaabaaba" ;
121
+ for ( i, ci) in string. char_indices ( ) {
122
+ let ip = i + ci. len_utf8 ( ) ;
123
+ for j in string[ ip..] . char_indices ( )
124
+ . map ( |( i, _) | i)
125
+ . chain ( Some ( string. len ( ) - ip) )
126
+ {
127
+ let pat = & string[ i..ip + j] ;
128
+ assert ! ( match string. find( pat) {
129
+ None => false ,
130
+ Some ( x) => x <= i,
131
+ } ) ;
132
+ assert ! ( match string. rfind( pat) {
133
+ None => false ,
134
+ Some ( x) => x >= i,
135
+ } ) ;
136
+ }
137
+ }
118
138
}
119
139
120
140
#[ test]
You can’t perform that action at this time.
0 commit comments