]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gdc.test/compilable/ddocunittest.d
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / compilable / ddocunittest.d
CommitLineData
b4c522fa 1// PERMUTE_ARGS: -unittest
5fee5ec3
IB
2// REQUIRED_ARGS: -D -w -o- -Dd${RESULTS_DIR}/compilable -o-
3// POST_SCRIPT: compilable/extra-files/ddocAny-postscript.sh
b4c522fa
IB
4
5module ddocunittest;
6
7/* Insert test-cases for documented unittests feature here. */
8
9/// foo function - 1 example
10int foo(int a, int b) { return a + b; }
11
12///
13unittest
14{
15 assert(foo(1, 1) == 2);
16}
17
18/// bar function - 1 example
19bool bar() { return true; }
20
21///
22unittest
23{
24 // documented
25 assert(bar());
26}
27
28/// placeholder
29unittest
30{
31}
32
33/// doo function - no examples
34void doo() { }
35
36///
37private unittest
38{
39 // undocumented
40 doo();
41}
42
43unittest
44{
45 // undocumented
46 doo();
47}
48
49/**
50add function - 3 examples
51
52Examples:
53
54----
55assert(add(1, 1) == 2);
56----
57*/
58int add(int a, int b) { return a + b; }
59
60///
61unittest
62{
63 // documented
64 assert(add(3, 3) == 6);
65 assert(add(4, 4) == 8);
66}
67
68unittest
69{
70 // undocumented
71 assert(add(2, 2) + add(2, 2) == 8);
72}
73
74///
75unittest
76{
77 // documented
78 assert(add(5, 5) == 10);
79 assert(add(6, 6) == 12);
80}
81
82/// class Foo
83immutable pure nothrow class Foo
84{
85 int x;
86
87 ///
88 unittest
89 {
90 // another foo example
91 Foo foo = new Foo;
92 }
93}
94
95///
96unittest
97{
98 Foo foo = new Foo;
99}
100
101pure
102{
103 const
104 {
105 immutable
106 {
107 /// some class - 1 example
108 class SomeClass {}
109 }
110 }
111}
112
113///
114unittest
115{
116 SomeClass sc = new SomeClass;
117}
118
119/// Outer - 1 example
120class Outer
121{
122 /// Inner
123 static class Inner
124 {
125 }
126
127 ///
128 unittest
129 {
130 Inner inner = new Inner;
131 }
132}
133
134///
135unittest
136{
137 Outer outer = new Outer;
138}
139
140/** foobar - no examples */
141void foobar()
142{
143}
144
145unittest
146{
147 foobar();
148}
149
150/**
151func - 4 examples
152Examples:
153---
154foo(1);
155---
156
157Examples:
158---
159foo(2);
160---
161*/
162void foo(int x) { }
163
164///
165unittest
166{
167 foo(2);
168}
169
170///
171unittest
172{
173 foo(4);
174}
175
176// ------------------------------------
177// insert import declaration between documented function and unittests
178
179///
180void fooImport() {}
181import core.stdc.stdio;
182/// test
183unittest { fooImport(); }
184
185///
186void fooStaticImport() {}
187static import core.stdc.stdlib;
188/// test
189unittest { fooStaticImport(); }
190
b4c522fa
IB
191///
192void fooSelectiveImport() {}
193import core.stdc.ctype : isalpha;
194/// test
195unittest { fooSelectiveImport(); }
196
197///
198void fooRenamedImport() {}
199import io = core.stdc.stdio;
200/// test
201unittest { fooRenamedImport(); }
202
5fee5ec3
IB
203/// This is a public import
204public import core.stdc.string;
205
206/// This is a mutiple public import
207public import core.stdc.stdarg, core.stdc.stdlib;
208
209/// This is a public selective import
210public import core.stdc.string : memcpy;
211
212/// This is a public selective renamed import
213public import core.stdc.string : copy = memcpy;
214
215/// This is a public multiple selective import
216public import core.stdc.string : memcpy, memcmp;
217
218/// This is a public multiple selective renamed import
219public import core.stdc.string : copy = memcpy, compare = memcmp;
220
221/// This is a public renamed import
222public import str = core.stdc.string;
223
224// This is a public import without a DDoc comment.
225// It should not be emitted to the documentation file.
226public import core.stdc.stdlib;
227
228
b4c522fa
IB
229// ------------------------------------
230// documented unittest after conditional declarations
231
232static if (true)
233 void fooConditionalDecl1a() {} /** */
234unittest { int x1a; } ///
235
236static if (true)
237{ void fooConditionalDecl1b() {} /** */ }
238unittest { int x1b; } ///
239
240static if (false)
241 void fooConditionalDecl2a() {} /** */
242unittest { int x2a; } ///
243
244static if (false)
245{ void fooConditionalDecl2b() {} /** */ }
246unittest { int x2b; } ///
247
248static if (true)
249{ void fooConditionalDecl3a() {} /** */ }
250else
251{ void barConditionalDecl3a() {} /** */ }
252unittest { int x3a; } ///
253
254static if (true)
255{ void fooConditionalDecl3b() {} /** */ }
256else
257{ void barConditionalDecl3b() {} /** */ }
258unittest { int x3b; } ///
259
260static if (false)
261 void fooConditionalDecl4a() {} /** */
262else
263 void barConditionalDecl4a() {} /** */
264unittest { int x4a; } ///
265
266static if (false)
267{ void fooConditionalDecl4b() {} /** */ }
268else
269{ void barConditionalDecl4b() {} /** */ }
270unittest { int x4b; } ///
271
272static if (true)
273{}
274else
275 void barConditionalDecl5a() {} /** */
276unittest { int x5a; } ///
277
278static if (true)
279{}
280else
281{ void barConditionalDecl5b() {} /** */ }
282unittest { int x5b; } ///
283
284static if (false)
285{}
286else
287 void barConditionalDecl6a() {} /** */
288///
289unittest { int x6a; }
290
291static if (false)
292{}
293else
294{ void barConditionalDecl6b() {} /** */ }
295///
296unittest { int x6b; }
297
298// ------------------------------------
5fee5ec3 299// https://issues.dlang.org/show_bug.cgi?id=9474
b4c522fa
IB
300
301///
302void foo9474() { }
303
304version(none)
305unittest { }
306
307/// Example
308unittest { foo9474(); }
309
310/// doc
311void bar9474() { }
312
313version(none)
314unittest { }
315
316/// Example
317unittest { bar9474(); }
318
319///
320struct S9474
321{
322}
323///
324unittest { S9474 s; }
325
326///
327auto autovar9474 = 1;
328///
329unittest { int v = autovar9474; }
330
331///
332auto autofun9474() { return 1; }
333///
334 unittest { int n = autofun9474(); }
335
336///
337template Template9474()
338{
339 /// Shouldn't link following unittest to here
340 void foo() {}
341}
342///
343unittest { alias Template9474!() T; }
344
345// ------------------------------------
5fee5ec3 346// https://issues.dlang.org/show_bug.cgi?id=9713
b4c522fa
IB
347
348///
349void fooNoDescription() {}
350///
351unittest { fooNoDescription(); }
352///
353unittest { if (true) {fooNoDescription(); } /* comment */ }
354
355// ------------------------------------
356
5fee5ec3 357/// test for https://issues.dlang.org/show_bug.cgi?id=9757
b4c522fa
IB
358void foo9757() {}
359/// ditto
360void bar9757() {}
361/// ditto
362void baz9757() {}
363///
364unittest { foo9757(); bar9757(); }
365///
366unittest { bar9757(); foo9757(); }
367
368/// with template functions
369auto redBlackTree(E)(E[] elems...)
370{
371 return 1;
372}
373/// ditto
374auto redBlackTree(bool allowDuplicates, E)(E[] elems...)
375{
376 return 2;
377}
378/// ditto
379auto redBlackTree(alias less, E)(E[] elems...)
5a0aa603 380if (__traits(compiles, (E a, E b) => mixin(less)))
b4c522fa
IB
381{
382 return 3;
383}
384///
385unittest
386{
387 auto rbt1 = redBlackTree(0, 1, 5, 7);
388 auto rbt2 = redBlackTree!string("hello", "world");
389 auto rbt3 = redBlackTree!true(0, 1, 5, 7, 5);
390 auto rbt4 = redBlackTree!"a > b"(0, 1, 5, 7);
391}
392
393// ------------------------------------
5fee5ec3 394// https://issues.dlang.org/show_bug.cgi?id=9758
b4c522fa
IB
395
396/// test
397void foo(){}
398
399///
400unittest { }
401
402// ------------------------------------
5fee5ec3 403// https://issues.dlang.org/show_bug.cgi?id=10519
b4c522fa
IB
404
405///
406bool balancedParens10519(string, char, char) { return true; }
407///
408unittest
409{
410 auto s = "1 + (2 * (3 + 1 / 2)";
411 assert(!balancedParens10519(s, '(', ')'));
412}
413
414// ------------------------------------
5fee5ec3 415// https://issues.dlang.org/show_bug.cgi?id=12097
b4c522fa
IB
416
417/// declaration
418struct S12097
419{
420 /// method
421 void foo() {}
422}
423
424/// ditto
425void f12097() {}
426
427/// ddoc code 1
428unittest
429{
430 int a = 1;
431}
432
433/// ditto
434struct T12097(T) {}
435
436/// ddoc code 2
437unittest
438{
439 int[] arr;
440}
441
442// ------------------------------------
5fee5ec3 443// https://issues.dlang.org/show_bug.cgi?id=14594
b4c522fa
IB
444
445/*******************
446 * testA
447 */
448void fun14594a()() {}
449///
450unittest { fun14594a(); }
451
452/*******************
453 * testB
454 */
455void fun14594b()() {}
456/// ditto
457void fun14594b(T)(T) {}
458///
459unittest { fun14594b(); fun14594b(1); }
460
461/*******************
462 * testC
463 */
464void fun14594c()() {}
465///
466unittest { fun14594c(); fun14594c(1); }
467/// ditto
468void fun14594c(T)(T) {}
469
470/*******************
471 * testD
472 */
473void fun14594d()() {}
474///
475unittest { fun14594d(); }
476/// ditto
477void fun14594d(T)(T) {}
478///
479unittest { fun14594d(1); }
480
481/*******************
482 * testE
483 */
484template fun14594e()
485{
486 /// concatenated doc-comment fun14594e
487 void fun14594e() {}
488 /// ignored-unittest fun14594e
489 unittest { fun14594e(); }
490}
491/// doc-unittest fun14594e
492unittest { fun14594e(); }
493
494/*******************
495 * testF
496 */
497template fun14594f()
498{
499 /// concatenated doc-comment fun14594f
500 void fun14594f() {}
501 /// ignored-unittest fun14594f
502 unittest { fun14594f(); }
503}
504/// ditto
505template fun14594f(T)
506{
507 /// ignored doc-comment fun14594f
508 void fun14594f(T) {}
509 /// ignored-unittest fun14594f
510 unittest { fun14594f(1); }
511}
512/// doc-unittest fun14594f
513unittest { fun14594f(); }
514
515// ------------------------------------
516
517void main() { }