// This file is auto-generated by alef — DO NOT EDIT.
// alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
// To regenerate: alef generate
// To verify freshness: alef verify --exit-code
// Issues & docs: https://github.com/kreuzberg-dev/alef
//! E2e tests for category: error

use kreuzberg::extract_bytes_sync;

#[test]
fn test_error_empty_bytes() {
    // Graceful handling of empty bytes (should not error)
    let content = std::fs::read(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../../test_documents/text/empty.txt"
    ))
    .expect("test_documents/text/empty.txt must exist");
    let mime_type = r#"text/plain"#;
    let config_json: serde_json::Value = serde_json::from_str(r#"{}"#).unwrap();
    let config = serde_json::from_value(config_json).unwrap();
    let _ = extract_bytes_sync(&content, mime_type, &config).expect("should succeed");
}

#[test]
fn test_error_empty_mime() {
    // Error when extracting with empty MIME type
    let content = std::fs::read(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../../test_documents/text/plain.txt"
    ))
    .expect("test_documents/text/plain.txt must exist");
    let mime_type = r#""#;
    let config_json: serde_json::Value = serde_json::from_str(r#"{}"#).unwrap();
    let config = serde_json::from_value(config_json).unwrap();
    let result = extract_bytes_sync(&content, mime_type, &config);
    assert!(result.is_err(), "expected call to fail");
}

#[test]
fn test_error_extract_bytes_conflicting_ocr() {
    // extract_bytes force+disable OCR
    let content = std::fs::read(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../../test_documents/text/fake_text.txt"
    ))
    .expect("test_documents/text/fake_text.txt must exist");
    let mime_type = r#"text/plain"#;
    let config_json: serde_json::Value = serde_json::from_str(r#"{"disable_ocr":true,"force_ocr":true}"#).unwrap();
    let config = serde_json::from_value(config_json).unwrap();
    let result = extract_bytes_sync(&content, mime_type, &config);
    assert!(result.is_err(), "expected call to fail");
}

#[test]
fn test_error_invalid_mime_format() {
    // Error when extracting with invalid MIME type format
    let content = std::fs::read(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../../test_documents/text/plain.txt"
    ))
    .expect("test_documents/text/plain.txt must exist");
    let mime_type = r#"not-a-mime"#;
    let config_json: serde_json::Value = serde_json::from_str(r#"{}"#).unwrap();
    let config = serde_json::from_value(config_json).unwrap();
    let result = extract_bytes_sync(&content, mime_type, &config);
    assert!(result.is_err(), "expected call to fail");
}

#[test]
fn test_error_unsupported_mime() {
    // Error when extracting with unsupported MIME type
    let content = std::fs::read(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../../test_documents/text/plain.txt"
    ))
    .expect("test_documents/text/plain.txt must exist");
    let mime_type = r#"application/x-nonexistent"#;
    let config_json: serde_json::Value = serde_json::from_str(r#"{}"#).unwrap();
    let config = serde_json::from_value(config_json).unwrap();
    let result = extract_bytes_sync(&content, mime_type, &config);
    assert!(result.is_err(), "expected call to fail");
}
