1 
2 module witchcraft.unittests.accessible;
3 
4 version(unittest)
5 {
6     import witchcraft;
7 
8     private class Secret
9     {
10         bool b;
11 
12         this()
13         {
14         }
15 
16         this(bool b)
17         {
18         }
19 
20         int foo()
21         {
22             return 5;
23         }
24     }
25 
26     class Foo : Secret
27     {
28         int x;
29         int y;
30 
31         private int z;
32 
33         this()
34         {
35         }
36 
37         private this(int x, int y)
38         {
39         }
40 
41         int bar()
42         {
43             return x + y + z;
44         }
45     }
46 
47     class Bar : Foo
48     {
49         mixin Witchcraft;
50 
51         string name;
52 
53         int foobar()
54         {
55             return foo * bar;
56         }
57     }
58 }
59 
60 unittest
61 {
62     auto bClass = Bar.metaof;
63     assert(bClass !is null);
64 
65     assert(bClass.getName == "Bar");
66     assert(bClass.isAccessible == true);
67     assert(bClass.getField("name").isAccessible == true);
68 
69     version(aggressive)
70     {
71         assert(bClass.getSuperClass.getName == "Foo");
72         assert(bClass.getSuperClass.isAccessible == true);
73         assert(bClass.getSuperClass.getField("x").isAccessible == true);
74         assert(bClass.getSuperClass.getField("y").isAccessible == true);
75         assert(bClass.getSuperClass.getField("z").isAccessible == false);
76 
77         assert(bClass.getSuperClass.getSuperClass.getName == "Secret");
78         assert(bClass.getSuperClass.getSuperClass.isAccessible == false);
79     }
80     else
81     {
82         assert(bClass.getSuperClass is null);
83     }
84 }