alef 0.25.39

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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
use super::{make_test_type, simple_type_mapper};
use crate::codegen::config_gen::{
    gen_csharp_record, gen_extendr_kwargs_constructor, gen_go_functional_options, gen_java_builder,
    gen_magnus_kwargs_constructor, gen_napi_defaults_constructor, gen_php_kwargs_constructor,
    gen_pyo3_kwargs_constructor, gen_rustler_kwargs_constructor,
};
use crate::core::ir::{CoreWrapper, FieldDef, PrimitiveType, TypeDef, TypeRef};

#[test]
fn test_gen_pyo3_kwargs_constructor() {
    let typ = make_test_type();
    let output = gen_pyo3_kwargs_constructor(&typ, &|tr: &TypeRef| match tr {
        TypeRef::Primitive(p) => format!("{:?}", p),
        TypeRef::String | TypeRef::Char => "str".to_string(),
        _ => "Any".to_string(),
    });

    assert!(output.contains("#[new]"));
    assert!(output.contains("#[pyo3(signature = ("));
    assert!(output.contains("timeout=30"));
    assert!(output.contains("enabled=True"));
    assert!(output.contains("name=\"default\""));
    assert!(output.contains("fn new("));
}

#[test]
fn test_gen_napi_defaults_constructor() {
    let typ = make_test_type();
    let output = gen_napi_defaults_constructor(&typ, &|tr: &TypeRef| match tr {
        TypeRef::Primitive(p) => format!("{:?}", p),
        TypeRef::String | TypeRef::Char => "String".to_string(),
        _ => "Value".to_string(),
    });

    assert!(output.contains("pub fn new(mut env: napi::Env, obj: napi::Object)"));
    assert!(output.contains("timeout"));
    assert!(output.contains("enabled"));
    assert!(output.contains("name"));
}

#[test]
fn test_gen_go_functional_options() {
    let typ = make_test_type();
    let output = gen_go_functional_options(&typ, &|tr: &TypeRef| match tr {
        TypeRef::Primitive(p) => match p {
            PrimitiveType::U64 => "uint64".to_string(),
            PrimitiveType::Bool => "bool".to_string(),
            _ => "interface{}".to_string(),
        },
        TypeRef::String | TypeRef::Char => "string".to_string(),
        _ => "interface{}".to_string(),
    });

    assert!(output.contains("type Config struct {"));
    assert!(output.contains("type ConfigOption func(*Config)"));
    assert!(output.contains("func WithConfigTimeout(val uint64) ConfigOption"));
    assert!(output.contains("func WithConfigEnabled(val bool) ConfigOption"));
    assert!(output.contains("func WithConfigName(val string) ConfigOption"));
    assert!(output.contains("func NewConfig(opts ...ConfigOption) *Config"));
}

#[test]
fn test_gen_java_builder() {
    let typ = make_test_type();
    let output = gen_java_builder(&typ, "dev.test", &|tr: &TypeRef| match tr {
        TypeRef::Primitive(p) => match p {
            PrimitiveType::U64 => "long".to_string(),
            PrimitiveType::Bool => "boolean".to_string(),
            _ => "int".to_string(),
        },
        TypeRef::String | TypeRef::Char => "String".to_string(),
        _ => "Object".to_string(),
    });

    assert!(output.contains("package dev.test;"));
    assert!(output.contains("public class ConfigBuilder"));
    assert!(output.contains("withTimeout"));
    assert!(output.contains("withEnabled"));
    assert!(output.contains("withName"));
    assert!(output.contains("public Config build()"));
}

#[test]
fn test_gen_csharp_record() {
    let typ = make_test_type();
    let output = gen_csharp_record(&typ, "MyNamespace", &|tr: &TypeRef| match tr {
        TypeRef::Primitive(p) => match p {
            PrimitiveType::U64 => "ulong".to_string(),
            PrimitiveType::Bool => "bool".to_string(),
            _ => "int".to_string(),
        },
        TypeRef::String | TypeRef::Char => "string".to_string(),
        _ => "object".to_string(),
    });

    assert!(output.contains("namespace MyNamespace;"));
    assert!(output.contains("public record Config"));
    assert!(output.contains("public ulong Timeout"));
    assert!(output.contains("public bool Enabled"));
    assert!(output.contains("public string Name"));
    assert!(output.contains("init;"));
}
fn test_gen_magnus_kwargs_constructor_hash_path_for_many_fields() {
    // Build a type with 16 fields (> MAGNUS_MAX_ARITY = 15) to force hash path
    let mut fields: Vec<FieldDef> = (0..16)
        .map(|i| FieldDef {
            name: format!("field_{i}"),
            ty: TypeRef::Primitive(PrimitiveType::U32),
            optional: false,
            default: None,
            doc: String::new(),
            sanitized: false,
            is_boxed: false,
            type_rust_path: None,
            cfg: None,
            typed_default: None,
            core_wrapper: CoreWrapper::None,
            vec_inner_core_wrapper: CoreWrapper::None,
            newtype_wrapper: None,
            serde_rename: None,
            serde_flatten: false,
            binding_excluded: false,
            binding_exclusion_reason: None,
            original_type: None,
        })
        .collect();
    // Make one field optional to exercise that branch in the hash constructor
    fields[0].optional = true;

    let typ = TypeDef {
        name: "BigConfig".to_string(),
        rust_path: "crate::BigConfig".to_string(),
        original_rust_path: String::new(),
        fields,
        methods: vec![],
        is_opaque: false,
        is_clone: true,
        is_copy: false,
        doc: String::new(),
        cfg: None,
        is_trait: false,
        has_default: true,
        has_stripped_cfg_fields: false,
        is_return_type: false,
        serde_rename_all: None,
        has_serde: false,
        super_traits: vec![],
        binding_excluded: false,
        binding_exclusion_reason: None,
        is_variant_wrapper: false,
        has_lifetime_params: false,
        version: Default::default(),
    };
    let output = gen_magnus_kwargs_constructor(&typ, &simple_type_mapper);

    assert!(
        output.contains("Option<magnus::RHash>"),
        "should accept RHash via scan_args"
    );
    assert!(output.contains("ruby.to_symbol("), "should use symbol lookup");
    // Optional field uses and_then without unwrap_or
    assert!(
        output.contains("field_0: kwargs.get(ruby.to_symbol(\"field_0\")).and_then(|v|"),
        "optional field should use and_then"
    );
    assert!(
        output.contains("field_0:").then_some(()).is_some(),
        "field_0 should appear in output"
    );
}

// -------------------------------------------------------------------------
// gen_php_kwargs_constructor
// -------------------------------------------------------------------------

#[test]
fn test_gen_php_kwargs_constructor_basic() {
    let typ = make_test_type();
    let output = gen_php_kwargs_constructor(&typ, &simple_type_mapper);

    assert!(
        output.contains("pub fn __construct("),
        "should use PHP constructor name"
    );
    // All params are Option<T>
    assert!(
        output.contains("timeout: Option<u64>"),
        "timeout param should be Option<u64>"
    );
    assert!(
        output.contains("enabled: Option<bool>"),
        "enabled param should be Option<bool>"
    );
    assert!(
        output.contains("name: Option<String>"),
        "name param should be Option<String>"
    );
    assert!(output.contains("-> Self {"), "should return Self");
    assert!(
        output.contains("timeout: timeout.unwrap_or(30),"),
        "should apply int default for timeout"
    );
    assert!(
        output.contains("enabled: enabled.unwrap_or(true),"),
        "should apply bool default for enabled"
    );
    assert!(
        output.contains("name: name.unwrap_or(\"default\".to_string()),"),
        "should apply string default for name"
    );
}

#[test]
fn test_gen_php_kwargs_constructor_optional_field_passthrough() {
    let mut typ = make_test_type();
    typ.fields.push(FieldDef {
        name: "tag".to_string(),
        ty: TypeRef::String,
        optional: true,
        default: None,
        doc: String::new(),
        sanitized: false,
        is_boxed: false,
        type_rust_path: None,
        cfg: None,
        typed_default: None,
        core_wrapper: CoreWrapper::None,
        vec_inner_core_wrapper: CoreWrapper::None,
        newtype_wrapper: None,
        serde_rename: None,
        serde_flatten: false,
        binding_excluded: false,
        binding_exclusion_reason: None,
        original_type: None,
    });
    let output = gen_php_kwargs_constructor(&typ, &simple_type_mapper);
    assert!(
        output.contains("tag,"),
        "optional field should be passed through directly"
    );
    assert!(!output.contains("tag.unwrap"), "optional field should not call unwrap");
}

#[test]
fn test_gen_php_kwargs_constructor_unwrap_or_default_for_primitive() {
    let mut typ = make_test_type();
    typ.fields.push(FieldDef {
        name: "retries".to_string(),
        ty: TypeRef::Primitive(PrimitiveType::U32),
        optional: false,
        default: None,
        doc: String::new(),
        sanitized: false,
        is_boxed: false,
        type_rust_path: None,
        cfg: None,
        typed_default: None,
        core_wrapper: CoreWrapper::None,
        vec_inner_core_wrapper: CoreWrapper::None,
        newtype_wrapper: None,
        serde_rename: None,
        serde_flatten: false,
        binding_excluded: false,
        binding_exclusion_reason: None,
        original_type: None,
    });
    let output = gen_php_kwargs_constructor(&typ, &simple_type_mapper);
    assert!(
        output.contains("retries: retries.unwrap_or_default(),"),
        "primitive with no default should use unwrap_or_default"
    );
}

// -------------------------------------------------------------------------
// gen_rustler_kwargs_constructor
// -------------------------------------------------------------------------

#[test]
fn test_gen_rustler_kwargs_constructor_basic() {
    let typ = make_test_type();
    let output = gen_rustler_kwargs_constructor(&typ, &simple_type_mapper);

    assert!(
        output.contains("pub fn new(opts: std::collections::HashMap<String, rustler::Term>)"),
        "should accept HashMap of Terms"
    );
    assert!(output.contains("Self {"), "should construct Self");
    // timeout has IntLiteral(30) — explicit unwrap_or
    assert!(
        output.contains("timeout: opts.get(\"timeout\").and_then(|t| t.decode().ok()).unwrap_or(30),"),
        "should apply int default for timeout"
    );
    // enabled has BoolLiteral(true) — explicit unwrap_or
    assert!(
        output.contains("enabled: opts.get(\"enabled\").and_then(|t| t.decode().ok()).unwrap_or(true),"),
        "should apply bool default for enabled"
    );
}

#[test]
fn test_gen_rustler_kwargs_constructor_optional_field() {
    let mut typ = make_test_type();
    typ.fields.push(FieldDef {
        name: "extra".to_string(),
        ty: TypeRef::String,
        optional: true,
        default: None,
        doc: String::new(),
        sanitized: false,
        is_boxed: false,
        type_rust_path: None,
        cfg: None,
        typed_default: None,
        core_wrapper: CoreWrapper::None,
        vec_inner_core_wrapper: CoreWrapper::None,
        newtype_wrapper: None,
        serde_rename: None,
        serde_flatten: false,
        binding_excluded: false,
        binding_exclusion_reason: None,
        original_type: None,
    });
    let output = gen_rustler_kwargs_constructor(&typ, &simple_type_mapper);
    assert!(
        output.contains("extra: opts.get(\"extra\").and_then(|t| t.decode().ok()),"),
        "optional field should decode without unwrap"
    );
}

#[test]
fn test_gen_rustler_kwargs_constructor_skips_binding_excluded_fields() {
    let mut typ = make_test_type();
    typ.fields.push(FieldDef {
        name: "internal_cache".to_string(),
        ty: TypeRef::String,
        optional: false,
        default: None,
        doc: String::new(),
        sanitized: false,
        is_boxed: false,
        type_rust_path: None,
        cfg: None,
        typed_default: None,
        core_wrapper: CoreWrapper::None,
        vec_inner_core_wrapper: CoreWrapper::None,
        newtype_wrapper: None,
        serde_rename: None,
        serde_flatten: false,
        binding_excluded: true,
        binding_exclusion_reason: Some("internal implementation detail".to_string()),
        original_type: None,
    });

    let output = gen_rustler_kwargs_constructor(&typ, &simple_type_mapper);

    assert!(
        !output.contains("internal_cache"),
        "binding-excluded fields must not be exposed in Rustler constructors; got:\n{output}"
    );
}

#[test]
fn test_gen_rustler_kwargs_constructor_named_type_uses_unwrap_or_default() {
    let mut typ = make_test_type();
    typ.fields.push(FieldDef {
        name: "inner".to_string(),
        ty: TypeRef::Named("InnerConfig".to_string()),
        optional: false,
        default: None,
        doc: String::new(),
        sanitized: false,
        is_boxed: false,
        type_rust_path: None,
        cfg: None,
        typed_default: None,
        core_wrapper: CoreWrapper::None,
        vec_inner_core_wrapper: CoreWrapper::None,
        newtype_wrapper: None,
        serde_rename: None,
        serde_flatten: false,
        binding_excluded: false,
        binding_exclusion_reason: None,
        original_type: None,
    });
    let output = gen_rustler_kwargs_constructor(&typ, &simple_type_mapper);
    assert!(
        output.contains("inner: opts.get(\"inner\").and_then(|t| t.decode().ok()).unwrap_or_default(),"),
        "Named type with no default should use unwrap_or_default"
    );
}

#[test]
fn test_gen_rustler_kwargs_constructor_string_field_uses_unwrap_or_default() {
    // A String field with a StringLiteral default contains "::", triggering the
    // is_enum_variant_default check — should fall back to unwrap_or_default().
    let mut typ = make_test_type();
    // 'name' field in make_test_type() has StringLiteral("default") — verify it
    let output = gen_rustler_kwargs_constructor(&typ, &simple_type_mapper);
    assert!(
        output.contains("name: opts.get(\"name\").and_then(|t| t.decode().ok()).unwrap_or_default(),"),
        "String field with quoted default should use unwrap_or_default"
    );
    // Also verify a plain string field (no default) also falls through to unwrap_or_default
    typ.fields.push(FieldDef {
        name: "label".to_string(),
        ty: TypeRef::String,
        optional: false,
        default: None,
        doc: String::new(),
        sanitized: false,
        is_boxed: false,
        type_rust_path: None,
        cfg: None,
        typed_default: None,
        core_wrapper: CoreWrapper::None,
        vec_inner_core_wrapper: CoreWrapper::None,
        newtype_wrapper: None,
        serde_rename: None,
        serde_flatten: false,
        binding_excluded: false,
        binding_exclusion_reason: None,
        original_type: None,
    });
    let output2 = gen_rustler_kwargs_constructor(&typ, &simple_type_mapper);
    assert!(
        output2.contains("label: opts.get(\"label\").and_then(|t| t.decode().ok()).unwrap_or_default(),"),
        "String field with no default should use unwrap_or_default"
    );
}

// -------------------------------------------------------------------------
// gen_extendr_kwargs_constructor
// -------------------------------------------------------------------------

#[test]
fn test_gen_extendr_kwargs_constructor_basic() {
    let typ = make_test_type();
    let empty_enums = ahash::AHashSet::new();
    let output = gen_extendr_kwargs_constructor(&typ, &simple_type_mapper, &empty_enums);

    assert!(output.contains("#[extendr]"), "should have extendr attribute");
    assert!(
        output.contains("pub fn new_config("),
        "function name should be lowercase type name"
    );
    // Fields appear as Option<T> parameters — Rust does not support param defaults.
    assert!(
        output.contains("timeout: Option<u64>"),
        "should accept timeout as Option<u64>: {output}"
    );
    assert!(
        output.contains("enabled: Option<bool>"),
        "should accept enabled as Option<bool>: {output}"
    );
    assert!(
        output.contains("name: Option<String>"),
        "should accept name as Option<String>: {output}"
    );
    assert!(output.contains("-> Config {"), "should return Config");
    assert!(
        output.contains("let mut __out = <Config>::default();"),
        "should base on Default impl: {output}"
    );
    assert!(
        output.contains("if let Some(v) = timeout { __out.timeout = v; }"),
        "should overlay caller-provided timeout"
    );
    assert!(
        output.contains("if let Some(v) = enabled { __out.enabled = v; }"),
        "should overlay caller-provided enabled"
    );
    assert!(
        output.contains("if let Some(v) = name { __out.name = v; }"),
        "should overlay caller-provided name"
    );
}

#[test]
fn test_gen_extendr_kwargs_constructor_uses_option_for_all_fields() {
    // Rust function-parameter defaults (`x: T = expr`) are a syntax error and
    // extendr 0.9 only supports defaults via the `#[extendr(default = "...")]`
    // attribute.  Verify that no field is emitted with a Rust-syntax default.
    let typ = make_test_type();
    let empty_enums = ahash::AHashSet::new();
    let output = gen_extendr_kwargs_constructor(&typ, &simple_type_mapper, &empty_enums);
    assert!(
        !output.contains("= TRUE") && !output.contains("= FALSE") && !output.contains("= \"default\""),
        "constructor must not use Rust-syntax param defaults: {output}"
    );
}

// -------------------------------------------------------------------------
// gen_go_functional_options — tuple-field filtering
// -------------------------------------------------------------------------

#[test]
fn test_gen_go_functional_options_skips_tuple_fields() {
    let mut typ = make_test_type();
    typ.fields.push(FieldDef {
        name: "_0".to_string(),
        ty: TypeRef::Primitive(PrimitiveType::U32),
        optional: false,
        default: None,
        doc: String::new(),
        sanitized: false,
        is_boxed: false,
        type_rust_path: None,
        cfg: None,
        typed_default: None,
        core_wrapper: CoreWrapper::None,
        vec_inner_core_wrapper: CoreWrapper::None,
        newtype_wrapper: None,
        serde_rename: None,
        serde_flatten: false,
        binding_excluded: false,
        binding_exclusion_reason: None,
        original_type: None,
    });
    let output = gen_go_functional_options(&typ, &simple_type_mapper);
    assert!(
        !output.contains("_0"),
        "tuple field _0 should be filtered out from Go output"
    );
}

// -------------------------------------------------------------------------
// as_type_path_prefix — tested indirectly through hash constructor
// -------------------------------------------------------------------------

#[test]
fn test_gen_magnus_hash_constructor_generic_type_prefix() {
    // A field with a Vec type should use <Vec<...>>::try_convert UFCS form
    let fields: Vec<FieldDef> = (0..16)
        .map(|i| FieldDef {
            name: format!("field_{i}"),
            ty: if i == 0 {
                TypeRef::Vec(Box::new(TypeRef::String))
            } else {
                TypeRef::Primitive(PrimitiveType::U32)
            },
            optional: false,
            default: None,
            doc: String::new(),
            sanitized: false,
            is_boxed: false,
            type_rust_path: None,
            cfg: None,
            typed_default: None,
            core_wrapper: CoreWrapper::None,
            vec_inner_core_wrapper: CoreWrapper::None,
            newtype_wrapper: None,
            serde_rename: None,
            serde_flatten: false,
            binding_excluded: false,
            binding_exclusion_reason: None,
            original_type: None,
        })
        .collect();
    let typ = TypeDef {
        name: "WideConfig".to_string(),
        rust_path: "crate::WideConfig".to_string(),
        original_rust_path: String::new(),
        fields,
        methods: vec![],
        is_opaque: false,
        is_clone: true,
        is_copy: false,
        doc: String::new(),
        cfg: None,
        is_trait: false,
        has_default: true,
        has_stripped_cfg_fields: false,
        is_return_type: false,
        serde_rename_all: None,
        has_serde: false,
        super_traits: vec![],
        binding_excluded: false,
        binding_exclusion_reason: None,
        is_variant_wrapper: false,
        has_lifetime_params: false,
        version: Default::default(),
    };
    let output = gen_magnus_kwargs_constructor(&typ, &simple_type_mapper);
    // Vec<String> is a generic type; must use <Vec<String>>::try_convert
    assert!(
        output.contains("<Vec<String>>::try_convert"),
        "generic types should use UFCS angle-bracket prefix: {output}"
    );
}

// -------------------------------------------------------------------------
// Bug B regression: Option<Option<T>> must not appear when field.optional==true
// and field.ty==Optional(T). This happens for "Update" structs where the core
// field is Option<Option<T>> — the binding flattens to Option<T>.
// -------------------------------------------------------------------------

#[test]
fn test_magnus_hash_constructor_no_double_option_when_ty_is_optional() {
    // field with optional=true AND ty=Optional(Usize) — represents a core Option<Option<usize>>
    // that should flatten to Option<usize> in the binding constructor.
    // simple_type_mapper maps Usize → "i64" (catch-all primitive arm).
    let field = FieldDef {
        name: "max_depth".to_string(),
        ty: TypeRef::Optional(Box::new(TypeRef::Primitive(PrimitiveType::Usize))),
        optional: true,
        default: None,
        doc: String::new(),
        sanitized: false,
        is_boxed: false,
        type_rust_path: None,
        cfg: None,
        typed_default: None,
        core_wrapper: CoreWrapper::None,
        vec_inner_core_wrapper: CoreWrapper::None,
        newtype_wrapper: None,
        serde_rename: None,
        serde_flatten: false,
        binding_excluded: false,
        binding_exclusion_reason: None,
        original_type: None,
    };
    // Build a large type (>15 fields) so the hash constructor is used
    let mut fields: Vec<FieldDef> = (0..15)
        .map(|i| FieldDef {
            name: format!("field_{i}"),
            ty: TypeRef::Primitive(PrimitiveType::U32),
            optional: false,
            default: None,
            doc: String::new(),
            sanitized: false,
            is_boxed: false,
            type_rust_path: None,
            cfg: None,
            typed_default: None,
            core_wrapper: CoreWrapper::None,
            vec_inner_core_wrapper: CoreWrapper::None,
            newtype_wrapper: None,
            serde_rename: None,
            serde_flatten: false,
            binding_excluded: false,
            binding_exclusion_reason: None,
            original_type: None,
        })
        .collect();
    fields.push(field);
    let typ = TypeDef {
        name: "UpdateConfig".to_string(),
        rust_path: "crate::UpdateConfig".to_string(),
        original_rust_path: String::new(),
        fields,
        methods: vec![],
        is_opaque: false,
        is_clone: true,
        is_copy: false,
        doc: String::new(),
        cfg: None,
        is_trait: false,
        has_default: true,
        has_stripped_cfg_fields: false,
        is_return_type: false,
        serde_rename_all: None,
        has_serde: false,
        super_traits: vec![],
        binding_excluded: false,
        binding_exclusion_reason: None,
        is_variant_wrapper: false,
        has_lifetime_params: false,
        version: Default::default(),
    };
    let output = gen_magnus_kwargs_constructor(&typ, &simple_type_mapper);
    // The try_convert call must be for the inner type (i64, as mapped by simple_type_mapper),
    // not Option<i64> (which would yield Option<Option<i64>>).
    assert!(
        !output.contains("Option<Option<"),
        "hash constructor must not emit double Option: {output}"
    );
    assert!(
        output.contains("i64::try_convert"),
        "hash constructor should call inner-type::try_convert, not Option<T>::try_convert: {output}"
    );
}