1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 module tanya.meta.tests.trait; 5 6 import tanya.meta.metafunction; 7 import tanya.meta.trait; 8 9 // typeof(null) is not a pointer. 10 @nogc nothrow pure @safe unittest 11 { 12 static assert(!isPointer!(typeof(null))); 13 static assert(!isPointer!(const shared typeof(null))); 14 15 enum typeOfNull : typeof(null) 16 { 17 null_ = null, 18 } 19 static assert(!isPointer!typeOfNull); 20 } 21 22 @nogc nothrow pure @safe unittest 23 { 24 static struct S 25 { 26 @property int opCall() 27 { 28 return 0; 29 } 30 } 31 S s; 32 static assert(isCallable!S); 33 static assert(isCallable!s); 34 } 35 36 @nogc nothrow pure @safe unittest 37 { 38 static assert(is(FunctionTypeOf!(void delegate()) == function)); 39 40 static void staticFunc() 41 { 42 } 43 auto functionPointer = &staticFunc; 44 static assert(is(FunctionTypeOf!staticFunc == function)); 45 static assert(is(FunctionTypeOf!functionPointer == function)); 46 47 void func() 48 { 49 } 50 auto dg = &func; 51 static assert(is(FunctionTypeOf!func == function)); 52 static assert(is(FunctionTypeOf!dg == function)); 53 54 interface I 55 { 56 @property int prop(); 57 } 58 static assert(is(FunctionTypeOf!(I.prop) == function)); 59 60 static struct S 61 { 62 void opCall() 63 { 64 } 65 } 66 class C 67 { 68 static void opCall() 69 { 70 } 71 } 72 S s; 73 74 static assert(is(FunctionTypeOf!s == function)); 75 static assert(is(FunctionTypeOf!C == function)); 76 static assert(is(FunctionTypeOf!S == function)); 77 } 78 79 @nogc nothrow pure @safe unittest 80 { 81 static struct S2 82 { 83 @property int opCall() 84 { 85 return 0; 86 } 87 } 88 S2 s2; 89 static assert(is(FunctionTypeOf!S2 == function)); 90 static assert(is(FunctionTypeOf!s2 == function)); 91 } 92 93 @nogc nothrow pure @safe unittest 94 { 95 static assert(!hasElaborateAssign!int); 96 97 static struct S1 98 { 99 void opAssign(S1) 100 { 101 } 102 } 103 static struct S2 104 { 105 void opAssign(int) 106 { 107 } 108 } 109 static struct S3 110 { 111 S1 s; 112 alias s this; 113 } 114 static assert(hasElaborateAssign!S1); 115 static assert(!hasElaborateAssign!(const S1)); 116 static assert(hasElaborateAssign!(S1[1])); 117 static assert(!hasElaborateAssign!(S1[0])); 118 static assert(!hasElaborateAssign!S2); 119 static assert(hasElaborateAssign!S3); 120 121 static struct S4 122 { 123 void opAssign(S4) 124 { 125 } 126 @disable this(this); 127 } 128 static assert(hasElaborateAssign!S4); 129 } 130 131 // Produces a tuple for an enum with only one member 132 @nogc nothrow pure @safe unittest 133 { 134 enum E : int 135 { 136 one = 0, 137 } 138 static assert(EnumMembers!E == AliasSeq!0); 139 } 140 141 @nogc nothrow pure @safe unittest 142 { 143 class RefCountedStore(T) 144 { 145 } 146 static assert(!isInnerClass!(RefCountedStore!int)); 147 } 148 149 @nogc nothrow pure @safe unittest 150 { 151 static struct DisabledOpEquals 152 { 153 @disable bool opEquals(typeof(this)) @nogc nothrow pure @safe; 154 155 int opCmp(typeof(this)) @nogc nothrow pure @safe 156 { 157 return 0; 158 } 159 } 160 static assert(!isEqualityComparable!DisabledOpEquals); 161 static assert(isOrderingComparable!DisabledOpEquals); 162 163 static struct OpEquals 164 { 165 bool opEquals(typeof(this)) @nogc nothrow pure @safe 166 { 167 return true; 168 } 169 } 170 static assert(isEqualityComparable!OpEquals); 171 static assert(!isOrderingComparable!OpEquals); 172 }