| 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 const I = 1; | 7 static const I = 1; |
| 8 static const II = 2; | 8 static const II = 2; |
| 9 static const III = 3; | 9 static const III = 3; |
| 10 static const IV = 4; | 10 static const IV = 4; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 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 const 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, identical(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, identical(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, identical(Point.origin, const Point(1, 1))); |
| 54 | 54 |
| 55 var p2 = new Point(0, getZero()); | 55 var p2 = new Point(0, getZero()); |
| 56 Expect.equals(true, Point.origin == p2); // Point.operator== | 56 Expect.equals(true, Point.origin == p2); // Point.operator== |
| 57 | 57 |
| 58 Expect.equals(true, const Point.X(5) === const Point(5, 0)); | 58 Expect.equals(true, identical(const Point.X(5), const Point(5, 0))); |
| 59 | 59 |
| 60 Line l1 = const Line(Point.origin, const Point(1, 1)); | 60 Line l1 = const Line(Point.origin, const Point(1, 1)); |
| 61 Line l2 = const Line(const Point(0, 0), const Point(1, 1)); | 61 Line l2 = const Line(const Point(0, 0), const Point(1, 1)); |
| 62 Line l3 = new Line(const Point(0, 0), const Point(1, 1)); | 62 Line l3 = new Line(const Point(0, 0), const Point(1, 1)); |
| 63 Expect.equals(true, l1 === l2); | 63 Expect.equals(true, identical(l1, l2)); |
| 64 | 64 |
| 65 final evenNumbers = const <int>[2, 2*2, 2*3, 2*4, 2*5]; | 65 final evenNumbers = const <int>[2, 2*2, 2*3, 2*4, 2*5]; |
| 66 Expect.equals(true, evenNumbers !== const [2, 4, 6, 8, 10]); | 66 Expect.equals(true, !identical(evenNumbers, const [2, 4, 6, 8, 10])); |
| 67 | 67 |
| 68 final c11dGermany1 = const {"black": 1, "red": 2, "yellow": 3}; | 68 final c11dGermany1 = const {"black": 1, "red": 2, "yellow": 3}; |
| 69 Expect.equals(true, | 69 Expect.equals(true, |
| 70 c11dGermany1 === const {"black": 1, "red": 2, "yellow": 3}); | 70 identical(c11dGermany1, const {"black": 1, "red": 2, "yellow": 3})); |
| 71 | 71 |
| 72 final c11dGermany2 = const {"black": 1, "red": 2, "yellow": 3}; | 72 final c11dGermany2 = const {"black": 1, "red": 2, "yellow": 3}; |
| 73 Expect.equals(true, c11dGermany1 === c11dGermany2); | 73 Expect.equals(true, identical(c11dGermany1, c11dGermany2)); |
| 74 | 74 |
| 75 final c11dBelgium = const {"black": 1, "yellow": 2, "red": 3}; | 75 final c11dBelgium = const {"black": 1, "yellow": 2, "red": 3}; |
| 76 Expect.equals(false, c11dGermany1 == c11dBelgium); | 76 Expect.equals(false, c11dGermany1 == c11dBelgium); |
| 77 Expect.equals(false, c11dGermany1 === c11dBelgium); | 77 Expect.equals(false, identical(c11dGermany1, c11dBelgium)); |
| 78 | 78 |
| 79 final c11dItaly = const {"green": 1, "red": 3, "white": 2}; | 79 final c11dItaly = const {"green": 1, "red": 3, "white": 2}; |
| 80 Expect.equals(true, | 80 Expect.equals(true, |
| 81 c11dItaly === const {"green": 1, "red": 3, "white": 2}); | 81 identical(c11dItaly, const {"green": 1, "red": 3, "white": 2})); |
| 82 Expect.equals(true, c11dItaly === Roman.VivaItalia); | 82 Expect.equals(true, identical(c11dItaly, Roman.VivaItalia)); |
| 83 | 83 |
| 84 Expect.equals(3, c11dItaly.length); | 84 Expect.equals(3, c11dItaly.length); |
| 85 Expect.equals(3, c11dItaly.keys.length); | 85 Expect.equals(3, c11dItaly.keys.length); |
| 86 Expect.equals(true, c11dItaly.containsKey("white")); | 86 Expect.equals(true, c11dItaly.containsKey("white")); |
| 87 Expect.equals(false, c11dItaly.containsKey("black")); | 87 Expect.equals(false, c11dItaly.containsKey("black")); |
| 88 | 88 |
| 89 // Make sure the map object is immutable. | 89 // Make sure the map object is immutable. |
| 90 bool caughtException = false; | 90 bool caughtException = false; |
| 91 try { | 91 try { |
| 92 c11dItaly["green"] = 0; | 92 c11dItaly["green"] = 0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 107 | 107 |
| 108 caughtException = false; | 108 caughtException = false; |
| 109 try { | 109 try { |
| 110 c11dItaly.remove("orange"); | 110 c11dItaly.remove("orange"); |
| 111 } on UnsupportedError catch (e) { | 111 } on UnsupportedError catch (e) { |
| 112 caughtException = true; | 112 caughtException = true; |
| 113 } | 113 } |
| 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 |