Skip to content

Commit 54d4316

Browse files
committed
add more tests
1 parent 5ccbcdc commit 54d4316

File tree

1 file changed

+70
-14
lines changed

1 file changed

+70
-14
lines changed

lib/std/Build/Step/Options.zig

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -478,46 +478,64 @@ test Options {
478478
world: bool = true,
479479
};
480480

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

491+
const NonExhaustiveEnum = enum(u8) {
492+
one,
493+
two,
494+
three,
495+
_,
496+
};
497+
486498
options.addOption(usize, "option1", 1);
487499
options.addOption(?usize, "option2", null);
488500
options.addOption(?usize, "option3", 3);
489501
options.addOption(comptime_int, "option4", 4);
502+
options.addOption(comptime_float, "option5", 0.125);
490503
options.addOption([]const u8, "string", "zigisthebest");
491504
options.addOption(?[]const u8, "optional_string", null);
492505
options.addOption([2][2]u16, "nested_array", nested_array);
493506
options.addOption([]const []const u16, "nested_slice", nested_slice);
494507
options.addOption(KeywordEnum, "keyword_enum", .@"0.8.1");
495508
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 },
507520
});
521+
options.addOption(??u32, "nested_optional1", 10);
522+
options.addOption(??u32, "nested_optional2", @as(?u32, null));
523+
options.addOption(??u32, "nested_optional3", null);
508524

509525
try std.testing.expectEqualStrings(
510526
\\pub const option1: usize = 1;
511527
\\
512-
\\pub const option2: ?usize = null;
528+
\\pub const option2: ?usize = @as(?usize, null);
513529
\\
514530
\\pub const option3: ?usize = 3;
515531
\\
516532
\\pub const option4: comptime_int = 4;
517533
\\
534+
\\pub const option5: comptime_float = 1.25e-1;
535+
\\
518536
\\pub const string: []const u8 = "zigisthebest";
519537
\\
520-
\\pub const optional_string: ?[]const u8 = null;
538+
\\pub const optional_string: ?[]const u8 = @as(?[]const u8, null);
521539
\\
522540
\\pub const nested_array: [2][2]u16 = .{
523541
\\ .{
@@ -575,10 +593,20 @@ test Options {
575593
\\};
576594
\\
577595
\\pub const normal2_struct: @"Build.Step.Options.decltest.Options.NormalStruct" = .{
578-
\\ .hello = null,
596+
\\ .hello = @as(?[]const u8, null),
579597
\\ .world = false,
580598
\\};
581599
\\
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+
\\
582610
\\pub const @"Build.Step.Options.decltest.Options.NestedStruct" = struct {
583611
\\ normal_struct: @"Build.Step.Options.decltest.Options.NormalStruct",
584612
\\ normal_enum: @"Build.Step.Options.decltest.Options.NormalEnum" = .foo,
@@ -592,6 +620,34 @@ test Options {
592620
\\ .normal_enum = .foo,
593621
\\};
594622
\\
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+
\\
595651
\\
596652
, options.contents.items);
597653

0 commit comments

Comments
 (0)