Skip to content

Commit

Permalink
Adds test, including importing a build.zig.zon
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonRemaley committed Feb 16, 2025
1 parent 6a98d03 commit f391a95
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/behavior/zon.zig
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,58 @@ test "recursive" {
const expected: Recursive = .{ .foo = &.{ .foo = null } };
try expectEqualDeep(expected, @as(Recursive, @import("zon/recursive.zon")));
}

test "anon" {
const expected = .{
.{
.bool_true = true,
.bool_false = false,
.string = "foo",
},
.{
null,
10,
36893488147419103232,
1.234,
'z',
.bar,
.{},
},
};

const actual = @import("zon/anon.zon");
try expectEqual(expected.len, actual.len);
try expectEqual(expected[1], actual[1]);
const expected_struct = expected[0];
const actual_struct = actual[0];
const expected_fields = @typeInfo(@TypeOf(expected_struct)).@"struct".fields;
const actual_fields = @typeInfo(@TypeOf(actual_struct)).@"struct".fields;
try expectEqual(expected_fields.len, actual_fields.len);
inline for (expected_fields) |field| {
try expectEqual(@field(expected_struct, field.name), @field(actual_struct, field.name));
}
}

test "build.zig.zon" {
const build = @import("zon/build.zig.zon");

try expectEqual(4, @typeInfo(@TypeOf(build)).@"struct".fields.len);
try expectEqualStrings("temp", build.name);
try expectEqualStrings("0.0.0", build.version);
try expectEqualStrings("0.0.0", build.version);

const dependencies = build.dependencies;
try expectEqual(2, @typeInfo(@TypeOf(dependencies)).@"struct".fields.len);

const example_0 = dependencies.example_0;
try expectEqual(2, @typeInfo(@TypeOf(dependencies)).@"struct".fields.len);
try expectEqualStrings("https://example.com/foo.tar.gz", example_0.url);
try expectEqualStrings("...", example_0.hash);

const example_1 = dependencies.example_1;
try expectEqual(2, @typeInfo(@TypeOf(dependencies)).@"struct".fields.len);
try expectEqualStrings("../foo", example_1.path);
try expectEqual(false, example_1.lazy);

try expectEqual(.{ "build.zig", "build.zig.zon", "src" }, build.paths);
}
16 changes: 16 additions & 0 deletions test/behavior/zon/anon.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.{
.{
.bool_true = true,
.bool_false = false,
.string = "foo",
},
.{
null,
10,
36893488147419103232,
1.234,
'z',
.bar,
.{},
},
}
20 changes: 20 additions & 0 deletions test/behavior/zon/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.{
// Comment
.name = "temp",
.version = "0.0.0",
.dependencies = .{
.example_0 = .{
.url = "https://example.com/foo.tar.gz",
.hash = "...",
},
.example_1 = .{
.path = "../foo",
.lazy = false,
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
},
}
9 changes: 9 additions & 0 deletions test/cases/compile_errors/@import_zon_anon_inf.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export fn entry() void {
_ = @import("zon/inf.zon");
}

// error
// imports=zon/inf.zon
//
// inf.zon:1:1: error: infinity requires a known result type
// tmp.zig:2:17: note: imported here
9 changes: 9 additions & 0 deletions test/cases/compile_errors/@import_zon_anon_nan.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export fn entry() void {
_ = @import("zon/nan.zon");
}

// error
// imports=zon/nan.zon
//
// nan.zon:1:1: error: nan requires a known result type
// tmp.zig:2:17: note: imported here
9 changes: 9 additions & 0 deletions test/cases/compile_errors/@import_zon_anon_neg_inf.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export fn entry() void {
_ = @import("zon/neg_inf.zon");
}

// error
// imports=zon/neg_inf.zon
//
// neg_inf.zon:1:1: error: negative infinity requires a known result type
// tmp.zig:2:17: note: imported here

0 comments on commit f391a95

Please sign in to comment.