Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: tests/language/src/CTConstTest.dart

Issue 10248007: test rename overhaul: step 8 - language tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/language/src/CTConst4Test.dart ('k') | tests/language/src/CallNonMethodFieldTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 // All things regarding compile time constant expressions.
5
6 interface Roman {
7 static final I = 1;
8 static final II = 2;
9 static final III = 3;
10 static final IV = 4;
11 static final V = 5;
12
13 static final VivaItalia = const {"green": 1, "red": 3, "white": 2};
14 }
15
16
17 class Point {
18 static final int zero = 0;
19
20 static final origin = const Point(0, 0);
21 static final origin2 = const Point(zero, Roman.IV - 4);
22
23 const Point(x, y) : x_= x, y_ = y;
24 const Point.X(x) : x_ = x, y_ = Roman.V - Roman.II - 3;
25
26 bool operator ==(final Point other) {
27 return (this.x_ == other.x_) && (this.y_ == other.y_);
28 }
29
30 final int x_, y_;
31 }
32
33
34 class Line {
35 const Line(Point begin, Point end) : beg_ = begin, end_ = end;
36 final Point beg_;
37 final Point end_;
38 }
39
40
41 class CTConstTest {
42 static int getZero() { return 0; }
43 static final naught = null;
44
45 static testMain() {
46 Expect.equals(0, Point.zero);
47 Expect.equals(0, Point.origin.x_);
48 Expect.equals(true, Point.origin === Point.origin2);
49 var p1 = const Point(0, 0);
50 Expect.equals(true, Point.origin === p1);
51
52 Expect.equals(false, Point.origin == const Point(1, 1));
53 Expect.equals(false, Point.origin === const Point(1, 1));
54
55 var p2 = new Point(0, getZero());
56 Expect.equals(true, Point.origin == p2); // Point.operator==
57
58 Expect.equals(true, const Point.X(5) === const Point(5, 0));
59
60 Line l1 = const Line(Point.origin, 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));
63 Expect.equals(true, l1 === l2);
64
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]);
67
68 final c11dGermany1 = const {"black": 1, "red": 2, "yellow": 3};
69 Expect.equals(true,
70 c11dGermany1 === const {"black": 1, "red": 2, "yellow": 3});
71
72 final c11dGermany2 = const {"black": 1, "red": 2, "yellow": 3};
73 Expect.equals(true, c11dGermany1 === c11dGermany2);
74
75 final c11dBelgium = const {"black": 1, "yellow": 2, "red": 3};
76 Expect.equals(false, c11dGermany1 == c11dBelgium);
77 Expect.equals(false, c11dGermany1 === c11dBelgium);
78
79 final c11dItaly = const {"green": 1, "red": 3, "white": 2};
80 Expect.equals(true,
81 c11dItaly === const {"green": 1, "red": 3, "white": 2});
82 Expect.equals(true, c11dItaly === Roman.VivaItalia);
83
84 Expect.equals(3, c11dItaly.length);
85 Expect.equals(3, c11dItaly.getKeys().length);
86 Expect.equals(true, c11dItaly.containsKey("white"));
87 Expect.equals(false, c11dItaly.containsKey("black"));
88
89 // Make sure the map object is immutable.
90 bool caughtException = false;
91 try {
92 c11dItaly["green"] = 0;
93 } catch (IllegalAccessException e) {
94 caughtException = true;
95 }
96 Expect.equals(true, caughtException);
97 Expect.equals(1, c11dItaly["green"]);
98
99 caughtException = false;
100 try {
101 c11dItaly.clear();
102 } catch (IllegalAccessException e) {
103 caughtException = true;
104 }
105 Expect.equals(true, caughtException);
106 Expect.equals(1, c11dItaly["green"]);
107
108 caughtException = false;
109 try {
110 c11dItaly.remove("orange");
111 } catch (IllegalAccessException e) {
112 caughtException = true;
113 }
114 Expect.equals(true, caughtException);
115 Expect.equals(1, c11dItaly["green"]);
116
117 Expect.equals(true, null === naught);
118 }
119 }
120
121 main() {
122 CTConstTest.testMain();
123 }
OLDNEW
« no previous file with comments | « tests/language/src/CTConst4Test.dart ('k') | tests/language/src/CallNonMethodFieldTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698