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

Unified Diff: test/map_mixin_test.dart

Issue 1852983002: Fix issues with protobuf equality comparisons (Closed) Base URL: git@github.com:dart-lang/dart-protobuf.git@master
Patch Set: tweak _deepEquals, improve tests Created 4 years, 8 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
« no previous file with comments | « test/json_test.dart ('k') | test/message_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/map_mixin_test.dart
diff --git a/test/map_mixin_test.dart b/test/map_mixin_test.dart
index 0fd974c5d919cc5a87ac24b7b2158c17dded307c..c7e6166e116c54fa6e78d0ae96dde6c8a56f4933 100644
--- a/test/map_mixin_test.dart
+++ b/test/map_mixin_test.dart
@@ -12,12 +12,12 @@ import 'dart:collection' show MapMixin;
import 'package:protobuf/src/protobuf/mixins/map_mixin.dart';
import 'package:test/test.dart' show test, expect, predicate, same, throws;
-import 'mock_util.dart' show MockMessage;
+import 'mock_util.dart' show MockMessage, mockInfo;
// A minimal protobuf implementation compatible with PbMapMixin.
class Rec extends MockMessage with MapMixin, PbMapMixin {
- get className => "Rec";
- Rec create() => new Rec();
+ get info_ => _info;
+ static final _info = mockInfo("Rec", () => new Rec());
@override
String toString() => "Rec(${val}, \"${str}\")";
@@ -65,4 +65,42 @@ main() {
expect(r["int32s"], [123]);
expect(r["int32s"], same(r["int32s"]));
});
+
+ test('operator== and hashCode work for Map mixin', () {
+ var a = new Rec();
+ expect(a == a, true);
+ expect(a == {}, false);
+ expect({} == a, false);
+
+ var b = new Rec();
+ expect(a.info_ == b.info_, true, reason: "BuilderInfo should be the same");
+ expect(a == b, true);
+ expect(a.hashCode, b.hashCode);
+
+ a.val = 123;
+ expect(a == b, false);
+ b.val = 123;
+ expect(a == b, true);
+ expect(a.hashCode, b.hashCode);
+
+ a.child = new Rec();
+ expect(a == b, false);
+ b.child = new Rec();
+ expect(a == b, true);
+ expect(a.hashCode, b.hashCode);
+ });
+
+ test("protobuf doesn't compare equal to a map with the same values", () {
+ var a = new Rec();
+ expect(a == new Map.from(a), false);
+ expect(new Map.from(a) == a, false);
+ });
+
+ test("reading protobuf values shouldn't change equality", () {
+ var a = new Rec();
+ var b = new Rec();
+ expect(a == b, true);
+ new Map.from(a);
+ expect(a == b, true);
+ });
}
« no previous file with comments | « test/json_test.dart ('k') | test/message_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698