Debian Codegraph @

gcc/testsuite/gdc.test/runnable/interface3.d

raw
1 /*
2 PERMUTE_ARGS:
3 RUN_OUTPUT:
4 ---
5 OK
6 ---
7 */
8
9 extern(C) int printf(const char*, ...);
10
11 interface IWriter
12 {
13 IWriter put (I1 x);
14 }
15
16 interface I1
17 {
18 void write (IWriter writer);
19 }
20
21 interface I2 : I1 {}
22
23 interface I3 : I2 {}
24
25 class Newline : I3
26 {
27 static int OKset;
28
29 void write (IWriter writer)
30 {
31 printf ("OK\n");
32 OKset += 1;
33 }
34 }
35
36
37
38 class Writer : IWriter
39 {
40 IWriter put (I1 x)
41 {
42 x.write (this);
43 return this;
44 }
45 }
46
47 class FlushWriter : Writer
48 {
49 override IWriter put (I1 x)
50 {
51 // have superclass handle the I1
52 super.put (x);
53
54 // flush output when we see a newline
55 if (cast(Newline) x)
56 {
57 }
58
59 return this;
60 }
61 }
62
63
64
65 void test (IWriter w)
66 {
67 //w.put (new Newline);
68
69 I3 NL = new Newline;
70 w.put (NL);
71 }
72
73
74 int main()
75 {
76 test (new FlushWriter);
77 assert(Newline.OKset == 1);
78 return 0;
79 }