Skip to content

Commit c89dd4a

Browse files
committed
add more tests
1 parent 338df8b commit c89dd4a

File tree

1 file changed

+73
-14
lines changed

1 file changed

+73
-14
lines changed

lib/std/Build/Step/Options.zig

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -480,46 +480,67 @@ test Options {
480480
world: bool = true,
481481
};
482482

483+
const NormalUnion = union(NormalEnum) {
484+
foo: u16,
485+
bar: [2]u8,
486+
};
487+
483488
const NestedStruct = struct {
484489
normal_struct: NormalStruct,
485490
normal_enum: NormalEnum = .foo,
486491
};
487492

493+
const NonExhaustiveEnum = enum(u8) {
494+
one,
495+
two,
496+
three,
497+
_,
498+
};
499+
488500
options.addOption(usize, "option1", 1);
489501
options.addOption(?usize, "option2", null);
490502
options.addOption(?usize, "option3", 3);
491503
options.addOption(comptime_int, "option4", 4);
504+
options.addOption(comptime_float, "option5", 0.125);
505+
options.addOption(@Type(.enum_literal), "option6", .foo);
492506
options.addOption([]const u8, "string", "zigisthebest");
493507
options.addOption(?[]const u8, "optional_string", null);
494508
options.addOption([2][2]u16, "nested_array", nested_array);
495509
options.addOption([]const []const u16, "nested_slice", nested_slice);
496510
options.addOption(KeywordEnum, "keyword_enum", .@"0.8.1");
497511
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 },
509523
});
524+
options.addOption(??u32, "nested_optional1", 10);
525+
options.addOption(??u32, "nested_optional2", @as(?u32, null));
526+
options.addOption(??u32, "nested_optional3", null);
510527

511528
try std.testing.expectEqualStrings(
512529
\\pub const option1: usize = 1;
513530
\\
514-
\\pub const option2: ?usize = null;
531+
\\pub const option2: ?usize = @as(?usize, null);
515532
\\
516533
\\pub const option3: ?usize = 3;
517534
\\
518535
\\pub const option4: comptime_int = 4;
519536
\\
537+
\\pub const option5: comptime_float = 1.25e-1;
538+
\\
539+
\\pub const option6: @Type(.enum_literal) = .foo;
540+
\\
520541
\\pub const string: []const u8 = "zigisthebest";
521542
\\
522-
\\pub const optional_string: ?[]const u8 = null;
543+
\\pub const optional_string: ?[]const u8 = @as(?[]const u8, null);
523544
\\
524545
\\pub const nested_array: [2][2]u16 = .{
525546
\\ .{
@@ -577,10 +598,20 @@ test Options {
577598
\\};
578599
\\
579600
\\pub const normal2_struct: @"Build.Step.Options.decltest.Options.NormalStruct" = .{
580-
\\ .hello = null,
601+
\\ .hello = @as(?[]const u8, null),
581602
\\ .world = false,
582603
\\};
583604
\\
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+
\\
584615
\\pub const @"Build.Step.Options.decltest.Options.NestedStruct" = struct {
585616
\\ normal_struct: @"Build.Step.Options.decltest.Options.NormalStruct",
586617
\\ normal_enum: @"Build.Step.Options.decltest.Options.NormalEnum" = .foo,
@@ -594,6 +625,34 @@ test Options {
594625
\\ .normal_enum = .foo,
595626
\\};
596627
\\
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+
\\
597656
\\
598657
, options.contents.items);
599658

0 commit comments

Comments
 (0)