]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gdc.test/compilable/ddocunittest.d
initialize pr94314-3.C counter
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / compilable / ddocunittest.d
CommitLineData
b4c522fa
IB
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
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
191///
192void fooPublicImport() {}
193public import core.stdc.string;
194/// test
195unittest { fooPublicImport(); }
196
197///
198void fooSelectiveImport() {}
199import core.stdc.ctype : isalpha;
200/// test
201unittest { fooSelectiveImport(); }
202
203///
204void fooRenamedImport() {}
205import io = core.stdc.stdio;
206/// test
207unittest { fooRenamedImport(); }
208
209// ------------------------------------
210// documented unittest after conditional declarations
211
212static if (true)
213 void fooConditionalDecl1a() {} /** */
214unittest { int x1a; } ///
215
216static if (true)
217{ void fooConditionalDecl1b() {} /** */ }
218unittest { int x1b; } ///
219
220static if (false)
221 void fooConditionalDecl2a() {} /** */
222unittest { int x2a; } ///
223
224static if (false)
225{ void fooConditionalDecl2b() {} /** */ }
226unittest { int x2b; } ///
227
228static if (true)
229{ void fooConditionalDecl3a() {} /** */ }
230else
231{ void barConditionalDecl3a() {} /** */ }
232unittest { int x3a; } ///
233
234static if (true)
235{ void fooConditionalDecl3b() {} /** */ }
236else
237{ void barConditionalDecl3b() {} /** */ }
238unittest { int x3b; } ///
239
240static if (false)
241 void fooConditionalDecl4a() {} /** */
242else
243 void barConditionalDecl4a() {} /** */
244unittest { int x4a; } ///
245
246static if (false)
247{ void fooConditionalDecl4b() {} /** */ }
248else
249{ void barConditionalDecl4b() {} /** */ }
250unittest { int x4b; } ///
251
252static if (true)
253{}
254else
255 void barConditionalDecl5a() {} /** */
256unittest { int x5a; } ///
257
258static if (true)
259{}
260else
261{ void barConditionalDecl5b() {} /** */ }
262unittest { int x5b; } ///
263
264static if (false)
265{}
266else
267 void barConditionalDecl6a() {} /** */
268///
269unittest { int x6a; }
270
271static if (false)
272{}
273else
274{ void barConditionalDecl6b() {} /** */ }
275///
276unittest { int x6b; }
277
278// ------------------------------------
279// 9474
280
281///
282void foo9474() { }
283
284version(none)
285unittest { }
286
287/// Example
288unittest { foo9474(); }
289
290/// doc
291void bar9474() { }
292
293version(none)
294unittest { }
295
296/// Example
297unittest { bar9474(); }
298
299///
300struct S9474
301{
302}
303///
304unittest { S9474 s; }
305
306///
307auto autovar9474 = 1;
308///
309unittest { int v = autovar9474; }
310
311///
312auto autofun9474() { return 1; }
313///
314 unittest { int n = autofun9474(); }
315
316///
317template Template9474()
318{
319 /// Shouldn't link following unittest to here
320 void foo() {}
321}
322///
323unittest { alias Template9474!() T; }
324
325// ------------------------------------
326// 9713
327
328///
329void fooNoDescription() {}
330///
331unittest { fooNoDescription(); }
332///
333unittest { if (true) {fooNoDescription(); } /* comment */ }
334
335// ------------------------------------
336
337/// test for bugzilla 9757
338void foo9757() {}
339/// ditto
340void bar9757() {}
341/// ditto
342void baz9757() {}
343///
344unittest { foo9757(); bar9757(); }
345///
346unittest { bar9757(); foo9757(); }
347
348/// with template functions
349auto redBlackTree(E)(E[] elems...)
350{
351 return 1;
352}
353/// ditto
354auto redBlackTree(bool allowDuplicates, E)(E[] elems...)
355{
356 return 2;
357}
358/// ditto
359auto redBlackTree(alias less, E)(E[] elems...)
360{
361 return 3;
362}
363///
364unittest
365{
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);
370}
371
372// ------------------------------------
373// Issue 9758
374
375/// test
376void foo(){}
377
378///
379unittest { }
380
381// ------------------------------------
382// Issue 10519
383
384///
385bool balancedParens10519(string, char, char) { return true; }
386///
387unittest
388{
389 auto s = "1 + (2 * (3 + 1 / 2)";
390 assert(!balancedParens10519(s, '(', ')'));
391}
392
393// ------------------------------------
394// Issue 12097
395
396/// declaration
397struct S12097
398{
399 /// method
400 void foo() {}
401}
402
403/// ditto
404void f12097() {}
405
406/// ddoc code 1
407unittest
408{
409 int a = 1;
410}
411
412/// ditto
413struct T12097(T) {}
414
415/// ddoc code 2
416unittest
417{
418 int[] arr;
419}
420
421// ------------------------------------
422// 14594
423
424/*******************
425 * testA
426 */
427void fun14594a()() {}
428///
429unittest { fun14594a(); }
430
431/*******************
432 * testB
433 */
434void fun14594b()() {}
435/// ditto
436void fun14594b(T)(T) {}
437///
438unittest { fun14594b(); fun14594b(1); }
439
440/*******************
441 * testC
442 */
443void fun14594c()() {}
444///
445unittest { fun14594c(); fun14594c(1); }
446/// ditto
447void fun14594c(T)(T) {}
448
449/*******************
450 * testD
451 */
452void fun14594d()() {}
453///
454unittest { fun14594d(); }
455/// ditto
456void fun14594d(T)(T) {}
457///
458unittest { fun14594d(1); }
459
460/*******************
461 * testE
462 */
463template fun14594e()
464{
465 /// concatenated doc-comment fun14594e
466 void fun14594e() {}
467 /// ignored-unittest fun14594e
468 unittest { fun14594e(); }
469}
470/// doc-unittest fun14594e
471unittest { fun14594e(); }
472
473/*******************
474 * testF
475 */
476template fun14594f()
477{
478 /// concatenated doc-comment fun14594f
479 void fun14594f() {}
480 /// ignored-unittest fun14594f
481 unittest { fun14594f(); }
482}
483/// ditto
484template fun14594f(T)
485{
486 /// ignored doc-comment fun14594f
487 void fun14594f(T) {}
488 /// ignored-unittest fun14594f
489 unittest { fun14594f(1); }
490}
491/// doc-unittest fun14594f
492unittest { fun14594f(); }
493
494// ------------------------------------
495
496void main() { }