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

Unified Diff: tests/corelib/null_test.dart

Issue 10979050: Ensure that hashCode and runtimeType work on null. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: And Nicolas' comments too. Created 8 years, 3 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
« tests/corelib/corelib.status ('K') | « tests/corelib/corelib.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/null_test.dart
diff --git a/tests/corelib/null_test.dart b/tests/corelib/null_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5815638445670609ddfaaf69221dd89bda1fb5ff
--- /dev/null
+++ b/tests/corelib/null_test.dart
@@ -0,0 +1,38 @@
+// 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.
+
+// Test that Null inherits properties from Object.
+
+main() {
+ var x;
+
+ Expect.isTrue(x is Object);
+ Expect.isTrue(x is Dynamic);
+ Expect.isTrue(x is! String);
+ Expect.isTrue(x is! int);
+
+ // These shouldn't throw.
+ x.runtimeType;
+ x.toString();
+ x.hashCode();
+
+ // operator== is inherited from Object. It's the same as identical.
+ // It's not really testable.
+ Expect.isTrue(identical(x, null));
+ Expect.isTrue(x == null);
+
+ // noSuchMethod must throw a NullPointerException.
+ Expect.throws(() => x.noSuchMethod(null, null),
+ (e) => e is NullPointerException);
+ Expect.throws(() => x.notThere(),
+ (e) => e is NullPointerException);
+
+ // Methods can be closurized and yields the same result.
+ var hc = x.hashCode;
+ Expect.equals(null.hashCode(), hc());
+ var ts = x.toString;
+ Expect.equals(null.toString(), ts());
+ var nsm = null.noSuchMethod;
ngeoffray 2012/09/27 11:00:29 Maybe you can remove these two lines, so that dart
Lasse Reichstein Nielsen 2012/09/27 11:25:13 Done.
+ Expect.throws(() => nsm(null, null), (e) => e is NullPointerException);
+}
« tests/corelib/corelib.status ('K') | « tests/corelib/corelib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698