@@ -480,46 +480,67 @@ test Options {
480
480
world : bool = true ,
481
481
};
482
482
483
+ const NormalUnion = union (NormalEnum ) {
484
+ foo : u16 ,
485
+ bar : [2 ]u8 ,
486
+ };
487
+
483
488
const NestedStruct = struct {
484
489
normal_struct : NormalStruct ,
485
490
normal_enum : NormalEnum = .foo ,
486
491
};
487
492
493
+ const NonExhaustiveEnum = enum (u8 ) {
494
+ one ,
495
+ two ,
496
+ three ,
497
+ _ ,
498
+ };
499
+
488
500
options .addOption (usize , "option1" , 1 );
489
501
options .addOption (? usize , "option2" , null );
490
502
options .addOption (? usize , "option3" , 3 );
491
503
options .addOption (comptime_int , "option4" , 4 );
504
+ options .addOption (comptime_float , "option5" , 0.125 );
505
+ options .addOption (@Type (.enum_literal ), "option6" , .foo );
492
506
options .addOption ([]const u8 , "string" , "zigisthebest" );
493
507
options .addOption (? []const u8 , "optional_string" , null );
494
508
options .addOption ([2 ][2 ]u16 , "nested_array" , nested_array );
495
509
options .addOption ([]const []const u16 , "nested_slice" , nested_slice );
496
510
options .addOption (KeywordEnum , "keyword_enum" , .@"0.8.1" );
497
511
options .addOption (std .SemanticVersion , "semantic_version" , try std .SemanticVersion .parse ("0.1.2-foo+bar" ));
498
- options .addOption (NormalEnum , "normal1_enum" , NormalEnum .foo );
499
- options .addOption (NormalEnum , "normal2_enum" , NormalEnum .bar );
500
- options .addOption (NormalStruct , "normal1_struct" , NormalStruct {
501
- .hello = "foo" ,
502
- });
503
- options .addOption (NormalStruct , "normal2_struct " , NormalStruct {
504
- . hello = null ,
505
- . world = false ,
506
- });
507
- options . addOption ( NestedStruct , "nested_struct" , NestedStruct {
508
- .normal_struct = . { .hello = "bar" },
512
+ options .addOption (NormalEnum , "normal1_enum" , .foo );
513
+ options .addOption (NormalEnum , "normal2_enum" , .bar );
514
+ options .addOption (NormalStruct , "normal1_struct" , .{ . hello = "foo" });
515
+ options . addOption ( NormalStruct , "normal2_struct" , .{ .hello = null , . world = false });
516
+ options . addOption ( NormalUnion , "normal_union" , .{ . bar = .{ 42 , 64 } });
517
+ options .addOption (NestedStruct , "nested_struct " , .{ . normal_struct = .{ . hello = "bar" } });
518
+ options . addOption ( NonExhaustiveEnum , "non_exhaustive_enum1" , .two );
519
+ options . addOption ( NonExhaustiveEnum , "non_exhaustive_enum2" , @enumFromInt ( 20 ));
520
+ options . addOption ([ 2 ] NormalStruct , "array_of_structs" , .{
521
+ .{ . hello = null },
522
+ .{ .hello = "zig" , . world = true },
509
523
});
524
+ options .addOption (?? u32 , "nested_optional1" , 10 );
525
+ options .addOption (?? u32 , "nested_optional2" , @as (? u32 , null ));
526
+ options .addOption (?? u32 , "nested_optional3" , null );
510
527
511
528
try std .testing .expectEqualStrings (
512
529
\\pub const option1: usize = 1;
513
530
\\
514
- \\pub const option2: ?usize = null;
531
+ \\pub const option2: ?usize = @as(?usize, null) ;
515
532
\\
516
533
\\pub const option3: ?usize = 3;
517
534
\\
518
535
\\pub const option4: comptime_int = 4;
519
536
\\
537
+ \\pub const option5: comptime_float = 1.25e-1;
538
+ \\
539
+ \\pub const option6: @Type(.enum_literal) = .foo;
540
+ \\
520
541
\\pub const string: []const u8 = "zigisthebest";
521
542
\\
522
- \\pub const optional_string: ?[]const u8 = null;
543
+ \\pub const optional_string: ?[]const u8 = @as(?[]const u8, null) ;
523
544
\\
524
545
\\pub const nested_array: [2][2]u16 = .{
525
546
\\ .{
@@ -577,10 +598,20 @@ test Options {
577
598
\\};
578
599
\\
579
600
\\pub const normal2_struct: @"Build.Step.Options.decltest.Options.NormalStruct" = .{
580
- \\ .hello = null,
601
+ \\ .hello = @as(?[]const u8, null) ,
581
602
\\ .world = false,
582
603
\\};
583
604
\\
605
+ \\pub const @"Build.Step.Options.decltest.Options.NormalUnion" = union(@"Build.Step.Options.decltest.Options.NormalEnum") {
606
+ \\ foo: u16,
607
+ \\ bar: [2]u8,
608
+ \\};
609
+ \\
610
+ \\pub const normal_union: @"Build.Step.Options.decltest.Options.NormalUnion" = .{ .bar = .{
611
+ \\ 42,
612
+ \\ 64,
613
+ \\} };
614
+ \\
584
615
\\pub const @"Build.Step.Options.decltest.Options.NestedStruct" = struct {
585
616
\\ normal_struct: @"Build.Step.Options.decltest.Options.NormalStruct",
586
617
\\ normal_enum: @"Build.Step.Options.decltest.Options.NormalEnum" = .foo,
@@ -594,6 +625,34 @@ test Options {
594
625
\\ .normal_enum = .foo,
595
626
\\};
596
627
\\
628
+ \\pub const @"Build.Step.Options.decltest.Options.NonExhaustiveEnum" = enum(u8) {
629
+ \\ one = 0,
630
+ \\ two = 1,
631
+ \\ three = 2,
632
+ \\ _,
633
+ \\};
634
+ \\
635
+ \\pub const non_exhaustive_enum1: @"Build.Step.Options.decltest.Options.NonExhaustiveEnum" = .two;
636
+ \\
637
+ \\pub const non_exhaustive_enum2: @"Build.Step.Options.decltest.Options.NonExhaustiveEnum" = @enumFromInt(20);
638
+ \\
639
+ \\pub const array_of_structs: [2]@"Build.Step.Options.decltest.Options.NormalStruct" = .{
640
+ \\ .{
641
+ \\ .hello = @as(?[]const u8, null),
642
+ \\ .world = true,
643
+ \\ },
644
+ \\ .{
645
+ \\ .hello = "zig",
646
+ \\ .world = true,
647
+ \\ },
648
+ \\};
649
+ \\
650
+ \\pub const nested_optional1: ??u32 = 10;
651
+ \\
652
+ \\pub const nested_optional2: ??u32 = @as(?u32, null);
653
+ \\
654
+ \\pub const nested_optional3: ??u32 = @as(??u32, null);
655
+ \\
597
656
\\
598
657
, options .contents .items );
599
658
0 commit comments