1 /// Types defined for unit testing. 2 module tests.types; 3 4 import jsonizer.jsonize; 5 6 version (unittest) { 7 } 8 else { 9 static assert(0, "Do not include tests dir unless in unit-test mode!"); 10 } 11 12 struct PrimitiveStruct { 13 mixin JsonizeMe; 14 15 @jsonize { 16 int i; 17 ulong l; 18 bool b; 19 float f; 20 double d; 21 string s; 22 } 23 } 24 25 struct PrivateFieldsStruct { 26 mixin JsonizeMe; 27 28 @jsonize private { 29 int i; 30 ulong l; 31 bool b; 32 float f; 33 double d; 34 string s; 35 } 36 } 37 38 struct PropertyStruct { 39 mixin JsonizeMe; 40 41 @jsonize @property { 42 // getters 43 auto i() { return _i; } 44 auto b() { return _b; } 45 auto f() { return _f; } 46 auto s() { return _s; } 47 48 // setters 49 void i(int val) { _i = val; } 50 void b(bool val) { _b = val; } 51 void f(float val) { _f = val; } 52 void s(string val) { _s = val; } 53 } 54 55 private: 56 int _i; 57 bool _b; 58 float _f; 59 string _s; 60 } 61 62 struct ArrayStruct { 63 mixin JsonizeMe; 64 65 @jsonize { 66 int[] i; 67 string[] s; 68 } 69 } 70 71 struct NestedArrayStruct { 72 mixin JsonizeMe; 73 74 @jsonize { 75 int[][] i; 76 string[][] s; 77 } 78 } 79 80 struct StaticArrayStruct { 81 mixin JsonizeMe; 82 83 @jsonize { 84 int[3] i; 85 string[2] s; 86 } 87 88 bool opEquals(StaticArrayStruct other) { 89 return i == other.i && s == other.s; 90 } 91 } 92 93 struct NestedStruct { 94 mixin JsonizeMe; 95 @jsonize { 96 int i; 97 string s; 98 Inner inner; 99 } 100 101 private struct Inner { 102 mixin JsonizeMe; 103 @jsonize { 104 double d; 105 int[] a; 106 } 107 } 108 109 this(int i, string s, double d, int[] a) { 110 this.i = i; 111 this.s = s; 112 inner = Inner(d, a); 113 } 114 } 115 116 struct AliasedTypeStruct { 117 mixin JsonizeMe; 118 alias Ints = int[]; 119 @jsonize Ints i; 120 } 121 122 struct CustomCtorStruct { 123 mixin JsonizeMe; 124 125 @disable this(); 126 127 @jsonize { 128 int i; 129 float f; 130 131 this(int i, float f) { 132 this.i = i; 133 this.f = f; 134 } 135 } 136 } 137 138 class SimpleClass { 139 mixin JsonizeMe; 140 @jsonize { 141 int i; 142 string s; 143 } 144 } 145 146 class OuterClass { 147 mixin JsonizeMe; 148 149 @jsonize { 150 int outerVal; 151 InnerClass inner; 152 } 153 154 class InnerClass { 155 mixin JsonizeMe; 156 @jsonize int innerVal; 157 158 override bool opEquals(Object obj) { 159 auto other = cast(InnerClass) obj; 160 return other !is null && this.innerVal == other.innerVal; 161 } 162 } 163 164 override bool opEquals(Object obj) { 165 auto other = cast(OuterClass) obj; 166 return other !is null && this.outerVal == other.outerVal; 167 } 168 } 169 170 class OuterClassCtor { 171 mixin JsonizeMe; 172 173 @jsonize { 174 int outerVal; 175 InnerClass inner; 176 } 177 178 class InnerClass { 179 mixin JsonizeMe; 180 @jsonize int i; 181 182 @jsonize this(int i) { this.i = i; } 183 } 184 185 override bool opEquals(Object obj) { 186 auto other = cast(OuterClassCtor) obj; 187 return other !is null && outerVal == other.outerVal && inner.i == other.inner.i; 188 } 189 } 190 191 struct GenericStruct(T) { 192 mixin JsonizeMe; 193 194 @jsonize T val; 195 } 196 197 struct IntStruct { 198 mixin JsonizeMe; 199 int i; 200 @jsonize this(int i) { this.i = i; } 201 }