#![cfg(test)]
use {
crate::Result,
super::Limit,
};
#[cfg(not(feature="tokio"))]
use std::io;
#[cfg(feature="tokio")]
use tokio::{
io,
runtime::Runtime,
};
#[test]
fn tests() -> Result<()> {
for limit in 0..99 {
let data = vec!(u8::try_from(limit).unwrap(); limit);
for limit in [Some(limit.saturating_sub(1)), Some(limit), limit.checked_add(1)].into_iter().filter_map(|l| l) {
let mut input = Limit::new(data.as_slice(), limit.try_into().unwrap());
let mut output = Vec::with_capacity(data.len());
#[cfg(not(feature="tokio"))]
let result = io::copy(&mut input, &mut output);
#[cfg(feature="tokio")]
let result = Runtime::new().unwrap().block_on(io::copy(&mut input, &mut output));
if limit >= data.len() {
result.unwrap();
assert_eq!(data, output);
} else {
result.unwrap_err();
}
}
}
Ok(())
}