Mercurial > projects > ldc
annotate tests/mini/dgs.d @ 650:aa6a0b7968f7
Added test case for bug #100
Removed dubious check for not emitting static private global in other modules without access. This should be handled properly somewhere else, it's causing unresolved global errors for stuff that should work (in MiniD)
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sun, 05 Oct 2008 17:28:15 +0200 |
parents | 1bb99290e03a |
children |
rev | line source |
---|---|
270
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
1
diff
changeset
|
1 |
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
1
diff
changeset
|
2 extern(C) int printf(char*, ...); |
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
1
diff
changeset
|
3 |
1 | 4 struct S |
5 { | |
6 int i; | |
7 int square() | |
8 { | |
9 return i*i; | |
10 } | |
11 int plus(int a) | |
12 { | |
13 return i + a; | |
14 } | |
15 int minus(int a) | |
16 { | |
17 return i - a; | |
18 } | |
19 int delegate(int) get(char op) | |
20 { | |
21 int delegate(int) rval; | |
22 if (op == '+') | |
23 rval = + | |
24 else if (op == '-') | |
25 rval = − | |
26 return rval; | |
27 } | |
28 } | |
29 | |
30 int calldg1(int delegate(int) dg, int i) | |
31 { | |
32 return dg(i); | |
33 } | |
34 | |
35 void delegate() retdg() | |
36 { | |
37 void delegate() dg; | |
38 return dg; | |
39 } | |
40 | |
41 void getretdg() | |
42 { | |
43 void delegate() dg; | |
44 dg = retdg(); | |
45 } | |
46 | |
47 class C | |
48 { | |
49 int i; | |
50 void m() | |
51 { | |
52 i = 42; | |
53 } | |
54 } | |
55 | |
56 void getclassdg() | |
57 { | |
58 scope c = new C; | |
59 void delegate() dg = &c.m; | |
60 assert(c.i != 42); | |
61 dg(); | |
62 assert(c.i == 42); | |
63 } | |
64 | |
65 void main() | |
66 { | |
67 printf("Delegate test\n"); | |
68 S s = S(4); | |
69 | |
70 auto dg = &s.square; | |
71 //assert(dg() == 16); | |
72 //dg(); | |
73 | |
74 /*auto dg1 = &s.plus; | |
75 assert(dg1(6) == 10); | |
76 | |
77 auto dg2 = &s.minus; | |
78 assert(calldg1(dg2,30) == -26); | |
79 | |
80 auto dg3 = s.get('+'); | |
81 assert(dg3(16) == 20); | |
82 | |
83 getretdg(); | |
84 getclassdg();*/ | |
85 | |
86 printf(" SUCCESS\n"); | |
87 } |