1 
2 module witchcraft.unittests.inheritance;
3 
4 import witchcraft;
5 
6 version(unittest)
7 {
8     abstract class Entity
9     {
10         mixin Witchcraft;
11 
12         ulong id;
13     }
14 
15     class User : Entity
16     {
17         mixin Witchcraft;
18 
19         string username;
20         string password;
21     }
22 
23     final class Admin : User
24     {
25         mixin Witchcraft;
26 
27         bool canBan;
28         bool canEdit;
29         bool canMute;
30     }
31 }
32 
33 unittest
34 {
35     import std.algorithm;
36 
37     Class eClass = Entity.metaof;
38     Class uClass = User.metaof;
39     Class aClass = Admin.metaof;
40 
41     assert(eClass !is null && uClass !is null && aClass !is null);
42 
43     assert(eClass.getName == "Entity");
44     assert(uClass.getName == "User");
45     assert(aClass.getName == "Admin");
46 
47     assert(eClass.isAbstract == true);
48     assert(uClass.isAbstract == false);
49     assert(aClass.isAbstract == false);
50 
51     assert(eClass.isFinal == false);
52     assert(uClass.isFinal == false);
53     assert(aClass.isFinal == true);
54 
55     enum eFields = [ "id" ];
56     enum uFields = [ "username", "password" ];
57     enum aFields = [ "canBan", "canEdit", "canMute" ];
58 
59     assert(eClass.getLocalFieldNames.isPermutation(eFields));
60     assert(uClass.getLocalFieldNames.isPermutation(uFields));
61     assert(aClass.getLocalFieldNames.isPermutation(aFields));
62 
63     assert(eClass.getFieldNames.isPermutation(eFields));
64     assert(uClass.getFieldNames.isPermutation(eFields ~ uFields));
65     assert(aClass.getFieldNames.isPermutation(eFields ~ uFields ~ aFields));
66 }
67 
68 unittest
69 {
70     Entity u = new User;
71     Entity a = new Admin;
72 
73     Class eClass = Entity.metaof;
74     Class uClass = u.getMetaType;
75     Class aClass = a.getMetaType;
76 
77     assert(eClass !is null && uClass !is null && aClass !is null);
78 
79     assert(eClass.getName == "Entity");
80     assert(uClass.getName == "User");
81     assert(aClass.getName == "Admin");
82 
83     version(aggressive)
84     {
85         assert(eClass.getSuperClass !is null);
86         assert(eClass.getSuperClass.getName == "Object");
87     }
88     else
89     {
90         assert(eClass.getSuperClass is null);
91     }
92 
93     assert(uClass.getSuperClass is eClass);
94     assert(aClass.getSuperClass is uClass);
95 
96     assert(eClass.getField("id") !is null);
97     assert(uClass.getField("id") !is null);
98     assert(aClass.getField("id") !is null);
99 
100     assert(eClass.getField("username")  is null);
101     assert(uClass.getField("username") !is null);
102     assert(aClass.getField("username") !is null);
103 
104     assert(eClass.getField("canEdit")  is null);
105     assert(uClass.getField("canEdit")  is null);
106     assert(aClass.getField("canEdit") !is null);
107 }