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

Unified Diff: tests/language/null_test.dart

Issue 23012003: Add Null class to dart:core. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« sdk/lib/core/null.dart ('K') | « tests/language/language.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/null_test.dart
diff --git a/tests/language/null_test.dart b/tests/language/null_test.dart
index 6ce22eec85a3a2733469f9880f508e414f27fcee..615a5648f025a98734a3d0e8387cecb8a8c5e066 100644
--- a/tests/language/null_test.dart
+++ b/tests/language/null_test.dart
@@ -1,54 +1,112 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2013, 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.
// Second dart test program.
import "package:expect/expect.dart";
-class NullTest {
- static int foo(var obj) {
+class BadInherit
+ extends Null /// 01: compile-time error
+ implements Null /// 02: compile-time error
+ {}
+
+class BadEquals {
+ int get hashCode => null.hashCode;
+ bool operator==(Object other) => other == null;
+}
+
+class NotCalled {
+ bool operator==(Object other) {
+ throw "SHOULD NOT GET HERE";
+ }
+}
+
+confuse(x) {
+ try { throw [x]; } catch (e) { return e[0]; }
+ return 42;
+}
+
+main() {
+ new BadInherit(); // Make sure class is referenced.
+
+ int foo(var obj) {
Expect.equals(null, obj);
}
- static bool compareToNull(var value) {
+ bool compareToNull(var value) {
return null == value;
}
- static bool compareWithNull(var value) {
+ bool compareWithNull(var value) {
return value == null;
}
- static int testMain() {
- var val = 1;
- var obj = null;
+ var val = 1;
+ var obj = confuse(null);
+ var bad = new BadEquals();
- Expect.equals(null, obj);
- Expect.equals(null, null);
+ Expect.isTrue(identical(obj, null));
- foo(obj);
- foo(null);
+ Expect.isTrue(null == null);
+ Expect.isTrue(null == obj);
+ Expect.isTrue(obj == null);
+ Expect.isTrue(obj == obj);
+
+ // Using == null or null == will not call any equality method.
+ Expect.isFalse(new NotCalled() == null);
+ Expect.isFalse(null == new NotCalled());
+ Expect.isFalse(new NotCalled() == obj);
+ Expect.isFalse(obj == new NotCalled());
+
+ Expect.isFalse(null == false);
+ Expect.isFalse(null == 0);
+ Expect.isFalse(null == "");
+ Expect.isFalse(null == []);
+ Expect.isFalse(null == 0.0);
+ Expect.isFalse(null == -0.0);
+ Expect.isFalse(null == double.NAN);
+
+ const t1 = null == null;
+ const t2 = null == 0;
+ const t3 = false == null;
+ Expect.isTrue(t1);
+ Expect.isFalse(t2);
+ Expect.isFalse(t3);
+
+ Expect.isFalse(bad == null);
+ Expect.isFalse(null == bad);
+
+ foo(obj);
+ foo(null);
- if (obj != null) {
- foo(null);
- } else {
- foo(obj);
- }
-
- Expect.isFalse(compareToNull(val));
- Expect.isTrue(compareToNull(obj));
- Expect.isFalse(compareWithNull(val));
- Expect.isTrue(compareWithNull(obj));
- Expect.isTrue(obj is Object);
- Expect.isFalse(obj is String);
- Expect.isTrue(obj is !String);
- Expect.isFalse(obj is !Object);
- Expect.isFalse(val is !Object);
-
- return 0;
+ if (obj != null) {
+ foo(null);
+ } else {
+ foo(obj);
}
-}
+ Expect.isTrue(null is Null);
+ Expect.isTrue(obj is Null);
+ Expect.isTrue(null is Object);
+ Expect.isTrue(obj is Object);
+ Expect.isTrue(null is dynamic);
+ Expect.isTrue(obj is dynamic);
+ Expect.isFalse(obj is String);
+ Expect.isFalse(null is! Null);
+ Expect.isFalse(obj is! Null);
+ Expect.isFalse(null is! Object);
+ Expect.isFalse(obj is! Object);
+ Expect.isFalse(null is! dynamic);
+ Expect.isFalse(obj is! dynamic);
+ Expect.isTrue(obj is !String);
+ Expect.isFalse(0 is Null); // It's just assignable.
-main() {
- NullTest.testMain();
+ Expect.equals("null", null.toString());
+ Expect.equals("null", "${null}");
+ Expect.equals(Null, null.runtimeType);
+
+ Expect.isFalse(compareToNull(val));
+ Expect.isTrue(compareToNull(obj));
+ Expect.isFalse(compareWithNull(val));
+ Expect.isTrue(compareWithNull(obj));
}
« sdk/lib/core/null.dart ('K') | « tests/language/language.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698