Skip to content

Commit

Permalink
More asserts in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0246 committed Sep 12, 2023
1 parent 7f26d69 commit 4e88bee
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,17 @@ mod tests {
let mut y = allocator.allocate();
unsafe { y.as_ptr().write(42) };

assert_eq!(allocator.slab_count(), 1);

mem::swap(unsafe { x.as_mut() }, unsafe { y.as_mut() });

unsafe { allocator.deallocate(x) };

let mut x2 = allocator.allocate();
unsafe { x2.as_ptr().write(12) };

assert_eq!(allocator.slab_count(), 1);

mem::swap(unsafe { y.as_mut() }, unsafe { x2.as_mut() });

unsafe { allocator.deallocate(y) };
Expand All @@ -470,6 +474,8 @@ mod tests {
let mut z = allocator.allocate();
unsafe { z.as_ptr().write(3) };

assert_eq!(allocator.slab_count(), 3);

mem::swap(unsafe { x.as_mut() }, unsafe { y.as_mut() });
mem::swap(unsafe { y.as_mut() }, unsafe { z.as_mut() });
mem::swap(unsafe { z.as_mut() }, unsafe { x.as_mut() });
Expand All @@ -479,6 +485,8 @@ mod tests {
let mut y2 = allocator.allocate();
unsafe { y2.as_ptr().write(20) };

assert_eq!(allocator.slab_count(), 3);

mem::swap(unsafe { x.as_mut() }, unsafe { y2.as_mut() });

unsafe { allocator.deallocate(x) };
Expand All @@ -492,6 +500,8 @@ mod tests {
let mut z2 = allocator.allocate();
unsafe { z2.as_ptr().write(30) };

assert_eq!(allocator.slab_count(), 3);

mem::swap(unsafe { x2.as_mut() }, unsafe { z2.as_mut() });

unsafe { allocator.deallocate(x2) };
Expand All @@ -512,11 +522,15 @@ mod tests {
let mut y = allocator.allocate();
unsafe { y.as_ptr().write(2) };

assert_eq!(allocator.slab_count(), 1);

mem::swap(unsafe { x.as_mut() }, unsafe { y.as_mut() });

let z = allocator.allocate();
unsafe { z.as_ptr().write(3) };

assert_eq!(allocator.slab_count(), 2);

unsafe { allocator.deallocate(x) };
unsafe { allocator.deallocate(z) };

Expand All @@ -526,6 +540,8 @@ mod tests {
let mut x2 = allocator.allocate();
unsafe { x2.as_ptr().write(10) };

assert_eq!(allocator.slab_count(), 2);

mem::swap(unsafe { x2.as_mut() }, unsafe { z2.as_mut() });

unsafe { allocator.deallocate(x2) };
Expand Down

0 comments on commit 4e88bee

Please sign in to comment.