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

Side by Side Diff: tests/corelib/map_test.dart

Issue 1319783003: Add static ensure() methods to unmodifiable views. Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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 unified diff | Download patch
« sdk/lib/collection/maps.dart ('K') | « sdk/lib/collection/maps.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library map_test; 5 library map_test;
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert' show JSON; 8 import 'dart:convert' show JSON;
9 9
10 Map newJsonMap() 10 Map newJsonMap()
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 hashCode: (int v) => v.hashCode, 116 hashCode: (int v) => v.hashCode,
117 isValidKey: (v) => v is int)); 117 isValidKey: (v) => v is int));
118 testOtherKeys(new MapBaseMap<int, int>()); 118 testOtherKeys(new MapBaseMap<int, int>());
119 testOtherKeys(new MapMixinMap<int, int>()); 119 testOtherKeys(new MapMixinMap<int, int>());
120 testOtherKeys(newJsonMap()); 120 testOtherKeys(newJsonMap());
121 testOtherKeys(newJsonMapCustomReviver()); 121 testOtherKeys(newJsonMapCustomReviver());
122 122
123 testUnmodifiableMap(const {1 : 37}); 123 testUnmodifiableMap(const {1 : 37});
124 testUnmodifiableMap(new UnmodifiableMapView({1 : 37})); 124 testUnmodifiableMap(new UnmodifiableMapView({1 : 37}));
125 testUnmodifiableMap(new UnmodifiableMapBaseMap([1, 37])); 125 testUnmodifiableMap(new UnmodifiableMapBaseMap([1, 37]));
126 testUnmodifiableMap(UnmodifiableMapView.ensure({1 : 37}));
Lasse Reichstein Nielsen 2015/08/27 07:59:04 Also test that UnmodifiableMapView.ensure called w
nweiz 2015/08/27 19:25:38 It does that in the body of [testUnmodifiableMap]
126 127
127 testFrom(); 128 testFrom();
128 } 129 }
129 130
130 131
131 void test(Map map) { 132 void test(Map map) {
132 testDeletedElement(map); 133 testDeletedElement(map);
133 testMap(map, 1, 2, 3, 4, 5, 6, 7, 8); 134 testMap(map, 1, 2, 3, 4, 5, 6, 7, 8);
134 map.clear(); 135 map.clear();
135 testMap(map, "value1", "value2", "value3", "value4", "value5", 136 testMap(map, "value1", "value2", "value3", "value4", "value5",
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 void testUnmodifiableMap(Map map) { 744 void testUnmodifiableMap(Map map) {
744 Expect.isTrue(map.containsKey(1)); 745 Expect.isTrue(map.containsKey(1));
745 testLength(1, map); 746 testLength(1, map);
746 Expect.equals(1, map.keys.first); 747 Expect.equals(1, map.keys.first);
747 Expect.equals(37, map.values.first); 748 Expect.equals(37, map.values.first);
748 749
749 Expect.throws(map.clear); 750 Expect.throws(map.clear);
750 Expect.throws(() { map.remove(1); }); 751 Expect.throws(() { map.remove(1); });
751 Expect.throws(() { map[2] = 42; }); 752 Expect.throws(() { map[2] = 42; });
752 Expect.throws(() { map.addAll({2 : 42}); }); 753 Expect.throws(() { map.addAll({2 : 42}); });
754
755 Expect.isTrue(identical(map, UnmodifiableMapView.ensure(map)));
753 } 756 }
754 757
755 class Customer { 758 class Customer {
756 final int id; 759 final int id;
757 final int secondId; 760 final int secondId;
758 const Customer(this.id, this.secondId); 761 const Customer(this.id, this.secondId);
759 int get hashCode => id; 762 int get hashCode => id;
760 bool operator==(Object other) { 763 bool operator==(Object other) {
761 if (other is! Customer) return false; 764 if (other is! Customer) return false;
762 Customer otherCustomer = other; 765 Customer otherCustomer = other;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 Map<Interface, Interface> interfaceMap = <Interface, Interface>{sub: sub}; 945 Map<Interface, Interface> interfaceMap = <Interface, Interface>{sub: sub};
943 expectMap(superMap, new Map<Super, Super>.from(interfaceMap)); 946 expectMap(superMap, new Map<Super, Super>.from(interfaceMap));
944 expectMap(superMap, new Map<Interface, Interface>.from(superMap)); 947 expectMap(superMap, new Map<Interface, Interface>.from(superMap));
945 expectMap(superMap, new HashMap<Super, Super>.from(interfaceMap)); 948 expectMap(superMap, new HashMap<Super, Super>.from(interfaceMap));
946 expectMap(superMap, new HashMap<Interface, Interface>.from(superMap)); 949 expectMap(superMap, new HashMap<Interface, Interface>.from(superMap));
947 expectMap(superMap, new LinkedHashMap<Super, Super>.from(interfaceMap)); 950 expectMap(superMap, new LinkedHashMap<Super, Super>.from(interfaceMap));
948 expectMap(superMap, new LinkedHashMap<Interface, Interface>.from(superMap)); 951 expectMap(superMap, new LinkedHashMap<Interface, Interface>.from(superMap));
949 expectMap(superMap, new SplayTreeMap<Super, Super>.from(interfaceMap)); 952 expectMap(superMap, new SplayTreeMap<Super, Super>.from(interfaceMap));
950 expectMap(superMap, new SplayTreeMap<Interface, Interface>.from(superMap)); 953 expectMap(superMap, new SplayTreeMap<Interface, Interface>.from(superMap));
951 } 954 }
OLDNEW
« sdk/lib/collection/maps.dart ('K') | « sdk/lib/collection/maps.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698