StructField(T)1struct StructField(T) 2 { 3 static T Field; 4 static alias Field this; 5 } 6 StructProperty(T)7struct StructProperty(T) 8 { 9 static T Field; 10 11 static @property T property() 12 { 13 return Field; 14 } 15 16 static @property void property(T value) 17 { 18 Field = value; 19 } 20 21 static alias property this; 22 } 23 ClassField(T)24class ClassField(T) 25 { 26 static T Field; 27 static alias Field this; 28 } 29 ClassProperty(T)30class ClassProperty(T) 31 { 32 static T Field; 33 34 static @property T property() 35 { 36 return Field; 37 } 38 39 static @property void property(T value) 40 { 41 Field = value; 42 } 43 44 static alias property this; 45 } 46 boolTest(T)47bool boolTest(T)() 48 { 49 alias t = T; 50 51 t = false; // tests AssignExp 52 assert(t == false); 53 54 bool boolValue = t; // tests AssignExp 55 assert(boolValue == false); 56 57 t = !t; // tests NotExp 58 assert(t == true); 59 60 boolValue = t; 61 assert(boolValue == true); 62 63 assert(boolValue && t); // tests AndAndExp 64 assert(t && boolValue); 65 66 boolValue = false; 67 assert(boolValue || t); // tests OrOrExp 68 assert(t || boolValue); 69 70 assert(t != boolValue); // tests CmpExp 71 assert(boolValue != t); 72 73 boolValue = true; 74 assert(t == boolValue); 75 assert(boolValue == t); 76 77 t = true; 78 return t; // tests ReturnStatement 79 } 80 intTest(T)81int intTest(T)() 82 { 83 alias t = T; 84 85 t = 42; // tests AssignExp 86 assert(t == 42); 87 88 int intValue = t; 89 assert(intValue == 42); 90 91 assert(t == 42); // tests CmpExp 92 assert(42 == t); 93 assert(t != 43); 94 assert(43 != t); 95 assert(t < 43); 96 assert(43 > t); 97 assert(t <= 42); 98 assert(42 >= t); 99 100 // These currently don't work for properties due to https://issues.dlang.org/show_bug.cgi?id=8006 101 static if (!(typeid(T) is typeid(StructProperty!int)) && !(typeid(T) is typeid(ClassProperty!int))) 102 { 103 t++; // test a few unary and binary operators 104 assert(t == 43); 105 106 t += 1; 107 assert(t == 44); 108 109 t--; 110 assert(t == 43); 111 112 t -= 1; 113 assert(t == 42); 114 } 115 116 assert(~t == ~42); // tests ComExp 117 118 return t; // tests ReturnStatement 119 } 120 main()121void main() 122 { 123 assert(boolTest!(StructField!(bool))()); 124 assert(boolTest!(StructProperty!(bool))()); 125 assert(boolTest!(ClassField!(bool))()); 126 assert(boolTest!(ClassProperty!(bool))()); 127 128 assert(intTest!(StructField!(int))() == 42); 129 assert(intTest!(StructProperty!(int))() == 42); 130 assert(intTest!(ClassField!(int))() == 42); 131 assert(intTest!(ClassProperty!(int))() == 42); 132 } 133