@@ -1076,6 +1076,55 @@ fn test_range() {
10761076 ( isize :: MAX as usize + 2 , Some ( isize :: MAX as usize + 2 ) ) ) ;
10771077}
10781078
1079+ #[ test]
1080+ fn test_range_nth ( ) {
1081+ assert_eq ! ( ( 10 ..15 ) . nth( 0 ) , Some ( 10 ) ) ;
1082+ assert_eq ! ( ( 10 ..15 ) . nth( 1 ) , Some ( 11 ) ) ;
1083+ assert_eq ! ( ( 10 ..15 ) . nth( 4 ) , Some ( 14 ) ) ;
1084+ assert_eq ! ( ( 10 ..15 ) . nth( 5 ) , None ) ;
1085+
1086+ let mut r = 10 ..20 ;
1087+ assert_eq ! ( r. nth( 2 ) , Some ( 12 ) ) ;
1088+ assert_eq ! ( r, 13 ..20 ) ;
1089+ assert_eq ! ( r. nth( 2 ) , Some ( 15 ) ) ;
1090+ assert_eq ! ( r, 16 ..20 ) ;
1091+ assert_eq ! ( r. nth( 10 ) , None ) ;
1092+ assert_eq ! ( r, 20 ..20 ) ;
1093+ }
1094+
1095+ #[ test]
1096+ fn test_range_from_nth ( ) {
1097+ assert_eq ! ( ( 10 ..) . nth( 0 ) , Some ( 10 ) ) ;
1098+ assert_eq ! ( ( 10 ..) . nth( 1 ) , Some ( 11 ) ) ;
1099+ assert_eq ! ( ( 10 ..) . nth( 4 ) , Some ( 14 ) ) ;
1100+
1101+ let mut r = 10 ..;
1102+ assert_eq ! ( r. nth( 2 ) , Some ( 12 ) ) ;
1103+ assert_eq ! ( r, 13 ..) ;
1104+ assert_eq ! ( r. nth( 2 ) , Some ( 15 ) ) ;
1105+ assert_eq ! ( r, 16 ..) ;
1106+ assert_eq ! ( r. nth( 10 ) , Some ( 26 ) ) ;
1107+ assert_eq ! ( r, 27 ..) ;
1108+ }
1109+
1110+ #[ test]
1111+ fn test_range_inclusive_nth ( ) {
1112+ assert_eq ! ( ( 10 ...15 ) . nth( 0 ) , Some ( 10 ) ) ;
1113+ assert_eq ! ( ( 10 ...15 ) . nth( 1 ) , Some ( 11 ) ) ;
1114+ assert_eq ! ( ( 10 ...15 ) . nth( 5 ) , Some ( 15 ) ) ;
1115+ assert_eq ! ( ( 10 ...15 ) . nth( 6 ) , None ) ;
1116+
1117+ let mut r = 10_u8 ...20 ;
1118+ assert_eq ! ( r. nth( 2 ) , Some ( 12 ) ) ;
1119+ assert_eq ! ( r, 13 ...20 ) ;
1120+ assert_eq ! ( r. nth( 2 ) , Some ( 15 ) ) ;
1121+ assert_eq ! ( r, 16 ...20 ) ;
1122+ assert_eq ! ( r. is_empty( ) , false ) ;
1123+ assert_eq ! ( r. nth( 10 ) , None ) ;
1124+ assert_eq ! ( r. is_empty( ) , true ) ;
1125+ assert_eq ! ( r, 1 ...0 ) ; // We may not want to document/promise this detail
1126+ }
1127+
10791128#[ test]
10801129fn test_range_step ( ) {
10811130 #![ allow( deprecated) ]
0 commit comments