| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | const expect = @import("std").testing.expect; |
| 2 | const builtin = @import("builtin"); |
| 3 | |
| 4 | test "@hasField" { |
| 5 | const struc = struct { |
| 6 | a: i32, |
| 7 | b: []u8, |
| 8 | }; |
| 9 | expect(@hasField(struc, "a") == true); |
| 10 | expect(@hasField(struc, "b") == true); |
| 11 | expect(@hasField(struc, "non-existant") == false); |
| 12 | |
| 13 | const unin = union { |
| 14 | a: u64, |
| 15 | b: []u16, |
| 16 | }; |
| 17 | expect(@hasField(unin, "a") == true); |
| 18 | expect(@hasField(unin, "b") == true); |
| 19 | expect(@hasField(unin, "non-existant") == false); |
| 20 | |
| 21 | const enm = enum { |
| 22 | a, |
| 23 | b, |
| 24 | }; |
| 25 | expect(@hasField(enm, "a") == true); |
| 26 | expect(@hasField(enm, "b") == true); |
| 27 | expect(@hasField(enm, "non-existant") == false); |
| 28 | |
| 29 | expect(@hasField(builtin, "os") == true); |
| 30 | } |