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); |
+ }); |
} |