1 // PERMUTE_ARGS: -unittest
2 // REQUIRED_ARGS: -D -w -o- -c -Dd${RESULTS_DIR}/compilable -o-
3 // POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh unittest
7 /* Insert test-cases for documented unittests feature here. */
9 /// foo function - 1 example
10 int foo(int a, int b) { return a + b; }
15 assert(foo(1, 1) == 2);
18 /// bar function - 1 example
19 bool bar() { return true; }
33 /// doo function - no examples
50 add function - 3 examples
55 assert(add(1, 1) == 2);
58 int add(int a, int b) { return a + b; }
64 assert(add(3, 3) == 6);
65 assert(add(4, 4) == 8);
71 assert(add(2, 2) + add(2, 2) == 8);
78 assert(add(5, 5) == 10);
79 assert(add(6, 6) == 12);
83 immutable pure nothrow class Foo
90 // another foo example
107 /// some class - 1 example
116 SomeClass sc = new SomeClass;
119 /// Outer - 1 example
130 Inner inner = new Inner;
137 Outer outer = new Outer;
140 /** foobar - no examples */
176 // ------------------------------------
177 // insert import declaration between documented function and unittests
181 import core.stdc.stdio;
183 unittest { fooImport(); }
186 void fooStaticImport() {}
187 static import core.stdc.stdlib;
189 unittest { fooStaticImport(); }
192 void fooPublicImport() {}
193 public import core.stdc.string;
195 unittest { fooPublicImport(); }
198 void fooSelectiveImport() {}
199 import core.stdc.ctype : isalpha;
201 unittest { fooSelectiveImport(); }
204 void fooRenamedImport() {}
205 import io = core.stdc.stdio;
207 unittest { fooRenamedImport(); }
209 // ------------------------------------
210 // documented unittest after conditional declarations
213 void fooConditionalDecl1a() {} /** */
214 unittest { int x1a; } ///
217 { void fooConditionalDecl1b() {} /** */ }
218 unittest { int x1b; } ///
221 void fooConditionalDecl2a() {} /** */
222 unittest { int x2a; } ///
225 { void fooConditionalDecl2b() {} /** */ }
226 unittest { int x2b; } ///
229 { void fooConditionalDecl3a() {} /** */ }
231 { void barConditionalDecl3a() {} /** */ }
232 unittest { int x3a; } ///
235 { void fooConditionalDecl3b() {} /** */ }
237 { void barConditionalDecl3b() {} /** */ }
238 unittest { int x3b; } ///
241 void fooConditionalDecl4a() {} /** */
243 void barConditionalDecl4a() {} /** */
244 unittest { int x4a; } ///
247 { void fooConditionalDecl4b() {} /** */ }
249 { void barConditionalDecl4b() {} /** */ }
250 unittest { int x4b; } ///
255 void barConditionalDecl5a() {} /** */
256 unittest { int x5a; } ///
261 { void barConditionalDecl5b() {} /** */ }
262 unittest { int x5b; } ///
267 void barConditionalDecl6a() {} /** */
269 unittest { int x6a; }
274 { void barConditionalDecl6b() {} /** */ }
276 unittest { int x6b; }
278 // ------------------------------------
288 unittest { foo9474(); }
297 unittest { bar9474(); }
304 unittest { S9474 s; }
307 auto autovar9474 = 1;
309 unittest { int v = autovar9474; }
312 auto autofun9474() { return 1; }
314 unittest { int n = autofun9474(); }
317 template Template9474()
319 /// Shouldn't link following unittest to here
323 unittest { alias Template9474!() T; }
325 // ------------------------------------
329 void fooNoDescription() {}
331 unittest { fooNoDescription(); }
333 unittest { if (true) {fooNoDescription(); } /* comment */ }
335 // ------------------------------------
337 /// test for bugzilla 9757
344 unittest { foo9757(); bar9757(); }
346 unittest { bar9757(); foo9757(); }
348 /// with template functions
349 auto redBlackTree(E)(E[] elems...)
354 auto redBlackTree(bool allowDuplicates, E)(E[] elems...)
359 auto redBlackTree(alias less, E)(E[] elems...)
366 auto rbt1 = redBlackTree(0, 1, 5, 7);
367 auto rbt2 = redBlackTree!string("hello", "world");
368 auto rbt3 = redBlackTree!true(0, 1, 5, 7, 5);
369 auto rbt4 = redBlackTree!"a > b"(0, 1, 5, 7);
372 // ------------------------------------
381 // ------------------------------------
385 bool balancedParens10519(string, char, char) { return true; }
389 auto s = "1 + (2 * (3 + 1 / 2)";
390 assert(!balancedParens10519(s, '(', ')'));
393 // ------------------------------------
421 // ------------------------------------
427 void fun14594a()() {}
429 unittest { fun14594a(); }
434 void fun14594b()() {}
436 void fun14594b(T)(T) {}
438 unittest { fun14594b(); fun14594b(1); }
443 void fun14594c()() {}
445 unittest { fun14594c(); fun14594c(1); }
447 void fun14594c(T)(T) {}
452 void fun14594d()() {}
454 unittest { fun14594d(); }
456 void fun14594d(T)(T) {}
458 unittest { fun14594d(1); }
465 /// concatenated doc-comment fun14594e
467 /// ignored-unittest fun14594e
468 unittest { fun14594e(); }
470 /// doc-unittest fun14594e
471 unittest { fun14594e(); }
478 /// concatenated doc-comment fun14594f
480 /// ignored-unittest fun14594f
481 unittest { fun14594f(); }
484 template fun14594f(T)
486 /// ignored doc-comment fun14594f
488 /// ignored-unittest fun14594f
489 unittest { fun14594f(1); }
491 /// doc-unittest fun14594f
492 unittest { fun14594f(); }
494 // ------------------------------------