use dia_files::{Limit, Result};
#[cfg(feature="tokio")]
use {
std::path::Path,
tokio::{
fs,
runtime::Runtime,
},
};
#[cfg(not(feature="tokio"))]
use std::{
fs,
path::Path,
};
macro_rules! file_name { () => { "path_ext.rs" }}
macro_rules! async_call { ($f: expr) => {{
#[cfg(feature="tokio")]
let r = $f.await;
#[cfg(not(feature="tokio"))]
let r = $f;
r
}}}
macro_rules! read_file { () => {{
let path = Path::new(file!()).parent().unwrap().join(file_name!());
let size = async_call!(fs::metadata(&path))?.len();
let data = async_call!(Limit::read_file(&path, size))?;
assert_eq!(data, include_bytes!(file_name!()));
Result::Ok(())
}}}
#[test]
fn limit_with_file() -> Result<()> {
#[cfg(feature="tokio")]
Runtime::new().unwrap().block_on(async move {
read_file!()
})?;
#[cfg(not(feature="tokio"))]
read_file!()?;
Ok(())
}