Skip to content

Commit 724c1e9

Browse files
committed
Add tests for AsRef, AsMut, Borrow, BorrowMut, From and ExactSizeIterator
1 parent 727b297 commit 724c1e9

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

lib.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,4 +935,69 @@ pub mod tests {
935935
assert_eq!(a.hash(&mut hasher), b.hash(&mut hasher));
936936
}
937937
}
938+
939+
#[test]
940+
fn test_as_ref() {
941+
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
942+
a.push(1);
943+
assert_eq!(a.as_ref(), [1]);
944+
a.push(2);
945+
assert_eq!(a.as_ref(), [1, 2]);
946+
a.push(3);
947+
assert_eq!(a.as_ref(), [1, 2, 3]);
948+
}
949+
950+
#[test]
951+
fn test_as_mut() {
952+
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
953+
a.push(1);
954+
assert_eq!(a.as_mut(), [1]);
955+
a.push(2);
956+
assert_eq!(a.as_mut(), [1, 2]);
957+
a.push(3);
958+
assert_eq!(a.as_mut(), [1, 2, 3]);
959+
a.as_mut()[1] = 4;
960+
assert_eq!(a.as_mut(), [1, 4, 3]);
961+
}
962+
963+
#[test]
964+
fn test_borrow() {
965+
use std::borrow::Borrow;
966+
967+
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
968+
a.push(1);
969+
assert_eq!(a.borrow(), [1]);
970+
a.push(2);
971+
assert_eq!(a.borrow(), [1, 2]);
972+
a.push(3);
973+
assert_eq!(a.borrow(), [1, 2, 3]);
974+
}
975+
976+
#[test]
977+
fn test_borrow_mut() {
978+
use std::borrow::BorrowMut;
979+
980+
let mut a: SmallVec<[u32; 2]> = SmallVec::new();
981+
a.push(1);
982+
assert_eq!(a.borrow_mut(), [1]);
983+
a.push(2);
984+
assert_eq!(a.borrow_mut(), [1, 2]);
985+
a.push(3);
986+
assert_eq!(a.borrow_mut(), [1, 2, 3]);
987+
BorrowMut::<[u32]>::borrow_mut(&mut a)[1] = 4;
988+
assert_eq!(a.borrow_mut(), [1, 4, 3]);
989+
}
990+
991+
#[test]
992+
fn test_from() {
993+
assert_eq!(&SmallVec::<[u32; 2]>::from(&[1][..])[..], [1]);
994+
assert_eq!(&SmallVec::<[u32; 2]>::from(&[1, 2, 3][..])[..], [1, 2, 3]);
995+
}
996+
997+
#[test]
998+
fn test_exact_size_iterator() {
999+
let mut vec = SmallVec::<[u32; 2]>::from(&[1, 2, 3][..]);
1000+
assert_eq!(vec.clone().into_iter().len(), 3);
1001+
assert_eq!(vec.drain().len(), 3);
1002+
}
9381003
}

0 commit comments

Comments
 (0)