Skip to content

Commit

Permalink
test(cordyceps): test cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Eliza Weisman <[email protected]>
  • Loading branch information
hawkw committed Jun 18, 2022
1 parent 52eb1cb commit 3a8e20b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 33 deletions.
33 changes: 11 additions & 22 deletions cordyceps/src/list/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ fn collect_vals(list: &List<Entry<'_>>) -> Vec<i32> {
list.iter().map(|entry| entry.val).collect::<Vec<_>>()
}

fn push_all<'a>(list: &mut List<Entry<'a>>, entries: impl IntoIterator<Item = Pin<&'a Entry<'a>>>) {
fn push_all<'a>(
list: &mut List<Entry<'a>>,
entries: impl IntoIterator<Item = &'a Pin<Box<Entry<'a>>>>,
) {
for entry in entries.into_iter() {
list.push_front(entry);
list.push_back(entry.as_ref());
}
}

Expand Down Expand Up @@ -226,13 +229,11 @@ fn push_pop_push_pop() {

#[test]
fn double_ended_iter() {
let a = entry(1);
let b = entry(2);
let c = entry(3);
let entries = [entry(1), entry(2), entry(3)];

let mut list = List::new();

push_all(&mut list, vec![c.as_ref(), b.as_ref(), a.as_ref()]);
push_all(&mut list, &entries);

let head_to_tail = list.iter().map(|entry| entry.val).collect::<Vec<_>>();
assert_eq!(&head_to_tail, &[1, 2, 3]);
Expand All @@ -247,17 +248,11 @@ fn double_ended_iter() {
/// > and do not cross: iteration is over when they meet in the middle.
#[test]
fn double_ended_iter_empties() {
let a = entry(1);
let b = entry(2);
let c = entry(3);
let d = entry(4);
let entries = [entry(1), entry(2), entry(3), entry(4)];

let mut list = List::new();

push_all(
&mut list,
vec![d.as_ref(), c.as_ref(), b.as_ref(), a.as_ref()],
);
push_all(&mut list, &entries);

let mut iter = list.iter();

Expand All @@ -273,17 +268,11 @@ fn double_ended_iter_empties() {

#[test]
fn drain_filter() {
let a = entry(1);
let b = entry(2);
let c = entry(3);
let d = entry(4);
let entries = [entry(1), entry(2), entry(3), entry(4)];

let mut list = List::new();

push_all(
&mut list,
vec![d.as_ref(), c.as_ref(), b.as_ref(), a.as_ref()],
);
push_all(&mut list, &entries);

{
// Create a scope so that the mutable borrow on the list is released
Expand Down
8 changes: 4 additions & 4 deletions cordyceps/src/list/tests/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use super::*;
fn move_peek() {
let _ = super::trace_init();

let entries = &[entry(1), entry(2), entry(3), entry(4), entry(5), entry(6)];
let entries = [entry(1), entry(2), entry(3), entry(4), entry(5), entry(6)];

let mut list = List::new();
push_all(&mut list, entries.iter().map(|entry| entry.as_ref()).rev());
push_all(&mut list, &entries);
let mut cursor = list.cursor_front_mut();
assert_eq!(val(cursor.current()), Some(1));
assert_eq!(val(cursor.peek_next()), Some(2));
Expand Down Expand Up @@ -105,14 +105,14 @@ fn move_peek() {
/// https://github.com/rust-lang/rust/blob/ec21d7ea3ca8e96863f175fbd4a6bfee79529d6c/library/alloc/src/collections/linked_list/tests.rs#L657-L714
#[test]
fn cursor_mut_insert() {
let entries = &[entry(1), entry(2), entry(3), entry(4), entry(5), entry(6)];
let entries = [entry(1), entry(2), entry(3), entry(4), entry(5), entry(6)];
let seven = entry(7);
let eight = entry(8);
let nine = entry(9);
let ten = entry(10);

let mut list = List::<Entry<'_>>::new();
push_all(&mut list, entries.iter().map(|entry| entry.as_ref()).rev());
push_all(&mut list, &entries);

let mut cursor = list.cursor_front_mut();
cursor.insert_before(seven.as_ref());
Expand Down
14 changes: 7 additions & 7 deletions cordyceps/src/list/tests/remove_by_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn first() {
// Remove first
let mut list = List::new();

push_all(&mut list, vec![c.as_ref(), b.as_ref(), a.as_ref()]);
push_all(&mut list, vec![&a, &b, &c]);
assert!(list.remove(ptr(&a)).is_some());
assert_clean!(a);
list.assert_valid();
Expand Down Expand Up @@ -43,7 +43,7 @@ fn first() {
// Remove first of two
let mut list = List::new();

push_all(&mut list, vec![b.as_ref(), a.as_ref()]);
push_all(&mut list, vec![&a, &b]);

assert!(list.remove(ptr(&a)).is_some());
assert_clean!(a);
Expand Down Expand Up @@ -75,7 +75,7 @@ fn middle() {
unsafe {
let mut list = List::new();

push_all(&mut list, vec![c.as_ref(), b.as_ref(), a.as_ref()]);
push_all(&mut list, vec![&a, &b, &c]);

assert!(list.remove(ptr(&a)).is_some());
assert_clean!(a);
Expand All @@ -93,7 +93,7 @@ fn middle() {
unsafe {
let mut list = List::new();

push_all(&mut list, vec![c.as_ref(), b.as_ref(), a.as_ref()]);
push_all(&mut list, vec![&a, &b, &c]);

assert!(list.remove(ptr(&b)).is_some());
assert_clean!(b);
Expand All @@ -120,7 +120,7 @@ fn last_middle() {
// Remove middle
let mut list = List::new();

push_all(&mut list, vec![c.as_ref(), b.as_ref(), a.as_ref()]);
push_all(&mut list, vec![&a, &b, &c]);

assert!(list.remove(ptr(&c)).is_some());
assert_clean!(c);
Expand All @@ -145,7 +145,7 @@ fn last() {
// Remove last item
let mut list = List::new();

push_all(&mut list, Some(a.as_ref()));
push_all(&mut list, Some(&a));

assert!(list.remove(ptr(&a)).is_some());
assert_clean!(a);
Expand All @@ -161,7 +161,7 @@ fn last() {
// Remove last of two
let mut list = List::new();

push_all(&mut list, vec![b.as_ref(), a.as_ref()]);
push_all(&mut list, vec![&a, &b]);

assert!(list.remove(ptr(&b)).is_some());
assert_clean!(b);
Expand Down

0 comments on commit 3a8e20b

Please sign in to comment.