zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

test_hasDecl_builtin.zig (576B) - Raw


      1 const std = @import("std");
      2 const expect = std.testing.expect;
      3 
      4 const Foo = struct {
      5     nope: i32,
      6 
      7     pub var blah = "xxx";
      8     const hi = 1;
      9 };
     10 
     11 test "@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