Documentation
/*
==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--

Dia-Files

Copyright (C) 2019-2025  Anonymous

There are several releases over multiple years,
they are listed as ranges, such as: "2019-2025".

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--
*/

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(())
}