webpage_quality_analyzer 1.0.2

High-performance webpage quality analyzer with 115 comprehensive metrics - Rust library with WASM, C++, and Python bindings
Documentation
//! Test the high-performance batch processing implementation

#[cfg(test)]
mod tests {
    use std::time::Instant;
    use webpage_quality_analyzer::{analyze, analyze_batch_high_performance, PageQualityReport};

    #[tokio::test]
    async fn test_batch_processing_performance() {
        // Create test URLs
        let urls = vec![
            "https://httpbin.org/html",
            "https://example.com",
            "https://httpbin.org/status/200",
        ];

        let start = Instant::now();
        let result = analyze_batch_high_performance(
            &urls, None, 10, // Lower concurrency for testing
            None,
        )
        .await;
        let duration = start.elapsed();

        assert!(result.is_ok(), "Batch processing should succeed");

        let json_output = result.unwrap();
        assert!(!json_output.is_empty(), "JSON output should not be empty");
        assert!(json_output.contains("["), "Output should be JSON array");

        println!(
            "Batch processed {} URLs in {:.3}s ({:.1} pages/sec)",
            urls.len(),
            duration.as_secs_f64(),
            urls.len() as f64 / duration.as_secs_f64()
        );
    }

    #[tokio::test]
    async fn test_json_optimization_modes() {
        // Generate a test report
        let test_html = r#"
            <html>
            <head><title>Test</title></head>
            <body><h1>Test</h1><p>Content</p></body>
            </html>
        "#;

        let report = analyze("https://test.com", Some(test_html))
            .await
            .expect("Should generate test report");
        let reports = vec![report];

        // Test different optimization levels
        let standard = PageQualityReport::export_batch(&reports, false)
            .expect("Standard optimization should work");

        let ultra_fast = PageQualityReport::export_batch(&reports, true)
            .expect("Ultra-fast optimization should work");

        assert!(!standard.is_empty(), "Standard JSON should not be empty");
        assert!(
            !ultra_fast.is_empty(),
            "Ultra-fast JSON should not be empty"
        );

        // Ultra-fast should be more compact
        assert!(
            ultra_fast.len() <= standard.len(),
            "Ultra-fast should be more compact or equal size"
        );

        // Both should be valid JSON arrays
        let _: serde_json::Value =
            serde_json::from_str(&standard).expect("Standard JSON should be valid");
        let _: serde_json::Value =
            serde_json::from_str(&ultra_fast).expect("Ultra-fast JSON should be valid");

        println!(
            "Standard: {} bytes, Ultra-fast: {} bytes",
            standard.len(),
            ultra_fast.len()
        );
    }

    #[tokio::test]
    async fn test_element_processor_integration() {
        // This test ensures ElementProcessor is working with our optimizations
        let test_html = r#"<html>
<head><title>Test</title></head>
<body>
    <h1>Heading</h1>
    <p>Paragraph 1</p>
    <p>Paragraph 2</p>
    <img src="test.jpg" alt="Test" />
    <a href="https://example.com">Link</a>
</body>
</html>"#;

        let report = analyze("https://test.com", Some(test_html))
            .await
            .expect("Should analyze test HTML");

        // Verify that element counting worked
        assert!(
            report.metrics.html_analysis.structure.headings_count > 0,
            "Should count headings"
        );
        assert!(report.score > 0.0, "Should have a positive score");
        assert!(!report.url.is_empty(), "Should have URL");

        println!(
            "Element processor integration test passed. Score: {}",
            report.score
        );
    }
}