@@ -1590,11 +1590,27 @@ fn test_bool_from_str() {
1590
1590
assert_eq ! ( "not even a boolean" . parse:: <bool >( ) . ok( ) , None ) ;
1591
1591
}
1592
1592
1593
- fn check_contains_all_substrings ( s : & str ) {
1594
- assert ! ( s. contains( "" ) ) ;
1595
- for i in 0 ..s. len ( ) {
1596
- for j in i + 1 ..=s. len ( ) {
1597
- assert ! ( s. contains( & s[ i..j] ) ) ;
1593
+ fn check_contains_all_substrings ( haystack : & str ) {
1594
+ let mut modified_needle = String :: new ( ) ;
1595
+
1596
+ for i in 0 ..haystack. len ( ) {
1597
+ // check different haystack lengths since we special-case short haystacks.
1598
+ let haystack = & haystack[ 0 ..i] ;
1599
+ assert ! ( haystack. contains( "" ) ) ;
1600
+ for j in 0 ..haystack. len ( ) {
1601
+ for k in j + 1 ..=haystack. len ( ) {
1602
+ let needle = & haystack[ j..k] ;
1603
+ assert ! ( haystack. contains( needle) ) ;
1604
+ modified_needle. clear ( ) ;
1605
+ modified_needle. push_str ( needle) ;
1606
+ modified_needle. replace_range ( 0 ..1 , "\0 " ) ;
1607
+ assert ! ( !haystack. contains( & modified_needle) ) ;
1608
+
1609
+ modified_needle. clear ( ) ;
1610
+ modified_needle. push_str ( needle) ;
1611
+ modified_needle. replace_range ( needle. len ( ) - 1 ..needle. len ( ) , "\0 " ) ;
1612
+ assert ! ( !haystack. contains( & modified_needle) ) ;
1613
+ }
1598
1614
}
1599
1615
}
1600
1616
}
0 commit comments