comparison test/typeinfo10.d @ 72:d7e764e62462 trunk

[svn r76] Fixed: TypeInfo for structs. Fixed: PostExp was unable to allocate storage for parameters. Fixed: Many types of functions and delegates were broken. Misc cleanups.
author lindquist
date Mon, 29 Oct 2007 03:28:12 +0100
parents
children
comparison
equal deleted inserted replaced
71:53d3086b5ad3 72:d7e764e62462
1 module typeinfo10;
2
3 struct S
4 {
5 long l;
6 float f;
7 void* vp;
8
9 hash_t toHash()
10 {
11 return l + cast(size_t)f;
12 }
13
14 int opEquals(S s)
15 {
16 return (s.l == l) && (s.f == f);
17 }
18
19 int opCmp(S a)
20 {
21 if (l == a.l) {
22 return (f < a.f) ? -1 : (f > a.f) ? 1 : 0;
23 }
24 return (l < a.l) ? -1 : 1;
25 }
26
27 char[] toString()
28 {
29 return "S instance";
30 }
31 }
32
33 void main()
34 {
35 S s=S(-1, 0);
36 S t=S(-1, 1);
37 S u=S(11,-1);
38 S v=S(12,13);
39
40 {
41 assert(s == s);
42 assert(s != t);
43 assert(s != v);
44 assert(s < t);
45 assert(u > s);
46 assert(v > u);
47 }
48
49 {
50 auto ti = typeid(S);
51 assert(ti.getHash(&s) == s.toHash());
52 assert(ti.equals(&s,&s));
53 assert(!ti.equals(&s,&t));
54 assert(!ti.equals(&s,&v));
55 assert(ti.compare(&s,&s) == 0);
56 assert(ti.compare(&s,&t) < 0);
57 assert(ti.compare(&u,&s) > 0);
58 assert(ti.compare(&v,&u) > 0);
59 {
60 auto tis = cast(TypeInfo_Struct)ti;
61 assert(tis.xtoString(&s) == s.toString());
62 }
63 }
64 }