1const std = @import("std");
2const expectEqual = std.testing.expectEqual;
3
4const Point = struct {
5 x: u32,
6 y: u32,
7
8 pub var z: u32 = 1;
9};
10
11test "field access by string" {
12 var p = Point{ .x = 0, .y = 0 };
13
14 @field(p, "x") = 4;
15 @field(p, "y") = @field(p, "x") + 1;
16
17 try expectEqual(4, @field(p, "x"));
18 try expectEqual(5, @field(p, "y"));
19}
20
21test "decl access by string" {
22 try expectEqual(1, @field(Point, "z"));
23
24 @field(Point, "z") = 2;
25 try expectEqual(2, @field(Point, "z"));
26}
27
28// test