Skip to content

Commit

Permalink
TST: more test cases for trait impls
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed Dec 19, 2021
1 parent b198496 commit f08b6c8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,29 @@ fn drop_write_chunk() {
// RingBuffer was already empty, nothing is dropped:
assert_eq!(unsafe { DROP_COUNT }, 7);
}

#[test]
fn trait_impls() {
let (mut p, mut c) = RingBuffer::<u8>::new(0);

if let Ok(chunk) = p.write_chunk(0) {
assert!(format!("{:?}", chunk).starts_with("WriteChunk"));
} else {
unreachable!();
}
if let Ok(chunk) = p.write_chunk_uninit(0) {
assert!(format!("{:?}", chunk).starts_with("WriteChunkUninit"));
} else {
unreachable!();
}
if let Ok(chunk) = c.read_chunk(0) {
assert!(format!("{:?}", chunk).starts_with("ReadChunk"));
let iter = chunk.into_iter();
assert!(format!("{:?}", iter).starts_with("ReadChunkIntoIter"));
} else {
unreachable!();
}
let e = c.read_chunk(100).unwrap_err();
assert_eq!(format!("{:?}", e), "TooFewSlots(0)");
assert_eq!(e.to_string(), "only 0 slots available in ring buffer");
}
20 changes: 20 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,23 @@ fn drops() {
assert_eq!(DROPS.load(Ordering::SeqCst), steps + additional);
}
}

#[test]
fn trait_impls() {
let (mut p, mut c) = RingBuffer::<u8>::new(0);

assert!(format!("{:?}", p.buffer()).starts_with("RingBuffer {"));
assert!(format!("{:?}", p).starts_with("Producer {"));
assert!(format!("{:?}", c).starts_with("Consumer {"));

assert_eq!(format!("{:?}", p.push(42).unwrap_err()), "Full(_)");
assert_eq!(p.push(42).unwrap_err().to_string(), "full ring buffer");
assert_eq!(format!("{:?}", c.pop().unwrap_err()), "Empty");
assert_eq!(c.pop().unwrap_err().to_string(), "empty ring buffer");
assert_eq!(format!("{:?}", c.peek().unwrap_err()), "Empty");
assert_eq!(c.peek().unwrap_err().to_string(), "empty ring buffer");

let (another_p, another_c) = RingBuffer::<u8>::new(0);
assert_ne!(p, another_p);
assert_ne!(c, another_c);
}

0 comments on commit f08b6c8

Please sign in to comment.