mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
38 lines
1.2 KiB
Zig
38 lines
1.2 KiB
Zig
const std = @import("std");
|
|
const builtin = @import("builtin");
|
|
const expect = std.testing.expect;
|
|
|
|
const Foo = @import("hasdecl/foo.zig");
|
|
|
|
const Bar = struct {
|
|
nope: i32,
|
|
|
|
const hi = 1;
|
|
pub var blah = "xxx";
|
|
};
|
|
|
|
test "@hasDecl" {
|
|
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
|
|
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
|
|
|
|
try expect(@hasDecl(Foo, "public_thing"));
|
|
try expect(!@hasDecl(Foo, "private_thing"));
|
|
try expect(!@hasDecl(Foo, "no_thing"));
|
|
|
|
try expect(@hasDecl(Bar, "hi"));
|
|
try expect(@hasDecl(Bar, "blah"));
|
|
try expect(!@hasDecl(Bar, "nope"));
|
|
}
|
|
|
|
test "@hasDecl using a sliced string literal" {
|
|
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
|
|
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
|
|
|
|
try expect(@hasDecl(@This(), "std") == true);
|
|
try expect(@hasDecl(@This(), "std"[0..0]) == false);
|
|
try expect(@hasDecl(@This(), "std"[0..1]) == false);
|
|
try expect(@hasDecl(@This(), "std"[0..2]) == false);
|
|
try expect(@hasDecl(@This(), "std"[0..3]) == true);
|
|
try expect(@hasDecl(@This(), "std"[0..]) == true);
|
|
}
|