Skip to content

WriteFmtLn

Description

Write formatted output to the standard output stream (FileStdout()) followed by a newline. This is a convenience macro calling FWriteFmtLn with FileStdout().

Parameters

Name Direction Description
fmtstr in Format string with {} placeholders.

Success

Placeholders in fmtstr are replaced by the passed arguments, and the resulting formatted string followed by a newline is written to standard output.

Failure

Failure might occur during memory allocation for the temporary string or during the write operation; the backend may also log an error message.

Usage example (Cross-references)

Usage examples (Cross-references)
                    StrMustResize(&s, n - 2);
                }
                WriteFmtLn("{}", s);
                StrDeinit(&s);
            }
    // 525:18 cxx_le_to_gt -- `new_size <= capacity` -> `new_size > capacity`.
    bool test_resize_grow_branch_allocates(void) {
        WriteFmtLn("Testing resize grow enlarges capacity (525:18)");
    
        typedef Vec(u32) U32Vec;
    // is deleted.
    bool test_resize_shrink_deinits_dropped(void) {
        WriteFmtLn("Testing resize shrink deinits dropped tail (527:13)");
    
        reset_deinit_state();
    // result is replaced by a constant.
    bool test_resize_grow_reserves_capacity(void) {
        WriteFmtLn("Testing resize grow reserves backing capacity (531:14)");
    
        typedef Vec(u64) U64Vec;
    // 534:21 cxx_assign_const -- grow-path `vec->length = new_size` -> const.
    bool test_resize_grow_sets_exact_length(void) {
        WriteFmtLn("Testing resize grow sets exact length (534:21)");
    
        typedef Vec(u32) U32Vec;
    // `n2 = 42`.
    bool test_reserve_pow2_seed(void) {
        WriteFmtLn("Testing reserve_pow2 rounds to a power of two (145:10)");
    
        typedef Vec(u32) U32Vec;
    
    bool test_vec_pop_back(void) {
        WriteFmtLn("Testing VecPopBack");
    
        // Create a vector of integers
    // Test VecPopFront function
    bool test_vec_pop_front(void) {
        WriteFmtLn("Testing VecPopFront");
    
        // Create a vector of integers
    // Test VecDelete function
    bool test_vec_delete(void) {
        WriteFmtLn("Testing VecDelete");
    
        // Create a vector of integers
    // Test VecDeleteFast function
    bool test_vec_delete_fast(void) {
        WriteFmtLn("Testing VecDeleteFast");
    
        // Create a vector of integers
    // Test VecDeleteRange function
    bool test_vec_delete_range(void) {
        WriteFmtLn("Testing VecDeleteRange");
    
        // Create a vector of integers
    // Test VecDeleteRangeFast
    bool test_vec_delete_range_fast(void) {
        WriteFmtLn("Testing VecDeleteRangeFast");
    
        // Create a vector of integers
    // Test VecDeleteLast function
    bool test_vec_delete_last(void) {
        WriteFmtLn("Testing VecDeleteLast");
    
        // Create a vector of integers
    // Test L-value standard delete operations
    bool test_lvalue_delete_operations(void) {
        WriteFmtLn("Testing L-value standard delete operations");
    
        // Create a vector of integers
    // Test R-value standard delete operations
    bool test_rvalue_delete_operations(void) {
        WriteFmtLn("Testing R-value standard delete operations");
    
        // Create a vector of integers
    // Test L-value fast delete operations
    bool test_lvalue_fast_delete_operations(void) {
        WriteFmtLn("Testing L-value fast delete operations");
    
        // Create a vector of integers
        // Check that the value at the deleted position is now the last value
        result = result && (VecAt(&vec, fast_index) == lastValue);
        WriteFmtLn(
            "Value at deleted position ({}) is now {} (expected {})\n",
            fast_index,
            result = result && found;
            if (!found) {
                WriteFmtLn("Value {} should be present but was not found", expected_values[i]);
            }
        }
    // Test R-value fast delete operations
    bool test_rvalue_fast_delete_operations(void) {
        WriteFmtLn("Testing R-value fast delete operations");
    
        // Create a vector of integers
        // Check that the value at the deleted position is now the last value
        result = result && (VecAt(&vec, 2) == lastValue);
        WriteFmtLn("Value at deleted position (2) is now {} (expected {})\n", VecAt(&vec, 2), lastValue);
    
        // Verify all expected values (except the deleted one and the moved one) are still present
            result = result && found;
            if (!found) {
                WriteFmtLn("Value {} should be present but was not found", expected_values[i]);
            }
        }
    // Test L-value delete range operations
    bool test_lvalue_delete_range_operations(void) {
        WriteFmtLn("Testing L-value delete range operations");
    
        // Create a vector of integers
    // Test R-value delete range operations
    bool test_rvalue_delete_range_operations(void) {
        WriteFmtLn("Testing R-value delete range operations");
    
        // Create a vector of integers
    // Test L-value fast delete range operations
    bool test_lvalue_fast_delete_range_operations(void) {
        WriteFmtLn("Testing L-value fast delete range operations");
    
        // Create a vector of integers
            result = result && !found;
            if (found) {
                WriteFmtLn("Value {} should be deleted but was found", valuesToDelete[i]);
            }
        }
            result = result && found;
            if (!found) {
                WriteFmtLn("Value {} should be present but was not found", remainingValues[i]);
            }
        }
    // Test R-value fast delete range operations
    bool test_rvalue_fast_delete_range_operations(void) {
        WriteFmtLn("Testing R-value fast delete range operations");
    
        // Create a vector of integers
            result = result && !found;
            if (found) {
                WriteFmtLn("Value {} should be deleted but was found", valuesToDelete[i]);
            }
        }
            result = result && found;
            if (!found) {
                WriteFmtLn("Value {} should be present but was not found", remainingValues[i]);
            }
        }
    // documented-valid; under the mutant it LOG_FATALs.
    bool test_fast_remove_whole_vector_succeeds(void) {
        WriteFmtLn("Testing fast remove of whole vector (413:23)");
    
        typedef Vec(int) IntVec;
    // stride` copies (almost) nothing into the caller's buffer.
    bool test_fast_remove_copies_out_removed_data(void) {
        WriteFmtLn("Testing fast remove populates removed_data (418:72)");
    
        typedef Vec(int) IntVec;
    // removed-data copy is replaced by a constant (0), so 0 bytes are copied.
    bool test_fast_remove_copies_out_removed_data_stride(void) {
        WriteFmtLn("Testing fast remove removed_data byte count (418:74)");
    
        typedef Vec(int) IntVec;
    // 422:23 cxx_init_const -- copy_deinit loop initializer `s = 0` -> `s = 42`.
    bool test_fast_remove_deinits_every_removed_element(void) {
        WriteFmtLn("Testing fast remove deinits every removed element (422:23)");
    
        reset_deinit_state();
    // 422:32 cxx_lt_to_ge -- loop guard `s < count` -> `s >= count`.
    bool test_fast_remove_deinit_runs_at_least_once(void) {
        WriteFmtLn("Testing fast remove deinit loop runs (422:32 ge)");
    
        reset_deinit_state();
    // iteration. Remove 2 of 4: real code deinits exactly 2.
    bool test_fast_remove_deinit_not_run_on_survivor(void) {
        WriteFmtLn("Testing fast remove deinit count is exact (422:32 le)");
    
        reset_deinit_state();
    // 422:42 cxx_post_inc_to_post_dec -- `s++` -> `s--`.
    bool test_fast_remove_deinit_runs_for_each(void) {
        WriteFmtLn("Testing fast remove deinit runs once per element (422:42)");
    
        reset_deinit_state();
    // removed elements in order.
    bool test_fast_remove_deinit_walks_each_element(void) {
        WriteFmtLn("Testing fast remove deinit walks each element (424:29)");
    
        reset_deinit_state();
    // `length + count`.
    bool test_fast_remove_zeroes_vacated_tail_sub(void) {
        WriteFmtLn("Testing fast remove zeroes vacated tail (449:40)");
    
        typedef Vec(int) IntVec;
    // `count / stride`.
    bool test_fast_remove_zeroes_vacated_tail_stride(void) {
        WriteFmtLn("Testing fast remove tail-zero byte count (449:70)");
    
        typedef Vec(int) IntVec;
    // tail-zeroing MemSet size is replaced by the constant 42.
    bool test_fast_remove_zeroes_vacated_tail_call(void) {
        WriteFmtLn("Testing fast remove tail-zero stride call (449:72)");
    
        typedef Vec(int) IntVec;
    
        if (!result) {
            WriteFmtLn("[DEBUG] JSON comparison failed");
            WriteFmt("[DEBUG] Expected: '");
            for (u64 i = 0; i < StrLen(&expected_clean); i++) {
                WriteFmt("{c}", StrBegin(&expected_clean)[i]);
            }
            WriteFmtLn("'");
    
            WriteFmt("[DEBUG] Got: '");
                WriteFmt("{c}", StrBegin(&output_clean)[i]);
            }
            WriteFmtLn("'");
        }
    // Test 1: Empty object writing
    bool test_empty_object_writing(void) {
        WriteFmtLn("Testing empty object writing");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    // Test 2: Empty array writing
    bool test_empty_array_writing(void) {
        WriteFmtLn("Testing empty array writing");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    // Test 3: Empty string writing
    bool test_empty_string_writing(void) {
        WriteFmtLn("Testing empty string writing");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    // Test 4: Negative numbers writing
    bool test_negative_numbers_writing(void) {
        WriteFmtLn("Testing negative numbers writing");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    // Test 5: Large numbers writing
    bool test_large_numbers_writing(void) {
        WriteFmtLn("Testing large numbers writing");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        // For large numbers, just check that valid JSON was produced
        if (StrLen(&json) > 0 && StrBegin(&json)[0] == '{' && StrBegin(&json)[StrLen(&json) - 1] == '}') {
            WriteFmtLn("[DEBUG] Large numbers test passed - produced valid JSON structure");
        } else {
            WriteFmtLn("[DEBUG] Large numbers test FAILED - invalid JSON structure");
            WriteFmtLn("[DEBUG] Large numbers test passed - produced valid JSON structure");
        } else {
            WriteFmtLn("[DEBUG] Large numbers test FAILED - invalid JSON structure");
            success = false;
        }
        }
    
        WriteFmtLn("[DEBUG] Large numbers JSON: {}", json);
    
        StrDeinit(&json);
    // Test 6: Zero values writing
    bool test_zero_values_writing(void) {
        WriteFmtLn("Testing zero values writing\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    // Test 7: Special characters writing
    bool test_special_characters_writing(void) {
        WriteFmtLn("Testing special characters writing");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        });
    
        WriteFmtLn("[DEBUG] Special characters JSON: {}", json);
    
        // Just verify that valid JSON structure was produced
        // Just verify that valid JSON structure was produced
        if (StrLen(&json) > 0 && StrBegin(&json)[0] == '{' && StrBegin(&json)[StrLen(&json) - 1] == '}') {
            WriteFmtLn("[DEBUG] Special characters test passed - produced valid JSON");
        } else {
            WriteFmtLn("[DEBUG] Special characters test FAILED - invalid JSON structure");
            WriteFmtLn("[DEBUG] Special characters test passed - produced valid JSON");
        } else {
            WriteFmtLn("[DEBUG] Special characters test FAILED - invalid JSON structure");
            success = false;
        }
    // Test 8: Escape sequences writing
    bool test_escape_sequences_writing(void) {
        WriteFmtLn("Testing escape sequences writing");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        });
    
        WriteFmtLn("[DEBUG] Escape sequences JSON: {}", json);
    
        // Verify valid JSON structure was produced
        // Verify valid JSON structure was produced
        if (StrLen(&json) > 0 && StrBegin(&json)[0] == '{' && StrBegin(&json)[StrLen(&json) - 1] == '}') {
            WriteFmtLn("[DEBUG] Escape sequences test passed - produced valid JSON");
        } else {
            WriteFmtLn("[DEBUG] Escape sequences test FAILED - invalid JSON structure");
            WriteFmtLn("[DEBUG] Escape sequences test passed - produced valid JSON");
        } else {
            WriteFmtLn("[DEBUG] Escape sequences test FAILED - invalid JSON structure");
            success = false;
        }
    // Test 9: Nested empty containers writing
    bool test_nested_empty_containers_writing(void) {
        WriteFmtLn("Testing nested empty containers writing");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    // Test 10: Mixed empty and filled containers writing
    bool test_mixed_empty_and_filled_writing(void) {
        WriteFmtLn("Testing mixed empty and filled containers writing");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    // Test 11: Boundary integers writing
    bool test_boundary_integers_writing(void) {
        WriteFmtLn("Testing boundary integers writing");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    // Test 12: Boundary floats writing
    bool test_boundary_floats_writing(void) {
        WriteFmtLn("Testing boundary floats writing");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        // Check for reasonable float formatting (exact precision may vary)
        if (StrLen(&json) > 0 && StrBegin(&json)[0] == '{' && StrBegin(&json)[StrLen(&json) - 1] == '}') {
            WriteFmtLn("[DEBUG] Boundary floats test passed - JSON: {}", json);
        } else {
            WriteFmtLn("[DEBUG] Boundary floats test FAILED");
            WriteFmtLn("[DEBUG] Boundary floats test passed - JSON: {}", json);
        } else {
            WriteFmtLn("[DEBUG] Boundary floats test FAILED");
            success = false;
        }
    // Test 13: Single values writing (minimal valid JSON objects)
    bool test_single_values_writing(void) {
        WriteFmtLn("Testing single values writing");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    // Test 1: Empty object reading
    bool test_empty_object_reading(void) {
        WriteFmtLn("Testing empty object reading");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        if (!obj1.found_anything) {     // Should still be true for empty object (reader block didn't execute)
            WriteFmtLn("[DEBUG] Empty object test 1 passed - no fields processed");
        } else {
            WriteFmtLn("[DEBUG] Empty object test 1 FAILED - unexpected field processing");
            WriteFmtLn("[DEBUG] Empty object test 1 passed - no fields processed");
        } else {
            WriteFmtLn("[DEBUG] Empty object test 1 FAILED - unexpected field processing");
            success = false;
        }
    
        if (!obj2.found_anything) { // Should still be true for empty object
            WriteFmtLn("[DEBUG] Empty object with whitespace test passed");
        } else {
            WriteFmtLn("[DEBUG] Empty object with whitespace test FAILED");
            WriteFmtLn("[DEBUG] Empty object with whitespace test passed");
        } else {
            WriteFmtLn("[DEBUG] Empty object with whitespace test FAILED");
            success = false;
        }
    // Test 2: Empty array reading
    bool test_empty_array_reading(void) {
        WriteFmtLn("Testing empty array reading");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        if (VecLen(&items) == 0) {
            WriteFmtLn("[DEBUG] Empty array test passed - no items added");
        } else {
            WriteFmtLn("[DEBUG] Empty array test FAILED - {} items found", VecLen(&items));
            WriteFmtLn("[DEBUG] Empty array test passed - no items added");
        } else {
            WriteFmtLn("[DEBUG] Empty array test FAILED - {} items found", VecLen(&items));
            success = false;
        }
    
        if (VecLen(&data) == 0) {
            WriteFmtLn("[DEBUG] Empty array with whitespace test passed");
        } else {
            WriteFmtLn("[DEBUG] Empty array with whitespace test FAILED");
            WriteFmtLn("[DEBUG] Empty array with whitespace test passed");
        } else {
            WriteFmtLn("[DEBUG] Empty array with whitespace test FAILED");
            success = false;
        }
        Zstr data_want = "line1\nline2\ttab";
        if (StrLen(&obj.path) != ZstrLen(path_want) || MemCompare(StrBegin(&obj.path), path_want, StrLen(&obj.path)) != 0) {
            WriteFmtLn("[DEBUG] Special characters FAILED: path content wrong");
            success = false;
        }
        if (StrLen(&obj.message) != ZstrLen(msg_want) ||
            MemCompare(StrBegin(&obj.message), msg_want, StrLen(&obj.message)) != 0) {
            WriteFmtLn("[DEBUG] Special characters FAILED: message content wrong");
            success = false;
        }
        }
        if (StrLen(&obj.data) != ZstrLen(data_want) || MemCompare(StrBegin(&obj.data), data_want, StrLen(&obj.data)) != 0) {
            WriteFmtLn("[DEBUG] Special characters FAILED: data content wrong");
            success = false;
        }
        for (u64 i = 0; i < sizeof(expect) / sizeof(expect[0]); i++) {
            if (StrLen(expect[i].got) != 1 || *StrBegin(expect[i].got) != expect[i].want) {
                WriteFmtLn(
                    "[DEBUG] Escape sequences FAILED: {} decoded wrong (len={})",
                    expect[i].name,
    // Test 10: Nested empty containers
    bool test_nested_empty_containers(void) {
        WriteFmtLn("Testing nested empty containers\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    // so a caller can detect the failure and fall back).
    bool test_scalar_readers_reject_malformed(void) {
        WriteFmtLn("Testing scalar readers reject malformed tokens");
    
        DefaultAllocator alloc   = DefaultAllocatorInit();
            StrIter out = JReadBool(si, &b);
            if (StrIterIndex(&out) != StrIterIndex(&si)) {
                WriteFmtLn("[DEBUG] JReadBool advanced on malformed 'tru3'");
                success = false;
            }
            StrIter out = JReadBool(si, &b);
            if (StrIterIndex(&out) != StrIterIndex(&si)) {
                WriteFmtLn("[DEBUG] JReadBool advanced on malformed 'fXlse'");
                success = false;
            }
            StrIter out = JReadBool(si, &b);
            if (StrIterIndex(&out) != StrIterIndex(&si)) {
                WriteFmtLn("[DEBUG] JReadBool advanced on too-short 'tr'");
                success = false;
            }
            StrIter out     = JReadNull(si, &is_null);
            if (StrIterIndex(&out) != StrIterIndex(&si)) {
                WriteFmtLn("[DEBUG] JReadNull advanced on malformed 'nuXX'");
                success = false;
            }
    // consume exactly the token (SUCCESS contract: advance past the token).
    bool test_scalar_readers_value_and_advance(void) {
        WriteFmtLn("Testing scalar readers parse + advance");
    
        DefaultAllocator alloc   = DefaultAllocatorInit();
            // value correct and exactly 4 bytes consumed
            if (!(b == true && StrIterIndex(&out) == 4)) {
                WriteFmtLn("[DEBUG] JReadBool 'true' value/advance wrong: b={}, idx={}", b, StrIterIndex(&out));
                success = false;
            }
            StrIter out = JReadBool(si, &b);
            if (!(b == false && StrIterIndex(&out) == 5)) {
                WriteFmtLn("[DEBUG] JReadBool 'false' value/advance wrong: b={}, idx={}", b, StrIterIndex(&out));
                success = false;
            }
            StrIter out     = JReadNull(si, &is_null);
            if (!(is_null == true && StrIterIndex(&out) == 4)) {
                WriteFmtLn("[DEBUG] JReadNull 'null' value/advance wrong: n={}, idx={}", is_null, StrIterIndex(&out));
                success = false;
            }
            StrIter out = JReadBool(si, &b);
            if (!(b == true && StrIterIndex(&out) == 4)) {
                WriteFmtLn("[DEBUG] JReadBool exact 'true' wrong: b={}, idx={}", b, StrIterIndex(&out));
                success = false;
            }
            StrIter out = JReadBool(si, &b);
            if (!(b == false && StrIterIndex(&out) == 5)) {
                WriteFmtLn("[DEBUG] JReadBool exact 'false' wrong: b={}, idx={}", b, StrIterIndex(&out));
                success = false;
            }
            StrIter out     = JReadNull(si, &is_null);
            if (!(is_null == true && StrIterIndex(&out) == 4)) {
                WriteFmtLn("[DEBUG] JReadNull exact 'null' wrong: n={}, idx={}", is_null, StrIterIndex(&out));
                success = false;
            }
    // the output cleared. A string without \u still parses.
    bool test_truncated_unicode_escape_rejected(void) {
        WriteFmtLn("Testing \\u escape rejection (truncated and complete)");
    
        DefaultAllocator alloc   = DefaultAllocatorInit();
            // Truncated escape -> failure -> iterator unchanged.
            if (StrIterIndex(&r) != StrIterIndex(&si)) {
                WriteFmtLn("[DEBUG] JReadString advanced on truncated escape case {}", i);
                success = false;
            }
            StrIter r   = JReadString(si, &out);
            if (StrIterIndex(&r) != StrIterIndex(&si)) {
                WriteFmtLn("[DEBUG] JReadString accepted a complete \\u escape (should reject): idx={}", StrIterIndex(&r));
                success = false;
            }
            }
            if (StrLen(&out) != 0) {
                WriteFmtLn("[DEBUG] JReadString left partial output on rejected \\u escape: len={}", StrLen(&out));
                success = false;
            }
            StrIter r   = JReadString(si, &out);
            if (StrIterIndex(&r) == StrIterIndex(&si) || StrIterIndex(&r) != StrIterLength(&r)) {
                WriteFmtLn("[DEBUG] JReadString failed on a plain string: idx={}", StrIterIndex(&r));
                success = false;
            }
            }
            if (StrLen(&out) != 5 || MemCompare(StrBegin(&out), "plain", 5) != 0) {
                WriteFmtLn("[DEBUG] JReadString decoded plain string wrong: len={}", StrLen(&out));
                success = false;
            }
    // JSkipObject / JSkipArray dispatch the reader relies on.
    bool test_unknown_keys_of_every_type_skipped(void) {
        WriteFmtLn("Testing unknown keys of every value type are skipped");
    
        DefaultAllocator alloc   = DefaultAllocatorInit();
        // consumed).
        if (wanted != 7) {
            WriteFmtLn("[DEBUG] wanted parsed wrong after skips: {}", wanted);
            success = false;
        }
        }
        if (StrIterIndex(&si) != StrIterLength(&si)) {
            WriteFmtLn(
                "[DEBUG] iterator did not consume whole object: idx={}, len={}",
                StrIterIndex(&si),
    // accepting a partial parse.
    bool test_malformed_object_rejected(void) {
        WriteFmtLn("Testing malformed objects are rejected (iterator rewinds)");
    
        DefaultAllocator alloc   = DefaultAllocatorInit();
            // On structural failure the macro restores si to its start.
            if (StrIterIndex(&si) != 0) {
                WriteFmtLn("[DEBUG] malformed object case {} did not rewind: idx={}", i, StrIterIndex(&si));
                success = false;
            }
    // the sign handling in JReadNumber (the negate step) as caller-observable.
    bool test_negative_number_exact_values(void) {
        WriteFmtLn("Testing negative number exact values");
    
        DefaultAllocator alloc   = DefaultAllocatorInit();
            StrIter out = JReadInteger(si, &v);
            if (!(StrIterIndex(&out) != StrIterIndex(&si) && v == -12345)) {
                WriteFmtLn("[DEBUG] JReadInteger '-12345' -> {}", v);
                success = false;
            }
            StrIter out = JReadInteger(si, &v);
            if (!(StrIterIndex(&out) != StrIterIndex(&si) && v == 12345)) {
                WriteFmtLn("[DEBUG] JReadInteger '12345' -> {}", v);
                success = false;
            }
            StrIter out = JReadFloat(si, &v);
            if (!(StrIterIndex(&out) != StrIterIndex(&si) && v == -2.5)) {
                WriteFmtLn("[DEBUG] JReadFloat '-2.5' -> {}", v);
                success = false;
            }
    // 42.0 for any integer. Parse "7" and pin *val == 7.0 (and advance).
    bool test_js_float_reads_integer_valued_number(void) {
        WriteFmtLn("Testing JReadFloat promotes an integer-valued number exactly");
    
        DefaultAllocator alloc   = DefaultAllocatorInit();
        // Must advance (token consumed) and yield exactly 7.0 -- not 42.0.
        if (StrIterIndex(&out) == StrIterIndex(&si)) {
            WriteFmtLn("[DEBUG] JReadFloat did not advance on integer '7'");
            success = false;
        }
        }
        if (val != 7.0) {
            WriteFmtLn("[DEBUG] JReadFloat integer-promotion wrong: expected 7.0, got {}", val);
            success = false;
        }
    // cannot coincide with the literal. 13 -> 13.0, never 42.0.
    bool test_js_float_reads_zero_valued_integer(void) {
        WriteFmtLn("Testing JReadFloat promotes a second integer value exactly");
    
        DefaultAllocator alloc   = DefaultAllocatorInit();
    
        if (StrIterIndex(&out) == StrIterIndex(&si)) {
            WriteFmtLn("[DEBUG] JReadFloat did not advance on integer '13'");
            success = false;
        }
        }
        if (val != 13.0) {
            WriteFmtLn("[DEBUG] JReadFloat integer-promotion wrong: expected 13.0, got {}", val);
            success = false;
        }
    // remain false -- assert it is NOT truthy.
    bool test_js_null_clears_flag_on_non_null(void) {
        WriteFmtLn("Testing JReadNull clears is_null on a non-null token");
    
        DefaultAllocator alloc   = DefaultAllocatorInit();
        // Malformed -> iterator rewinds (no advance).
        if (StrIterIndex(&out) != StrIterIndex(&si)) {
            WriteFmtLn("[DEBUG] JReadNull advanced on malformed 'nuII'");
            success = false;
        }
        // The unconditional clear must have run: a truthy mutant fails here.
        if (is_null != false) {
            WriteFmtLn("[DEBUG] JReadNull left is_null truthy on non-null input: {}", is_null);
            success = false;
        }
    // mutant cannot satisfy one test by sabotaging the other.
    bool test_js_null_sets_flag_on_null(void) {
        WriteFmtLn("Testing JReadNull sets is_null on a real null token");
    
        DefaultAllocator alloc   = DefaultAllocatorInit();
    
        if (!(is_null == true && StrIterIndex(&out) == 4)) {
            WriteFmtLn("[DEBUG] JReadNull 'null' value/advance wrong: n={}, idx={}", is_null, StrIterIndex(&out));
            success = false;
        }
    // Test 1: Simple value round-trip
    bool test_simple_roundtrip(void) {
        WriteFmtLn("Testing simple value round-trip");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        });
    
        WriteFmtLn("[DEBUG] Generated JSON: {}", json);
    
        // Read back from JSON
        if (original.count == parsed.count && original.temperature == parsed.temperature &&
            original.enabled == parsed.enabled && StrCmp(&original.message, &parsed.message) == 0) {
            WriteFmtLn("[DEBUG] Simple round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Simple round-trip test FAILED");
            WriteFmtLn("[DEBUG] Simple round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Simple round-trip test FAILED");
            WriteFmtLn(
                "[DEBUG] Original: count={}, temp={}, enabled={}, msg='{}'",
        } else {
            WriteFmtLn("[DEBUG] Simple round-trip test FAILED");
            WriteFmtLn(
                "[DEBUG] Original: count={}, temp={}, enabled={}, msg='{}'",
                original.count,
                StrBegin(&original.message)
            );
            WriteFmtLn(
                "[DEBUG] Parsed: count={}, temp={}, enabled={}, msg='{}'",
                parsed.count,
    // Test 2: Numeric precision round-trip
    bool test_numeric_roundtrip(void) {
        WriteFmtLn("Testing numeric precision round-trip");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        });
    
        WriteFmtLn("[DEBUG] Numeric JSON: {}", json);
    
        // Read back from JSON
    
        if (ints_match && floats_match) {
            WriteFmtLn("[DEBUG] Numeric round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Numeric round-trip test FAILED");
            WriteFmtLn("[DEBUG] Numeric round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Numeric round-trip test FAILED");
            WriteFmtLn("[DEBUG] Integers match: {}", ints_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Floats match: {}", floats_match ? "true" : "false");
        } else {
            WriteFmtLn("[DEBUG] Numeric round-trip test FAILED");
            WriteFmtLn("[DEBUG] Integers match: {}", ints_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Floats match: {}", floats_match ? "true" : "false");
            success = false;
            WriteFmtLn("[DEBUG] Numeric round-trip test FAILED");
            WriteFmtLn("[DEBUG] Integers match: {}", ints_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Floats match: {}", floats_match ? "true" : "false");
            success = false;
        }
    // Test 3: Boolean round-trip
    bool test_boolean_roundtrip(void) {
        WriteFmtLn("Testing boolean round-trip");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        if (original.flag1 == parsed.flag1 && original.flag2 == parsed.flag2 && original.flag3 == parsed.flag3 &&
            original.flag4 == parsed.flag4) {
            WriteFmtLn("[DEBUG] Boolean round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Boolean round-trip test FAILED");
            WriteFmtLn("[DEBUG] Boolean round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Boolean round-trip test FAILED");
            success = false;
        }
    // Test 4: String round-trip
    bool test_string_roundtrip(void) {
        WriteFmtLn("Testing string round-trip");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
            StrCmp(&original.with_spaces, &parsed.with_spaces) == 0 &&
            StrCmp(&original.with_special, &parsed.with_special) == 0) {
            WriteFmtLn("[DEBUG] String round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] String round-trip test FAILED");
            WriteFmtLn("[DEBUG] String round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] String round-trip test FAILED");
            success = false;
        }
    // Test 5: Array round-trip
    bool test_array_roundtrip(void) {
        WriteFmtLn("Testing array round-trip");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        if (numbers_match && strings_match) {
            WriteFmtLn("[DEBUG] Array round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Array round-trip test FAILED");
            WriteFmtLn("[DEBUG] Array round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Array round-trip test FAILED");
            WriteFmtLn(
                "[DEBUG] Numbers match: {} (orig {}, parsed {})\n",
        } else {
            WriteFmtLn("[DEBUG] Array round-trip test FAILED");
            WriteFmtLn(
                "[DEBUG] Numbers match: {} (orig {}, parsed {})\n",
                numbers_match ? "true" : "false",
                VecLen(&parsed_numbers)
            );
            WriteFmtLn(
                "[DEBUG] Strings match: {} (orig {}, parsed {})\n",
                strings_match ? "true" : "false",
    // Test 6: Nested object round-trip
    bool test_nested_object_roundtrip(void) {
        WriteFmtLn("Testing nested object round-trip");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        // Compare
        if (compare_persons(&original_person, &parsed_person)) {
            WriteFmtLn("[DEBUG] Nested object round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Nested object round-trip test FAILED");
            WriteFmtLn("[DEBUG] Nested object round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Nested object round-trip test FAILED");
            success = false;
        }
    // Test 7: Complex data round-trip
    bool test_complex_data_roundtrip(void) {
        WriteFmtLn("Testing complex data round-trip");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        });
    
        WriteFmtLn("[DEBUG] Complex JSON length: {}", json);
    
        // Read back from JSON
    
        if (user_match && config_match && numbers_match && flags_match) {
            WriteFmtLn("[DEBUG] Complex data round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Complex data round-trip test FAILED");
            WriteFmtLn("[DEBUG] Complex data round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Complex data round-trip test FAILED");
            WriteFmtLn("[DEBUG] User match: {}", user_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Config match: {}", config_match ? "true" : "false");
        } else {
            WriteFmtLn("[DEBUG] Complex data round-trip test FAILED");
            WriteFmtLn("[DEBUG] User match: {}", user_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Config match: {}", config_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Numbers match: {}", numbers_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Complex data round-trip test FAILED");
            WriteFmtLn("[DEBUG] User match: {}", user_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Config match: {}", config_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Numbers match: {}", numbers_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Flags match: {}", flags_match ? "true" : "false");
            WriteFmtLn("[DEBUG] User match: {}", user_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Config match: {}", config_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Numbers match: {}", numbers_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Flags match: {}", flags_match ? "true" : "false");
            success = false;
            WriteFmtLn("[DEBUG] Config match: {}", config_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Numbers match: {}", numbers_match ? "true" : "false");
            WriteFmtLn("[DEBUG] Flags match: {}", flags_match ? "true" : "false");
            success = false;
        }
    // Test 8: Empty containers round-trip
    bool test_empty_containers_roundtrip(void) {
        WriteFmtLn("Testing empty containers round-trip");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        if (StrLen(&parsed_str) == 0 && VecLen(&parsed_numbers) == 0 && VecLen(&parsed_strings) == 0 &&
            !found_empty_object) { // Empty object should not execute the content
            WriteFmtLn("[DEBUG] Empty containers round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Empty containers round-trip test FAILED");
            WriteFmtLn("[DEBUG] Empty containers round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Empty containers round-trip test FAILED");
            WriteFmtLn(
                "[DEBUG] String length: {}, numbers: {}, strings: {}, found_obj: {}\n",
        } else {
            WriteFmtLn("[DEBUG] Empty containers round-trip test FAILED");
            WriteFmtLn(
                "[DEBUG] String length: {}, numbers: {}, strings: {}, found_obj: {}\n",
                StrLen(&parsed_str),
    // Test 9: Edge cases round-trip
    bool test_edge_cases_roundtrip(void) {
        WriteFmtLn("Testing edge cases round-trip");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
            original.zero_float == parsed.zero_float && original.true_val == parsed.true_val &&
            original.false_val == parsed.false_val) {
            WriteFmtLn("[DEBUG] Edge cases round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Edge cases round-trip test FAILED");
            WriteFmtLn("[DEBUG] Edge cases round-trip test passed");
        } else {
            WriteFmtLn("[DEBUG] Edge cases round-trip test FAILED");
            success = false;
        }
Last updated on