master
1const std = @import("std");
2const expect = std.testing.expect;
3
4const Foo = struct {
5 nope: i32,
6
7 pub var blah = "xxx";
8 const hi = 1;
9};
10
11test "@hasDecl" {
12 try expect(@hasDecl(Foo, "blah"));
13
14 // Even though `hi` is private, @hasDecl returns true because this test is
15 // in the same file scope as Foo. It would return false if Foo was declared
16 // in a different file.
17 try expect(@hasDecl(Foo, "hi"));
18
19 // @hasDecl is for declarations; not fields.
20 try expect(!@hasDecl(Foo, "nope"));
21 try expect(!@hasDecl(Foo, "nope1234"));
22}
23
24// test