1 | --
|
---|
2 | -- Copyright (c) 2010 Jiri Svoboda
|
---|
3 | -- All rights reserved.
|
---|
4 | --
|
---|
5 | -- Redistribution and use in source and binary forms, with or without
|
---|
6 | -- modification, are permitted provided that the following conditions
|
---|
7 | -- are met:
|
---|
8 | --
|
---|
9 | -- o Redistributions of source code must retain the above copyright
|
---|
10 | -- notice, this list of conditions and the following disclaimer.
|
---|
11 | -- o Redistributions in binary form must reproduce the above copyright
|
---|
12 | -- notice, this list of conditions and the following disclaimer in the
|
---|
13 | -- documentation and/or other materials provided with the distribution.
|
---|
14 | -- o The name of the author may not be used to endorse or promote products
|
---|
15 | -- derived from this software without specific prior written permission.
|
---|
16 | --
|
---|
17 | -- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | -- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | -- OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | -- IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | -- NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | -- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | --
|
---|
28 |
|
---|
29 | class EnumDemo is
|
---|
30 | fun Main(), static is
|
---|
31 | var color : ChessColor;
|
---|
32 |
|
---|
33 | Console.WriteLine("Set color to ChessColor.Black.");
|
---|
34 | color = ChessColor.Black;
|
---|
35 |
|
---|
36 | Console.Write("Test color == ChessColor.Black.. ");
|
---|
37 | if color == ChessColor.Black then
|
---|
38 | Console.WriteLine("True - OK");
|
---|
39 | else
|
---|
40 | Console.WriteLine("False - Fail!");
|
---|
41 | raise new Error.Base();
|
---|
42 | end
|
---|
43 |
|
---|
44 | Console.Write("Test color != ChessColor.Black.. ");
|
---|
45 | if color != ChessColor.Black then
|
---|
46 | Console.WriteLine("True - Fail!");
|
---|
47 | raise new Error.Base();
|
---|
48 | else
|
---|
49 | Console.WriteLine("False - OK");
|
---|
50 | end
|
---|
51 |
|
---|
52 | Console.Write("Test color == ChessColor.White.. ");
|
---|
53 | if color == ChessColor.White then
|
---|
54 | Console.WriteLine("True - Fail!");
|
---|
55 | raise new Error.Base();
|
---|
56 | else
|
---|
57 | Console.WriteLine("False - OK");
|
---|
58 | end
|
---|
59 |
|
---|
60 | Console.Write("Test color != ChessColor.White.. ");
|
---|
61 | if color != ChessColor.White then
|
---|
62 | Console.WriteLine("True - OK");
|
---|
63 | else
|
---|
64 | Console.WriteLine("False - Fail!");
|
---|
65 | raise new Error.Base();
|
---|
66 | end
|
---|
67 |
|
---|
68 | Console.WriteLine("Success");
|
---|
69 |
|
---|
70 | -- Test enum declared in non-CSI scope
|
---|
71 |
|
---|
72 | var ptype : ChessPiece;
|
---|
73 |
|
---|
74 | ptype = ChessPiece.King;
|
---|
75 | end
|
---|
76 |
|
---|
77 | -- Enumerated type declared inside a class
|
---|
78 | enum ChessColor is
|
---|
79 | White;
|
---|
80 | Black;
|
---|
81 | end
|
---|
82 | end
|
---|
83 |
|
---|
84 | -- Enumerated type declared outside any class
|
---|
85 | enum ChessPiece is
|
---|
86 | King;
|
---|
87 | Queen;
|
---|
88 | Bishop;
|
---|
89 | Knight;
|
---|
90 | Rook;
|
---|
91 | Pawn;
|
---|
92 | end
|
---|