Skip to content

Commit 547f209

Browse files
committed
add more tests
1 parent 0de5e81 commit 547f209

File tree

1 file changed

+173
-10
lines changed

1 file changed

+173
-10
lines changed

lib/std/Build/Step/Options.zig

Lines changed: 173 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -464,105 +464,239 @@ test Options {
464464
bar,
465465
};
466466

467+
const NormalUnion = union(NormalEnum) {
468+
foo: []const u8,
469+
bar: u32 align(8),
470+
};
471+
472+
const NonExhaustiveEnum = enum(u8) {
473+
one,
474+
two,
475+
three,
476+
_,
477+
};
478+
467479
const nested_array = [2][2]u16{
468480
[2]u16{ 300, 200 },
469481
[2]u16{ 300, 200 },
470482
};
471483
const nested_slice: []const []const u16 = &[_][]const u16{ &nested_array[0], &nested_array[1] };
472484

485+
const Empty = struct {};
486+
473487
const NormalStruct = struct {
474488
hello: ?[]const u8,
475489
world: bool = true,
476490
};
477491

492+
const PackedStruct = packed struct {
493+
age: u32,
494+
height: u32,
495+
_: u32 = 0,
496+
};
497+
498+
const ExternStruct = extern struct {
499+
age: u32,
500+
height: u32,
501+
};
502+
478503
const NestedStruct = struct {
479-
normal_struct: NormalStruct,
504+
normal_struct: NormalStruct align(1),
480505
normal_enum: NormalEnum = .foo,
481506
};
482507

508+
const Tuple = struct { []const u8, []const u8 };
509+
const ComptimeTuple = struct { comptime u32 = 100 };
510+
483511
options.addOption(usize, "option1", 1);
484512
options.addOption(?usize, "option2", null);
485513
options.addOption(?usize, "option3", 3);
486514
options.addOption(comptime_int, "option4", 4);
515+
options.addOption(comptime_float, "option5", std.math.pi);
487516
options.addOption([]const u8, "string", "zigisthebest");
517+
options.addOption([:0]const u8, "string2", "zigisthebest");
488518
options.addOption(?[]const u8, "optional_string", null);
519+
options.addOption(?[:0]const u8, "optional_string2", null);
489520
options.addOption([2][2]u16, "nested_array", nested_array);
490521
options.addOption([]const []const u16, "nested_slice", nested_slice);
491522
options.addOption(KeywordEnum, "keyword_enum", .@"0.8.1");
492523
options.addOption(std.SemanticVersion, "semantic_version", try std.SemanticVersion.parse("0.1.2-foo+bar"));
493524
options.addOption(NormalEnum, "normal1_enum", NormalEnum.foo);
494525
options.addOption(NormalEnum, "normal2_enum", NormalEnum.bar);
526+
options.addOption([]const NormalEnum, "normal_enum_array", &[_]NormalEnum{ .foo, .bar, .foo });
527+
options.addOption(NormalUnion, "normal_union", NormalUnion{ .bar = 64 });
528+
options.addOption(NonExhaustiveEnum, "non_exhaustive_enum1", .one);
529+
options.addOption(NonExhaustiveEnum, "non_exhaustive_enum2", @enumFromInt(20));
530+
options.addOption([]const Empty, "empty", &[_]Empty{.{}});
495531
options.addOption(NormalStruct, "normal1_struct", NormalStruct{
496532
.hello = "foo",
497533
});
498534
options.addOption(NormalStruct, "normal2_struct", NormalStruct{
499535
.hello = null,
500536
.world = false,
501537
});
538+
options.addOption(ExternStruct, "extern_struct", .{ .age = 100, .height = 100 });
539+
options.addOption([2:.{ .age = 10, .height = 1000 }]PackedStruct, "packed_struct_array_with_sentinel", .{
540+
.{ .age = 45, .height = 0 },
541+
.{ .age = 100, .height = 100 },
542+
});
502543
options.addOption(NestedStruct, "nested_struct", NestedStruct{
503544
.normal_struct = .{ .hello = "bar" },
504545
});
546+
options.addOption(Tuple, "tuple", .{ "foo", "bar" });
547+
options.addOption([]const Tuple, "tuple_slice", &.{
548+
.{ "foo", "bar" },
549+
.{ "abc", "def" },
550+
});
551+
options.addOption(ComptimeTuple, "comptime_tuple", .{100});
505552

506553
try std.testing.expectEqualStrings(
507554
\\pub const option1: usize = 1;
555+
\\
508556
\\pub const option2: ?usize = null;
557+
\\
509558
\\pub const option3: ?usize = 3;
559+
\\
510560
\\pub const option4: comptime_int = 4;
561+
\\
562+
\\pub const option5: comptime_float = 3.1415926535897932384626433832795028e0;
563+
\\
511564
\\pub const string: []const u8 = "zigisthebest";
565+
\\
566+
\\pub const string2: [:0]const u8 = "zigisthebest";
567+
\\
512568
\\pub const optional_string: ?[]const u8 = null;
513-
\\pub const nested_array: [2][2]u16 = [2][2]u16 {
514-
\\ [2]u16 {
569+
\\
570+
\\pub const optional_string2: ?[:0]const u8 = null;
571+
\\
572+
\\pub const nested_array: [2][2]u16 = .{
573+
\\ .{
515574
\\ 300,
516575
\\ 200,
517576
\\ },
518-
\\ [2]u16 {
577+
\\ .{
519578
\\ 300,
520579
\\ 200,
521580
\\ },
522581
\\};
523-
\\pub const nested_slice: []const []const u16 = &[_][]const u16 {
524-
\\ &[_]u16 {
582+
\\
583+
\\pub const nested_slice: []const []const u16 = &.{
584+
\\ &.{
525585
\\ 300,
526586
\\ 200,
527587
\\ },
528-
\\ &[_]u16 {
588+
\\ &.{
529589
\\ 300,
530590
\\ 200,
531591
\\ },
532592
\\};
533-
\\pub const @"Build.Step.Options.decltest.Options.KeywordEnum" = enum (u0) {
593+
\\
594+
\\pub const @"Build.Step.Options.decltest.Options.KeywordEnum" = enum(u0) {
534595
\\ @"0.8.1" = 0,
535596
\\};
597+
\\
536598
\\pub const keyword_enum: @"Build.Step.Options.decltest.Options.KeywordEnum" = .@"0.8.1";
599+
\\
537600
\\pub const semantic_version: @import("std").SemanticVersion = .{
538601
\\ .major = 0,
539602
\\ .minor = 1,
540603
\\ .patch = 2,
541604
\\ .pre = "foo",
542605
\\ .build = "bar",
543606
\\};
544-
\\pub const @"Build.Step.Options.decltest.Options.NormalEnum" = enum (u1) {
607+
\\
608+
\\pub const @"Build.Step.Options.decltest.Options.NormalEnum" = enum(u1) {
545609
\\ foo = 0,
546610
\\ bar = 1,
547611
\\};
612+
\\
548613
\\pub const normal1_enum: @"Build.Step.Options.decltest.Options.NormalEnum" = .foo;
614+
\\
549615
\\pub const normal2_enum: @"Build.Step.Options.decltest.Options.NormalEnum" = .bar;
616+
\\
617+
\\pub const normal_enum_array: []const @"Build.Step.Options.decltest.Options.NormalEnum" = &.{
618+
\\ .foo,
619+
\\ .bar,
620+
\\ .foo,
621+
\\};
622+
\\
623+
\\pub const @"Build.Step.Options.decltest.Options.NormalUnion" = union(@"Build.Step.Options.decltest.Options.NormalEnum") {
624+
\\ foo: []const u8,
625+
\\ bar: u32 align(8),
626+
\\};
627+
\\
628+
\\pub const normal_union: @"Build.Step.Options.decltest.Options.NormalUnion" = .{ .bar = 64 };
629+
\\
630+
\\pub const @"Build.Step.Options.decltest.Options.NonExhaustiveEnum" = enum(u8) {
631+
\\ one = 0,
632+
\\ two = 1,
633+
\\ three = 2,
634+
\\ _,
635+
\\};
636+
\\
637+
\\pub const non_exhaustive_enum1: @"Build.Step.Options.decltest.Options.NonExhaustiveEnum" = .one;
638+
\\
639+
\\pub const non_exhaustive_enum2: @"Build.Step.Options.decltest.Options.NonExhaustiveEnum" = @enumFromInt(20);
640+
\\
641+
\\pub const @"Build.Step.Options.decltest.Options.Empty" = struct {};
642+
\\
643+
\\pub const empty: []const @"Build.Step.Options.decltest.Options.Empty" = &.{
644+
\\ .{},
645+
\\};
646+
\\
550647
\\pub const @"Build.Step.Options.decltest.Options.NormalStruct" = struct {
551648
\\ hello: ?[]const u8,
552649
\\ world: bool = true,
553650
\\};
651+
\\
554652
\\pub const normal1_struct: @"Build.Step.Options.decltest.Options.NormalStruct" = .{
555653
\\ .hello = "foo",
556654
\\ .world = true,
557655
\\};
656+
\\
558657
\\pub const normal2_struct: @"Build.Step.Options.decltest.Options.NormalStruct" = .{
559658
\\ .hello = null,
560659
\\ .world = false,
561660
\\};
661+
\\
662+
\\pub const @"Build.Step.Options.decltest.Options.ExternStruct" = extern struct {
663+
\\ age: u32,
664+
\\ height: u32,
665+
\\};
666+
\\
667+
\\pub const extern_struct: @"Build.Step.Options.decltest.Options.ExternStruct" = .{
668+
\\ .age = 100,
669+
\\ .height = 100,
670+
\\};
671+
\\
672+
\\pub const @"Build.Step.Options.decltest.Options.PackedStruct" = packed struct(u96) {
673+
\\ age: u32,
674+
\\ height: u32,
675+
\\ _: u32 = 0,
676+
\\};
677+
\\
678+
\\pub const packed_struct_array_with_sentinel: [2:.{
679+
\\ .age = 10,
680+
\\ .height = 1000,
681+
\\ ._ = 0,
682+
\\}]@"Build.Step.Options.decltest.Options.PackedStruct" = .{
683+
\\ .{
684+
\\ .age = 45,
685+
\\ .height = 0,
686+
\\ ._ = 0,
687+
\\ },
688+
\\ .{
689+
\\ .age = 100,
690+
\\ .height = 100,
691+
\\ ._ = 0,
692+
\\ },
693+
\\};
694+
\\
562695
\\pub const @"Build.Step.Options.decltest.Options.NestedStruct" = struct {
563-
\\ normal_struct: @"Build.Step.Options.decltest.Options.NormalStruct",
696+
\\ normal_struct: @"Build.Step.Options.decltest.Options.NormalStruct" align(1),
564697
\\ normal_enum: @"Build.Step.Options.decltest.Options.NormalEnum" = .foo,
565698
\\};
699+
\\
566700
\\pub const nested_struct: @"Build.Step.Options.decltest.Options.NestedStruct" = .{
567701
\\ .normal_struct = .{
568702
\\ .hello = "bar",
@@ -571,6 +705,35 @@ test Options {
571705
\\ .normal_enum = .foo,
572706
\\};
573707
\\
708+
\\pub const tuple: struct {
709+
\\ []const u8,
710+
\\ []const u8,
711+
\\} = .{
712+
\\ "foo",
713+
\\ "bar",
714+
\\};
715+
\\
716+
\\pub const tuple_slice: []const struct {
717+
\\ []const u8,
718+
\\ []const u8,
719+
\\} = &.{
720+
\\ .{
721+
\\ "foo",
722+
\\ "bar",
723+
\\ },
724+
\\ .{
725+
\\ "abc",
726+
\\ "def",
727+
\\ },
728+
\\};
729+
\\
730+
\\pub const comptime_tuple: struct {
731+
\\ comptime u32 = 100,
732+
\\} = .{
733+
\\ 100,
734+
\\};
735+
\\
736+
\\
574737
, options.contents.items);
575738

576739
_ = try std.zig.Ast.parse(arena.allocator(), try options.contents.toOwnedSliceSentinel(0), .zig);

0 commit comments

Comments
 (0)