1 module cogito.tests.meta; 2 3 import cogito; 4 import std.sumtype; 5 6 @("Top-level static if") 7 unittest 8 { 9 auto meter = runOnCode(q{ 10 static if (true) 11 { 12 alias Integer = int; 13 } 14 }); 15 16 assert(meter.tryMatch!((Source source) => source.score) == 1); 17 } 18 19 @("static foreach declaration") 20 unittest 21 { 22 auto meter = runOnCode(q{ 23 static foreach (const a; 0..1) 24 { 25 alias Integer = int; 26 } 27 }); 28 29 assert(meter.tryMatch!((Source source) => source.score) == 1); 30 } 31 32 @("Static foreach statement") 33 unittest 34 { 35 auto meter = runOnCode(q{ 36 void f() 37 { 38 static foreach (const a; 0..1) 39 { 40 alias Integer = int; 41 } 42 } 43 }); 44 45 assert(meter.tryMatch!((Source source) => source.score) == 1); 46 } 47 48 @("Version block") 49 unittest 50 { 51 auto meter = runOnCode(q{ 52 version (Version) 53 { 54 alias Integer = int; 55 } 56 }); 57 58 assert(meter.tryMatch!((Source source) => source.score) == 1); 59 } 60 61 @("Static if in a function") 62 unittest 63 { 64 auto meter = runOnCode(q{ 65 void f() 66 { 67 static if (true) 68 { 69 } 70 } 71 }); 72 73 assert(meter.tryMatch!((Source source) => source.score) == 1); 74 } 75 76 @("Static else declaration") 77 unittest 78 { 79 auto meter = runOnCode(q{ 80 static if (true) 81 { 82 } 83 else 84 { 85 } 86 }); 87 88 assert(meter.tryMatch!((Source source) => source.score) == 2); 89 } 90 91 @("Static else-if declaration") 92 unittest 93 { 94 auto meter = runOnCode(q{ 95 static if (true) 96 { 97 } 98 else static if (false) 99 { 100 } 101 }); 102 103 assert(meter.tryMatch!((Source source) => source.score) == 2); 104 } 105 106 @("Multiple nested static-else-if declarations") 107 unittest 108 { 109 auto meter = runOnCode(q{ 110 static if (true) 111 { 112 static if (true) 113 { 114 } 115 else static if (false) 116 { 117 } 118 else static if (false) 119 { 120 } 121 } 122 else 123 { 124 } 125 }); 126 127 assert(meter.tryMatch!((Source source) => source.score) == 5); 128 } 129 130 @("Multiple nested static-else-if statements") 131 unittest 132 { 133 auto meter = runOnCode(q{ 134 void f() 135 { 136 static if (true) 137 { 138 static if (true) 139 { 140 } 141 else static if (false) 142 { 143 } 144 else static if (false) 145 { 146 } 147 } 148 else 149 { 150 } 151 } 152 }); 153 154 assert(meter.tryMatch!((Source source) => source.score) == 6); 155 } 156 157 @("debug") 158 unittest 159 { 160 auto meter = runOnCode(q{ 161 void f() 162 { 163 debug 164 { 165 } 166 } 167 }); 168 169 assert(meter.tryMatch!((Source source) => source.score) == 1); 170 } 171 172 @("debug-else") 173 unittest 174 { 175 auto meter = runOnCode(q{ 176 void f() 177 { 178 debug 179 { 180 } 181 else 182 { 183 } 184 } 185 }); 186 187 assert(meter.tryMatch!((Source source) => source.score) == 2); 188 } 189 190 @("struct template identifier") 191 unittest 192 { 193 auto meter = runOnCode(q{ 194 struct S(T) 195 { 196 void f() 197 { 198 } 199 } 200 }); 201 202 assert(meter.tryMatch!((Source source) => source.inner).front.name == "S"); 203 } 204 205 @("class template identifier") 206 unittest 207 { 208 auto meter = runOnCode(q{ 209 class C(T) 210 { 211 void f() 212 { 213 } 214 } 215 }); 216 217 assert(meter.tryMatch!((Source source) => source.inner).front.name == "C"); 218 } 219 220 @("template identifier") 221 unittest 222 { 223 auto meter = runOnCode(q{ 224 template T() 225 { 226 void f() 227 { 228 } 229 } 230 }); 231 232 assert(meter.tryMatch!((Source source) => source.inner).front.name == "T"); 233 }