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