#[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() {
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, 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() {
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];
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"
);
assert!(
ultra_fast.len() <= standard.len(),
"Ultra-fast should be more compact or equal size"
);
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() {
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");
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
);
}
}