Skip to content

Commit 842502c

Browse files
committed
Adds test, including importing a build.zig.zon
1 parent 6a98d03 commit 842502c

File tree

6 files changed

+117
-0
lines changed

6 files changed

+117
-0
lines changed

test/behavior/zon.zig

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,57 @@ test "recursive" {
517517
const expected: Recursive = .{ .foo = &.{ .foo = null } };
518518
try expectEqualDeep(expected, @as(Recursive, @import("zon/recursive.zon")));
519519
}
520+
521+
test "anon" {
522+
const expected = .{
523+
.{
524+
.bool_true = true,
525+
.bool_false = false,
526+
.string = "foo",
527+
},
528+
.{
529+
null,
530+
10,
531+
36893488147419103232,
532+
1.234,
533+
'z',
534+
.bar,
535+
.{},
536+
},
537+
};
538+
539+
const actual = @import("zon/anon.zon");
540+
try expectEqual(expected.len, actual.len);
541+
try expectEqual(expected[1], actual[1]);
542+
const expected_struct = expected[0];
543+
const actual_struct = actual[0];
544+
const expected_fields = @typeInfo(@TypeOf(expected_struct)).@"struct".fields;
545+
const actual_fields = @typeInfo(@TypeOf(actual_struct)).@"struct".fields;
546+
try expectEqual(expected_fields.len, actual_fields.len);
547+
inline for (expected_fields) |field| {
548+
try expectEqual(@field(expected_struct, field.name), @field(actual_struct, field.name));
549+
}
550+
}
551+
552+
test "build.zig.zon" {
553+
const build = @import("zon/build.zig.zon");
554+
555+
try expectEqual(4, @typeInfo(@TypeOf(build)).@"struct".fields.len);
556+
try expectEqualStrings("temp", build.name);
557+
try expectEqualStrings("0.0.0", build.version);
558+
559+
const dependencies = build.dependencies;
560+
try expectEqual(2, @typeInfo(@TypeOf(dependencies)).@"struct".fields.len);
561+
562+
const example_0 = dependencies.example_0;
563+
try expectEqual(2, @typeInfo(@TypeOf(dependencies)).@"struct".fields.len);
564+
try expectEqualStrings("https://example.com/foo.tar.gz", example_0.url);
565+
try expectEqualStrings("...", example_0.hash);
566+
567+
const example_1 = dependencies.example_1;
568+
try expectEqual(2, @typeInfo(@TypeOf(dependencies)).@"struct".fields.len);
569+
try expectEqualStrings("../foo", example_1.path);
570+
try expectEqual(false, example_1.lazy);
571+
572+
try expectEqual(.{ "build.zig", "build.zig.zon", "src" }, build.paths);
573+
}

test/behavior/zon/anon.zon

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.{
2+
.{
3+
.bool_true = true,
4+
.bool_false = false,
5+
.string = "foo",
6+
},
7+
.{
8+
null,
9+
10,
10+
36893488147419103232,
11+
1.234,
12+
'z',
13+
.bar,
14+
.{},
15+
},
16+
}

test/behavior/zon/build.zig.zon

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.{
2+
// Comment
3+
.name = "temp",
4+
.version = "0.0.0",
5+
.dependencies = .{
6+
.example_0 = .{
7+
.url = "https://example.com/foo.tar.gz",
8+
.hash = "...",
9+
},
10+
.example_1 = .{
11+
.path = "../foo",
12+
.lazy = false,
13+
},
14+
},
15+
.paths = .{
16+
"build.zig",
17+
"build.zig.zon",
18+
"src",
19+
},
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export fn entry() void {
2+
_ = @import("zon/inf.zon");
3+
}
4+
5+
// error
6+
// imports=zon/inf.zon
7+
//
8+
// inf.zon:1:1: error: infinity requires a known result type
9+
// tmp.zig:2:17: note: imported here
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export fn entry() void {
2+
_ = @import("zon/nan.zon");
3+
}
4+
5+
// error
6+
// imports=zon/nan.zon
7+
//
8+
// nan.zon:1:1: error: nan requires a known result type
9+
// tmp.zig:2:17: note: imported here
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export fn entry() void {
2+
_ = @import("zon/neg_inf.zon");
3+
}
4+
5+
// error
6+
// imports=zon/neg_inf.zon
7+
//
8+
// neg_inf.zon:1:1: error: negative infinity requires a known result type
9+
// tmp.zig:2:17: note: imported here

0 commit comments

Comments
 (0)