OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // All things regarding compile time constant expressions. | 4 // All things regarding compile time constant expressions. |
5 | 5 |
6 interface Roman { | 6 interface Roman { |
7 static final I = 1; | 7 static const I = 1; |
8 static final II = 2; | 8 static const II = 2; |
9 static final III = 3; | 9 static const III = 3; |
10 static final IV = 4; | 10 static const IV = 4; |
11 static final V = 5; | 11 static const V = 5; |
12 | 12 |
13 static final VivaItalia = const {"green": 1, "red": 3, "white": 2}; | 13 static const VivaItalia = const {"green": 1, "red": 3, "white": 2}; |
14 } | 14 } |
15 | 15 |
16 | 16 |
17 class Point { | 17 class Point { |
18 static final int zero = 0; | 18 static const int zero = 0; |
19 | 19 |
20 static final origin = const Point(0, 0); | 20 static const origin = const Point(0, 0); |
21 static final origin2 = const Point(zero, Roman.IV - 4); | 21 static const origin2 = const Point(zero, Roman.IV - 4); |
22 | 22 |
23 const Point(x, y) : x_= x, y_ = y; | 23 const Point(x, y) : x_= x, y_ = y; |
24 const Point.X(x) : x_ = x, y_ = Roman.V - Roman.II - 3; | 24 const Point.X(x) : x_ = x, y_ = Roman.V - Roman.II - 3; |
25 | 25 |
26 bool operator ==(final Point other) { | 26 bool operator ==(final Point other) { |
27 return (this.x_ == other.x_) && (this.y_ == other.y_); | 27 return (this.x_ == other.x_) && (this.y_ == other.y_); |
28 } | 28 } |
29 | 29 |
30 final int x_, y_; | 30 final int x_, y_; |
31 } | 31 } |
32 | 32 |
33 | 33 |
34 class Line { | 34 class Line { |
35 const Line(Point begin, Point end) : beg_ = begin, end_ = end; | 35 const Line(Point begin, Point end) : beg_ = begin, end_ = end; |
36 final Point beg_; | 36 final Point beg_; |
37 final Point end_; | 37 final Point end_; |
38 } | 38 } |
39 | 39 |
40 | 40 |
41 class CTConstTest { | 41 class CTConstTest { |
42 static int getZero() { return 0; } | 42 static int getZero() { return 0; } |
43 static final naught = null; | 43 static const naught = null; |
44 | 44 |
45 static testMain() { | 45 static testMain() { |
46 Expect.equals(0, Point.zero); | 46 Expect.equals(0, Point.zero); |
47 Expect.equals(0, Point.origin.x_); | 47 Expect.equals(0, Point.origin.x_); |
48 Expect.equals(true, Point.origin === Point.origin2); | 48 Expect.equals(true, Point.origin === Point.origin2); |
49 var p1 = const Point(0, 0); | 49 var p1 = const Point(0, 0); |
50 Expect.equals(true, Point.origin === p1); | 50 Expect.equals(true, Point.origin === p1); |
51 | 51 |
52 Expect.equals(false, Point.origin == const Point(1, 1)); | 52 Expect.equals(false, Point.origin == const Point(1, 1)); |
53 Expect.equals(false, Point.origin === const Point(1, 1)); | 53 Expect.equals(false, Point.origin === const Point(1, 1)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 Expect.equals(true, caughtException); | 114 Expect.equals(true, caughtException); |
115 Expect.equals(1, c11dItaly["green"]); | 115 Expect.equals(1, c11dItaly["green"]); |
116 | 116 |
117 Expect.equals(true, null === naught); | 117 Expect.equals(true, null === naught); |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 main() { | 121 main() { |
122 CTConstTest.testMain(); | 122 CTConstTest.testMain(); |
123 } | 123 } |
OLD | NEW |