mirror of
https://github.com/dart-lang/sdk
synced 2024-10-03 13:22:01 +00:00
2dcd56ef43
There are far too many files here to review everyone carefully. Spot checking most of the diffs look good as test code is generally written with less care than application code so lots of ugly formatting get through. If people notice files where the automated formatting bothers them feel free to comment indicating file names and I'll move spaces within comments to make the formatting cleaner and use comments to force block formatting as I have done for other case where formatting looked bad. BUG= R=efortuna@google.com Review-Url: https://codereview.chromium.org/2771453003 .
132 lines
3.7 KiB
Dart
132 lines
3.7 KiB
Dart
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
// All things regarding compile time constant expressions.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
abstract class Roman {
|
|
static const I = 1;
|
|
static const II = 2;
|
|
static const III = 3;
|
|
static const IV = 4;
|
|
static const V = 5;
|
|
|
|
static const VivaItalia = const {"green": 1, "red": 3, "white": 2};
|
|
}
|
|
|
|
class Point {
|
|
static const int zero = 0;
|
|
|
|
static const origin = const Point(0, 0);
|
|
static const origin2 = const Point(zero, Roman.IV - 4);
|
|
|
|
const Point(x, y)
|
|
: x_ = x,
|
|
y_ = y;
|
|
const Point.X(x)
|
|
: x_ = x,
|
|
y_ = Roman.V - Roman.II - 3;
|
|
|
|
bool operator ==(final Point other) {
|
|
return (this.x_ == other.x_) && (this.y_ == other.y_);
|
|
}
|
|
|
|
final int x_, y_;
|
|
}
|
|
|
|
class Line {
|
|
const Line(Point begin, Point end)
|
|
: beg_ = begin,
|
|
end_ = end;
|
|
final Point beg_;
|
|
final Point end_;
|
|
}
|
|
|
|
class CTConstTest {
|
|
static int getZero() {
|
|
return 0;
|
|
}
|
|
|
|
static const naught = null;
|
|
|
|
static testMain() {
|
|
Expect.equals(0, Point.zero);
|
|
Expect.equals(0, Point.origin.x_);
|
|
Expect.equals(true, identical(Point.origin, Point.origin2));
|
|
var p1 = const Point(0, 0);
|
|
Expect.equals(true, identical(Point.origin, p1));
|
|
|
|
Expect.equals(false, Point.origin == const Point(1, 1));
|
|
Expect.equals(false, identical(Point.origin, const Point(1, 1)));
|
|
|
|
var p2 = new Point(0, getZero());
|
|
Expect.equals(true, Point.origin == p2); // Point.operator==
|
|
|
|
Expect.equals(true, identical(const Point.X(5), const Point(5, 0)));
|
|
|
|
Line l1 = const Line(Point.origin, const Point(1, 1));
|
|
Line l2 = const Line(const Point(0, 0), const Point(1, 1));
|
|
Line l3 = new Line(const Point(0, 0), const Point(1, 1));
|
|
Expect.equals(true, identical(l1, l2));
|
|
|
|
final evenNumbers = const <int>[2, 2 * 2, 2 * 3, 2 * 4, 2 * 5];
|
|
Expect.equals(true, !identical(evenNumbers, const [2, 4, 6, 8, 10]));
|
|
|
|
final c11dGermany1 = const {"black": 1, "red": 2, "yellow": 3};
|
|
Expect.equals(true,
|
|
identical(c11dGermany1, const {"black": 1, "red": 2, "yellow": 3}));
|
|
|
|
final c11dGermany2 = const {"black": 1, "red": 2, "yellow": 3};
|
|
Expect.equals(true, identical(c11dGermany1, c11dGermany2));
|
|
|
|
final c11dBelgium = const {"black": 1, "yellow": 2, "red": 3};
|
|
Expect.equals(false, c11dGermany1 == c11dBelgium);
|
|
Expect.equals(false, identical(c11dGermany1, c11dBelgium));
|
|
|
|
final c11dItaly = const {"green": 1, "red": 3, "white": 2};
|
|
Expect.equals(
|
|
true, identical(c11dItaly, const {"green": 1, "red": 3, "white": 2}));
|
|
Expect.equals(true, identical(c11dItaly, Roman.VivaItalia));
|
|
|
|
Expect.equals(3, c11dItaly.length);
|
|
Expect.equals(3, c11dItaly.keys.length);
|
|
Expect.equals(true, c11dItaly.containsKey("white"));
|
|
Expect.equals(false, c11dItaly.containsKey("black"));
|
|
|
|
// Make sure the map object is immutable.
|
|
bool caughtException = false;
|
|
try {
|
|
c11dItaly["green"] = 0;
|
|
} on UnsupportedError catch (e) {
|
|
caughtException = true;
|
|
}
|
|
Expect.equals(true, caughtException);
|
|
Expect.equals(1, c11dItaly["green"]);
|
|
|
|
caughtException = false;
|
|
try {
|
|
c11dItaly.clear();
|
|
} on UnsupportedError catch (e) {
|
|
caughtException = true;
|
|
}
|
|
Expect.equals(true, caughtException);
|
|
Expect.equals(1, c11dItaly["green"]);
|
|
|
|
caughtException = false;
|
|
try {
|
|
c11dItaly.remove("orange");
|
|
} on UnsupportedError catch (e) {
|
|
caughtException = true;
|
|
}
|
|
Expect.equals(true, caughtException);
|
|
Expect.equals(1, c11dItaly["green"]);
|
|
|
|
Expect.equals(true, null == naught);
|
|
}
|
|
}
|
|
|
|
main() {
|
|
CTConstTest.testMain();
|
|
}
|