| 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); |
| 3 | const expect = std.testing.expect; |
| 4 | |
| 5 | const Foo = @import("hasdecl/foo.zig"); |
| 6 | |
| 7 | pub const Bar = struct { |
| 8 | nope: i32, |
| 9 | |
| 10 | const hi = 1; |
| 11 | pub var blah = "xxx"; |
| 12 | }; |
| 13 | |
| 14 | test "@hasDecl" { |
| 15 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; |
| 16 | |
| 17 | try expect(@hasDecl(Foo, "public_thing")); |
| 18 | try expect(!@hasDecl(Foo, "private_thing")); |
| 19 | try expect(!@hasDecl(Foo, "no_thing")); |
| 20 | |
| 21 | try expect(!@hasDecl(Bar, "hi")); |
| 22 | try expect(@hasDecl(Bar, "blah")); |
| 23 | try expect(!@hasDecl(Bar, "nope")); |
| 24 | } |
| 25 | |
| 26 | test "@hasDecl using a sliced string literal" { |
| 27 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; |
| 28 | |
| 29 | try expect(@hasDecl(@This(), "Bar") == true); |
| 30 | try expect(@hasDecl(@This(), "Bar"[0..0]) == false); |
| 31 | try expect(@hasDecl(@This(), "Bar"[0..1]) == false); |
| 32 | try expect(@hasDecl(@This(), "Bar"[0..2]) == false); |
| 33 | try expect(@hasDecl(@This(), "Bar"[0..3]) == true); |
| 34 | try expect(@hasDecl(@This(), "Bar"[0..]) == true); |
| 35 | } |