mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
31 lines
550 B
Zig
31 lines
550 B
Zig
const std = @import("std");
|
|
|
|
const Point = struct {
|
|
x: u32,
|
|
y: u32,
|
|
|
|
pub var z: u32 = 1;
|
|
};
|
|
|
|
test "field access by string" {
|
|
const expect = std.testing.expect;
|
|
var p = Point{ .x = 0, .y = 0 };
|
|
|
|
@field(p, "x") = 4;
|
|
@field(p, "y") = @field(p, "x") + 1;
|
|
|
|
try expect(@field(p, "x") == 4);
|
|
try expect(@field(p, "y") == 5);
|
|
}
|
|
|
|
test "decl access by string" {
|
|
const expect = std.testing.expect;
|
|
|
|
try expect(@field(Point, "z") == 1);
|
|
|
|
@field(Point, "z") = 2;
|
|
try expect(@field(Point, "z") == 2);
|
|
}
|
|
|
|
// test
|