2005-04-17 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / tests / test-40.cs
1 using System;
2
3 public class Blah {
4
5         enum Bar {
6                 a = MyEnum.Foo,
7                 b = A.c,
8                 c = MyEnum.Bar,
9                 d = myconstant
10         }
11         
12         public enum MyEnum : byte {
13                 Foo = 254,
14                 Bar = (byte) B.y
15         }
16
17         enum A {
18                 a, b, c
19         }
20         
21         enum B {
22                 x, y, z
23         }
24         
25         enum AA : byte { a, b }
26         enum BB : ulong { x, y }
27
28         const int myconstant = 30;
29
30         enum Compute { two = AA.b + B.y }
31         
32         // The constant assignment follows a different path             
33         const Bar bar_assignment = 0;
34         
35         public static int Main ()
36         {
37                 byte b = (byte) MyEnum.Foo;
38                 
39                 Console.WriteLine ("Foo has a value of " + b);
40
41                 if (b != 254)
42                         return 1;
43                 
44                 int i = (int) A.a;
45                 int j = (int) B.x;
46                 int k = (int) A.c;
47                 int l = (int) AA.b + 1;
48
49                 if ((int) Compute.two != 2)
50                         return 10;
51                 if (i != j)
52                         return 1;
53
54                 if (k != l)
55                         return 1;
56
57                 A var = A.b;
58
59                 i = (int) Bar.a;
60
61                 if (i != 254)
62                         return 1;
63
64                 i = (int) Bar.b;
65
66                 if (i != 2)
67                         return 1;
68
69                 j = (int) Bar.c;
70
71                 if (j != 1)
72                         return 1;
73
74                 j = (int) Bar.d;
75
76                 if (j != 30)
77                         return 1;
78
79                 Enum e = Bar.d;
80                 if (e.ToString () != "d")
81                         return 15;
82
83                 //
84                 // Test "U operator (E x, E x)"
85                 //
86                 // Notice that the Microsoft C# compiler wont compile the following
87                 // code, that is a bug in their compiler, see section 14.7.5 of the
88                 // spec.
89
90                 if ((A.c - A.a) != 2)
91                         return 16;
92
93                 if ((A.c - 1) != A.b)
94                         return 17;
95                 
96                 Console.WriteLine ("Value: " + e.ToString ());
97                 Console.WriteLine ("Enum emission test okay");
98                 return 0;
99         }
100 }