alef 0.79.5

Opinionated polyglot binding generator for Rust libraries
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
//! Kotlin `render_assertion` scalar-pipeline dispatch: the per-assertion-type match that runs
//! once every field-shape gate has declined and `assertion_scalar_context` has computed the
//! accessor expressions and shape flags.
//!
//! Split out of `assertions.rs` at the concept boundary -- `render_scalar_assertion` mirrors the
//! original single `match` exactly; every arm's body is a verbatim extraction, grouped into
//! shared helpers only where several match patterns already funnelled into the same behavior
//! (the four ordering comparisons, `starts_with`/`ends_with`, `min_length`/`max_length`,
//! `count_min`/`count_equals`, `is_true`/`is_false`) — no behavior change. ~keep

use std::fmt::Write as FmtWrite;

use crate::e2e::field_access::FieldResolver;
use crate::e2e::fixture::Assertion;

/// Compute the scalar-pipeline context (`assertion_scalar_context::compute_scalar_context`) and
/// immediately dispatch it (`render_scalar_assertion`) -- the single call `render_assertion`
/// makes once every field-shape gate has declined, so it stays under the file's
/// function-length cap. Verbatim orchestration, no behavior change. ~keep
#[allow(clippy::too_many_arguments)]
pub(super) fn render_scalar_pipeline(
    out: &mut String,
    assertion: &Assertion,
    field_resolver: &FieldResolver,
    result_var: &str,
    result_is_simple: bool,
    result_is_option: bool,
    enum_fields: &std::collections::HashSet<String>,
    json_scalar_fields: &std::collections::HashSet<String>,
    fields_c_types: &std::collections::HashMap<String, String>,
    kotlin_android_style: bool,
    is_streaming: bool,
    not_error_may_assert_presence: bool,
) {
    let (
        field_expr,
        string_field_expr,
        nonnull_field_expr,
        string_expr,
        field_is_optional,
        field_is_collection,
        field_is_long,
    ) = super::assertion_scalar_context::compute_scalar_context(
        assertion,
        field_resolver,
        result_var,
        result_is_simple,
        result_is_option,
        enum_fields,
        json_scalar_fields,
        fields_c_types,
        kotlin_android_style,
    );

    render_scalar_assertion(
        out,
        assertion,
        &field_expr,
        &string_field_expr,
        &nonnull_field_expr,
        &string_expr,
        field_is_optional,
        field_is_collection,
        field_is_long,
        result_var,
        result_is_simple,
        result_is_option,
        kotlin_android_style,
        is_streaming,
        not_error_may_assert_presence,
    );
}

/// The assertion types `render_value_arm` handles -- every arm whose output depends only on the
/// already-computed field-expression variants, never on `result_is_option`/`is_streaming`/
/// presence-template concerns. Named once so the top dispatcher and `render_value_arm` can never
/// disagree about which arms belong to which half. ~keep
const VALUE_ASSERTION_TYPES: &[&str] = &[
    "equals",
    "contains",
    "contains_all",
    "not_contains",
    "contains_any",
    "greater_than",
    "less_than",
    "greater_than_or_equal",
    "less_than_or_equal",
    "starts_with",
    "ends_with",
    "min_length",
    "max_length",
    "count_min",
    "count_equals",
    "is_true",
    "is_false",
    "matches_regex",
];

/// Dispatch on assertion type once every field-shape gate has declined and the scalar-pipeline
/// context (`field_expr` and its derived string/non-null/enum-aware variants, plus the
/// `field_is_*` shape flags) has been computed. Split into `render_value_arm` and
/// `render_presence_arm` to keep this dispatcher itself under the file's function-length cap --
/// the split point is exactly where `render_assertion`'s original single `match` already read as
/// two families of arms; no behavior change.
#[allow(clippy::too_many_arguments)]
pub(super) fn render_scalar_assertion(
    out: &mut String,
    assertion: &Assertion,
    field_expr: &str,
    string_field_expr: &str,
    nonnull_field_expr: &str,
    string_expr: &str,
    field_is_optional: bool,
    field_is_collection: bool,
    field_is_long: bool,
    result_var: &str,
    result_is_simple: bool,
    result_is_option: bool,
    kotlin_android_style: bool,
    is_streaming: bool,
    not_error_may_assert_presence: bool,
) {
    if VALUE_ASSERTION_TYPES.contains(&assertion.assertion_type.as_str()) {
        render_value_arm(
            out,
            assertion,
            field_expr,
            string_field_expr,
            nonnull_field_expr,
            string_expr,
            field_is_optional,
            field_is_collection,
            field_is_long,
            result_var,
            result_is_simple,
        );
    } else {
        render_presence_arm(
            out,
            assertion,
            field_expr,
            string_field_expr,
            field_is_collection,
            field_is_optional,
            result_var,
            result_is_option,
            kotlin_android_style,
            is_streaming,
            not_error_may_assert_presence,
        );
    }
}

/// The field-expression-only half of the original `match`: every arm whose rendering depends
/// only on the already-computed `field_expr` variants, not on `result_is_option`/`is_streaming`/
/// presence-template concerns. ~keep
#[allow(clippy::too_many_arguments)]
fn render_value_arm(
    out: &mut String,
    assertion: &Assertion,
    field_expr: &str,
    string_field_expr: &str,
    nonnull_field_expr: &str,
    string_expr: &str,
    field_is_optional: bool,
    field_is_collection: bool,
    field_is_long: bool,
    result_var: &str,
    result_is_simple: bool,
) {
    match assertion.assertion_type.as_str() {
        "equals" => render_equals_arm(out, assertion, field_is_long, string_expr, nonnull_field_expr),
        "contains" => render_contains_arm(out, assertion, field_is_collection, string_expr),
        "contains_all" => render_contains_all_arm(out, assertion, field_is_collection, string_expr),
        "not_contains" => render_not_contains_arm(out, assertion, field_is_collection, string_expr),
        "contains_any" => render_contains_any_arm(out, assertion, string_expr),
        "greater_than" => render_greater_than_arm(out, assertion, nonnull_field_expr),
        "less_than" => render_less_than_arm(out, assertion, nonnull_field_expr),
        "greater_than_or_equal" => render_greater_than_or_equal_arm(out, assertion, nonnull_field_expr),
        "less_than_or_equal" => render_less_than_or_equal_arm(out, assertion, nonnull_field_expr),
        "starts_with" => render_starts_with_arm(out, assertion, string_expr),
        "ends_with" => render_ends_with_arm(out, assertion, string_expr),
        "min_length" => {
            render_min_length_arm(
                out,
                assertion,
                result_is_simple,
                field_expr,
                result_var,
                string_field_expr,
            );
        }
        "max_length" => {
            render_max_length_arm(
                out,
                assertion,
                result_is_simple,
                field_expr,
                result_var,
                string_field_expr,
            );
        }
        "count_min" => render_count_min_arm(out, assertion, nonnull_field_expr),
        "count_equals" => render_count_equals_arm(out, assertion, nonnull_field_expr),
        "is_true" => render_is_true_arm(out, field_is_optional, field_expr),
        "is_false" => render_is_false_arm(out, field_is_optional, field_expr),
        "matches_regex" => {
            if let Some(expected) = &assertion.value {
                let kotlin_val = super::values::json_to_kotlin(expected);
                let _ = writeln!(
                    out,
                    "        assertTrue(Regex({kotlin_val}).containsMatchIn({string_expr}), \"expected value to match regex: \" + {kotlin_val})"
                );
            }
        }
        other => unreachable!("render_value_arm called for non-value assertion type {other}"),
    }
}

/// The presence/misc half of the original `match`: `not_empty`/`is_empty` (which need
/// `result_is_option`/`kotlin_android_style` for their Optional-vs-nullable presence templates),
/// `not_error`/`error`/`method_result`, and the final catch-all panic. ~keep
#[allow(clippy::too_many_arguments)]
fn render_presence_arm(
    out: &mut String,
    assertion: &Assertion,
    field_expr: &str,
    string_field_expr: &str,
    field_is_collection: bool,
    field_is_optional: bool,
    result_var: &str,
    result_is_option: bool,
    kotlin_android_style: bool,
    is_streaming: bool,
    not_error_may_assert_presence: bool,
) {
    match assertion.assertion_type.as_str() {
        "not_empty" | "is_empty" => render_empty_presence_arm(
            out,
            assertion,
            EmptyPresenceContext {
                result_is_option,
                kotlin_android_style,
                field_is_collection,
                field_is_optional,
                field_expr,
                string_field_expr,
            },
        ),
        // See `not_error::render_not_error` for why this is not a no-op. WHETHER it may assert
        // presence at all is decided once, centrally, by `not_error_presence::may_assert_presence`
        // -- passed in as `not_error_may_assert_presence` -- not re-derived here.
        "not_error" => {
            super::not_error::render_not_error(out, result_var, not_error_may_assert_presence, is_streaming);
        }
        "error" => {
            // Handled at the test method level.
        }
        "method_result" => {
            // Placeholder: Kotlin support for method_result would need sample_language integration.
            let _ = writeln!(
                out,
                "        // method_result assertions not yet implemented for Kotlin"
            );
        }
        other => {
            panic!("Kotlin e2e generator: unsupported assertion type: {other}");
        }
    }
}

fn render_equals_arm(
    out: &mut String,
    assertion: &Assertion,
    field_is_long: bool,
    string_expr: &str,
    nonnull_field_expr: &str,
) {
    if let Some(expected) = &assertion.value {
        // Suffix integer literals with `L` when the target field is a Java `long`
        // (uint64_t / int64_t in C FFI terms). Without the suffix, Kotlin infers
        // the literal as `Int`, causing a type mismatch with `Long` at runtime.
        let kotlin_val = if field_is_long && expected.is_number() && !expected.is_f64() {
            format!("{}L", expected)
        } else {
            super::values::json_to_kotlin(expected)
        };
        if expected.is_string() {
            let _ = writeln!(out, "        assertEquals({kotlin_val}, {string_expr})");
        } else {
            let _ = writeln!(out, "        assertEquals({kotlin_val}, {nonnull_field_expr})");
        }
    }
}

fn render_contains_arm(out: &mut String, assertion: &Assertion, field_is_collection: bool, string_expr: &str) {
    if let Some(expected) = &assertion.value {
        let kotlin_val = super::values::json_to_kotlin(expected);
        if field_is_collection {
            // `(list as List<String>)` is an unchecked erasure cast that
            // succeeds at runtime even for `List<StructureItem>` etc.
            // `.contains("Module")` then compares records against a
            // String and always fails. Stringifying the collection
            // mirrors the Java emitter (`toString().toLowerCase().contains(...)`)
            // and matches both `List<String>` and `List<ComplexType>`.
            let _ = writeln!(
                out,
                "        assertTrue({string_expr}.toString().lowercase().contains({kotlin_val}.toString().lowercase()), \"expected to contain: \" + {kotlin_val})"
            );
        } else {
            // String substring check. Use the field expression directly so
            // `String.contains(CharSequence)` resolves without a cast.
            let _ = writeln!(
                out,
                "        assertTrue({string_expr}.contains({kotlin_val}), \"expected to contain: \" + {kotlin_val})"
            );
        }
    }
}

fn render_contains_all_arm(out: &mut String, assertion: &Assertion, field_is_collection: bool, string_expr: &str) {
    if let Some(values) = &assertion.values {
        for val in values {
            let kotlin_val = super::values::json_to_kotlin(val);
            if field_is_collection {
                let _ = writeln!(
                    out,
                    "        assertTrue({string_expr}.toString().lowercase().contains({kotlin_val}.toString().lowercase()), \"expected to contain: \" + {kotlin_val})"
                );
            } else {
                let _ = writeln!(
                    out,
                    "        assertTrue({string_expr}.contains({kotlin_val}), \"expected to contain: \" + {kotlin_val})"
                );
            }
        }
    }
}

fn render_not_contains_arm(out: &mut String, assertion: &Assertion, field_is_collection: bool, string_expr: &str) {
    for expected in assertion.expected_values() {
        let kotlin_val = super::values::json_to_kotlin(expected);
        if field_is_collection {
            let _ = writeln!(
                out,
                "        assertFalse({string_expr}.toString().lowercase().contains({kotlin_val}.toString().lowercase()), \"expected NOT to contain: \" + {kotlin_val})"
            );
        } else {
            let _ = writeln!(
                out,
                "        assertFalse({string_expr}.contains({kotlin_val}), \"expected NOT to contain: \" + {kotlin_val})"
            );
        }
    }
}

/// For optional fields, the field type may be a non-String object (e.g. DocumentStructure) for
/// which `.orEmpty()` is undefined. A null-check is the safe primitive: it works for any
/// reference type and matches the Java codegen's `Optional.ofNullable(...).isEmpty()`. When the
/// bare result is `T?` (result_is_option) the same null-check applies, because `.isEmpty()` is
/// undefined on arbitrary nullable types. The JVM Kotlin e2e tests call the Java facade class
/// which returns `java.util.Optional<T>` for option results — use `.isPresent` rather than `!=
/// null` so the assertion semantics match the JVM return type. The kotlin-android wrapper
/// unwraps `Optional<T>` to Kotlin's `T?` at the boundary, so its bare-option result is a
/// nullable reference and must use `!= null` instead.
#[derive(Clone, Copy)]
struct EmptyPresenceContext<'a> {
    result_is_option: bool,
    kotlin_android_style: bool,
    field_is_collection: bool,
    field_is_optional: bool,
    field_expr: &'a str,
    string_field_expr: &'a str,
}

fn render_empty_presence_arm(out: &mut String, assertion: &Assertion, context: EmptyPresenceContext<'_>) {
    if assertion.assertion_type == "not_empty" {
        render_not_empty_arm(out, assertion, context);
    } else {
        render_is_empty_arm(out, assertion, context);
    }
}

fn render_not_empty_arm(out: &mut String, assertion: &Assertion, context: EmptyPresenceContext<'_>) {
    let bare_result_is_option =
        context.result_is_option && assertion.field.as_deref().filter(|f| !f.is_empty()).is_none();
    if bare_result_is_option && !context.kotlin_android_style {
        out.push_str(&crate::e2e::template_env::render(
            "kotlin/not_empty_assertion.kt.jinja",
            minijinja::context! { predicate => format!("{}.isPresent", context.field_expr) },
        ));
    } else if context.field_is_collection && (bare_result_is_option || context.field_is_optional) {
        out.push_str(&crate::e2e::template_env::render(
            "kotlin/not_empty_assertion.kt.jinja",
            minijinja::context! { predicate => format!("{}?.isNotEmpty() == true", context.field_expr) },
        ));
    } else if bare_result_is_option || context.field_is_optional {
        out.push_str(&crate::e2e::template_env::render(
            "kotlin/not_empty_assertion.kt.jinja",
            minijinja::context! { predicate => format!("{} != null", context.field_expr) },
        ));
    } else {
        let _ = writeln!(
            out,
            "        assertFalse({}.isEmpty(), \"expected non-empty value\")",
            context.string_field_expr
        );
    }
}

fn render_is_empty_arm(out: &mut String, assertion: &Assertion, context: EmptyPresenceContext<'_>) {
    let bare_result_is_option =
        context.result_is_option && assertion.field.as_deref().filter(|f| !f.is_empty()).is_none();
    if bare_result_is_option && !context.kotlin_android_style {
        out.push_str(&crate::e2e::template_env::render(
            "kotlin/is_empty_assertion.kt.jinja",
            minijinja::context! { predicate => format!("{}.isEmpty", context.field_expr) },
        ));
    } else if context.field_is_collection && (bare_result_is_option || context.field_is_optional) {
        // Symmetric with `not_empty`'s `field_is_collection && (bare_result_is_option ||
        // field_is_optional)` branch above: an optional collection reached through
        // `field_is_optional` (e.g. `Option<Vec<T>>`) must null-check before calling
        // `.isEmpty()`, or a genuinely-empty-but-present collection throws instead of
        // asserting true. `?: true` treats a null (absent) collection as empty too,
        // matching every other backend's "null counts as empty" semantics for this
        // assertion type. ~keep
        out.push_str(&crate::e2e::template_env::render(
            "kotlin/is_empty_assertion.kt.jinja",
            minijinja::context! { predicate => format!("({}?.isEmpty() ?: true)", context.field_expr) },
        ));
    } else if bare_result_is_option || context.field_is_optional {
        out.push_str(&crate::e2e::template_env::render(
            "kotlin/is_empty_assertion.kt.jinja",
            minijinja::context! { predicate => format!("{} == null", context.field_expr) },
        ));
    } else {
        out.push_str(&crate::e2e::template_env::render(
            "kotlin/is_empty_assertion.kt.jinja",
            minijinja::context! { predicate => format!("{}.isEmpty()", context.string_field_expr) },
        ));
    }
}

fn render_contains_any_arm(out: &mut String, assertion: &Assertion, string_expr: &str) {
    if let Some(values) = &assertion.values {
        let checks: Vec<String> = values
            .iter()
            .map(|v| {
                let kotlin_val = super::values::json_to_kotlin(v);
                format!("{string_expr}.contains({kotlin_val})")
            })
            .collect();
        let joined = checks.join(" || ");
        let _ = writeln!(
            out,
            "        assertTrue({joined}, \"expected to contain at least one of the specified values\")"
        );
    }
}

fn render_greater_than_arm(out: &mut String, assertion: &Assertion, nonnull_field_expr: &str) {
    if let Some(val) = &assertion.value {
        let kotlin_val = super::values::json_to_kotlin(val);
        let _ = writeln!(
            out,
            "        assertTrue({nonnull_field_expr} > {kotlin_val}, \"expected > {kotlin_val}\")"
        );
    }
}

fn render_less_than_arm(out: &mut String, assertion: &Assertion, nonnull_field_expr: &str) {
    if let Some(val) = &assertion.value {
        let kotlin_val = super::values::json_to_kotlin(val);
        let _ = writeln!(
            out,
            "        assertTrue({nonnull_field_expr} < {kotlin_val}, \"expected < {kotlin_val}\")"
        );
    }
}

fn render_greater_than_or_equal_arm(out: &mut String, assertion: &Assertion, nonnull_field_expr: &str) {
    if let Some(val) = &assertion.value {
        let kotlin_val = super::values::json_to_kotlin(val);
        let _ = writeln!(
            out,
            "        assertTrue({nonnull_field_expr} >= {kotlin_val}, \"expected >= {kotlin_val}\")"
        );
    }
}

fn render_less_than_or_equal_arm(out: &mut String, assertion: &Assertion, nonnull_field_expr: &str) {
    if let Some(val) = &assertion.value {
        let kotlin_val = super::values::json_to_kotlin(val);
        let _ = writeln!(
            out,
            "        assertTrue({nonnull_field_expr} <= {kotlin_val}, \"expected <= {kotlin_val}\")"
        );
    }
}

fn render_starts_with_arm(out: &mut String, assertion: &Assertion, string_expr: &str) {
    if let Some(expected) = &assertion.value {
        let kotlin_val = super::values::json_to_kotlin(expected);
        let _ = writeln!(
            out,
            "        assertTrue({string_expr}.startsWith({kotlin_val}), \"expected to start with: \" + {kotlin_val})"
        );
    }
}

fn render_ends_with_arm(out: &mut String, assertion: &Assertion, string_expr: &str) {
    if let Some(expected) = &assertion.value {
        let kotlin_val = super::values::json_to_kotlin(expected);
        let _ = writeln!(
            out,
            "        assertTrue({string_expr}.endsWith({kotlin_val}), \"expected to end with: \" + {kotlin_val})"
        );
    }
}

/// For simple result types (ByteArray), use .size; for String use .length
fn render_min_length_arm(
    out: &mut String,
    assertion: &Assertion,
    result_is_simple: bool,
    field_expr: &str,
    result_var: &str,
    string_field_expr: &str,
) {
    if let Some(val) = &assertion.value
        && let Some(n) = val.as_u64()
    {
        let length_accessor = if result_is_simple && field_expr == result_var {
            "size"
        } else {
            "length"
        };
        let _ = writeln!(
            out,
            "        assertTrue({string_field_expr}.{length_accessor} >= {n}, \"expected {length_accessor} >= {n}\")"
        );
    }
}

/// For simple result types (ByteArray), use .size; for String use .length
fn render_max_length_arm(
    out: &mut String,
    assertion: &Assertion,
    result_is_simple: bool,
    field_expr: &str,
    result_var: &str,
    string_field_expr: &str,
) {
    if let Some(val) = &assertion.value
        && let Some(n) = val.as_u64()
    {
        let length_accessor = if result_is_simple && field_expr == result_var {
            "size"
        } else {
            "length"
        };
        let _ = writeln!(
            out,
            "        assertTrue({string_field_expr}.{length_accessor} <= {n}, \"expected {length_accessor} <= {n}\")"
        );
    }
}

fn render_count_min_arm(out: &mut String, assertion: &Assertion, nonnull_field_expr: &str) {
    if let Some(val) = &assertion.value
        && let Some(n) = val.as_u64()
    {
        let _ = writeln!(
            out,
            "        assertTrue({nonnull_field_expr}.size >= {n}, \"expected at least {n} elements\")"
        );
    }
}

fn render_count_equals_arm(out: &mut String, assertion: &Assertion, nonnull_field_expr: &str) {
    if let Some(val) = &assertion.value
        && let Some(n) = val.as_u64()
    {
        let _ = writeln!(
            out,
            "        assertEquals({n}, {nonnull_field_expr}.size, \"expected exactly {n} elements\")"
        );
    }
}

/// `T?`: "is_true" means "present" -- `field_expr == true` never type-errors in Kotlin (`==` is
/// Any?-to-Any? structural equality) but it also never matches a non-Boolean nullable (e.g.
/// `DataNode?`), so the assertion always fails at runtime even when the field is present. `!=
/// null` is the interpretation that holds for any T, matching the Rust `.is_some()` convention
/// for this assertion type. ~keep
fn render_is_true_arm(out: &mut String, field_is_optional: bool, field_expr: &str) {
    if field_is_optional {
        let _ = writeln!(
            out,
            "        assertTrue({field_expr} != null, \"expected true (non-null)\")"
        );
    } else {
        let _ = writeln!(out, "        assertTrue({field_expr} == true, \"expected true\")");
    }
}

fn render_is_false_arm(out: &mut String, field_is_optional: bool, field_expr: &str) {
    if field_is_optional {
        let _ = writeln!(
            out,
            "        assertTrue({field_expr} == null, \"expected false (null)\")"
        );
    } else {
        let _ = writeln!(out, "        assertTrue({field_expr} == false, \"expected false\")");
    }
}