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/>.

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

#![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(())
}