master
 1const std = @import("std");
 2
 3const Point = struct {
 4    x: u32,
 5    y: u32,
 6
 7    pub var z: u32 = 1;
 8};
 9
10test "field access by string" {
11    const expect = std.testing.expect;
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 expect(@field(p, "x") == 4);
18    try expect(@field(p, "y") == 5);
19}
20
21test "decl access by string" {
22    const expect = std.testing.expect;
23
24    try expect(@field(Point, "z") == 1);
25
26    @field(Point, "z") = 2;
27    try expect(@field(Point, "z") == 2);
28}
29
30// test