1 module reflection; 2 3 4 import autowrap.reflection; 5 import unit_threaded; 6 import std.typecons: Yes; 7 8 9 @("isStatic") 10 @safe pure unittest { 11 static struct Struct { 12 int foo(); 13 static int bar(); 14 } 15 16 static assert(!isStatic!(Struct.foo)); 17 static assert( isStatic!(Struct.bar)); 18 } 19 20 21 @("Functions.export") 22 @safe pure unittest { 23 alias functions = Functions!(Module("modules.functions")); 24 functions.length.should == 2; 25 26 static import modules.functions; 27 28 functions[0].name.should == "stringRet"; 29 static assert(__traits(isSame, functions[0].module_, modules.functions)); 30 functions[0].moduleName.should == "modules.functions"; 31 static assert(__traits(isSame, functions[0].symbol, modules.functions.stringRet)); 32 33 functions[1].name.should == "twice"; 34 static assert(__traits(isSame, functions[1].module_, modules.functions)); 35 functions[1].moduleName.should == "modules.functions"; 36 static assert(__traits(isSame, functions[1].symbol, modules.functions.twice)); 37 } 38 39 40 @("Functions.all") 41 @safe pure unittest { 42 alias functions = Functions!(Module("modules.functions", Yes.alwaysExport)); 43 functions.length.should == 3; 44 } 45 46 47 @("BinaryOperators") 48 @safe pure unittest { 49 50 static struct Number { 51 int i; 52 Number opBinary(string op)(Number other) if(op == "+") { 53 return Number(i + other.i); 54 } 55 Number opBinary(string op)(Number other) if(op == "-") { 56 return Number(i - other.i); 57 } 58 Number opBinaryRight(string op)(int other) if(op == "+") { 59 return Number(i + other); 60 } 61 } 62 63 static assert( 64 [BinaryOperators!Number] == 65 [ 66 BinaryOperator("+", BinOpDir.left | BinOpDir.right), 67 BinaryOperator("-", BinOpDir.left), 68 ] 69 ); 70 } 71 72 73 @("UnaryOperators") 74 @safe pure unittest { 75 76 static struct Struct { 77 int opUnary(string op)() if(op == "+") { return 42; } 78 int opUnary(string op)() if(op == "~") { return 33; } 79 } 80 81 static assert([UnaryOperators!Struct] == ["+", "~"]); 82 } 83 84 85 @("AssignOperators") 86 @safe pure unittest { 87 88 static struct Number { 89 int i; 90 Number opOpAssign(string op)(Number other) if(op == "+") { 91 return Number(i + other.i); 92 } 93 Number opOpAssign(string op)(Number other) if(op == "-") { 94 return Number(i - other.i); 95 } 96 Number opOpAssignRight(string op)(int other) if(op == "+") { 97 return Number(i + other); 98 } 99 } 100 101 static assert([AssignOperators!Number] == ["+", "-"]); 102 } 103 104 105 @("isUserAggregate!DateTime") 106 @safe pure unittest { 107 import std.datetime: DateTime; 108 static assert(!isUserAggregate!DateTime); 109 } 110 111 112 @("isUserAggregate!Tuple") 113 @safe pure unittest { 114 import std.typecons: Tuple; 115 static assert(!isUserAggregate!(Tuple!(int, double))); 116 } 117 118 119 @("isPrimordialType") 120 @safe pure unittest { 121 static assert(is(PrimordialType!int == int)); 122 static assert(is(PrimordialType!(int[]) == int)); 123 static assert(is(PrimordialType!(int[][]) == int)); 124 static assert(is(PrimordialType!(double[][]) == double)); 125 static assert(is(PrimordialType!(string[][]) == char)); 126 static assert(is(PrimordialType!(int*) == int)); 127 static assert(is(PrimordialType!(int**) == int)); 128 }