#![allow(clippy::unwrap_used, clippy::expect_used)]
// Copyright © 2023 - 2026 Static Site Generator (SSG). All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Benchmark suite for the Static Site Generator.
//!
//! This module contains performance benchmarks for critical operations
//! in the static site generator, including file operations and content processing.

use criterion::Criterion;
use staticdatagen::utilities::file::add;
use std::hint::black_box;
use std::path::PathBuf;

/// Runs a benchmark that measures the performance of the `add` function.
///
/// This benchmark measures file addition performance by repeatedly calling
/// the `add` function with a test path and measuring execution time.
///
/// # Arguments
///
/// * `c` - A reference to a `Criterion` instance used for benchmark configuration
///         and measurement.
///
/// # Example Output
///
/// ```text
/// add function      time: [10.123 µs 10.234 µs 10.345 µs]
/// ```
#[allow(dead_code, unreachable_pub)]
pub fn bench_file(c: &mut Criterion) {
    let path = PathBuf::from("content");
    let _ = c.bench_function("add function", |b| {
        b.iter(|| {
            let result = add(&path);
            match result {
                Ok(data) => {
                    // Assign the black_box result to ignore it properly
                    let _ = black_box(data);
                }
                Err(e) => {
                    eprintln!("Error: {e}");
                }
            }
        });
    });
}

#[cfg(test)]
mod tests {
    #[test]
    fn test_bench_setup() {
        let path = std::path::PathBuf::from("content");
        let result = staticdatagen::utilities::file::add(&path);
        assert!(result.is_ok() || result.is_err());
    }
}
