2019-05-27 06:35:35 +01:00
|
|
|
const expect = @import("std").testing.expect;
|
|
|
|
const builtin = @import("builtin");
|
|
|
|
|
|
|
|
test "@hasField" {
|
|
|
|
const struc = struct {
|
|
|
|
a: i32,
|
|
|
|
b: []u8,
|
2019-07-02 21:52:55 +01:00
|
|
|
|
|
|
|
pub const nope = 1;
|
2019-05-27 06:35:35 +01:00
|
|
|
};
|
2021-05-04 19:23:22 +01:00
|
|
|
try expect(@hasField(struc, "a") == true);
|
|
|
|
try expect(@hasField(struc, "b") == true);
|
|
|
|
try expect(@hasField(struc, "non-existant") == false);
|
|
|
|
try expect(@hasField(struc, "nope") == false);
|
2019-05-27 06:35:35 +01:00
|
|
|
|
|
|
|
const unin = union {
|
|
|
|
a: u64,
|
|
|
|
b: []u16,
|
2019-07-02 21:52:55 +01:00
|
|
|
|
|
|
|
pub const nope = 1;
|
2019-05-27 06:35:35 +01:00
|
|
|
};
|
2021-05-04 19:23:22 +01:00
|
|
|
try expect(@hasField(unin, "a") == true);
|
|
|
|
try expect(@hasField(unin, "b") == true);
|
|
|
|
try expect(@hasField(unin, "non-existant") == false);
|
|
|
|
try expect(@hasField(unin, "nope") == false);
|
2019-05-27 06:35:35 +01:00
|
|
|
|
|
|
|
const enm = enum {
|
|
|
|
a,
|
|
|
|
b,
|
2019-07-02 21:52:55 +01:00
|
|
|
|
|
|
|
pub const nope = 1;
|
2019-05-27 06:35:35 +01:00
|
|
|
};
|
2021-05-04 19:23:22 +01:00
|
|
|
try expect(@hasField(enm, "a") == true);
|
|
|
|
try expect(@hasField(enm, "b") == true);
|
|
|
|
try expect(@hasField(enm, "non-existant") == false);
|
|
|
|
try expect(@hasField(enm, "nope") == false);
|
2019-05-27 06:35:35 +01:00
|
|
|
}
|