Separate non-documentation tests from the code
This commit is contained in:
27
tests/tanya/meta/tests/metafunction.d
Normal file
27
tests/tanya/meta/tests/metafunction.d
Normal file
@ -0,0 +1,27 @@
|
||||
module tanya.meta.tests.metafunction;
|
||||
|
||||
import tanya.meta.metafunction;
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
enum cmp(int x, int y) = x - y;
|
||||
static assert(isSorted!(cmp));
|
||||
static assert(isSorted!(cmp, 1));
|
||||
static assert(isSorted!(cmp, 1, 2, 2));
|
||||
static assert(isSorted!(cmp, 1, 2, 2, 4));
|
||||
static assert(isSorted!(cmp, 1, 2, 2, 4, 8));
|
||||
static assert(!isSorted!(cmp, 32, 2, 2, 4, 8));
|
||||
static assert(isSorted!(cmp, 32, 32));
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
enum cmp(int x, int y) = x < y;
|
||||
static assert(isSorted!(cmp));
|
||||
static assert(isSorted!(cmp, 1));
|
||||
static assert(isSorted!(cmp, 1, 2, 2));
|
||||
static assert(isSorted!(cmp, 1, 2, 2, 4));
|
||||
static assert(isSorted!(cmp, 1, 2, 2, 4, 8));
|
||||
static assert(!isSorted!(cmp, 32, 2, 2, 4, 8));
|
||||
static assert(isSorted!(cmp, 32, 32));
|
||||
}
|
169
tests/tanya/meta/tests/trait.d
Normal file
169
tests/tanya/meta/tests/trait.d
Normal file
@ -0,0 +1,169 @@
|
||||
module tanya.meta.tests.trait;
|
||||
|
||||
import tanya.meta.metafunction;
|
||||
import tanya.meta.trait;
|
||||
|
||||
// typeof(null) is not a pointer.
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static assert(!isPointer!(typeof(null)));
|
||||
static assert(!isPointer!(const shared typeof(null)));
|
||||
|
||||
enum typeOfNull : typeof(null)
|
||||
{
|
||||
null_ = null,
|
||||
}
|
||||
static assert(!isPointer!typeOfNull);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static struct S
|
||||
{
|
||||
@property int opCall()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
S s;
|
||||
static assert(isCallable!S);
|
||||
static assert(isCallable!s);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static assert(is(FunctionTypeOf!(void delegate()) == function));
|
||||
|
||||
static void staticFunc()
|
||||
{
|
||||
}
|
||||
auto functionPointer = &staticFunc;
|
||||
static assert(is(FunctionTypeOf!staticFunc == function));
|
||||
static assert(is(FunctionTypeOf!functionPointer == function));
|
||||
|
||||
void func()
|
||||
{
|
||||
}
|
||||
auto dg = &func;
|
||||
static assert(is(FunctionTypeOf!func == function));
|
||||
static assert(is(FunctionTypeOf!dg == function));
|
||||
|
||||
interface I
|
||||
{
|
||||
@property int prop();
|
||||
}
|
||||
static assert(is(FunctionTypeOf!(I.prop) == function));
|
||||
|
||||
static struct S
|
||||
{
|
||||
void opCall()
|
||||
{
|
||||
}
|
||||
}
|
||||
class C
|
||||
{
|
||||
static void opCall()
|
||||
{
|
||||
}
|
||||
}
|
||||
S s;
|
||||
|
||||
static assert(is(FunctionTypeOf!s == function));
|
||||
static assert(is(FunctionTypeOf!C == function));
|
||||
static assert(is(FunctionTypeOf!S == function));
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static struct S2
|
||||
{
|
||||
@property int opCall()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
S2 s2;
|
||||
static assert(is(FunctionTypeOf!S2 == function));
|
||||
static assert(is(FunctionTypeOf!s2 == function));
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static assert(!hasElaborateAssign!int);
|
||||
|
||||
static struct S1
|
||||
{
|
||||
void opAssign(S1)
|
||||
{
|
||||
}
|
||||
}
|
||||
static struct S2
|
||||
{
|
||||
void opAssign(int)
|
||||
{
|
||||
}
|
||||
}
|
||||
static struct S3
|
||||
{
|
||||
S1 s;
|
||||
alias s this;
|
||||
}
|
||||
static assert(hasElaborateAssign!S1);
|
||||
static assert(!hasElaborateAssign!(const S1));
|
||||
static assert(hasElaborateAssign!(S1[1]));
|
||||
static assert(!hasElaborateAssign!(S1[0]));
|
||||
static assert(!hasElaborateAssign!S2);
|
||||
static assert(hasElaborateAssign!S3);
|
||||
|
||||
static struct S4
|
||||
{
|
||||
void opAssign(S4)
|
||||
{
|
||||
}
|
||||
@disable this(this);
|
||||
}
|
||||
static assert(hasElaborateAssign!S4);
|
||||
}
|
||||
|
||||
// Produces a tuple for an enum with only one member
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
enum E : int
|
||||
{
|
||||
one = 0,
|
||||
}
|
||||
static assert(EnumMembers!E == AliasSeq!0);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
class RefCountedStore(T)
|
||||
{
|
||||
}
|
||||
static assert(!isInnerClass!(RefCountedStore!int));
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static struct DisabledOpEquals
|
||||
{
|
||||
@disable bool opEquals(typeof(this)) @nogc nothrow pure @safe;
|
||||
|
||||
int opCmp(typeof(this)) @nogc nothrow pure @safe
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
static assert(!isEqualityComparable!DisabledOpEquals);
|
||||
static assert(isOrderingComparable!DisabledOpEquals);
|
||||
|
||||
static struct OpEquals
|
||||
{
|
||||
bool opEquals(typeof(this)) @nogc nothrow pure @safe
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
static assert(isEqualityComparable!OpEquals);
|
||||
static assert(!isOrderingComparable!OpEquals);
|
||||
}
|
50
tests/tanya/meta/tests/transform.d
Normal file
50
tests/tanya/meta/tests/transform.d
Normal file
@ -0,0 +1,50 @@
|
||||
module tanya.meta.tests.transform;
|
||||
|
||||
import tanya.meta.transform;
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static assert(is(CommonType!(void*, int*) == void*));
|
||||
static assert(is(CommonType!(void*, const(int)*) == const(void)*));
|
||||
static assert(is(CommonType!(void*, const(void)*) == const(void)*));
|
||||
static assert(is(CommonType!(int*, void*) == void*));
|
||||
static assert(is(CommonType!(const(int)*, void*) == const(void)*));
|
||||
static assert(is(CommonType!(const(void)*, void*) == const(void)*));
|
||||
|
||||
static assert(is(CommonType!() == void));
|
||||
static assert(is(CommonType!(int*, const(int)*) == const(int)*));
|
||||
static assert(is(CommonType!(int**, const(int)**) == const(int*)*));
|
||||
|
||||
static assert(is(CommonType!(float, double) == double));
|
||||
static assert(is(CommonType!(float, int) == void));
|
||||
|
||||
static assert(is(CommonType!(bool, const bool) == bool));
|
||||
static assert(is(CommonType!(int, bool) == void));
|
||||
static assert(is(CommonType!(int, void) == void));
|
||||
static assert(is(CommonType!(Object, void*) == void));
|
||||
|
||||
class A
|
||||
{
|
||||
}
|
||||
static assert(is(CommonType!(A, Object) == Object));
|
||||
static assert(is(CommonType!(const(A)*, Object*) == const(Object)*));
|
||||
static assert(is(CommonType!(A, typeof(null)) == A));
|
||||
|
||||
class B : A
|
||||
{
|
||||
}
|
||||
class C : A
|
||||
{
|
||||
}
|
||||
static assert(is(CommonType!(B, C) == A));
|
||||
|
||||
static struct S
|
||||
{
|
||||
int opCast(T : int)()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
static assert(is(CommonType!(S, int) == void));
|
||||
static assert(is(CommonType!(const S, S) == const S));
|
||||
}
|
Reference in New Issue
Block a user