@@ -520,6 +520,46 @@ fn array_clone_from() {
520520 assert_eq ! ( & t, & reference[ ..] ) ;
521521}
522522
523+ #[ test]
524+ fn array_index_usize ( ) {
525+ let v = ArrayVec :: from ( [ 1 , 2 , 3 ] ) ;
526+ assert_eq ! ( v[ 1 ] , 2 ) ;
527+ }
528+
529+ #[ should_panic( expected="index out of bounds: the len is 3 but the index is 3" ) ]
530+ #[ test]
531+ fn array_index_usize_out_of_bounds ( ) {
532+ let v = ArrayVec :: from ( [ 1 , 2 , 3 ] ) ;
533+ let _ = v[ 3 ] ; // out of bounds
534+ }
535+
536+ #[ test]
537+ fn array_index_range ( ) {
538+ let v = ArrayVec :: from ( [ 1 , 2 , 3 ] ) ;
539+ assert_eq ! ( & v[ 1 ..3 ] , [ 2 , 3 ] . as_ref( ) ) ;
540+ }
541+
542+ #[ should_panic( expected="range end index 4 out of range for slice of length 3" ) ]
543+ #[ test]
544+ fn array_index_range_out_of_bounds ( ) {
545+ let v = ArrayVec :: from ( [ 1 , 2 , 3 ] ) ;
546+ let _ = v[ 1 ..4 ] ; // out of bounds
547+ }
548+
549+ #[ test]
550+ fn array_indexmut_usize ( ) {
551+ let mut v = ArrayVec :: from ( [ 1 , 2 , 3 ] ) ;
552+ v[ 1 ] = 0 ;
553+ assert_eq ! ( v, ArrayVec :: from( [ 1 , 0 , 3 ] ) ) ;
554+ }
555+
556+ #[ should_panic( expected="index out of bounds: the len is 3 but the index is 3" ) ]
557+ #[ test]
558+ fn array_indexmut_usize_out_of_bounds ( ) {
559+ let mut v = ArrayVec :: from ( [ 1 , 2 , 3 ] ) ;
560+ v[ 3 ] = 0 ; // out of bounds
561+ }
562+
523563#[ cfg( feature="std" ) ]
524564#[ test]
525565fn test_string ( ) {
0 commit comments