// 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: code

test "code_shebang_detection" {
    // Test language detection from shebang line via bytes input
    suppress_abort();
    var gpa: std.heap.DebugAllocator(.{}) = .init;
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    const _result_json = try kreuzberg.extract_file_sync("code/script.sh", "text/x-source-code", "{}");
    defer std.heap.c_allocator.free(_result_json);
    var _parsed = try std.json.parseFromSlice(std.json.Value, allocator, _result_json, .{});
    defer _parsed.deinit();
    const result = &_parsed.value;
    try testing.expectEqualStrings("text/x-source-code", std.mem.trim(u8, result.object.get("mime_type").?.string, " \n\r\t"));
    try testing.expect(result.object.get("content").?.string.len >= 10);
    {
        const _jva0 = result.object.get("content").?;
        const _jsa0 = if (_jva0 == .string) _jva0.string else try std.json.Stringify.valueAlloc(std.heap.c_allocator, _jva0, .{});
        defer if (_jva0 != .string) std.heap.c_allocator.free(_jsa0);
        try testing.expect(std.mem.indexOf(u8, _jsa0, "build") != null);
    }
    {
        const _jva1 = result.object.get("content").?;
        const _jsa1 = if (_jva1 == .string) _jva1.string else try std.json.Stringify.valueAlloc(std.heap.c_allocator, _jva1, .{});
        defer if (_jva1 != .string) std.heap.c_allocator.free(_jsa1);
        try testing.expect(std.mem.indexOf(u8, _jsa1, "clean") != null);
    }
}
