@@ -1154,9 +1154,7 @@ fn collect_from_iter() {
1154
1154
#[ test]
1155
1155
fn test_collect_with_spill ( ) {
1156
1156
let input = "0123456" ;
1157
- let collected: SmallVec < char , 4 > = input
1158
- . chars ( )
1159
- . collect ( ) ;
1157
+ let collected: SmallVec < char , 4 > = input. chars ( ) . collect ( ) ;
1160
1158
assert_eq ! ( collected, & [ '0' , '1' , '2' , '3' , '4' , '5' , '6' ] ) ;
1161
1159
}
1162
1160
@@ -1186,3 +1184,96 @@ fn test_spare_capacity_mut() {
1186
1184
assert ! ( spare. len( ) >= 1 ) ;
1187
1185
assert_eq ! ( spare. as_ptr( ) . cast:: <u8 >( ) , unsafe { v. as_ptr( ) . add( 3 ) } ) ;
1188
1186
}
1187
+
1188
+ // Adopted from `tests/test_buf_mut.rs` in the `bytes` crate.
1189
+ #[ cfg( feature = "bytes" ) ]
1190
+ mod buf_mut {
1191
+ use bytes:: BufMut as _;
1192
+
1193
+ type SmallVec = crate :: SmallVec < u8 , 8 > ;
1194
+
1195
+ #[ test]
1196
+ fn test_smallvec_as_mut_buf ( ) {
1197
+ let mut buf = SmallVec :: with_capacity ( 64 ) ;
1198
+
1199
+ assert_eq ! ( buf. remaining_mut( ) , isize :: MAX as usize ) ;
1200
+
1201
+ assert ! ( buf. chunk_mut( ) . len( ) >= 64 ) ;
1202
+
1203
+ buf. put ( & b"zomg" [ ..] ) ;
1204
+
1205
+ assert_eq ! ( & buf, b"zomg" ) ;
1206
+
1207
+ assert_eq ! ( buf. remaining_mut( ) , isize :: MAX as usize - 4 ) ;
1208
+ assert_eq ! ( buf. capacity( ) , 64 ) ;
1209
+
1210
+ for _ in 0 ..16 {
1211
+ buf. put ( & b"zomg" [ ..] ) ;
1212
+ }
1213
+
1214
+ assert_eq ! ( buf. len( ) , 68 ) ;
1215
+ }
1216
+
1217
+ #[ test]
1218
+ fn test_smallvec_put_bytes ( ) {
1219
+ let mut buf = SmallVec :: new ( ) ;
1220
+ buf. push ( 17 ) ;
1221
+ buf. put_bytes ( 19 , 2 ) ;
1222
+ assert_eq ! ( [ 17 , 19 , 19 ] , & buf[ ..] ) ;
1223
+ }
1224
+
1225
+ #[ test]
1226
+ fn test_put_u8 ( ) {
1227
+ let mut buf = SmallVec :: with_capacity ( 8 ) ;
1228
+ buf. put_u8 ( 33 ) ;
1229
+ assert_eq ! ( b"\x21 " , & buf[ ..] ) ;
1230
+ }
1231
+
1232
+ #[ test]
1233
+ fn test_put_u16 ( ) {
1234
+ let mut buf = SmallVec :: with_capacity ( 8 ) ;
1235
+ buf. put_u16 ( 8532 ) ;
1236
+ assert_eq ! ( b"\x21 \x54 " , & buf[ ..] ) ;
1237
+
1238
+ buf. clear ( ) ;
1239
+ buf. put_u16_le ( 8532 ) ;
1240
+ assert_eq ! ( b"\x54 \x21 " , & buf[ ..] ) ;
1241
+ }
1242
+
1243
+ #[ test]
1244
+ fn test_put_int ( ) {
1245
+ let mut buf = SmallVec :: with_capacity ( 8 ) ;
1246
+ buf. put_int ( 0x1020304050607080 , 3 ) ;
1247
+ assert_eq ! ( b"\x60 \x70 \x80 " , & buf[ ..] ) ;
1248
+ }
1249
+
1250
+ #[ test]
1251
+ #[ should_panic]
1252
+ fn test_put_int_nbytes_overflow ( ) {
1253
+ let mut buf = SmallVec :: with_capacity ( 8 ) ;
1254
+ buf. put_int ( 0x1020304050607080 , 9 ) ;
1255
+ }
1256
+
1257
+ #[ test]
1258
+ fn test_put_int_le ( ) {
1259
+ let mut buf = SmallVec :: with_capacity ( 8 ) ;
1260
+ buf. put_int_le ( 0x1020304050607080 , 3 ) ;
1261
+ assert_eq ! ( b"\x80 \x70 \x60 " , & buf[ ..] ) ;
1262
+ }
1263
+
1264
+ #[ test]
1265
+ #[ should_panic]
1266
+ fn test_put_int_le_nbytes_overflow ( ) {
1267
+ let mut buf = SmallVec :: with_capacity ( 8 ) ;
1268
+ buf. put_int_le ( 0x1020304050607080 , 9 ) ;
1269
+ }
1270
+
1271
+ #[ test]
1272
+ #[ should_panic( expected = "advance out of bounds: the len is 8 but advancing by 12" ) ]
1273
+ fn test_smallvec_advance_mut ( ) {
1274
+ let mut buf = SmallVec :: with_capacity ( 8 ) ;
1275
+ unsafe {
1276
+ buf. advance_mut ( 12 ) ;
1277
+ }
1278
+ }
1279
+ }
0 commit comments