| 1 | use craterust-analyzer cargo ringbuf 0.3.3 crate/::{HeapRbrust-analyzer cargo ringbuf 0.3.3 alias/HeapRb#, Rbrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/Rb#}; |
| 2 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/::Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#; |
| 3 | |
| 4 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 5 | fn skiprust-analyzer cargo ringbuf 0.3.3 tests/skip/skip().() { |
| 6 | // Initialize ringbuffer, prod and cons |
| 7 | let rb = HeapRbrust-analyzer cargo ringbuf 0.3.3 alias/HeapRb#::<i8>::newrust-analyzer cargo ringbuf 0.3.3 ring_buffer/init/impl#[`SharedRb<T, Vec<MaybeUninit<T>>>`]new().(10); |
| 8 | let (mut prod, mut cons) = rb.splitrust-analyzer cargo ringbuf 0.3.3 ring_buffer/shared/impl#[`SharedRb<T, C>`]split().(); |
| 9 | let mut i = 0; |
| 10 | |
| 11 | // Fill the buffer |
| 12 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#10 { |
| 13 | prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(i).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 14 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`AddAssign<Self>`]add_assign().1; |
| 15 | } |
| 16 | |
| 17 | // Pop in the middle of the buffer |
| 18 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cons.skiprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]skip().(5), 5); |
| 19 | |
| 20 | // Make sure changes are taken into account |
| 21 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cons.poprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 5); |
| 22 | |
| 23 | // Fill the buffer again |
| 24 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#5 { |
| 25 | prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(i).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 26 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`AddAssign<Self>`]add_assign().1; |
| 27 | } |
| 28 | |
| 29 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cons.skiprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]skip().(6), 6); |
| 30 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cons.poprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), 12); |
| 31 | |
| 32 | // Fill the buffer again |
| 33 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#7 { |
| 34 | prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(i).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 35 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`AddAssign<Self>`]add_assign().1; |
| 36 | } |
| 37 | |
| 38 | // Ask too much, delete the max number of items |
| 39 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cons.skiprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]skip().(10), 9); |
| 40 | |
| 41 | // Try to remove more than possible |
| 42 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cons.skiprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]skip().(1), 0); |
| 43 | |
| 44 | // Make sure it is still usable |
| 45 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cons.poprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#); |
| 46 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(0), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())); |
| 47 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cons.poprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]pop().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0)); |
| 48 | } |
| 49 | |
| 50 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 51 | fn skip_droprust-analyzer cargo ringbuf 0.3.3 tests/skip/skip_drop().() { |
| 52 | let rc = Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::<()>::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T>`]new().(()); |
| 53 | |
| 54 | static Nrust-analyzer cargo ringbuf 0.3.3 tests/skip/N.: usize = 10; |
| 55 | |
| 56 | let rb = HeapRbrust-analyzer cargo ringbuf 0.3.3 alias/HeapRb#::<Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<()>>::newrust-analyzer cargo ringbuf 0.3.3 ring_buffer/init/impl#[`SharedRb<T, Vec<MaybeUninit<T>>>`]new().(Nrust-analyzer cargo ringbuf 0.3.3 tests/skip/N.); |
| 57 | let (mut prod, mut cons) = rb.splitrust-analyzer cargo ringbuf 0.3.3 ring_buffer/shared/impl#[`SharedRb<T, C>`]split().(); |
| 58 | |
| 59 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#Nrust-analyzer cargo ringbuf 0.3.3 tests/skip/N. { |
| 60 | prod.pushrust-analyzer cargo ringbuf 0.3.3 producer/impl#[`Producer<T, R>`]push().(rc.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T, A>`][Clone]clone().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 61 | } |
| 62 | |
| 63 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cons.lenrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]len().(), Nrust-analyzer cargo ringbuf 0.3.3 tests/skip/N.); |
| 64 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::strong_countrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T, A>`]strong_count().(&rc), Nrust-analyzer cargo ringbuf 0.3.3 tests/skip/N. +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1); |
| 65 | |
| 66 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cons.skiprust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]skip().(Nrust-analyzer cargo ringbuf 0.3.3 tests/skip/N.), Nrust-analyzer cargo ringbuf 0.3.3 tests/skip/N.); |
| 67 | |
| 68 | // Check ring buffer is empty |
| 69 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(cons.lenrust-analyzer cargo ringbuf 0.3.3 consumer/impl#[`Consumer<T, R>`]len().(), 0); |
| 70 | // Check that items are dropped |
| 71 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::strong_countrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T, A>`]strong_count().(&rc), 1); |
| 72 | } |
| 73 | |
| 74 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 75 | #[should_panic] |
| 76 | fn skip_panicrust-analyzer cargo ringbuf 0.3.3 tests/skip/skip_panic().() { |
| 77 | let mut rb = HeapRbrust-analyzer cargo ringbuf 0.3.3 alias/HeapRb#::<i32>::newrust-analyzer cargo ringbuf 0.3.3 ring_buffer/init/impl#[`SharedRb<T, Vec<MaybeUninit<T>>>`]new().(2); |
| 78 | rb.pushrust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/Rb#push().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 79 | rb.skiprust-analyzer cargo ringbuf 0.3.3 ring_buffer/rb/Rb#skip().(2); |
| 80 | } |