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