Skip to content

StrInit

Description

Initialize a Str. Inside a Scope block the allocator argument may be omitted; the internal MisraScope allocator is used. Otherwise pass a typed allocator handle or a raw Allocator *.

Usage example (Cross-references)

Usage examples (Cross-references)
        do {                                                                                                               \
            HeapAllocator UNPL(log_alloc) = HeapAllocatorInit();                                                           \
            Str           UNPL(m)         = StrInit(&UNPL(log_alloc));                                                     \
            StrAppendFmt(&UNPL(m), __VA_ARGS__);                                                                           \
            LogWrite(LOG_MESSAGE_TYPE_FATAL, __func__, __LINE__, StrBegin(&UNPL(m)));                                      \
        do {                                                                                                               \
            HeapAllocator UNPL(log_alloc) = HeapAllocatorInit();                                                           \
            Str           UNPL(m)         = StrInit(&UNPL(log_alloc));                                                     \
            StrAppendFmt(&UNPL(m), __VA_ARGS__);                                                                           \
            LogWrite(LOG_MESSAGE_TYPE_ERROR, __func__, __LINE__, StrBegin(&UNPL(m)));                                      \
        do {                                                                                                               \
            HeapAllocator UNPL(log_alloc) = HeapAllocatorInit();                                                           \
            Str           UNPL(m)         = StrInit(&UNPL(log_alloc));                                                     \
            StrAppendFmt(&UNPL(m), __VA_ARGS__);                                                                           \
            LogWrite(LOG_MESSAGE_TYPE_INFO, __func__, __LINE__, StrBegin(&UNPL(m)));                                       \
            i32           UNPL(sys_eno)   = (i32)(eno);                                                                    \
            HeapAllocator UNPL(log_alloc) = HeapAllocatorInit();                                                           \
            Str           UNPL(m)         = StrInit(&UNPL(log_alloc));                                                     \
            StrAppendFmt(&UNPL(m), __VA_ARGS__);                                                                           \
            StrInitStack(UNPL(syserr), 256) {                                                                              \
            i32           UNPL(sys_eno)   = (i32)(eno);                                                                    \
            HeapAllocator UNPL(log_alloc) = HeapAllocatorInit();                                                           \
            Str           UNPL(m)         = StrInit(&UNPL(log_alloc));                                                     \
            StrAppendFmt(&UNPL(m), __VA_ARGS__);                                                                           \
            StrInitStack(UNPL(syserr), 256) {                                                                              \
            i32           UNPL(sys_eno)   = (i32)(eno);                                                                    \
            HeapAllocator UNPL(log_alloc) = HeapAllocatorInit();                                                           \
            Str           UNPL(m)         = StrInit(&UNPL(log_alloc));                                                     \
            StrAppendFmt(&UNPL(m), __VA_ARGS__);                                                                           \
            StrInitStack(UNPL(syserr), 256) {                                                                              \
    #define ProcReadFromStdoutFmt(p, ...)                                                                                  \
        do {                                                                                                               \
            Str UNPL(buf) = StrInit();                                                                                     \
            ProcReadFromStdout((p), &UNPL(buf));                                                                           \
            Zstr UNPL(in) = StrBegin(&UNPL(buf));                                                                          \
    #define ProcReadFromStderrFmt(p, ...)                                                                                  \
        do {                                                                                                               \
            Str UNPL(buf) = StrInit();                                                                                     \
            ProcReadFromStderr((p), &UNPL(buf));                                                                           \
            Zstr UNPL(in) = StrBegin(&UNPL(buf));                                                                          \
    #define ProcWriteToStdinFmt(p, ...)                                                                                    \
        do {                                                                                                               \
            Str UNPL(buf) = StrInit();                                                                                     \
            StrAppendFmt(&UNPL(buf), __VA_ARGS__);                                                                         \
            ProcWriteToStdin((p), &UNPL(buf));                                                                             \
    #define ProcWriteToStdinFmtLn(p, ...)                                                                                  \
        do {                                                                                                               \
            Str UNPL(buf) = StrInit();                                                                                     \
            StrAppendFmt(&UNPL(buf), __VA_ARGS__);                                                                         \
            StrPushBackR(&UNPL(buf), '\n');                                                                                 \
    #define JR_STR(si, str)                                                                                                \
        do {                                                                                                               \
            Str UNPL(my_str) = StrInit();                                                                                  \
            si               = JReadString((si), &UNPL(my_str));                                                           \
            (str)            = UNPL(my_str);                                                                               \
        do {                                                                                                               \
            if (!StrCmp(&key, (k))) {                                                                                      \
                Str UNPL(my_str) = StrInit();                                                                              \
                si               = JReadString((si), &UNPL(my_str));                                                       \
                (str)            = UNPL(my_str);                                                                           \
                                                                                                                           \
                                                                                                                           \
                Str key = StrInit();                                                                                       \
                                                                                                                           \
                /* key start */                                                                                            \
        // treats as a fatal arg violation. An empty source clones to an
        // empty fresh Str.
        Str copy = (StrLen(src) == 0) ? StrInit((Allocator *)alloc) :
                                        StrInitFromCstr(StrBegin(src), StrLen(src), (Allocator *)alloc);
        *(Str *)dst_ptr = copy;
    
        // Create Str with capacity
        Str str = StrInit(alloc);
    
        // Fill with data or generate simple pattern if not enough input
    
        HeapAllocator h    = HeapAllocatorInit();
        Str           full = StrInit(&h);
        StrAppendFmt(&full, "[{}] [{}:{}] {}\n", (Zstr)NAMES[type], (Zstr)tag, line, (Zstr)msg);
            StackFrame frames[32];
            size       n     = CaptureStackTrace(frames, 32, 1);
            Str        trace = StrInit(&h);
            // FormatStackTrace takes `Allocator *` -- legitimate erasure
            // boundary; pass at the call site, no intermediate variable.
    
        // Usage line: "usage: name [OPTIONS] --req <REQ>... <POS>..."
        Str usage = StrInit(self->alloc);
        StrPushBackMany(&usage, "usage: ");
        StrPushBackMany(&usage, self->name);
            n_specs = 64;
        for (u64 i = 0; i < n_specs; ++i) {
            left_col[i] = StrInit(self->alloc);
            left_w[i]   = spec_format_left(VecPtrAt(&self->specs, i), &left_col[i]);
            if (left_w[i] > max_w)
        // sense. Library-internal scratch keeps the debug-build instrumentation.
        DefaultAllocator scratch = DefaultAllocatorInit();
        Str              tmp     = StrInit(&scratch);
        bool             ok      = str_append_fmt(&tmp, fmt, args, argc);
        if (ok) {
        }
    
        out = StrInit(&scratch);
        ok  = str_append_fmt(&out, fmtstr, argv, argc);
        // DefaultAllocator: rendered size is caller-controlled (open-ended).
        DefaultAllocator scratch = DefaultAllocatorInit();
        Str              tmp     = StrInit(&scratch);
        bool             ok      = render_binary_fmt(&tmp, fmtstr, argv, argc);
        if (ok) {
        }
    
        Str buffer = StrInit(&scratch);
        i32 fd     = FileFd(file);
        }
    
        *out = StrInit(alloc);
    
        if (!float_try_to_str(&canonical, value, alloc)) {
            u64  frac   = 0;
    
            result = StrInit(alloc);
    
            if (StrBegin(&canonical)[0] == '-') {
        }
    
        *out = StrInit(alloc);
    
        if (!int_try_to_str(&digits, &value->significand, alloc)) {
        }
    
        result = StrInit(alloc);
    
        if (FloatIsZero(value)) {
        allocator_ptr = arg->allocator;
        previous      = *out;
        temp          = StrInit(allocator_ptr);
    
        default_fmt        = fmt_info ? *fmt_info :
        }
    
        temp   = StrInit(FloatAllocator(value));
        parsed = FloatInit(FloatAllocator(value));
        }
    
        *out = StrInit(alloc);
        if (len == 0) {
            return true;
    
    Str str_init_from_cstr(Zstr cstr, size len, Allocator *alloc) {
        Str result = StrInit(alloc);
    
        // Try-form leaves `result` empty-but-valid on OOM, so the caller
    
        MemSet(dst, 0, sizeof(Str));
        *dst             = StrInit(clone_allocator);
        dst->copy_init   = src->copy_init;
        dst->copy_deinit = src->copy_deinit;
        // Borrowed substring view: data points into the caller's bytes and
        // capacity stays 0 so StrToU64 never tries to grow it.
        Str temp_str      = StrInit(str->allocator);
        temp_str.data     = str->data + pos;
        temp_str.length   = str->length - pos;
    
        if (!int_try_to_str(&result, value, alloc)) {
            result = StrInit(alloc);
        }
        }
    
        *out = StrInit(alloc);
    
        if (!int_validate_radix(radix)) {
        }
    
        result = StrInit(alloc);
    
        // Extract digits in the largest radix^k chunk that still fits in a u64, so
    
        if (!int_try_to_str_radix(&result, value, radix, uppercase, alloc)) {
            result = StrInit(alloc);
        }
        ValidateFloat(out);
        result = FloatInit(FloatAllocator(out));
        digits = StrInit(FloatAllocator(out));
    
        if (pos < length && (text[pos] == '+' || text[pos] == '-')) {
        }
    
        *out = StrInit(alloc);
    
        if (FloatIsZero(value)) {
        }
    
        result = StrInit(alloc);
    
        if (value->negative) {
    
        if (!float_try_to_str(&result, value, alloc)) {
            result = StrInit(alloc);
        }
        }
    
        *out = StrInit(alloc);
        if (bv->length == 0) {
            return true;
            if (!StrPushBackR(out, bit_char)) {
                StrDeinit(out);
                *out = StrInit(alloc);
                return false;
            }
    
        if (!bitvec_try_to_str(&result, bv, alloc)) {
            result = StrInit(alloc);
        }
            return;
        }
        Str rendered = StrInit(meta);
    #if !defined(LOG_NO_BACKTRACE) || !LOG_NO_BACKTRACE
        FormatStackTrace(&rendered, frames, count, meta);
    // Returns true on success; `out` is populated with an opened Elf.
    static bool try_open_sidecar(Zstr main_path, const Elf *main, Elf *out, Allocator *alloc) {
        Str path = StrInit(alloc);
    
        // (1) Build-ID
    
        // (1) exact CodeView path
        *out_path = StrInit(StrAllocator(out_path));
        StrPushBackMany(out_path, cv->pdb_path);
        if (sys_path_exists(StrBegin(out_path)))
            return true;
    
        Str pdb_path = StrInit(alloc);
        if (!find_pdb(&entry->pe, StrBegin(&entry->module_path), &pdb_path)) {
            StrDeinit(&pdb_path);
    
    static void parse_hosts_path(HostsTable *table, Zstr path, Allocator *alloc) {
        Str buf = StrInit(alloc);
        if (!slurp_file(path, &buf)) {
            StrDeinit(&buf);
    
    static void parse_resolv_path(DnsAddrs *out, Zstr path, Allocator *alloc) {
        Str buf = StrInit(alloc);
        if (!slurp_file(path, &buf)) {
            StrDeinit(&buf);
        if (!self || !path)
            return false;
        Str buf = StrInit(self->allocator);
        StrPushBackMany(&buf, path, len);
        bool ok = dns_add_path(self, StrBegin(&buf), do_hosts, do_resolv);
    
    Str socket_addr_format(const SocketAddr *addr, Allocator *alloc) {
        Str out = StrInit(alloc);
        if (!addr || addr->length == 0) {
            return out;
        }
    
        Str path = StrInit(alloc);
        if (!compose_dsym_path(StrBegin(&e->module_path), &path)) {
            StrDeinit(&path);
        PROCESS_INFORMATION pi = {0};
    
        Str cmdline = StrInit(alloc);
        StrPushBackMany(&cmdline, filepath);
        for (char **arg = argv + 1; *arg; ++arg) {
        out->allocator   = alloc;
        out->entries     = VecInitT(out->entries, alloc);
        out->string_pool = StrInit(alloc);
    
        if (!info_bytes || info_size == 0)
    // Decode one resource record. Advances the iter past the record.
    static bool decode_record(BufIter *it, DnsRecord *rec, Allocator *alloc) {
        rec->name   = StrInit(alloc);
        rec->target = StrInit(alloc);
        rec->rdata  = VecInitT(rec->rdata, alloc);
    static bool decode_record(BufIter *it, DnsRecord *rec, Allocator *alloc) {
        rec->name   = StrInit(alloc);
        rec->target = StrInit(alloc);
        rec->rdata  = VecInitT(rec->rdata, alloc);
        MemSet(rec->ipv4, 0, sizeof(rec->ipv4));
        // Skip echoed question section: each question is qname + qtype(2) + qclass(2).
        for (u16 i = 0; i < qd; ++i) {
            Str dummy = StrInit(alloc);
            if (!decode_name(&it, &dummy)) {
                StrDeinit(&dummy);
        char c;
        while (StrIterPeek(&si, &c)) {
            Str     key   = StrInit(MapAllocator(cfg));
            Str     value = StrInit(MapAllocator(cfg));
            StrIter read_si;
        while (StrIterPeek(&si, &c)) {
            Str     key   = StrInit(MapAllocator(cfg));
            Str     value = StrInit(MapAllocator(cfg));
            StrIter read_si;
    
        if (!value) {
            return StrInit(MapAllocator(cfg));
        }
    
        if (!value) {
            return StrInit(MapAllocator(cfg));
        }
        out->data      = taken;
        out->functions = VecInitT(out->functions, BufAllocator(&taken));
        out->name_pool = StrInit(BufAllocator(&taken));
    
        u32 num_dir_bytes  = 0;
        }
        MemSet(out, 0, sizeof(*out));
        out->raw     = StrInit(alloc);
        out->entries = VecInitT(out->entries, alloc);
        }
        MemSet(out, 0, sizeof(*out));
        out->raw     = StrInit(alloc);
        out->entries = VecInitT(out->entries, alloc);
        if (!FileIsOpen(f)) {
        }
        MemSet(out, 0, sizeof(*out));
        out->raw     = StrInit(alloc);
        out->entries = VecInitT(out->entries, alloc);
        if (len) {
        const HttpHeader *src = (const HttpHeader *)src_ptr;
    
        dst->key   = StrInit((Allocator *)alloc);
        dst->value = StrInit((Allocator *)alloc);
    
        dst->key   = StrInit((Allocator *)alloc);
        dst->value = StrInit((Allocator *)alloc);
    
        if (!StrInitCopy(&dst->key, &src->key)) {
        Allocator *alloc   = req->allocator;
        Zstr       cursor  = in;
        Str        method  = StrInit(alloc);
        Str        version = StrInit(alloc);
        Zstr       cursor  = in;
        Str        method  = StrInit(alloc);
        Str        version = StrInit(alloc);
    
        StrReadFmt(cursor, "{} {} {}\r\n", method, req->url, version);
        response->content_type = content_type;
        StrDeinit(&response->body);
        response->body = StrInit(response->allocator);
        if (FileReadAndClose(filepath, &response->body) < 0) {
            LOG_ERROR("failed to read file: {}", filepath);
    
    Str http_response_serialize(const HttpResponse *response, Allocator *alloc) {
        Str out = StrInit(alloc);
    
        if (!response) {
                LOG_ERROR("HttpResponseSerialize: failed to append body");
                StrDeinit(&out);
                return StrInit(alloc);
            }
        }
            }
    
            Str key = StrInit(&scratch);
    
            // key start
        // stack-backed buffer is unsafe -- DefaultAllocator is the right fit.
        DefaultAllocator scratch = DefaultAllocatorInit();
        Str              ns      = StrInit(&scratch);
    
        bool is_neg = false;
            // valid input. DefaultAllocator is the right fit here.
            DefaultAllocator scratch = DefaultAllocatorInit();
            Str              s       = StrInit(&scratch);
            si                       = JReadString(si, &s);
            StrDeinit(&s);
        out->allocator   = alloc;
        out->entries     = VecInitT(out->entries, alloc);
        out->string_pool = StrInit(alloc);
    
        const ElfSection *line_section = ElfFindSection(elf, ".debug_line");
    static void log_request_summary(Zstr client_addr, Zstr prefix_bytes, size prefix_len) {
        Scope(scope, DefaultAllocator) {
            Str raw = StrInit(scope);
            StrPushBackMany(&raw, prefix_bytes);
        }
    
        Str body = StrInit(alloc_base);
        i64 got  = FileRead(&f, &body);
        FileClose(&f);
        }
    
        Str body = StrInit(alloc_base);
        i64 got  = FileRead(&f, &body);
        FileClose(&f);
        File r   = FileOpen(&path, "rb");
        ok       = ok && FileIsOpen(&r);
        Str body = StrInit(alloc_base);
        i64 got  = FileRead(&r, &body);
        FileClose(&r);
    
        File r    = FileOpen(&path, "rb");
        Str  body = StrInit(alloc_base);
        i64  got  = FileRead(&r, &body);
        FileClose(&r);
        bool ok    = (wrote == (i64)n);
    
        Str body = StrInit(alloc_base);
        i64 got  = FileReadAndClose(&path, &body);
        ok       = ok && (got == (i64)n) && (StrLen(&body) == (size)n) && ZstrCompare(StrBegin(&body), payload) == 0;
        FileRemove(&path);
    
        Str  body = StrInit(alloc_base);
        i64  got  = FileReadAndClose(&path, &body);
        bool ok   = (got == -1);
    
        // Confirm the write landed.
        Str  body = StrInit(alloc_base);
        File r    = FileOpen(&path, "rb");
        i64  got  = FileRead(&r, &body);
        FileClose(&owner);
    
        Str body = StrInit(alloc_base);
        i64 got  = FileReadAndClose(&path, &body);
        ok       = ok && (got == 10) && ZstrCompare(StrBegin(&body), "helloworld") == 0;
        ok = ok && (FileSeek(&f, 10, FILE_SEEK_SET) == 10);
    
        Str body = StrInit(alloc_base);
        i64 got  = FileRead(&f, &body);
        FileClose(&f);
        File f   = FileOpen(&path, "rb");
        ok       = ok && FileIsOpen(&f);
        Str body = StrInit(alloc_base);
        i64 got  = FileRead(&f, &body);
        FileClose(&f);
        bool ok    = (wrote == (i64)n);
    
        Str body = StrInit(alloc_base);
        i64 got  = FileReadAndClose(&path, &body);
        ok       = ok && (got == (i64)n) && (StrLen(&body) == (size)n) && ZstrCompare(StrBegin(&body), payload) == 0;
        ok        = ok && (wrote == 0);
    
        Str body = StrInit(alloc_base);
        i64 got  = FileReadAndClose(&path, &body);
        ok       = ok && (got == 0) && (StrLen(&body) == 0);
        ok        = ok && (wrote == 5);
    
        Str body = StrInit(alloc_base);
        i64 got  = FileReadAndClose(&path, &body);
        ok       = ok && (got == 5) && ZstrCompare(StrBegin(&body), "12345") == 0;
        FileClose(&seed);
    
        Str in = StrInit(alloc_base);
        StrAppendFmt(&in, "string-content");
        bool ok    = (wrote == (i64)StrLen(&in));
    
        Str body = StrInit(alloc_base);
        i64 got  = FileReadAndClose(&path, &body);
        ok       = ok && (got == (i64)StrLen(&in)) && ZstrCompare(StrBegin(&body), "string-content") == 0;
        FileClose(&f2);
    
        Str b1 = StrInit(alloc_base);
        Str b2 = StrInit(alloc_base);
        ok     = ok && (FileReadAndClose(&p1, &b1) == 3) && ZstrCompare(StrBegin(&b1), "one") == 0;
    
        Str b1 = StrInit(alloc_base);
        Str b2 = StrInit(alloc_base);
        ok     = ok && (FileReadAndClose(&p1, &b1) == 3) && ZstrCompare(StrBegin(&b1), "one") == 0;
        ok     = ok && (FileReadAndClose(&p2, &b2) == 6) && ZstrCompare(StrBegin(&b2), "twotwo") == 0;
    
        // The file was truncated to empty.
        Str body = StrInit(alloc_base);
        i64 got  = FileReadAndClose(&path, &body);
        ok       = ok && (got == 0) && (StrLen(&body) == 0);
        // counted as a leak by the very report we're about to generate.
        HeapAllocator scratch = HeapAllocatorInit();
        Str           out     = StrInit(&scratch);
        DebugAllocatorReportLeaks(&dbg, &out);
    
        HeapAllocator scratch = HeapAllocatorInit();
        Str           out     = StrInit(&scratch);
        DebugAllocatorReportLeaks(&dbg, &out);
    
        HeapAllocator scratch = HeapAllocatorInit();
        Str           out     = StrInit(&scratch);
        DebugAllocatorReportLeaks(&dbg, &out);
    
        HeapAllocator scratch = HeapAllocatorInit();
        Str           out     = StrInit(&scratch);
        DebugAllocatorReportLeaks(&dbg, &out);
    
        // Build the out-of-range marker "#N " that only the `<=` mutant emits.
        Str ns = StrInit(&scratch);
        StrAppendFmt(&ns, "#{} ", n);
        ArgParse         p = ArgParseInit("prog", NULL, &a);
    
        Str name = StrInit(&a);
        ArgOptional(&p, NULL, "--name", &name, "n");
    // ---------------------------------------------------------------------------
    static void capture_help(ArgParse *p, Str *out) {
        Str  tmp_path = StrInit(p->alloc);
        File tmp      = FileOpenTemp(&tmp_path, p->alloc);
        StrDeinit(&tmp_path);
    static bool help_equals(ArgParse *p, Zstr expected) {
        DefaultAllocator a   = DefaultAllocatorInit();
        Str              out = StrInit(&a);
        capture_help(p, &out);
        bool ok = (StrLen(&out) == ZstrLen(expected)) && (ZstrCompare(StrBegin(&out), expected) == 0);
    
        DefaultAllocator a2  = DefaultAllocatorInit();
        Str              out = StrInit(&a2);
        capture_help(&p, &out);
    // read it back into `out`. Returns true on a clean ARG_RUN_HELP capture.
    static bool capture_help_file(ArgParse *p, Str *out) {
        Str  tmp_path = StrInit(p->alloc);
        File tmp      = FileOpenTemp(&tmp_path, p->alloc);
        StrDeinit(&tmp_path);
        DefaultAllocator a    = DefaultAllocatorInit();
        ArgParse         p    = ArgParseInit("prog", NULL, &a);
        Str              name = StrInit(&a);
        StrPushBackMany(&name, "stale");
        ArgOptional(&p, NULL, "--name", &name, "n");
        Zstr             v = NULL;
        ArgRequired(&p, "-l", "--listen", &v, "addr");
        Str  help = StrInit(&a);
        bool got  = capture_help_file(&p, &help);
        bool ok   = got && str_contains(&help, "<LISTEN>");
        Zstr             v = NULL;
        ArgRequired(&p, NULL, "--read-only", &v, "mode");
        Str  help = StrInit(&a);
        bool got  = capture_help_file(&p, &help);
        bool ok   = got && str_contains(&help, "<READ_ONLY>");
        Zstr             v = NULL;
        ArgRequired(&p, NULL, "--port", &v, "p");
        Str  help = StrInit(&a);
        bool got  = capture_help_file(&p, &help);
        // The metavar is "<PORT>", never "<__PORT>".
        Zstr             v = NULL;
        ArgRequired(&p, "-x", NULL, &v, "x");
        Str  help = StrInit(&a);
        bool got  = capture_help_file(&p, &help);
        bool ok   = got && str_contains(&help, "<VALUE>");
        Zstr             v = NULL;
        ArgRequired(&p, NULL, "--ip6", &v, "x");
        Str  help = StrInit(&a);
        bool got  = capture_help_file(&p, &help);
        bool ok   = got && str_contains(&help, "<IP6>");
        Zstr             v = NULL;
        ArgRequired(&p, NULL, "--gzip", &v, "x");
        Str  help = StrInit(&a);
        bool got  = capture_help_file(&p, &help);
        // "gzip" -> "GZIP": the trailing 'z' in the middle must be upper.
        Zstr             v = NULL;
        ArgRequired(&p, NULL, "--abc", &v, "x");
        Str  help = StrInit(&a);
        bool got  = capture_help_file(&p, &help);
        bool ok   = got && str_contains(&help, "<ABC>");
        Zstr             s = NULL;
        ArgPositional(&p, "source", &s, "from");
        Str  help = StrInit(&a);
        bool got  = capture_help_file(&p, &help);
        bool ok   = got && str_contains(&help, "<source>");
        Zstr             v = NULL;
        ArgRequired(&p, "-l", "--listen", &v, "addr");
        Str  help = StrInit(&a);
        bool got  = capture_help_file(&p, &help);
        bool ok   = got && str_contains(&help, "-l, --listen");
        Zstr             v = NULL;
        ArgRequired(&p, "-l", "--listen", &v, "addr");
        Str  help = StrInit(&a);
        bool got  = capture_help_file(&p, &help);
        // Full left column for this spec: two-space indent, short, ", ",
        u32              t = 0;
        ArgOptional(&p, NULL, "--timeout", &t, "secs");
        Str  help = StrInit(&a);
        bool got  = capture_help_file(&p, &help);
        // No short form: rendered as four spaces then the long name.
        bool             f = false;
        ArgFlag(&p, "-v", "--verbose", &f, "v");
        Str  help = StrInit(&a);
        bool got  = capture_help_file(&p, &help);
        // The verbose flag must appear but with no "<VERBOSE>" metavar.
        ArgFlag(&p, "-a", "--a", &aa, "AAA");
        ArgRequired(&p, NULL, "--a-very-long-option-name", &bb, "BBB");
        Str  help = StrInit(&a);
        bool got  = capture_help_file(&p, &help);
        // The short flag "--a" help ("AAA") must be padded so it starts at
    // ---------------------------------------------------------------------------
    static ArgRun capture_run(ArgParse *p, int argc, char **argv, Str *out) {
        Str  tmp_path = StrInit(p->alloc);
        File tmp      = FileOpenTemp(&tmp_path, p->alloc);
        StrDeinit(&tmp_path);
    
        char  *argv[] = {(char *)"prog", (char *)"first", (char *)"extra"};
        Str    out    = StrInit(&a);
        ArgRun rc     = capture_run(&p, 3, argv, &out);
    
        char  *argv[] = {(char *)"prog"};
        Str    out    = StrInit(&a);
        ArgRun rc     = capture_run(&p, 1, argv, &out);
    
        char  *argv[] = {(char *)"prog", tok};
        Str    out    = StrInit(&a);
        ArgRun rc     = capture_run(&p, 2, argv, &out);
    static bool test_iso_write_utc(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
        DateTime         d     = DateTimeFromUnixNs(T_2021 * NS_PER_SEC, 0);
        StrAppendFmt(&s, "{}", d);
    static bool test_iso_write_offset(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
        DateTime         d     = DateTimeFromUnixNs(T_2021 * NS_PER_SEC, IST);
        StrAppendFmt(&s, "{}", d);
    static bool test_iso_write_nanos(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
        DateTime         d     = DateTimeFromUnixNs(T_2021 * NS_PER_SEC + 123456789ull, 0);
        StrAppendFmt(&s, "{}", d);
    static bool test_iso_io_roundtrip(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
        DateTime         a     = DateTimeFromUnixNs(T_2021 * NS_PER_SEC + 123456789ull, MST);
        StrAppendFmt(&s, "{}", a);
        Float f    = FloatInit(&alloc.base);
        bool  ok   = FloatTryFromStr(&f, "1E2");
        Str   text = StrInit(&alloc.base);
    
        text = FloatToStr(&f);
        Float b = FloatFromStr("0.1", &alloc.base); // exp -1
        Float r = FloatInit(&alloc.base);
        Str   t = StrInit(&alloc.base);
    
        FloatAdd(&r, &a, &b);
        Float z = FloatFromStr("0", &alloc.base);    // exp 0, zero
        Float r = FloatInit(&alloc.base);
        Str   t = StrInit(&alloc.base);
    
        FloatAdd(&r, &a, &z);
    
        Float value = FloatFromStr("12.5", &alloc.base);
        Str   text  = StrInit(&alloc.base);
    
        FloatNegate(&value);
        Float b            = FloatFromStr("0.03", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatAdd(&result_value, &a, &b);
        Float b            = FloatFromStr(FLOAT_TEST_VERY_LARGE_TWOS, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatAdd(&result_value, &a, &b);
        Int   whole        = IntFrom(2, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatAdd(&result_value, &a, &b);
        Float b            = FloatFromStr("2", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatSub(&result_value, &a, &b);
        Float b            = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatSub(&result_value, &a, &b);
        Int   whole        = IntFrom(2, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatSub(&result_value, &a, &b);
        Float b            = FloatFromStr("-0.2", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatMul(&result_value, &a, &b);
        Float b            = FloatFromStr("2", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatMul(&result_value, &a, &b);
        Int   whole        = IntFrom(2, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatMul(&result_value, &a, &b);
        Float b            = FloatFromStr("8", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatDiv(&result_value, &a, &b, 3);
        Float b            = FloatFromStr("2", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatDiv(&result_value, &a, &b, 0);
        Int   whole        = IntFrom(3, &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatDiv(&result_value, &a, &b, 1);
        Float b            = FloatFromStr("5", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatAdd(&result_value, &a, &b);
        Float b            = FloatFromStr("-5", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatAdd(&result_value, &a, &b);
        Float b            = FloatFromStr("1.00", &alloc.base);
        Float result_value = FloatInit(&alloc.base);
        Str   text         = StrInit(&alloc.base);
    
        FloatAdd(&result_value, &a, &b);
        Float f    = FloatInit(&alloc.base);
        bool  ok   = FloatTryFromStr(&f, "+5");
        Str   text = StrInit(&alloc.base);
    
        text = FloatToStr(&f);
        Float f    = FloatInit(&alloc.base);
        bool  ok   = FloatTryFromStr(&f, "19");
        Str   text = StrInit(&alloc.base);
    
        text = FloatToStr(&f);
        Float b        = FloatFromStr("3", &alloc.base);
        Float quotient = FloatInit(&alloc.base);
        Str   text     = StrInit(&alloc.base);
    
        bool ok     = FloatDiv(&quotient, &a, &b, 8);
        Float value        = FloatFromStr("1234500e-2", ALLOCATOR_OF(&alloc));
        Int   result_value = IntInit(ALLOCATOR_OF(&alloc));
        Str   text         = StrInit(ALLOCATOR_OF(&alloc));
    
        bool result = FloatToInt(&result_value, &value);
    
        Float v   = FloatFromStr("12.5", &dbg.base);
        Str   out = StrInit(&dbg.base);
    
        bool ok = FloatTryToStr(&out, &v);
    
        Float v   = FloatFromStr("1200", &dbg.base); // exponent >= 0 arm
        Str   out = StrInit(&dbg.base);
    
        bool ok = FloatTryToStr(&out, &v);
    
        // Pattern "101" as a Str on a separate (untracked) allocator.
        Str pattern = StrInit(pbase);
        StrPushBackR(&pattern, '1');
        StrPushBackR(&pattern, '0');
        Int b            = IntFrom(1, &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Str text         = StrInit(&alloc.base);
    
        IntAdd(&result_value, &a, &b);
        Int result_value = IntInit(&alloc.base);
        Int huge         = IntFromStr("123456789012345678901234567890", &alloc.base);
        Str text         = StrInit(&alloc.base);
    
        IntAdd(&result_value, &base, &rhs);
        Int preserved    = IntFrom(99, &alloc.base);
        Int huge         = IntFromStr("12345678901234567890", &alloc.base);
        Str text         = StrInit(&alloc.base);
    
        bool result = IntSub(&result_value, &base, &rhs);
        Int value        = IntFromStr("12345678901234567890", &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Str text         = StrInit(&alloc.base);
    
        IntMul(&result_value, &value, 25u);
        Int exponent     = IntFrom(20, &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Str text         = StrInit(&alloc.base);
    
        IntPow(&result_value, &base, 20u);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Str qtext     = StrInit(&alloc.base);
    
        IntDivMod(&quotient, &remainder, &dividend, 97u);
        Int dividend     = IntFromStr("12345678901234567890", &alloc.base);
        Int result_value = IntInit(&alloc.base);
        Str text         = StrInit(&alloc.base);
    
        bool result = IntDivExact(&result_value, &dividend, 90u);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Str text      = StrInit(&alloc.base);
    
        IntDivMod(&quotient, &remainder, &dividend, 97);
        Int value = IntFromStr("1000000000", &alloc.base);
        Int next  = IntInit(&alloc.base);
        Str text  = StrInit(&alloc.base);
    
        bool ok = IntNextPrime(&next, &value);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Str qtext     = StrInit(&alloc.base);
    
        bool ok = int_div_mod_u64(&quotient, &remainder, &dividend, 97u);
        Int quotient  = IntInit(&alloc.base);
        Int remainder = IntInit(&alloc.base);
        Str qtext     = StrInit(&alloc.base);
    
        bool ok = int_div_mod_i64(&quotient, &remainder, &dividend, (i64)13);
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        Point2D p  = {.x = 3, .y = 4};
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        Point2D p     = {.x = -1, .y = 2};
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        Point2D src = {.x = 100, .y = -200};
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        Bounds b = {
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        Bounds src = {
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        Region r = {
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        Region src = {
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        Region region = {
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  output  = StrInit(&alloc);
        bool success = true;
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str   output  = StrInit(&alloc);
        bool  success = true;
        Float exact   = FloatFromStr("1234567890.012345", alloc_base);
    bool test_str_write_fmt_clears(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
        StrAppendFmt(&s, "old prefix ");
        StrWriteFmt(&s, "fresh {}", LVAL(42));
    bool test_str_patch_fmt(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
        StrAppendFmt(&s, "AAAAAAAA");
        size before_length = StrLen(&s);
    
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
        Buf              b      = BufInit(&alloc);
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    bool test_datetime_iso_write(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
        bool             ok    = true;
        u64              base  = 1609459200ull * 1000000000ull; // 2021-01-01T00:00:00Z
        bool             ok    = false;
        if (FileIsOpen(&f)) {
            Str back = StrInit(&alloc);
            FileRead(&f, &back);
            ok = (ZstrCompare(StrBegin(&back), expect) == 0);
        Zstr in = "\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"";
    
        Str  s   = StrInit(&alloc);
        Zstr out = READ1(in, "{s}", TO_TYPE_SPECIFIC_IO(Str, &s));
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
        bool ok     = true;
    
        Str s = StrInit(&alloc);
        StrPushBackR(&s, (char)0x0F); // single byte 0x0F -> "f"
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
        bool ok     = true;
    
        Str s = StrInit(&alloc);
        StrPushBackR(&s, (char)0x0F);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
        bool ok     = true;
    
        Str s = StrInit(&alloc);
        StrPushBackR(&s, (char)0x01);
        StrPushBackR(&s, (char)0x02);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
        bool ok     = true;
    
        Str s = StrInit(&alloc);
        StrPushBackR(&s, (char)0x05);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
    static bool test_m13_zstr_hex_multibyte(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        Zstr s = "AB"; // 0x41 0x42
    static bool test_m13_zstr_hex_single_byte(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        Zstr s = "Z"; // 0x5a
    static bool test_m13_zstr_hex_lowercase_letters(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        Zstr s = "\xab"; // single byte 0xab
    static bool test_m13_zstr_hex_uppercase_letters(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        Zstr s = "\xab";
    static bool test_m13_zstr_hex_zero_pad_nibble(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        Zstr s = "\x05"; // single byte 0x05
    static bool test_m13_zstr_hex_no_pad_two_digits(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        Zstr s = "\xfe";
    static bool test_m13_zstr_precision_truncate(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        Zstr s = "Hello";
    static bool test_m13_zstr_precision_longer_noop(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        Zstr s = "Hi";
    static bool test_m13_zstr_precision_zero_empty(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        Zstr s = "Hello";
    static bool test_m13_zstr_precision_one(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        Zstr s = "Hello";
    static bool test_m13_zstr_pad_after_prefix(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        Zstr s = "Hi";
    static bool test_m13_zstr_left_pad_after_prefix(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        Zstr s = "Hi";
    static bool test_m13_zstr_empty_padded(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        Zstr s = "";
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str   output = StrInit(&alloc);
        bool  ok     = true;
        Float v      = FloatFromStr("1.0", alloc_base);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str   output = StrInit(&alloc);
        bool  ok     = true;
        Float v      = FloatFromStr("0.0", alloc_base);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str   output = StrInit(&alloc);
        bool  ok     = true;
        Float v      = FloatFromStr("0.0", alloc_base);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str   output = StrInit(&alloc);
        bool  ok     = true;
        Float v      = FloatFromStr("12.0", alloc_base);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str   output = StrInit(&alloc);
        bool  ok     = true;
        Float v      = FloatFromStr("12345.67", alloc_base);
    static bool test_m24_zero_pad_positive_exact(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m24_zero_pad_width_equals_content_no_pad(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m24_zero_pad_negative_sign_kept_ahead(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m24_zero_pad_positive_no_sign_shift(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m24_zero_pad_negative_wide(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m24_zero_pad_hex_width16_exact(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  output = StrInit(&alloc);
        bool ok     = true;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str   out = StrInit(&alloc);
        Float v   = FloatFromStr("1.0", &alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str   out = StrInit(&alloc);
        Float v   = FloatFromStr("0.001", &alloc.base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str   out = StrInit(&alloc);
        Float v   = FloatFromStr("1e12", &alloc.base);
    static bool test_m28_i64_hex_lower(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        i64 v = 255; // 0xff
    static bool test_m28_i64_hex_upper(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        i64 v = 255;
    static bool test_m28_i64_binary(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        i64 v = 5; // 0b101
    static bool test_m28_i64_octal(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        i64 v = 8; // 0o10
    static bool test_m28_i64_decimal_negative(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        i64 v = -42;
    static bool test_m28_i64_width_after_prefix(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        i64 v = 42;
    static bool test_m28_i64_zeropad_after_prefix(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        i64 v = 42;
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  output  = StrInit(&alloc);
        Int  a       = IntFrom(0x41, alloc_base); // 'A'
        bool success = true;
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  output  = StrInit(&alloc);
        Int  a       = IntFrom(0x7a, alloc_base); // 'z'
        bool success = true;
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  output  = StrInit(&alloc);
        Int  seven   = IntFrom(7, alloc_base);
        bool success = true;
    static bool test_m3_unclosed_brace_fails(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        i32  v  = 5;
    static bool test_m3_raw_u8(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        u8   v  = 200;
    static bool test_m3_raw_u16(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        u16  v  = 258;
    static bool test_m3_raw_u32(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        u32  v  = 65538;
    static bool test_m3_raw_u64(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        u64  v  = 4294967298ULL;
    static bool test_m3_raw_i64(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        i64  v  = 4294967298LL;
    static bool test_m3_raw_f64(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        f64  v  = 1.5;
    static bool test_m30_u64_width_pad_with_prefix(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m30_u64_width_pad_no_prefix(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m30_u64_zero_pad_with_prefix(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
        Str              out        = StrInit(&alloc);
        Float            v          = FloatFromStr("12345.67", alloc_base);
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
        Str              out        = StrInit(&alloc);
        Float            v          = FloatFromStr("12345.67", alloc_base);
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
        Str              out        = StrInit(&alloc);
        Float            v          = FloatFromStr("1.2", alloc_base);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str    out = StrInit(&alloc);
        BitVec bv  = BitVecFromStr("1", alloc_base);
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
        Str              output     = StrInit(&alloc);
    
        Zstr name = "hello";
    static bool test_m33_i8_char_emits(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        i8 v = (i8)'Q';
    static bool test_m33_f32_char_emits_four_bytes(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        // Choose a bit pattern whose 4 bytes are all printable: 0x42434445 -> "BCDE".
    bool test_if_1230_hex_low_nibble_digit_selection(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
        // write_int_as_chars path instead), so render a Str holding the byte 0x1A.
        // 0x1A: hi nibble 0x01 (<10 -> '1'), low nibble 0x0A (>=10 -> 'a') => "\x1a".
        Str src = StrInit(&alloc);
        StrPushBackR(&src, 0x1A);
        StrAppendFmt(&out, "{c}", src);
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
        Str              out        = StrInit(&alloc);
        bool             ok         = true;
    bool test_if_238_zero_pad_exact_width_boundary(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    bool test_if_257_space_pad_exact_width_boundary(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    bool test_if_514_patch_fmt_behaviour(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
        bool             ok    = true;
    bool test_if_1703_str_zero_width_no_pad(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    bool test_if_2067_f64_default_and_explicit_precision(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m4_seekable_position_advance(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              path  = StrInit(&alloc);
        File             f     = m4_make_temp(&alloc, &path, "42 zzzzzzz", 10);
        bool             ok    = FileIsOpen(&f);
    static bool test_m4_cur_pos_from_probe(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              path  = StrInit(&alloc);
        File             f     = m4_make_temp(&alloc, &path, "7", 1);
        bool             ok    = FileIsOpen(&f);
    static bool test_m4_consumed_offset_exact(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              path  = StrInit(&alloc);
        File             f     = m4_make_temp(&alloc, &path, "53 and more text", 16);
        bool             ok    = FileIsOpen(&f);
    static bool test_m8_zero_pad_width5(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m8_zero_pad_width7_double_zero(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m8_zero_pad_width9(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m8_width9_space_pad(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m8_precision9_string(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    #define DBG_BEGIN(dbg, out)                                                                                            \
        DebugAllocator dbg = DebugAllocatorInit();                                                                         \
        Str            out = StrInit(&dbg)
    
    #define LEAK_CFG                                                                                                       \
        DebugAllocator dbg  = DebugAllocatorInitWith(LEAK_CFG);                                                            \
        Allocator     *adbg = ALLOCATOR_OF(&dbg);                                                                          \
        Str            out  = StrInit(adbg);                                                                               \
        bool           ok   = true
    static bool test_pfs_zero_pad_detect(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        u32              v     = 7;
        StrAppendFmt(&out, "{05}", v);
    static bool test_pfs_width_parse(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        Zstr             s     = "ab";
        StrAppendFmt(&out, "{4}", s);
    static bool test_pfs_precision_parse(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        f64              v     = 3.14159;
        StrAppendFmt(&out, "{.2}", v);
    static bool test_pfs_dot_no_digit_rejected(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        StrAppendFmt(&out, "literal");
        i32  v  = 5;
    static bool test_pad_zeros_signed(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        i32              v     = -7;
        StrAppendFmt(&out, "{05}", v);
    static bool test_pad_zeros_exact_and_under(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        u32              v     = 123;
        StrAppendFmt(&out, "{03}", v);
    static bool test_strpad_exact_and_under(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        Zstr             s     = "abc";
        StrAppendFmt(&out, "{3}", s);
    static bool test_brace_escape_open(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        StrAppendFmt(&out, "a{​{b");
        bool ok = (ZstrCompare(StrBegin(&out), "a{b") == 0);
    static bool test_brace_escape_close(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        StrAppendFmt(&out, "a}}b");
        bool ok = (ZstrCompare(StrBegin(&out), "a}b") == 0);
    static bool test_brace_scan_close(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        u32              v     = 0xAB;
        StrAppendFmt(&out, "{x}", v);
    static bool test_raw_write_u16_value(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        u16              v     = 0x1234; // 4660
        bool             rc    = StrAppendFmt(&out, "{<2r}", v);
    static bool test_raw_write_u64_value(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        u64              v     = 0x0102030405060708ULL; // 72623859790382856
        bool             rc    = StrAppendFmt(&out, "{>8r}", v);
    static bool test_fwrite_roundtrip(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              path  = StrInit(&alloc);
        File             f     = FileOpenTemp(&path, &alloc);
        bool             ok    = FileIsOpen(&f);
            File r = FileOpen(StrBegin(&path), "r");
            if (FileIsOpen(&r)) {
                Str back = StrInit(&alloc);
                FileRead(&r, &back);
                ok = ok && (ZstrCompare(StrBegin(&back), "n=42\n") == 0);
    static bool test_fwrite_empty_skipped(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              path  = StrInit(&alloc);
        File             f     = FileOpenTemp(&path, &alloc);
        bool             ok    = FileIsOpen(&f);
            File r = FileOpen(StrBegin(&path), "r");
            if (FileIsOpen(&r)) {
                Str back = StrInit(&alloc);
                FileRead(&r, &back);
                ok = ok && (ZstrCompare(StrBegin(&back), "X") == 0);
    static bool test_str_hex_no_leak(void) {
        DBG_BEGIN(dbg, out);
        Str s = StrInit(&dbg);
        StrPushBackR(&s, (char)0x01);
        StrPushBackR(&s, (char)0x4F); // multi-digit so StrLen(&hex)!=1 path
    static bool test_str_hex_nibble_no_leak(void) {
        DBG_BEGIN(dbg, out);
        Str s = StrInit(&dbg);
        StrPushBackR(&s, (char)0x05);
        StrAppendFmt(&out, "{x}", s);
    static bool test_str_width_gate(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        Str              s     = StrInitFromZstr("hi", &alloc);
        StrAppendFmt(&out, "{}", s); // width 0 default
    static bool test_zstr_width_gate(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        Zstr             s     = "hi";
        StrAppendFmt(&out, "{}", s);
    static bool test_u64_width_gate(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        u64              v     = 42;
        StrAppendFmt(&out, "{}", v);
    static bool test_i64_width_gate(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        i64              v     = -42;
        StrAppendFmt(&out, "{}", v);
    static bool test_f64_char_bytes(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        // Build a double whose 8 BE bytes are all printable ASCII: "ABCDEFGH".
        f64 v;
    static bool test_f64_inf_sign(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        f64              ninf  = -F64_INFINITY;
        StrAppendFmt(&out, "{}", ninf);
    static bool test_f64_default_precision(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        f64              v     = 1.5;
        StrAppendFmt(&out, "{}", v);
    static bool test_f64_width_gate(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        f64              v     = 1.5;
        StrAppendFmt(&out, "{.1}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("12345.67", ab);
        StrAppendFmt(&out, "{e}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("1.0", ab);
        StrAppendFmt(&out, "{e}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("2.0", ab);
        StrAppendFmt(&out, "{e}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("3.14159", ab);
        StrAppendFmt(&out, "{.2}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("5", ab);
        StrAppendFmt(&out, "{.3}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("1.5", ab);
        StrAppendFmt(&out, "{}", v);
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Float            v     = FloatFromStr("1.5", ab);
        StrAppendFmt(&out, "AB");
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        BitVec           bv    = BitVecFromStr("101", ab);
        StrAppendFmt(&out, "{}", bv);
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *ab    = ALLOCATOR_OF(&alloc);
        Str              out   = StrInit(&alloc);
        Int              v     = IntFrom(42, ab);
        StrAppendFmt(&out, "{}", v);
    bool test_leak_write_str_hex_per_byte_freed(void) {
        HeapAllocator sa = HeapAllocatorInit();
        Str           s  = StrInit(ALLOCATOR_OF(&sa));
        for (int i = 0; i < 8; ++i)
            StrPushBackR(&s, (char)0xAB);
            StrPushBackR(&s, (char)0xAB);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Str            out = StrInit(ALLOCATOR_OF(&dbg));
        bool           ok  = StrAppendFmt(&out, "{x}", s) && (StrLen(&out) > 0);
        StrDeinit(&out);
        Float         v  = FloatFromStr("12345.67", ALLOCATOR_OF(&fa));
    
        Str  out = StrInit(adbg);
        bool ok  = StrAppendFmt(&out, "{e}", v);
        ok       = ok && (StrLen(&out) > 0);
        Float         v  = FloatFromStr("0.0", ALLOCATOR_OF(&fa));
    
        Str  out = StrInit(adbg);
        bool ok  = StrAppendFmt(&out, "{.3e}", v);
        ok       = ok && (StrLen(&out) > 0);
        Float         v  = FloatFromStr("3.14159", ALLOCATOR_OF(&fa));
    
        Str  out = StrInit(adbg);
        bool ok  = StrAppendFmt(&out, "{.2}", v);
        ok       = ok && (StrLen(&out) > 0);
        Float         v  = FloatFromStr("42", ALLOCATOR_OF(&fa));
    
        Str  out = StrInit(adbg);
        bool ok  = StrAppendFmt(&out, "{.2}", v);
        ok       = ok && (StrLen(&out) > 0);
    
        Zstr s   = "AB"; // multi-byte Zstr -> hex loop runs per byte
        Str  out = StrInit(adbg);
        bool ok  = StrAppendFmt(&out, "{x}", s);
        ok       = ok && (StrLen(&out) > 0);
    
        i32  v   = -123456;
        Str  out = StrInit(adbg);
        bool ok  = StrAppendFmt(&out, "{}", v);
        ok       = ok && (StrLen(&out) > 0);
    bool test_leak_write_str_freed(void) {
        HeapAllocator va = HeapAllocatorInit();
        Str           s  = StrInit(ALLOCATOR_OF(&va));
        StrAppendFmt(&s, "payload");
        LEAK_WRITE_PRELUDE();
        bool success = true;
    
        Str s = StrInit(&alloc);
        z     = "Hello";
        StrReadFmt(z, "{}", s);
    
        i32 num  = 0;
        Str name = StrInit(&alloc);
        z        = "Count: 42, Name: Alice";
        StrReadFmt(z, "Count: {}, Name: {}", num, name);
        success = success && abc_pass;
    
        Str str_val = StrInit(&alloc);
        z           = "Hello";
        StrReadFmt(z, "{c}", str_val);
        StrDeinit(&str_val);
    
        str_val = StrInit(&alloc);
        z       = "\"World\"";
        StrReadFmt(z, "{cs}", str_val);
        // Test 1: :a (lowercase) conversion
        {
            Str  result = StrInit(&alloc);
            Zstr in     = "Hello World";
        // Test 1.1: :a (lowercase) conversion
        {
            Str  result = StrInit(&alloc);
            Zstr in     = "Hello World";
        // Test 2: :A (uppercase) conversion
        {
            Str  result = StrInit(&alloc);
            Zstr in     = "hello world";
        // Test 2.1: :A (uppercase) conversion
        {
            Str  result1 = StrInit(&alloc);
            Str  result2 = StrInit(&alloc);
            Zstr in      = "hello world";
        {
            Str  result1 = StrInit(&alloc);
            Str  result2 = StrInit(&alloc);
            Zstr in      = "hello world";
        // Test 2.2: :A (uppercase) conversion
        {
            Str  result1 = StrInit(&alloc);
            Str  result2 = StrInit(&alloc);
            Zstr in      = "hello world mighty misra";
        {
            Str  result1 = StrInit(&alloc);
            Str  result2 = StrInit(&alloc);
            Zstr in      = "hello world mighty misra";
        // Test 3: :a with quoted string
        {
            Str  result = StrInit(&alloc);
            Zstr in     = "\"MiXeD CaSe\"";
        // Test 4: :A with quoted string containing special characters
        {
            Str  result = StrInit(&alloc);
            Zstr in     = "\"abc123XYZ\"";
        // Test 5: Regular :c format (no case conversion) for comparison
        {
            Str  result = StrInit(&alloc);
            Zstr in     = "Hello World";
        Int oct = IntInit(alloc_base);
    
        Str dec_text = StrInit(&alloc);
        Str hex_text = StrInit(&alloc);
        Str bin_text = StrInit(&alloc);
    
        Str dec_text = StrInit(&alloc);
        Str hex_text = StrInit(&alloc);
        Str bin_text = StrInit(&alloc);
        Str oct_text = StrInit(&alloc);
        Str dec_text = StrInit(&alloc);
        Str hex_text = StrInit(&alloc);
        Str bin_text = StrInit(&alloc);
        Str oct_text = StrInit(&alloc);
        Str hex_text = StrInit(&alloc);
        Str bin_text = StrInit(&alloc);
        Str oct_text = StrInit(&alloc);
    
        z = "123456789012345678901234567890";
        Float neg = FloatInit(alloc_base);
    
        Str dec_text = StrInit(&alloc);
        Str sci_text = StrInit(&alloc);
        Str neg_text = StrInit(&alloc);
    
        Str dec_text = StrInit(&alloc);
        Str sci_text = StrInit(&alloc);
        Str neg_text = StrInit(&alloc);
        Str dec_text = StrInit(&alloc);
        Str sci_text = StrInit(&alloc);
        Str neg_text = StrInit(&alloc);
    
        z = "1234567890.012345";
    static bool test_m3_double_close_brace_escape(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
    
        bool ok = StrAppendFmt(&out, "}}");
    static bool test_m33_char_hex_escape_nibbles(void) {
        DefaultAllocator alloc  = DefaultAllocatorInit();
        Str              output = StrInit(&alloc);
    
        u16 v = (u16)0x1AE0; // big-endian bytes: 0x1A, 0xE0
    static bool test_m4_end_pos_sizes_full_read(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              path  = StrInit(&alloc);
    
        // 50 leading spaces, then the number well past byte index 42.
    static bool test_m4_empty_file_no_parse(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              path  = StrInit(&alloc);
        File             f     = m4_make_temp(&alloc, &path, "", 0);
        bool             ok    = FileIsOpen(&f);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  s = StrInit(&alloc);
        Zstr z = "\\x41BC"; // backslash, x, 4, 1, B, C  ->  'A', 'B', 'C'
        StrReadFmt(z, "{}", s);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  s = StrInit(&alloc);
        Zstr z = "\\x41"; // -> 'A'
        StrReadFmt(z, "{}", s);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  s = StrInit(&alloc);
        Zstr z = "\\x61";                             // -> 'a'
        StrReadFmt(z, "{A}", s);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str s = StrInit(&alloc);
        // "\x41BC" inside double quotes -> decoded "ABC"
        Zstr z = "\"\\x41BC\"";
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  s = StrInit(&alloc);
        Zstr z = "\"\\x41\""; // quoted -> 'A'
        StrReadFmt(z, "{s}", s);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str  s = StrInit(&alloc);
        Zstr z = "\"\\x61\"";                         // quoted -> 'a'
        StrReadFmt(z, "{As}", s);
    static bool test_m9_escape_both_digit_nibbles(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m9_escape_high_digit_nonzero(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m9_escape_letter_boundary_lowercase(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m9_escape_letter_above_boundary_lowercase(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m9_escape_letter_boundary_uppercase(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m9_escape_letter_above_boundary_uppercase(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_m9_escape_mixed_nibbles(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              out   = StrInit(&alloc);
        bool             ok    = true;
    static bool test_read_escape_budget_anchor(void) {
        DefaultAllocator a   = DefaultAllocatorInit();
        Str              out = StrInit(ALLOCATOR_OF(&a));
        Zstr             p   = "\\n\\n#rest";
        StrReadFmt(p, "{}#", out);
    static bool test_read_long_string_no_cap(void) {
        DefaultAllocator a   = DefaultAllocatorInit();
        Str              out = StrInit(ALLOCATOR_OF(&a));
        // Quoted string of 50 chars: max_read_len (= rem_in) must allow the full
        // read; the `max_read_len = rem_in` survivor would cap it at 42.
        DefaultAllocator alloc = DefaultAllocatorInit();
        Zstr             in    = "\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\""; // 50 A's quoted
        Str              s     = StrInit(&alloc);
        Zstr             out   = READ1(in, "{s}", TO_TYPE_SPECIFIC_IO(Str, &s));
        bool             ok    = (out != NULL) && (StrLen(&s) == 50);
    static bool test_fread_seekable(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              path  = StrInit(&alloc);
        File             f     = FileOpenTemp(&path, &alloc);
        bool             ok    = FileIsOpen(&f);
    static bool test_fread_rollback(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              path  = StrInit(&alloc);
        File             f     = FileOpenTemp(&path, &alloc);
        bool             ok    = FileIsOpen(&f);
    static bool leak_quoted_unterminated(Zstr input, Zstr fmt) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Str            s   = StrInit(ALLOCATOR_OF(&dbg));
        Zstr           p   = input;
        StrReadFmt(p, fmt, s); // reader frees s on the unterminated/error branch
    bool test_leak_read_unquoted_bad_escape_freed(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Str            s   = StrInit(ALLOCATOR_OF(&dbg));
        Zstr           p   = "aaaaaaaaaaaaaaaaaaaaaaaa\\q"; // 24 'a' + invalid \q
        StrReadFmt(p, "{}", s);
    
    
        Str s = StrInit(&alloc);
    
        // Reserve more space than needed
    
    
        Str s = StrInit(&alloc);
    
        // Reserve more space
        // Test with an empty string
        StrDeinit(&s);
        s = StrInit(&alloc);
    
        // Reverse the string
    // Test StrInit function
    bool test_str_init(void) {
        WriteFmt("Testing StrInit\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str s = StrInit(&alloc);
    
        // Validate the string
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str s = StrInit(&alloc);
        StrAppendFmt(&s, "Hello, {}!", &"World"[0]);
    
        Str src = StrInitFromZstr("Hello, World!", &alloc);
        Str dst = StrInit(&alloc);
    
        // Copy src to dst
    
        Str  dup    = StrInitFromStr(&src, &alloc);
        Str  dst    = StrInit(&alloc);
        bool copied = StrInitCopy(&dst, &src);
        src.__magic = 0;
    
        Str dst = StrInit(&alloc);
        (void)StrInitCopy(&dst, &src); // ValidateStr(src) must abort on real code
    
        // Create a Str object
        Str s = StrInit(&alloc);
    
        // Check that it behaves like a Vec of chars
    
        // Create a valid Str
        Str s = StrInit(&alloc);
    
        // This should not crash
    
        // Create an invalid Str by corrupting its fields
        Str s = StrInit(&alloc);
    
        // Corrupt the string to make it invalid
    
    
        Str s = StrInit(&alloc);
    
        // Test decimal conversion
    
    
        Str s = StrInit(&alloc);
    
        // Test positive decimal conversion
    
    
        Str s = StrInit(&alloc);
    
        // Test integer conversion
    
        for (size i = 0; i < sizeof(u64_values) / sizeof(u64_values[0]); i++) {
            Str s = StrInit(&alloc);
    
            // Test decimal round-trip
    
        for (size i = 0; i < sizeof(i64_values) / sizeof(i64_values[0]); i++) {
            Str s = StrInit(&alloc);
    
            // Test decimal round-trip
        for (size i = 0; i < sizeof(f64_values) / sizeof(f64_values[0]); i++) {
            for (u8 precision = 1; precision <= 6; precision++) {
                Str s = StrInit(&alloc);
    
                StrFloatFormat config = {.precision = precision, .force_sci = false, .uppercase = false};
        // Test base boundary conditions
        for (u8 base = 2; base <= 36; base++) {
            Str s = StrInit(&alloc);
    
            // Test with base value itself
    
        // Test extreme values
        Str s = StrInit(&alloc);
    
        // Test maximum u64
    
        for (u8 precision = 1; precision <= 17; precision++) {
            Str s = StrInit(&alloc);
    
            StrFloatFormat config = {.precision = precision, .force_sci = false, .uppercase = false};
    
        for (size i = 0; i < sizeof(sci_values) / sizeof(sci_values[0]); i++) {
            Str s = StrInit(&alloc);
    
            // Force scientific notation
    
        for (u8 base = 2; base <= 36; base++) {
            Str s = StrInit(&alloc);
    
            StrIntFormat config = {.base = base, .uppercase = false};
        // Test each base from 2 to 36
        for (u8 base = 2; base <= 36; base++) {
            Str s = StrInit(&alloc);
    
            // Test StrFromU64
        // Test uppercase digits for bases that use letters (11-36)
        for (u8 base = 11; base <= 36; base++) {
            Str s = StrInit(&alloc);
    
            StrIntFormat config = {.base = base, .uppercase = true, .use_prefix = false};
        for (size i = 0; i < sizeof(test_values) / sizeof(test_values[0]); i++) {
            for (u8 base = 2; base <= 36; base++) {
                Str s = StrInit(&alloc);
    
                StrIntFormat config = {.base = base, .uppercase = false, .use_prefix = false};
            u64 test_value = i * 1000007; // Large prime multiplier
    
            Str          s      = StrInit(&alloc);
            StrIntFormat config = {.base = 10, .uppercase = false};
            StrFromU64(&s, test_value, &config);
                f64 test_value = mantissa * F64Pow((10.0), (i32)(exp));
    
                Str            s      = StrInit(&alloc);
                StrFloatFormat config = {.precision = 6, .force_sci = false, .uppercase = false};
                StrFromF64(&s, test_value, &config);
        WriteFmt("Testing StrFromF64 NaN emits exactly 3 bytes\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
    
        StrFloatFormat config = {.precision = 2, .force_sci = false, .uppercase = false};
        WriteFmt("Testing StrFromF64 inf emits exactly 3 bytes\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
    
        StrFloatFormat config = {.precision = 2, .force_sci = false, .uppercase = false};
        WriteFmt("Testing StrFromF64 0.0001 stays fixed notation\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
    
        StrFloatFormat config = {.precision = 6, .force_sci = false, .uppercase = false};
        WriteFmt("Testing StrFromF64 1e7 uses scientific notation\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
    
        StrFloatFormat config = {.precision = 2, .force_sci = false, .uppercase = false};
        WriteFmt("Testing StrFromF64 scientific precision 0 omits dot\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
    
        StrFloatFormat config = {.precision = 0, .force_sci = true, .uppercase = false};
        WriteFmt("Testing StrFromF64 zero exponent prints +00\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
    
        StrFloatFormat config = {.precision = 2, .force_sci = true, .uppercase = false};
        WriteFmt("Testing StrFromF64 scientific success returns handle\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
    
        StrFloatFormat config = {.precision = 2, .force_sci = true, .uppercase = false};
        WriteFmt("Testing StrFromF64 fixed success returns handle\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
    
        StrFloatFormat config = {.precision = 2, .force_sci = false, .uppercase = false};
        WriteFmt("Testing StrFromF64 fixed precision 0 omits dot\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
    
        StrFloatFormat config = {.precision = 0, .force_sci = false, .uppercase = false};
        WriteFmt("Testing StrFromF64 fixed fraction scale seed\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
    
        StrFloatFormat config = {.precision = 3, .force_sci = false, .uppercase = false};
        WriteFmt("Testing StrFromF64 fixed half-up rounding\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
        Str              s     = StrInit(&alloc);
    
        StrFloatFormat config = {.precision = 3, .force_sci = false, .uppercase = false};
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str          s      = StrInit(&alloc);
        StrIntFormat config = {.base = 10, .uppercase = false};
        StrFromI64(&s, INT64_MIN, &config);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str            s      = StrInit(&alloc);
        StrFloatFormat config = {.precision = 1, .force_sci = false, .uppercase = false};
        StrFromF64(&s, 2.25, &config);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str            s      = StrInit(&alloc);
        StrFloatFormat config = {.precision = 1, .force_sci = false, .uppercase = false};
        StrFromF64(&s, 2.25, &config);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str          s      = StrInit(&alloc);
        StrIntFormat config = {.base = 37, .uppercase = false};
        Str         *ret    = StrFromU64(&s, 5, &config);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Str          s      = StrInit(&alloc);
        StrIntFormat config = {.base = 10, .uppercase = false};
        Str         *ret    = StrFromU64(&s, 12345, &config);
        BudgetAllocator bp      = BudgetAllocatorInit(buf, sizeof(buf), 8);
    
        Str          s      = StrInit(&bp);
        StrIntFormat config = {.base = 10, .uppercase = false};
        // 10-digit value: any growth request exceeds the 8-byte slot.
        BudgetAllocator bp      = BudgetAllocatorInit(buf, sizeof(buf), 8);
    
        Str            s      = StrInit(&bp);
        StrFloatFormat config = {.precision = 0, .force_sci = false, .uppercase = false};
        // Positive 15-digit value, precision 0 -> the integer digits are the only
        BudgetAllocator bp       = BudgetAllocatorInit(buf, sizeof(buf), 8);
    
        Str            s      = StrInit(&bp);
        StrFloatFormat config = {.precision = 2, .force_sci = true, .uppercase = false};
        Str           *ret    = StrFromF64(&s, 1.23e150, &config);
    
        // Build a new string by iterating through each character with its index
        Str result = StrInit(&alloc);
        StrForeachIdx(&s, chr, idx) {
            StrAppendFmt(&result, "{c}{}", chr, idx);
    
        // Build a new string by iterating through each character in reverse with its index
        Str result = StrInit(&alloc);
    
        StrForeachReverseIdx(&s, chr, idx) {
    
        // Build a new string by iterating through each character pointer with its index
        Str result = StrInit(&alloc);
        StrForeachPtrIdx(&s, chrptr, idx) {
            // Append the character (via pointer) and its index to the result string
    
        // Build a new string by iterating through each character pointer in reverse with its index
        Str result = StrInit(&alloc);
    
        StrForeachReversePtrIdx(&s, chrptr, idx) {
    
        // Build a new string by iterating through each character
        Str result = StrInit(&alloc);
        StrForeach(&s, chr) {
            // Append the character to the result string
    
        // Build a new string by iterating through each character in reverse
        Str  result     = StrInit(&alloc);
        size char_count = 0;
    
        // Build a new string by iterating through each character pointer
        Str result = StrInit(&alloc);
        StrForeachPtr(&s, chrptr) {
            // Append the character (via pointer) to the result string
    
        // Build a new string by iterating through each character pointer in reverse
        Str  result     = StrInit(&alloc);
        size char_count = 0;
    
        // Build a new string by iterating through a range of characters with indices
        Str result = StrInit(&alloc);
        StrForeachInRangeIdx(&s, chr, idx, 6, 11) {
            // Append the character and its index to the result string
    
        // Test with empty range
        Str empty_result = StrInit(&alloc);
        StrForeachInRangeIdx(&s, chr, idx, 3, 3) {
            // This block should not execute
    
        // Build a new string by iterating through a range of characters
        Str result = StrInit(&alloc);
        StrForeachInRange(&s, chr, 0, 5) {
            // Append the character to the result string
    
        // Test with range at the end of the string
        Str end_result = StrInit(&alloc);
        StrForeachInRange(&s, chr, 6, 11) {
            // Append the character to the result string
    
        // Build a new string by iterating through a range of character pointers with indices
        Str result = StrInit(&alloc);
        StrForeachPtrInRangeIdx(&s, chrptr, idx, 6, 11) {
            // Append the character and its index to the result string
    
        // Build a new string by iterating through a range of character pointers
        Str result = StrInit(&alloc);
        StrForeachPtrInRange(&s, chrptr, 0, 5) {
            // Append the character to the result string
    
    
        Str s = StrInit(&alloc);
    
        bool result = (StrLen(&s) == 0);
                    si = JSkipWhitespace(si);                                                                              \
                }                                                                                                          \
                Str key       = StrInit(&alloc);                                                                           \
                UNPL(read_si) = JReadString(si, &key);                                                                     \
                if (StrIterIndex(&UNPL(read_si)) == StrIterIndex(&si)) {                                                   \
    #define JR_STR(si, str)                                                                                                \
        do {                                                                                                               \
            Str UNPL(my_str) = StrInit(&alloc);                                                                            \
            si               = JReadString((si), &UNPL(my_str));                                                           \
            (str)            = UNPL(my_str);                                                                               \
        do {                                                                                                               \
            if (!StrCmp(&key, (k))) {                                                                                      \
                Str UNPL(my_str) = StrInit(&alloc);                                                                        \
                si               = JReadString((si), &UNPL(my_str));                                                       \
                (str)            = UNPL(my_str);                                                                           \
        size       n = bt_capture_outer(frames, 32);
    
        Str rendered = StrInit(alloc_base);
        FormatStackTrace(&rendered, frames, n, alloc_base);
        ok                 = ok && VecLen(&frames) >= 2;
    
        Str rendered = StrInit(alloc_base);
        FormatStackTrace(&rendered, &frames, alloc_base);
        size       n = bt_capture_outer(frames, 16);
    
        Str out = StrInit(alloc_base);
        FormatStackTraceWith(&out, frames, n, &res);
        size       n = cfi_capture_outer(&res, frames, 32);
    
        Str rendered = StrInit(alloc_base);
        FormatStackTraceWith(&rendered, frames, n, &res);
    // FileRemove + StrDeinit). The on-disk file holds exactly `body`.
    static Str write_temp(Allocator *a, Zstr body) {
        Str  path = StrInit(a);
        File f    = file_open_temp(&path, a);
        if (FileIsOpen(&f)) {
        Allocator       *a     = ALLOCATOR_OF(&alloc);
    
        Str  body   = StrInit(a);
        Zstr pad    = "# padding line to push the fixture past the four kilobyte chunk\n";
        u64  padlen = ZstrLen(pad);
        bool             ok    = true;
    
        Str spec = StrInit(a);
        StrAppendFmt(&spec, "{}", (Zstr) "1.2.3.4:4660");
        MachoCache cache = MachoCacheInit(base);
    
        Str mod = StrInit(base);
        StrPushBackMany(&mod, bin_path);
        build_blob(blob, secs, 1);
    
        Str  path = StrInit(base);
        File f    = FileOpenTemp(&path, base);
        if (!FileIsOpen(&f)) {
        junk[1] = 'Y';
    
        Str  path = StrInit(base);
        File f    = FileOpenTemp(&path, base);
        if (!FileIsOpen(&f)) {
        ProcMaps       pm;
        MemSet(&pm, 0, sizeof(pm));
        pm.raw     = StrInit(ALLOCATOR_OF(&alloc));
        pm.entries = VecInitT(pm.entries, ALLOCATOR_OF(&alloc));
    
        HttpResponse response = HttpResponseInit(alloc_base);
        Str          body     = StrInit(alloc_base);
        StrAppendFmt(&body, "<h1>hi</h1>");
        HttpRespondWithHtml(&response, HTTP_RESPONSE_CODE_OK, &body);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str raw = StrInit(alloc_base);
        StrAppendFmt(&raw, "GET / HTTP/1.1\r\n");
        // 101 headers -- one past the cap of 100.
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str raw = StrInit(alloc_base);
        StrAppendFmt(&raw, "GET / HTTP/1.1\r\n");
        for (u64 i = 0; i < 100; i++) {
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path = StrInit(alloc_base);
        File f    = FileOpenTemp(&path, alloc_base);
        bool ok   = FileIsOpen(&f);
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path = StrInit(alloc_base);
        File f    = FileOpenTemp(&path, alloc_base);
        bool ok   = FileIsOpen(&f);
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        Str first = StrInit(adbg);
        StrAppendFmt(&first, "<h1>first-body-long-enough-to-heap-allocate</h1>");
        HttpRespondWithHtml(&response, HTTP_RESPONSE_CODE_OK, &first);
    
        Str second = StrInit(adbg);
        StrAppendFmt(&second, "<h1>second-body-also-long-enough-to-heap</h1>");
        // Second call must free the first body before installing the second.
    
        // Pre-fill body with a heap-backed string.
        Str first = StrInit(adbg);
        StrAppendFmt(&first, "<h1>old-body-long-enough-to-force-heap-here</h1>");
        HttpResponse response = HttpResponseInit(adbg);
    
        // Create a temp file with content.
        Str  path    = StrInit(adbg);
        File f       = FileOpenTemp(&path, adbg);
        bool ok      = FileIsOpen(&f);
        StrIter si      = StrIterFromStr(json);
    
        Str name = StrInit(&alloc);
        Str city = StrInit(&alloc);
    
        Str name = StrInit(&alloc);
        Str city = StrInit(&alloc);
    
        JR_OBJ(si, {
    
        Person person = {0};
        person.name   = StrInit(&alloc);
    
        JR_OBJ(si, {
    
        Config config    = {0};
        config.log_level = StrInit(&alloc);
    
        JR_OBJ(si, {
        JR_OBJ(si, {
            JR_ARR_KV(si, "languages", {
                Str lang = StrInit(&alloc);
                JR_STR(si, lang);
                VecPushBack(&languages, lang);
            bool active;
        } data = {
            {StrInit(&alloc), StrInit(&alloc)},
            false
        };
    
        SimpleProduct product = {0};
        product.name          = StrInit(&alloc);
        product.tags          = VecInitWithDeepCopyT(product.tags, NULL, StrDeinit, &alloc);
            JR_FLT_KV(si, "price", product.price);
            JR_ARR_KV(si, "tags", {
                Str tag = StrInit(&alloc);
                JR_STR(si, tag);
                VecPushBack(&product.tags, tag);
        // Create a copy of expected without spaces for comparison
        Str expected_str   = StrInitFromZstr(expected, alloc);
        Str output_clean   = StrInit(alloc);
        Str expected_clean = StrInit(alloc);
        Str expected_str   = StrInitFromZstr(expected, alloc);
        Str output_clean   = StrInit(alloc);
        Str expected_clean = StrInit(alloc);
    
        // Remove spaces and newlines from both strings for comparison
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        // Write completely empty object
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        Vec(i32) empty_numbers = VecInit(&alloc);
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        Str empty_name = StrInit(&alloc);
        Str  json    = StrInit(&alloc);
    
        Str empty_name = StrInit(&alloc);
        Str empty_desc = StrInit(&alloc);
    
        Str empty_name = StrInit(&alloc);
        Str empty_desc = StrInit(&alloc);
    
        JW_OBJ(json, {
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        i32 temp    = -25;
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        i64 big_int     = 9223372036854775807LL;
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        i32  int_zero   = 0;
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        // Note: These are the actual characters, not escape sequences
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        // These contain actual special characters that should be escaped
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        Vec(i32) empty_list = VecInit(&alloc);
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        Vec(i32) empty_arr  = VecInit(&alloc);
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        i64 max_int   = 2147483647LL;
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        f64 tiny          = 0.000001;
    
        bool success = true;
        Str  json1   = StrInit(&alloc);
        Str  json2   = StrInit(&alloc);
        Str  json3   = StrInit(&alloc);
        bool success = true;
        Str  json1   = StrInit(&alloc);
        Str  json2   = StrInit(&alloc);
        Str  json3   = StrInit(&alloc);
        Str  json4   = StrInit(&alloc);
        Str  json1   = StrInit(&alloc);
        Str  json2   = StrInit(&alloc);
        Str  json3   = StrInit(&alloc);
        Str  json4   = StrInit(&alloc);
        Str  json2   = StrInit(&alloc);
        Str  json3   = StrInit(&alloc);
        Str  json4   = StrInit(&alloc);
    
        // Single integer
    bool compare_json_output(const Str *output, Zstr expected, DefaultAllocator *alloc) {
        Str expected_str   = StrInitFromZstr(expected, alloc);
        Str output_clean   = StrInit(alloc);
        Str expected_clean = StrInit(alloc);
        Str expected_str   = StrInitFromZstr(expected, alloc);
        Str output_clean   = StrInit(alloc);
        Str expected_clean = StrInit(alloc);
    
        // Remove whitespace from both strings for comparison
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        struct {
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        struct {
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        ApiResponse response = {
            JW_OBJ_KV(json, "data", {
                // Write dynamic key for source function ID
                Str source_key = StrInit(&alloc);
                u64 source_id  = VecLen(&response.data) > 0 ? VecAt(&response.data, 0).source_function_id : 0;
                StrAppendFmt(&source_key, "{}", source_id);
                    if (VecLen(&response.data) > 0) {
                        AnnSymbol *s          = &VecAt(&response.data, 0);
                        Str        target_key = StrInit(&alloc);
                        StrAppendFmt(&target_key, "{}", s->target_function_id);
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        Vec(FunctionInfo) functions = VecInitWithDeepCopy(NULL, FunctionInfoDeinit, &alloc);
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        SearchResult result = {0};
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        Vec(AnnSymbol) symbols = VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc);
            JW_OBJ_KV(json, "functions", {
                VecForeach(&symbols, symbol) {
                    Str source_key = StrInit(&alloc);
                    StrAppendFmt(&source_key, "{}", symbol.source_function_id);
    
                    JW_OBJ_KV(json, StrBegin(&source_key), {
                Str target_key = StrInit(&alloc);
                StrAppendFmt(&target_key, "{}", symbol.target_function_id);
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        // Create strings for the nested structure
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        Vec(u32) numbers = VecInit(&alloc);
            bool active;
            f64  score;
        } data = {0, StrInit(&alloc), false, 0.0};
    
        JR_OBJ(si, {
            Str status;
        } data = {
            {0, {StrInit(&alloc), 0}},
            StrInit(&alloc)
        };
        } data = {
            {0, {StrInit(&alloc), 0}},
            StrInit(&alloc)
        };
            } company;
        } data = {
            {{{StrInit(&alloc), 0, 0.0}}, StrInit(&alloc)}
        };
                    // Properly initialize all Str fields
                    AnnSymbol sym             = {0};
                    sym.analysis_name         = StrInit(&alloc);
                    sym.function_name         = StrInit(&alloc);
                    sym.sha256                = StrInit(&alloc);
                    AnnSymbol sym             = {0};
                    sym.analysis_name         = StrInit(&alloc);
                    sym.function_name         = StrInit(&alloc);
                    sym.sha256                = StrInit(&alloc);
                    sym.function_mangled_name = StrInit(&alloc);
                    sym.analysis_name         = StrInit(&alloc);
                    sym.function_name         = StrInit(&alloc);
                    sym.sha256                = StrInit(&alloc);
                    sym.function_mangled_name = StrInit(&alloc);
                    sym.source_function_id    = source_function_id;
                    sym.function_name         = StrInit(&alloc);
                    sym.sha256                = StrInit(&alloc);
                    sym.function_mangled_name = StrInit(&alloc);
                    sym.source_function_id    = source_function_id;
                    sym.target_function_id    = target_function_id;
        StrIter si = StrIterFromStr(json);
    
        ApiResponse response = {false, StrInit(&alloc), VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc)};
    
        JR_OBJ(si, {
                        // Properly initialize all Str fields
                        AnnSymbol sym             = {0};
                        sym.analysis_name         = StrInit(&alloc);
                        sym.function_name         = StrInit(&alloc);
                        sym.sha256                = StrInit(&alloc);
                        AnnSymbol sym             = {0};
                        sym.analysis_name         = StrInit(&alloc);
                        sym.function_name         = StrInit(&alloc);
                        sym.sha256                = StrInit(&alloc);
                        sym.function_mangled_name = StrInit(&alloc);
                        sym.analysis_name         = StrInit(&alloc);
                        sym.function_name         = StrInit(&alloc);
                        sym.sha256                = StrInit(&alloc);
                        sym.function_mangled_name = StrInit(&alloc);
                        sym.source_function_id    = source_function_id;
                        sym.function_name         = StrInit(&alloc);
                        sym.sha256                = StrInit(&alloc);
                        sym.function_mangled_name = StrInit(&alloc);
                        sym.source_function_id    = source_function_id;
                        sym.target_function_id    = (u64)ZstrToI64(StrBegin(&key), NULL);
    
        FunctionInfo info = {0};
        info.name         = StrInit(&alloc);
    
        JR_OBJ(si, {
    
        ModelInfo info = {0};
        info.name      = StrInit(&alloc);
    
        JR_OBJ(si, {
    
        SearchResult result = {0};
        result.binary_name  = StrInit(&alloc);
        result.sha256       = StrInit(&alloc);
        result.tags         = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit, &alloc);
        SearchResult result = {0};
        result.binary_name  = StrInit(&alloc);
        result.sha256       = StrInit(&alloc);
        result.tags         = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit, &alloc);
        result.created_at   = StrInit(&alloc);
        result.sha256       = StrInit(&alloc);
        result.tags         = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit, &alloc);
        result.created_at   = StrInit(&alloc);
        result.model_name   = StrInit(&alloc);
        result.owned_by     = StrInit(&alloc);
        result.tags         = VecInitWithDeepCopyT(result.tags, NULL, StrDeinit, &alloc);
        result.created_at   = StrInit(&alloc);
        result.model_name   = StrInit(&alloc);
        result.owned_by     = StrInit(&alloc);
        result.created_at   = StrInit(&alloc);
        result.model_name   = StrInit(&alloc);
        result.owned_by     = StrInit(&alloc);
    
        JR_OBJ(si, {
        StrIter si = StrIterFromStr(json);
    
        ApiResponse response = {false, StrInit(&alloc), VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc)};
    
        WriteFmt("[DEBUG] About to parse JSON...\n");
                        // Properly initialize all Str fields
                        AnnSymbol sym             = {0};
                        sym.analysis_name         = StrInit(&alloc);
                        sym.function_name         = StrInit(&alloc);
                        sym.sha256                = StrInit(&alloc);
                        AnnSymbol sym             = {0};
                        sym.analysis_name         = StrInit(&alloc);
                        sym.function_name         = StrInit(&alloc);
                        sym.sha256                = StrInit(&alloc);
                        sym.function_mangled_name = StrInit(&alloc);
                        sym.analysis_name         = StrInit(&alloc);
                        sym.function_name         = StrInit(&alloc);
                        sym.sha256                = StrInit(&alloc);
                        sym.function_mangled_name = StrInit(&alloc);
                        sym.source_function_id    = source_function_id;
                        sym.function_name         = StrInit(&alloc);
                        sym.sha256                = StrInit(&alloc);
                        sym.function_mangled_name = StrInit(&alloc);
                        sym.source_function_id    = source_function_id;
                        sym.target_function_id    = (u64)ZstrToI64(StrBegin(&key), NULL);
        StrIter si = StrIterFromStr(json);
    
        ApiResponse response = {false, StrInit(&alloc), VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc)};
    
        WriteFmt("[DEBUG] About to parse JSON...\n");
                        // Properly initialize all Str fields
                        AnnSymbol sym             = {0};
                        sym.analysis_name         = StrInit(&alloc);
                        sym.function_name         = StrInit(&alloc);
                        sym.sha256                = StrInit(&alloc);
                        AnnSymbol sym             = {0};
                        sym.analysis_name         = StrInit(&alloc);
                        sym.function_name         = StrInit(&alloc);
                        sym.sha256                = StrInit(&alloc);
                        sym.function_mangled_name = StrInit(&alloc);
                        sym.analysis_name         = StrInit(&alloc);
                        sym.function_name         = StrInit(&alloc);
                        sym.sha256                = StrInit(&alloc);
                        sym.function_mangled_name = StrInit(&alloc);
                        sym.source_function_id    = source_function_id;
                        sym.function_name         = StrInit(&alloc);
                        sym.sha256                = StrInit(&alloc);
                        sym.function_mangled_name = StrInit(&alloc);
                        sym.source_function_id    = source_function_id;
                        sym.target_function_id    = (u64)ZstrToI64(StrBegin(&key), NULL);
        // Create a copy of expected without spaces for comparison
        Str expected_str   = StrInitFromZstr(expected, alloc);
        Str output_clean   = StrInit(alloc);
        Str expected_clean = StrInit(alloc);
        Str expected_str   = StrInitFromZstr(expected, alloc);
        Str output_clean   = StrInit(alloc);
        Str expected_clean = StrInit(alloc);
    
        // Remove spaces and newlines from both strings for comparison
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        Str name = StrInitFromZstr("Alice", &alloc);
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        u32 count = 42;
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        bool enabled = true;
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        Person person = {1001, StrInitFromZstr("Bob", &alloc), 25, true, 50000.0};
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        Config config = {false, 30, StrInitFromZstr("INFO", &alloc)};
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        Vec(Str) languages = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        struct {
    
        bool success = true;
        Str  json    = StrInit(&alloc);
    
        SimpleProduct product = {0};
        JR_OBJ(si2, {
            JR_ARR_KV(si2, "data", {
                Str value = StrInit(&alloc);
                JR_STR(si2, value);
                VecPushBack(&data, value);
            Str name;
            Str description;
        } obj = {StrInit(&alloc), StrInit(&alloc)};
    
        JR_OBJ(si, {
            Str message;
            Str data;
        } obj = {StrInit(&alloc), StrInit(&alloc), StrInit(&alloc)};
    
        JR_OBJ(si, {
            Str tab;
        } obj = {
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
        } obj = {
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc)
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc)
        };
            StrInit(&alloc),
            StrInit(&alloc),
            StrInit(&alloc)
        };
            i32  value;
            bool flag;
        } obj = {StrInit(&alloc), 0, false};
    
        JR_OBJ(si, {
            Str     j   = StrInitFromZstr(cases[i], &alloc);
            StrIter si  = StrIterFromStr(j);
            Str     out = StrInit(&alloc);
            StrIter r   = JReadString(si, &out);
            // Truncated escape -> failure -> iterator unchanged.
            Str     j   = StrInitFromZstr("\"a\\u00e9b\"", &alloc);
            StrIter si  = StrIterFromStr(j);
            Str     out = StrInit(&alloc);
            StrIter r   = JReadString(si, &out);
            if (StrIterIndex(&r) != StrIterIndex(&si)) {
            Str     j   = StrInitFromZstr("\"plain\"", &alloc);
            StrIter si  = StrIterFromStr(j);
            Str     out = StrInit(&alloc);
            StrIter r   = JReadString(si, &out);
            if (StrIterIndex(&r) == StrIterIndex(&si) || StrIterIndex(&r) != StrIterLength(&r)) {
    
        // Write to JSON
        Str json = StrInit(&alloc);
        JW_OBJ(json, {
            JW_INT_KV(json, "count", original.count);
            bool enabled;
            Str  message;
        } parsed = {0, 0.0, false, StrInit(&alloc)};
    
        StrIter si = StrIterFromStr(json);
    
        // Write to JSON
        Str json = StrInit(&alloc);
        JW_OBJ(json, {
            JW_INT_KV(json, "big_int", original.big_int);
    
        // Write to JSON
        Str json = StrInit(&alloc);
        JW_OBJ(json, {
            JW_BOOL_KV(json, "flag1", original.flag1);
            Str with_special;
        } original = {
            StrInit(&alloc),
            StrInitFromZstr("hello", &alloc),
            StrInitFromZstr("hello world with spaces", &alloc),
    
        // Write to JSON
        Str json = StrInit(&alloc);
        JW_OBJ(json, {
            JW_STR_KV(json, "empty", original.empty);
            Str with_spaces;
            Str with_special;
        } parsed = {StrInit(&alloc), StrInit(&alloc), StrInit(&alloc), StrInit(&alloc)};
    
        StrIter si = StrIterFromStr(json);
    
        // Write to JSON
        Str json = StrInit(&alloc);
        JW_OBJ(json, {
            JW_ARR_KV(json, "numbers", original_numbers, num, { JW_INT(json, num); });
            });
            JR_ARR_KV(si, "strings", {
                Str str = StrInit(&alloc);
                JR_STR(si, str);
                VecPushBack(&parsed_strings, str);
    
        // Write to JSON
        Str json = StrInit(&alloc);
        JW_OBJ(json, {
            JW_OBJ_KV(json, "user", {
    
        // Read back from JSON
        TestPerson parsed_person = {0, StrInit(&alloc), 0, false, 0.0};
    
        StrIter si = StrIterFromStr(json);
    
        // Write to JSON
        Str json = StrInit(&alloc);
        JW_OBJ(json, {
            JW_OBJ_KV(json, "user", {
        // Read back from JSON
        ComplexData parsed       = {0};
        parsed.user              = (TestPerson) {0, StrInit(&alloc), 0, false, 0.0};
        parsed.config.debug_mode = true; // opposite of original
        parsed.config.timeout    = 0;
        parsed.config.debug_mode = true; // opposite of original
        parsed.config.timeout    = 0;
        parsed.config.log_level  = StrInit(&alloc);
        parsed.config.features   = VecInitWithDeepCopyT(parsed.config.features, NULL, StrDeinit, &alloc);
        parsed.numbers           = VecInitT(parsed.numbers, &alloc);
                JR_STR_KV(si, "log_level", parsed.config.log_level);
                JR_ARR_KV(si, "features", {
                    Str feature = StrInit(&alloc);
                    JR_STR(si, feature);
                    VecPushBack(&parsed.config.features, feature);
        Vec(i32) empty_numbers = VecInit(&alloc);
        Vec(Str) empty_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
        Str empty_str          = StrInit(&alloc);
    
        // Write to JSON
    
        // Write to JSON
        Str json = StrInit(&alloc);
        JW_OBJ(json, {
            JW_STR_KV(json, "empty_string", empty_str);
        Vec(i32) parsed_numbers = VecInit(&alloc);
        Vec(Str) parsed_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
        Str  parsed_str         = StrInit(&alloc);
        bool found_empty_object = false;
            });
            JR_ARR_KV(si, "empty_strings", {
                Str str = StrInit(&alloc);
                JR_STR(si, str);
                VecPushBack(&parsed_strings, str);
    
        // Write to JSON
        Str json = StrInit(&alloc);
        JW_OBJ(json, {
            JW_INT_KV(json, "max_int", original.max_int);
        Str              src         = StrInitFromZstr("host = localhost\n", &alloc);
        StrIter          input       = StrIterFromStr(src);
        Str              host_copy   = StrInit(&alloc);
        Str             *stored_host = NULL;
        bool             result      = true;
Last updated on