aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/zon.zig
diff options
context:
space:
mode:
authorMason Remaley <mason@anthropicstudios.com>2025-02-15 15:42:59 -0800
committermlugg <mlugg@mlugg.co.uk>2025-04-02 05:53:22 +0100
commit06ee383da9a23016dcb25ff7cb6811e3dc2c387e (patch)
treea1f407023746af27e8338c08b34a57336ae50cc6 /test/behavior/zon.zig
parent1b62a22268117340ee7a17f019df01cd39ec1421 (diff)
downloadzig-06ee383da9a23016dcb25ff7cb6811e3dc2c387e.tar.gz
zig-06ee383da9a23016dcb25ff7cb6811e3dc2c387e.zip
compiler: allow `@import` of ZON without a result type
In particular, this allows importing `build.zig.zon` at comptime.
Diffstat (limited to 'test/behavior/zon.zig')
-rw-r--r--test/behavior/zon.zig54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/behavior/zon.zig b/test/behavior/zon.zig
index 2003a87600..8a43b4894e 100644
--- a/test/behavior/zon.zig
+++ b/test/behavior/zon.zig
@@ -517,3 +517,57 @@ 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);
+
+ 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);
+}