@@ -5,6 +5,7 @@ use std::panic;
55use std:: rc:: Rc ;
66use std:: sync:: atomic:: { Ordering :: Relaxed , AtomicUsize } ;
77use std:: thread;
8+ use std:: f64:: NAN ;
89
910use rand:: { Rng , RngCore , thread_rng} ;
1011use rand:: seq:: SliceRandom ;
@@ -1655,3 +1656,60 @@ fn repeat_generic_slice() {
16551656 vec![ 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 , 1 , 2 , 3 , 4 ]
16561657 ) ;
16571658}
1659+
1660+ #[ test]
1661+ fn test_match_indices_simple ( ) {
1662+ let haystack = & [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 , 2.0 , 3.0 , 2.0 , 4.0 , 8.0 ] [ ..] ;
1663+ let needle = & [ 2.0 , 3.0 ] [ ..] ;
1664+
1665+ assert_eq ! ( haystack. match_indices( needle) . collect:: <Vec <_>>( ) , vec![
1666+ ( 1 , needle) ,
1667+ ( 8 , needle) ,
1668+ ] ) ;
1669+ }
1670+
1671+ #[ test]
1672+ fn test_match_indices_nan_haystack ( ) {
1673+ let haystack = & [ 1.0 , 2.0 , NAN , 1.0 , 2.0 , NAN , 1.0 , NAN , NAN , NAN , 2.0 , 1.0 , 2.0 ] [ ..] ;
1674+ let needle = & [ 1.0 , 2.0 ] [ ..] ;
1675+
1676+ assert_eq ! ( haystack. match_indices( needle) . collect:: <Vec <_>>( ) , vec![
1677+ ( 0 , needle) ,
1678+ ( 3 , needle) ,
1679+ ( 11 , needle) ,
1680+ ] ) ;
1681+ }
1682+
1683+ #[ test]
1684+ fn test_match_indices_nan_needle ( ) {
1685+ let haystack = & [ 1.0 , 2.0 , NAN , 1.0 , 2.0 , NAN , 1.0 , NAN , NAN , NAN , 2.0 , 1.0 , 2.0 ] [ ..] ;
1686+ let needle = & [ 1.0 , 2.0 ] [ ..] ;
1687+
1688+ assert_eq ! ( haystack. match_indices( needle) . collect:: <Vec <_>>( ) , vec![
1689+ ( 0 , needle) ,
1690+ ( 3 , needle) ,
1691+ ( 11 , needle) ,
1692+ ] ) ;
1693+ }
1694+
1695+ #[ test]
1696+ fn test_match_indices_negative_zero ( ) {
1697+ let haystack = & [ 1.0 , 2.0 , NAN , 1.0 , 2.0 , NAN , 1.0 , NAN , NAN , NAN , 2.0 , 1.0 , 2.0 ] [ ..] ;
1698+ let needle = & [ 1.0 , 2.0 ] [ ..] ;
1699+
1700+ assert_eq ! ( haystack. match_indices( needle) . collect:: <Vec <_>>( ) , vec![
1701+ ( 0 , needle) ,
1702+ ( 3 , needle) ,
1703+ ( 11 , needle) ,
1704+ ] ) ;
1705+ }
1706+
1707+ #[ test]
1708+ fn test_replace ( ) {
1709+ let haystack = & b" empowering everyone to build reliable and efficient software." [ ..] ;
1710+
1711+ assert_eq ! (
1712+ haystack. replace( & b" e" [ ..] , b" **E**" ) ,
1713+ b" **E**mpowering **E**veryone to build reliable and **E**fficient software." . to_vec( )
1714+ ) ;
1715+ }
0 commit comments