use proptest::prelude::*;
use ricecoder_tools::webfetch::{WebfetchInput, WebfetchOutput, WebfetchTool};
proptest! {
#[test]
fn prop_webfetch_content_retrieval(url in prop_oneof![
Just("https://example.com"),
Just("http://example.com"),
Just("https://example.com/path"),
Just("https://example.com:8080/path?query=value"),
]) {
let result = WebfetchTool::validate_url(url);
prop_assert!(result.is_ok());
}
}
proptest! {
#[test]
fn prop_webfetch_timeout_enforcement(url in prop_oneof![
Just("https://example.com"),
Just("https://httpbin.org/delay/15"),
]) {
let input = WebfetchInput::new(url);
prop_assert!(!input.url.is_empty());
}
}
proptest! {
#[test]
fn prop_webfetch_content_truncation(
size in 0usize..100000usize
) {
let content = String::from("x").repeat(size);
let output = WebfetchOutput::new(content, size);
if output.original_size > output.returned_size {
prop_assert!(output.truncated, "Should be marked as truncated when returned_size < original_size");
} else {
prop_assert!(!output.truncated, "Should not be marked as truncated when returned_size == original_size");
}
prop_assert!(output.returned_size <= output.original_size);
}
}
proptest! {
#[test]
fn test_webfetch_input_creation_property(url in prop_oneof![
Just("https://example.com"),
Just("http://example.com"),
Just("https://example.com/path"),
]) {
let input = WebfetchInput::new(url);
prop_assert!(!input.url.is_empty());
prop_assert!(input.max_size.is_none());
}
}
proptest! {
#[test]
fn test_webfetch_output_truncation_property(size in 0usize..100000usize) {
let content = String::from("x").repeat(size.min(100000));
let output = WebfetchOutput::new(content, size);
if output.original_size > output.returned_size {
prop_assert!(output.truncated);
} else {
prop_assert!(!output.truncated);
}
}
}
proptest! {
#[test]
fn test_url_validation_scheme_property(url in prop_oneof![
Just("https://example.com"),
Just("http://example.com"),
Just("ftp://example.com"),
Just("file:///path/to/file"),
]) {
let result = WebfetchTool::validate_url(url);
if url.starts_with("http://") || url.starts_with("https://") {
prop_assert!(result.is_ok());
} else {
prop_assert!(result.is_err());
}
}
}
proptest! {
#[test]
fn test_url_validation_localhost_property(url in prop_oneof![
Just("http://localhost"),
Just("http://localhost:8080"),
Just("http://127.0.0.1"),
Just("http://127.0.0.1:8080"),
Just("http://example.com"),
]) {
let result = WebfetchTool::validate_url(url);
if url.contains("localhost") || url.contains("127.0.0.1") {
prop_assert!(result.is_err());
} else {
prop_assert!(result.is_ok());
}
}
}
proptest! {
#[test]
fn test_webfetch_input_max_size_property(size in 0usize..1000000usize) {
let input = WebfetchInput::new("https://example.com").with_max_size(size);
prop_assert!(input.max_size.is_some());
}
}