// 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
const std = @import("std");
const testing = std.testing;
const kreuzberg = @import("kreuzberg");

// Suppress C++ global destructor aborts that break zig's --listen=- IPC
extern "c" fn signal(sig: i32, handler: usize) usize;
var _abort_handler_installed: bool = false;
fn suppress_abort() void {
    if (!_abort_handler_installed) {
        // SIGABRT = 6 on POSIX; SIG_IGN = 1
        _ = signal(6, 1);
        _abort_handler_installed = true;
    }
}

// E2e tests for category: error

test "error_empty_bytes" {
    // Graceful handling of empty bytes (should not error)
    suppress_abort();
    const content_bytes = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "text/empty.txt", std.heap.c_allocator, .unlimited);
    defer std.heap.c_allocator.free(content_bytes);
    const _result_json = try kreuzberg.extract_bytes_sync(content_bytes, "text/plain", "{}");
    defer std.heap.c_allocator.free(_result_json);
}

test "error_empty_mime" {
    // Error when extracting with empty MIME type
    suppress_abort();
    const content_bytes = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "text/plain.txt", std.heap.c_allocator, .unlimited);
    defer std.heap.c_allocator.free(content_bytes);
    const _result_json = kreuzberg.extract_bytes_sync(content_bytes, "", "{}") catch {
        try testing.expect(true); // Error occurred as expected
        return;
    };
    _ = _result_json;
}

test "error_extract_bytes_conflicting_ocr" {
    // extract_bytes force+disable OCR
    suppress_abort();
    const content_bytes = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "text/fake_text.txt", std.heap.c_allocator, .unlimited);
    defer std.heap.c_allocator.free(content_bytes);
    const _result_json = kreuzberg.extract_bytes_sync(content_bytes, "text/plain", "{\"disable_ocr\":true,\"force_ocr\":true}") catch {
        try testing.expect(true); // Error occurred as expected
        return;
    };
    _ = _result_json;
}

test "error_invalid_mime_format" {
    // Error when extracting with invalid MIME type format
    suppress_abort();
    const content_bytes = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "text/plain.txt", std.heap.c_allocator, .unlimited);
    defer std.heap.c_allocator.free(content_bytes);
    const _result_json = kreuzberg.extract_bytes_sync(content_bytes, "not-a-mime", "{}") catch {
        try testing.expect(true); // Error occurred as expected
        return;
    };
    _ = _result_json;
}

test "error_unsupported_mime" {
    // Error when extracting with unsupported MIME type
    suppress_abort();
    const content_bytes = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "text/plain.txt", std.heap.c_allocator, .unlimited);
    defer std.heap.c_allocator.free(content_bytes);
    const _result_json = kreuzberg.extract_bytes_sync(content_bytes, "application/x-nonexistent", "{}") catch {
        try testing.expect(true); // Error occurred as expected
        return;
    };
    _ = _result_json;
}
