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

Unified Diff: tests/language/savannah_test.dart

Issue 10956026: - Add definition of "int hashCode()" to Object. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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
Index: tests/language/savannah_test.dart
===================================================================
--- tests/language/savannah_test.dart (revision 12648)
+++ tests/language/savannah_test.dart (working copy)
@@ -3,10 +3,11 @@
// BSD-style license that can be found in the LICENSE file.
// Dart test using an identity hash.
-interface BigGame extends Hashable {
+abstract class BigGame {
final String name;
}
+// Giraffe overrides hashCode and provides its own identity hash.
class Giraffe implements BigGame {
final String name;
final int identityHash_;
@@ -27,6 +28,7 @@
}
}
+// Zebra relies on the system provided identity hash.
class Zebra implements BigGame {
final String name;
Zebra(this.name) {}
@@ -37,44 +39,38 @@
static void testMain() {
Map<BigGame, String> savannah = new Map<BigGame, String>();
+
Giraffe giraffe1 = new Giraffe("Tony");
Giraffe giraffe2 = new Giraffe("Rose");
savannah[giraffe1] = giraffe1.name;
savannah[giraffe2] = giraffe2.name;
+ print("giraffe1 hash: ${giraffe1.hashCode()}");
+ print("giraffe2 hash: ${giraffe2.hashCode()}");
var count = savannah.length;
print("getCount is $count");
Expect.equals(2, count);
+
print("giraffe1: ${savannah[giraffe1]}");
print("giraffe2: ${savannah[giraffe2]}");
Expect.equals("Tony", savannah[giraffe1]);
Expect.equals("Rose", savannah[giraffe2]);
- bool caught = false;
- Zebra zebra1 = new Zebra("Paul");
- Zebra zebra2 = new Zebra("Joe");
- try {
- savannah[zebra1] = zebra1.name;
- savannah[zebra2] = zebra2.name;
- } on NoSuchMethodError catch (e) {
- print("Caught: $e");
- caught = true;
- }
- Expect.equals(true, caught);
+ Zebra zebra1 = new Zebra("Paolo");
+ Zebra zebra2 = new Zebra("Zeeta");
+ savannah[zebra1] = zebra1.name;
+ savannah[zebra2] = zebra2.name;
+ print("zebra1 hash: ${zebra1.hashCode()}");
+ print("zebra2 hash: ${zebra2.hashCode()}");
count = savannah.length;
print("getCount is $count");
- Expect.equals(2, count);
+ Expect.equals(4, count);
- caught = false;
- try {
- print("zebra1: ${savannah[zebra1]}");
- print("zebra2: ${savannah[zebra2]}");
- } on NoSuchMethodError catch (e) {
- print("Caught: $e");
- caught = true;
- }
- Expect.equals(true, caught);
+ print("zebra1: ${savannah[zebra1]}");
+ print("zebra2: ${savannah[zebra2]}");
+ Expect.equals("Paolo", savannah[zebra1]);
+ Expect.equals("Zeeta", savannah[zebra2]);
}
}
« lib/compiler/implementation/lib/core_patch.dart ('K') | « tests/language/language_dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698