1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
// Copyright © 2023-2025 Andrea Corbellini and contributors
// SPDX-License-Identifier: BSD-3-Clause
#![cfg(feature = "std")]
use circular_buffer::CircularBuffer;
#[cfg(not(miri))]
const SIZE: usize = 2 * 1024 * 1024; // 2 MiB
#[cfg(miri)]
const SIZE: usize = 2 * 1024; // 2 KiB
#[test]
fn large_boxed() {
let chunk = b"abcdefghijklmnopqrstuvxyz0123456789";
let mut buf = CircularBuffer::<SIZE, u8>::boxed();
let mut vec = Vec::new();
assert_ne!(SIZE % chunk.len(), 0);
assert_eq!(buf.len(), 0);
assert!(buf.is_empty());
assert!(!buf.is_full());
assert_eq!(buf.as_slices().0, &[][..]);
assert_eq!(buf.as_slices().1, &[][..]);
for _ in 0..(SIZE / chunk.len()) {
buf.extend_from_slice(&chunk[..]);
vec.extend_from_slice(&chunk[..]);
assert_eq!(buf.len(), vec.len());
assert!(!buf.is_empty());
assert!(!buf.is_full());
assert_eq!(buf.as_slices().0, &vec[..]);
assert_eq!(buf.as_slices().1, &[][..]);
}
for _ in 0..(SIZE / chunk.len()) {
buf.extend_from_slice(&chunk[..]);
vec.extend_from_slice(&chunk[..]);
assert_eq!(buf.len(), SIZE);
assert!(!buf.is_empty());
assert!(buf.is_full());
assert_eq!(buf.as_slices().0, &vec[vec.len() - SIZE..SIZE]);
assert_eq!(buf.as_slices().1, &vec[SIZE..]);
}
}
|