alef 0.107.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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
//! NAPI binding/core conversion coverage, split from tests.rs.

use super::NapiBackend;
use super::methods::gen_tagged_enum_core_to_binding;
use super::tests::*;
use crate::core::backend::Backend;
use crate::core::ir::{EnumDef, EnumVariant, FieldDef, TypeRef};
use ahash::AHashSet;

/// Regression coverage for the `clippy::redundant_field_names` fix: an optional tagged-enum
/// field whose type needs no cast/wrap (e.g. plain `Option<String>`) falls into the fallback
/// match arm in `gen_tagged_enum_core_to_binding`, where the destructured core-side variable
/// is bound under the same name as the binding field it fills. The field-init expression must
/// use shorthand (`text`), never `text: text`.
#[test]
fn core_to_binding_uses_shorthand_for_self_assigned_optional_field() {
    let enum_def = EnumDef {
        name: "Content".to_string(),
        rust_path: "fixture_core::Content".to_string(),
        variants: vec![EnumVariant {
            name: "Text".to_string(),
            fields: vec![FieldDef {
                name: "text".to_string(),
                ty: TypeRef::String,
                optional: true,
                ..Default::default()
            }],
            ..Default::default()
        }],
        serde_content: None,
        serde_tag: Some("type".to_string()),
        serde_rename_all: Some("snake_case".to_string()),
        ..Default::default()
    };

    let struct_names = AHashSet::new();
    let core_to_binding = gen_tagged_enum_core_to_binding(&enum_def, "fixture_core", "Js", &struct_names, None, &[]);

    assert!(
        !core_to_binding.contains("text: text"),
        "self-assigned optional field must use shorthand, not `text: text`:\n{core_to_binding}"
    );
    assert!(
        core_to_binding.contains("text }") || core_to_binding.contains("text,"),
        "expected field-init shorthand for `text`:\n{core_to_binding}"
    );
}

/// Same fallback arm, but for a field whose type does need a cast/wrap (`Vec<Named>` maps
/// through `.into()`) — this must keep the real `field: expr` form, not collapse to shorthand.
#[test]
fn core_to_binding_keeps_expr_form_when_conversion_is_required() {
    let enum_def = EnumDef {
        name: "Content".to_string(),
        rust_path: "fixture_core::Content".to_string(),
        variants: vec![EnumVariant {
            name: "Items".to_string(),
            fields: vec![FieldDef {
                name: "items".to_string(),
                ty: TypeRef::Vec(Box::new(TypeRef::Named("Widget".to_string()))),
                optional: true,
                ..Default::default()
            }],
            ..Default::default()
        }],
        serde_content: None,
        serde_tag: Some("type".to_string()),
        serde_rename_all: Some("snake_case".to_string()),
        ..Default::default()
    };

    let struct_names = AHashSet::new();
    let core_to_binding = gen_tagged_enum_core_to_binding(&enum_def, "fixture_core", "Js", &struct_names, None, &[]);

    assert!(
        core_to_binding.contains("items: items.map(|v| v.into_iter().map(Into::into).collect())"),
        "Vec<Named> optional field must keep its real conversion expression:\n{core_to_binding}"
    );
}

/// Regression test: an optional `Named` tagged-enum field whose type has a generated binding
/// struct (`has_binding` in the old code) must NOT be dereferenced unless the CORE field is
/// actually `Option<Box<T>>`. Before the fix, `core_to_binding_field_init` picked the deref
/// form purely off `has_binding`, so a plain (unboxed) `Option<T>` field emitted
/// `nested.map(|v| (*v).into())`, which fails to compile with E0614 because `v` is `T`, not
/// `Box<T>`. Mirrors the real-world defect on `DocxAppProperties`/`CoreProperties`/`YearRange`
/// fields (all plain `Option<T>`, all with a binding struct, none boxed).
#[test]
fn core_to_binding_optional_unboxed_named_field_is_not_dereferenced() {
    let enum_def = EnumDef {
        name: "Content".to_string(),
        rust_path: "fixture_core::Content".to_string(),
        variants: vec![EnumVariant {
            name: "WithNested".to_string(),
            fields: vec![FieldDef {
                name: "nested".to_string(),
                ty: TypeRef::Named("Nested".to_string()),
                optional: true,
                is_boxed: false,
                ..Default::default()
            }],
            ..Default::default()
        }],
        serde_content: None,
        serde_tag: Some("type".to_string()),
        serde_rename_all: Some("snake_case".to_string()),
        ..Default::default()
    };

    // `struct_names` containing "Nested" is what makes `has_binding` true for this field --
    // exactly the condition the old code (wrongly) used to decide whether to dereference.
    let mut struct_names = AHashSet::new();
    struct_names.insert("Nested".to_string());
    let core_to_binding = gen_tagged_enum_core_to_binding(&enum_def, "fixture_core", "Js", &struct_names, None, &[]);

    assert!(
        !core_to_binding.contains("nested.map(|v| (*v).into())"),
        "unboxed Option<T> field must not be dereferenced (E0614 -- v is T, not Box<T>):\n{core_to_binding}"
    );
    assert!(
        core_to_binding.contains("nested: nested.map(|v| v.into())"),
        "expected the unboxed optional Named field conversion:\n{core_to_binding}"
    );
}

fn node_config() -> crate::core::config::ResolvedCrateConfig {
    let cfg: crate::core::config::new_config::NewAlefConfig = toml::from_str(
        r#"
[workspace]
languages = ["node"]

[[crates]]
name = "test-lib"
sources = ["src/lib.rs"]
"#,
    )
    .unwrap();
    cfg.resolve().unwrap().remove(0)
}

/// Regression test for issue #380, exercised through the real `NapiBackend::generate_bindings`
/// path (not just the `gen_function` unit): a `&mut T` DTO parameter on a unit-returning free
/// function must render as a binding that returns the mutated intermediate.
#[test]
fn generate_bindings_writeback_free_function_returns_mutated_dto() {
    use crate::core::ir::{ApiSurface, FunctionDef, ParamDef, PrimitiveType, TypeDef};

    let api = ApiSurface {
        crate_name: "test-lib".to_string(),
        version: "0.1.0".to_string(),
        types: vec![TypeDef {
            name: "Record".to_string(),
            rust_path: "test_lib::Record".to_string(),
            has_serde: true,
            fields: vec![FieldDef {
                name: "score".to_string(),
                ty: TypeRef::Primitive(PrimitiveType::U32),
                ..Default::default()
            }],
            ..Default::default()
        }],
        functions: vec![FunctionDef {
            name: "tag_record".to_string(),
            rust_path: "test_lib::tag_record".to_string(),
            params: vec![ParamDef {
                name: "record".to_string(),
                ty: TypeRef::Named("Record".to_string()),
                is_ref: true,
                is_mut: true,
                ..Default::default()
            }],
            return_type: TypeRef::Unit,
            ..Default::default()
        }],
        ..Default::default()
    };

    let files = NapiBackend.generate_bindings(&api, &node_config()).unwrap();
    let lib = files.iter().find(|f| f.path.ends_with("lib.rs")).unwrap();

    assert!(
        lib.content.contains("record_core.into()"),
        "expected the write-back tail through the real generate_bindings path:\n{}",
        lib.content
    );
}

/// `reject_unsupported_writeback` must fire through the real `NapiBackend::generate_bindings`
/// path: a `&mut T` DTO param on a function that ALSO returns a value has no free return slot
/// for the write-back value, so generation must fail loudly (naming the function).
#[test]
fn generate_bindings_rejects_mut_dto_param_with_non_unit_return() {
    use crate::core::ir::{ApiSurface, FunctionDef, ParamDef, PrimitiveType, TypeDef};

    let api = ApiSurface {
        crate_name: "test-lib".to_string(),
        version: "0.1.0".to_string(),
        types: vec![TypeDef {
            name: "Record".to_string(),
            rust_path: "test_lib::Record".to_string(),
            has_serde: true,
            fields: vec![FieldDef {
                name: "score".to_string(),
                ty: TypeRef::Primitive(PrimitiveType::U32),
                ..Default::default()
            }],
            ..Default::default()
        }],
        functions: vec![FunctionDef {
            name: "tag_and_count".to_string(),
            rust_path: "test_lib::tag_and_count".to_string(),
            params: vec![ParamDef {
                name: "record".to_string(),
                ty: TypeRef::Named("Record".to_string()),
                is_ref: true,
                is_mut: true,
                ..Default::default()
            }],
            return_type: TypeRef::Primitive(PrimitiveType::U32),
            ..Default::default()
        }],
        ..Default::default()
    };

    let error = NapiBackend
        .generate_bindings(&api, &node_config())
        .expect_err("a `&mut` DTO param plus a non-unit return must be rejected at generation time");
    let message = error.to_string();
    assert!(
        message.contains("tag_and_count"),
        "diagnostic must name the offending function:\n{message}"
    );
}

#[test]
fn promoted_required_method_and_constructor_parameters_return_invalid_arg() {
    use super::constructors::napi_variant_wrapper_constructor;
    use super::types::{gen_opaque_instance_method, gen_static_method};
    use crate::backends::napi::type_map::NapiMapper;
    use crate::core::ir::{MethodDef, ParamDef, PrimitiveType, ReceiverKind, TypeDef, TypeRef};
    use std::collections::HashMap;

    let params = vec![
        ParamDef {
            name: "label".into(),
            ty: TypeRef::String,
            optional: true,
            ..Default::default()
        },
        ParamDef {
            name: "limit".into(),
            ty: TypeRef::Primitive(PrimitiveType::U32),
            ..Default::default()
        },
    ];
    let instance = MethodDef {
        name: "apply".into(),
        params: params.clone(),
        return_type: TypeRef::Primitive(PrimitiveType::U32),
        receiver: Some(ReceiverKind::Ref),
        ..Default::default()
    };
    let static_method = MethodDef {
        name: "build".into(),
        params: params.clone(),
        return_type: TypeRef::Named("Widget".into()),
        ..Default::default()
    };
    let constructor = MethodDef {
        name: "new".into(),
        params,
        return_type: TypeRef::Named("Widget".into()),
        ..Default::default()
    };
    let typ = TypeDef {
        name: "Widget".into(),
        rust_path: "sample_core::Widget".into(),
        is_opaque: true,
        is_variant_wrapper: true,
        methods: vec![instance.clone(), static_method.clone(), constructor],
        ..Default::default()
    };
    let mapper = NapiMapper::new("Js".into());
    let cfg = NapiBackend::binding_config("sample_core", "Js", true);
    let empty = AHashSet::new();
    let instance_output = gen_opaque_instance_method(
        &instance,
        &mapper,
        &typ,
        &cfg,
        &empty,
        "Js",
        &crate::adapters::AdapterBodies::new(),
        &ahash::AHashMap::new(),
        &empty,
        &HashMap::new(),
    );
    let static_output = gen_static_method(&static_method, &mapper, &typ, &cfg, &empty, "Js", &empty);
    let constructor_output = napi_variant_wrapper_constructor(&typ, &mapper, "sample_core", "Js").unwrap();

    for output in [&instance_output, &static_output, &constructor_output] {
        assert!(output.contains("label: Option<String>, limit: Option<u32>"), "{output}");
        assert!(output.contains("limit.ok_or_else"), "{output}");
        assert!(
            output.contains("-> Result") || output.contains("-> napi::Result"),
            "{output}"
        );
        assert!(!output.contains("expect("), "{output}");
    }
}

#[test]
fn flattened_optional_transparent_wrapper_uses_one_binding_option_layer() {
    use crate::codegen::conversions::ConversionConfig;
    use crate::core::ir::{FieldDef, NewtypeContainer, TypeDef, TypeRef};

    let typ = TypeDef {
        name: "Report".into(),
        rust_path: "fixture_core::Report".into(),
        fields: vec![FieldDef {
            name: "nested_optional_credential".into(),
            ty: TypeRef::Optional(Box::new(TypeRef::String)),
            optional: true,
            newtype_wrapper: Some(transparent_string_wrapper_with_methods(
                vec![vec![NewtypeContainer::Optional, NewtypeContainer::Optional]],
                "new_secret",
                "expose_secret",
            )),
            ..Default::default()
        }],
        has_default: true,
        ..Default::default()
    };
    let config = ConversionConfig {
        type_name_prefix: "Js",
        cast_large_ints_to_i64: true,
        cast_f32_to_f64: true,
        optionalize_defaults: true,
        optionalize_bare_field_defaults: true,
        ..Default::default()
    };

    let to_core = super::transparent_newtypes::gen_from_binding_to_core(&typ, "fixture_core", &config);
    assert!(
        to_core.contains("__result.nested_optional_credential =")
            && to_core.contains("map(fixture_core::SecretString::new_secret)")
            && to_core.contains(".map(Some)"),
        "the single JS optional must convert once and reconstruct the outer Rust Option:\n{to_core}"
    );
    assert!(
        !to_core.contains("map(|value| fixture_core::SecretString::new_secret(value))"),
        "flattened optional wrapper must not emit Clippy's redundant-closure shape:\n{to_core}"
    );
    assert!(
        !to_core.contains("map(|value| (value).map("),
        "a String inside the flattened JS Option is not another iterator/Option:\n{to_core}"
    );

    let from_core =
        super::transparent_newtypes::gen_from_core_to_binding(&typ, "fixture_core", &AHashSet::new(), &config);
    assert!(
        from_core.contains("flatten()") && from_core.contains("expose_secret()"),
        "the two Rust options must flatten before consuming the wrapper:\n{from_core}"
    );
    assert!(
        !from_core.contains("nested_optional_credential.flatten().map(|v| v.to_string())"),
        "an explicit transparent wrapper must not require Display:\n{from_core}"
    );
}

#[test]
fn root_optional_transparent_wrapper_field_uses_configured_constructor_function() {
    use crate::codegen::conversions::ConversionConfig;
    use crate::core::ir::{FieldDef, NewtypeContainer, TypeDef, TypeRef};

    let typ = TypeDef {
        name: "Report".into(),
        rust_path: "fixture_core::Report".into(),
        fields: vec![FieldDef {
            name: "optional_credential".into(),
            ty: TypeRef::String,
            optional: true,
            newtype_wrapper: Some(transparent_string_wrapper_with_methods(
                vec![vec![NewtypeContainer::Optional]],
                "new_secret",
                "expose_secret",
            )),
            ..Default::default()
        }],
        ..Default::default()
    };

    let output = super::transparent_newtypes::gen_from_binding_to_core(
        &typ,
        "fixture_core",
        &ConversionConfig {
            type_name_prefix: "Js",
            ..Default::default()
        },
    );

    assert!(
        output.contains("optional_credential: (val.optional_credential).map(fixture_core::SecretString::new_secret)"),
        "root optional wrapper must use the configured constructor function:\n{output}"
    );
    assert!(
        !output.contains("map(|value| fixture_core::SecretString::new_secret(value))"),
        "root optional wrapper must not emit Clippy's redundant-closure shape:\n{output}"
    );
}

#[test]
fn constructor_owned_root_optional_wrapper_uses_configured_constructor_function() {
    use crate::codegen::conversions::ConversionConfig;
    use crate::core::ir::{FieldDef, MethodDef, NewtypeContainer, ParamDef, TypeDef, TypeRef};

    for has_lifetime_params in [false, true] {
        let field = FieldDef {
            name: "optional_credential".into(),
            ty: TypeRef::String,
            optional: true,
            newtype_wrapper: Some(transparent_string_wrapper_with_methods(
                vec![vec![NewtypeContainer::Optional]],
                "new_secret",
                "expose_secret",
            )),
            ..Default::default()
        };
        let typ = TypeDef {
            name: "Report".into(),
            rust_path: "fixture_core::Report".into(),
            fields: vec![field],
            methods: vec![MethodDef {
                name: "new".into(),
                params: vec![ParamDef {
                    name: "optional_credential".into(),
                    ty: TypeRef::String,
                    optional: true,
                    ..Default::default()
                }],
                is_static: true,
                ..Default::default()
            }],
            has_lifetime_params,
            ..Default::default()
        };

        let output = super::transparent_newtypes::gen_from_binding_to_core(
            &typ,
            "fixture_core",
            &ConversionConfig {
                type_name_prefix: "Js",
                ..Default::default()
            },
        );

        assert!(output.contains("::new("), "constructor path must be emitted:\n{output}");
        assert!(
            output.contains("(val.optional_credential).map(fixture_core::SecretString::new_secret)"),
            "constructor argument must use the configured wrapper constructor:\n{output}"
        );
        assert!(
            !output.contains("map(|value| fixture_core::SecretString::new_secret(value))"),
            "constructor argument must not emit a redundant closure:\n{output}"
        );
    }
}

#[test]
fn constructor_owned_flattened_wrapper_preserves_nested_container_traversal() {
    use crate::codegen::conversions::ConversionConfig;
    use crate::core::ir::{FieldDef, MethodDef, NewtypeContainer, ParamDef, TypeDef, TypeRef};

    let ty = TypeRef::Optional(Box::new(TypeRef::Vec(Box::new(TypeRef::Map(
        Box::new(TypeRef::String),
        Box::new(TypeRef::String),
    )))));
    let wrapper = transparent_string_wrapper(vec![
        vec![
            NewtypeContainer::Optional,
            NewtypeContainer::Optional,
            NewtypeContainer::Vec,
            NewtypeContainer::MapKey,
        ],
        vec![
            NewtypeContainer::Optional,
            NewtypeContainer::Optional,
            NewtypeContainer::Vec,
            NewtypeContainer::MapValue,
        ],
    ]);
    let typ = TypeDef {
        name: "Report".into(),
        rust_path: "fixture_core::Report".into(),
        fields: vec![FieldDef {
            name: "secrets".into(),
            ty: ty.clone(),
            optional: true,
            newtype_wrapper: Some(wrapper),
            ..Default::default()
        }],
        methods: vec![MethodDef {
            name: "new".into(),
            params: vec![ParamDef {
                name: "secrets".into(),
                ty,
                optional: true,
                ..Default::default()
            }],
            is_static: true,
            ..Default::default()
        }],
        ..Default::default()
    };

    let output = super::transparent_newtypes::gen_from_binding_to_core(
        &typ,
        "fixture_core",
        &ConversionConfig {
            type_name_prefix: "Js",
            ..Default::default()
        },
    );

    assert!(output.contains("::new("), "constructor path must be emitted:\n{output}");
    assert!(
        output.contains("fixture_core::SecretString::from(key)")
            && output.contains("fixture_core::SecretString::from(value)"),
        "nested map keys and values must still construct wrappers:\n{output}"
    );
    assert!(
        output.contains(".map(Some)"),
        "outer Rust option must be restored:\n{output}"
    );
}

#[test]
fn flattened_optional_wrapper_recurses_through_vec_map_and_named_sibling() {
    use crate::codegen::conversions::ConversionConfig;
    use crate::core::ir::{FieldDef, NewtypeContainer, TypeDef, TypeRef};

    let typ = TypeDef {
        name: "Report".into(),
        rust_path: "fixture_core::Report".into(),
        fields: vec![FieldDef {
            name: "nested_optional_segments".into(),
            ty: TypeRef::Optional(Box::new(TypeRef::Vec(Box::new(TypeRef::Map(
                Box::new(TypeRef::String),
                Box::new(TypeRef::Named("Segment".into())),
            ))))),
            optional: true,
            newtype_wrapper: Some(transparent_string_wrapper(vec![vec![
                NewtypeContainer::Optional,
                NewtypeContainer::Optional,
                NewtypeContainer::Vec,
                NewtypeContainer::MapKey,
            ]])),
            ..Default::default()
        }],
        ..Default::default()
    };
    let config = ConversionConfig {
        type_name_prefix: "Js",
        cast_large_ints_to_i64: true,
        cast_f32_to_f64: true,
        optionalize_defaults: true,
        optionalize_bare_field_defaults: true,
        ..Default::default()
    };

    let to_core = super::transparent_newtypes::gen_from_binding_to_core(&typ, "fixture_core", &config);
    assert!(to_core.contains("fixture_core::SecretString::from(key)"), "{to_core}");
    assert!(
        to_core.contains("(value).into()"),
        "the JsSegment map value must convert to Segment:\n{to_core}"
    );

    let from_core =
        super::transparent_newtypes::gen_from_core_to_binding(&typ, "fixture_core", &AHashSet::new(), &config);
    assert!(from_core.contains("(key).into_inner()"), "{from_core}");
    assert!(
        from_core.contains("(value).into()"),
        "the Segment map value must convert to JsSegment:\n{from_core}"
    );
}

#[test]
fn excluded_flattened_optional_wrapper_requires_no_generated_conversion() {
    use crate::codegen::conversions::ConversionConfig;
    use crate::core::ir::{FieldDef, NewtypeContainer, TypeDef, TypeRef};

    let typ = TypeDef {
        name: "HiddenReport".into(),
        rust_path: "fixture_core::HiddenReport".into(),
        fields: vec![FieldDef {
            name: "hidden_credential".into(),
            ty: TypeRef::Optional(Box::new(TypeRef::String)),
            optional: true,
            binding_excluded: true,
            newtype_wrapper: Some(transparent_string_wrapper(vec![vec![
                NewtypeContainer::Optional,
                NewtypeContainer::Optional,
            ]])),
            ..Default::default()
        }],
        has_default: true,
        ..Default::default()
    };
    let config = ConversionConfig {
        type_name_prefix: "Js",
        ..Default::default()
    };

    let to_core = super::transparent_newtypes::gen_from_binding_to_core(&typ, "fixture_core", &config);
    let from_core =
        super::transparent_newtypes::gen_from_core_to_binding(&typ, "fixture_core", &AHashSet::new(), &config);

    assert!(!to_core.contains("hidden_credential"), "{to_core}");
    assert!(!from_core.contains("hidden_credential"), "{from_core}");
}

#[test]
fn nested_optional_boxed_enum_fallback_defaults_the_complete_container() {
    use crate::core::ir::{FieldDef, NewtypeContainer, TypeRef};

    let field = FieldDef {
        name: "_0".into(),
        ty: TypeRef::Optional(Box::new(TypeRef::String)),
        optional: true,
        is_boxed: true,
        newtype_wrapper: Some(transparent_string_wrapper(vec![vec![
            NewtypeContainer::Optional,
            NewtypeContainer::Optional,
        ]])),
        ..Default::default()
    };

    assert_eq!(
        super::transparent_newtypes::default_to_core(&field),
        "Default::default()"
    );
}