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

Side by Side Diff: pkg/collection/test/wrapper_test.dart

Issue 141703009: Add toString to delegating collections in package:collection. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « pkg/collection/lib/wrappers.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 /// Tests wrapper utilities. 5 /// Tests wrapper utilities.
6 6
7 import "dart:collection"; 7 import "dart:collection";
8 import "package:collection/collection.dart"; 8 import "package:collection/collection.dart";
9 import "package:unittest/unittest.dart"; 9 import "package:unittest/unittest.dart";
10 10
(...skipping 19 matching lines...) Expand all
30 abstract class Expector { 30 abstract class Expector {
31 getWrappedObject(action(Invocation i)); 31 getWrappedObject(action(Invocation i));
32 // Hack to test assignment ([]=) because it doesn't return the result 32 // Hack to test assignment ([]=) because it doesn't return the result
33 // of the member call. Instead use (expect..[4]=5).equal[4]=5 where 33 // of the member call. Instead use (expect..[4]=5).equal[4]=5 where
34 // you would normally use expect[4].equals[4] for non-assignments. 34 // you would normally use expect[4].equals[4] for non-assignments.
35 var equals; 35 var equals;
36 36
37 noSuchMethod(Invocation m) => new _Equals(equals = getWrappedObject((m2) { 37 noSuchMethod(Invocation m) => new _Equals(equals = getWrappedObject((m2) {
38 testInvocations(m, m2); 38 testInvocations(m, m2);
39 })); 39 }));
40
41 toString() => new _Equals(equals = getWrappedObject((m2) {
42 testInvocations(TO_STRING_INVOCATION, m2);
43 }));
40 } 44 }
41 45
42 // An object with a field called "equals", only introduced into the 46 // An object with a field called "equals", only introduced into the
43 // flow to allow writing expect.xxx.equals.xxx. 47 // flow to allow writing expect.xxx.equals.xxx.
44 class _Equals { 48 class _Equals {
45 final equals; 49 final equals;
46 _Equals(this.equals); 50 _Equals(this.equals);
47 } 51 }
48 52
53 class SyntheticInvocation implements Invocation {
54 static const int METHOD = 0x00;
55 static const int GETTER = 0x01;
56 static const int SETTER = 0x02;
57 final Symbol memberName;
58 final List positionalArguments;
59 final Map namedArguments;
60 final int _type;
61 const SyntheticInvocation(this.memberName,
62 this.positionalArguments,
63 this.namedArguments,
64 this._type);
65 bool get isMethod => _type == METHOD;
66
67 bool get isGetter => _type == GETTER;
68
69 bool get isSetter => _type == SETTER;
70
71 bool get isAccessor => isGetter || isSetter;
72 }
73
49 // Parameterization of noSuchMethod. 74 // Parameterization of noSuchMethod.
50 class NSM { 75 class NSM {
51 Function _action; 76 Function _action;
52 NSM(this._action); 77 NSM(this._action);
53 noSuchMethod(Invocation i) => _action(i); 78 noSuchMethod(Invocation i) => _action(i);
54 } 79 }
55 80
81 const TO_STRING_INVOCATION = const SyntheticInvocation(
82 #toString, const[], const{}, SyntheticInvocation.METHOD);
83
56 // LikeNSM, but has types Iterable, Set and List to allow it as 84 // LikeNSM, but has types Iterable, Set and List to allow it as
57 // argument to DelegatingIterable/Set/List. 85 // argument to DelegatingIterable/Set/List.
58 class IterableNSM extends NSM implements Iterable, Set, List, Queue { 86 class IterableNSM extends NSM implements Iterable, Set, List, Queue {
59 IterableNSM(action(Invocation i)) : super(action); 87 IterableNSM(action(Invocation i)) : super(action);
60 noSuchMethod(Invocation i) => super.noSuchMethod(i); // Silence warnings 88 noSuchMethod(Invocation i) => super.noSuchMethod(i); // Silence warnings
89 toString() => super.noSuchMethod(TO_STRING_INVOCATION);
61 } 90 }
62 91
63 // Expector that wraps in DelegatingIterable. 92 // Expector that wraps in DelegatingIterable.
64 class IterableExpector extends Expector { 93 class IterableExpector extends Expector {
65 getWrappedObject(void action(Invocation i)) { 94 getWrappedObject(void action(Invocation i)) {
66 return new DelegatingIterable(new IterableNSM(action)); 95 return new DelegatingIterable(new IterableNSM(action));
67 } 96 }
68 } 97 }
69 98
70 // Expector that wraps in DelegatingList. 99 // Expector that wraps in DelegatingList.
(...skipping 14 matching lines...) Expand all
85 class QueueExpector extends Expector { 114 class QueueExpector extends Expector {
86 getWrappedObject(void action(Invocation i)) { 115 getWrappedObject(void action(Invocation i)) {
87 return new DelegatingQueue(new IterableNSM(action)); 116 return new DelegatingQueue(new IterableNSM(action));
88 } 117 }
89 } 118 }
90 119
91 // Like NSM but implements Map to allow as argument for DelegatingMap. 120 // Like NSM but implements Map to allow as argument for DelegatingMap.
92 class MapNSM extends NSM implements Map { 121 class MapNSM extends NSM implements Map {
93 MapNSM(action(Invocation i)) : super(action); 122 MapNSM(action(Invocation i)) : super(action);
94 noSuchMethod(Invocation i) => super.noSuchMethod(i); 123 noSuchMethod(Invocation i) => super.noSuchMethod(i);
124 toString() => super.noSuchMethod(TO_STRING_INVOCATION);
95 } 125 }
96 126
97 // Expector that wraps in DelegatingMap. 127 // Expector that wraps in DelegatingMap.
98 class MapExpector extends Expector { 128 class MapExpector extends Expector {
99 getWrappedObject(void action(Invocation i)) { 129 getWrappedObject(void action(Invocation i)) {
100 return new DelegatingMap(new MapNSM(action)); 130 return new DelegatingMap(new MapNSM(action));
101 } 131 }
102 } 132 }
103 133
104 // Utility values to use as arguments in calls. 134 // Utility values to use as arguments in calls.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 expect.single.equals.single; 169 expect.single.equals.single;
140 expect.singleWhere(func1).equals.singleWhere(func1); 170 expect.singleWhere(func1).equals.singleWhere(func1);
141 expect.skip(5).equals.skip(5); 171 expect.skip(5).equals.skip(5);
142 expect.skipWhile(func1).equals.skipWhile(func1); 172 expect.skipWhile(func1).equals.skipWhile(func1);
143 expect.take(5).equals.take(5); 173 expect.take(5).equals.take(5);
144 expect.takeWhile(func1).equals.takeWhile(func1); 174 expect.takeWhile(func1).equals.takeWhile(func1);
145 expect.toList(growable: true).equals.toList(); 175 expect.toList(growable: true).equals.toList();
146 expect.toList(growable: true).equals.toList(growable: true); 176 expect.toList(growable: true).equals.toList(growable: true);
147 expect.toList(growable: false).equals.toList(growable: false); 177 expect.toList(growable: false).equals.toList(growable: false);
148 expect.toSet().equals.toSet(); 178 expect.toSet().equals.toSet();
179 expect.toString().equals.toString();
149 expect.where(func1).equals.where(func1); 180 expect.where(func1).equals.where(func1);
150 } 181 }
151 182
152 void testList(var expect) { 183 void testList(var expect) {
153 testIterable(expect); 184 testIterable(expect);
154 185
155 expect[4].equals[4]; 186 expect[4].equals[4];
156 (expect..[4] = 5).equals[4] = 5; 187 (expect..[4] = 5).equals[4] = 5;
157 188
158 expect.add(val).equals.add(val); 189 expect.add(val).equals.add(val);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 expect.containsKey(val).equals.containsKey(val); 255 expect.containsKey(val).equals.containsKey(val);
225 expect.containsValue(val).equals.containsValue(val); 256 expect.containsValue(val).equals.containsValue(val);
226 expect.forEach(func2).equals.forEach(func2); 257 expect.forEach(func2).equals.forEach(func2);
227 expect.isEmpty.equals.isEmpty; 258 expect.isEmpty.equals.isEmpty;
228 expect.isNotEmpty.equals.isNotEmpty; 259 expect.isNotEmpty.equals.isNotEmpty;
229 expect.keys.equals.keys; 260 expect.keys.equals.keys;
230 expect.length.equals.length; 261 expect.length.equals.length;
231 expect.putIfAbsent(val, func0).equals.putIfAbsent(val, func0); 262 expect.putIfAbsent(val, func0).equals.putIfAbsent(val, func0);
232 expect.remove(val).equals.remove(val); 263 expect.remove(val).equals.remove(val);
233 expect.values.equals.values; 264 expect.values.equals.values;
265 expect.toString().equals.toString();
234 } 266 }
235 267
236 test("Iterable", () { 268 test("Iterable", () {
237 testIterable(new IterableExpector()); 269 testIterable(new IterableExpector());
238 }); 270 });
239 271
240 test("List", () { 272 test("List", () {
241 testList(new ListExpector()); 273 testList(new ListExpector());
242 }); 274 });
243 275
244 test("Set", () { 276 test("Set", () {
245 testSet(new SetExpector()); 277 testSet(new SetExpector());
246 }); 278 });
247 279
248 test("Queue", () { 280 test("Queue", () {
249 testQueue(new QueueExpector()); 281 testQueue(new QueueExpector());
250 }); 282 });
251 283
252 test("Map", () { 284 test("Map", () {
253 testMap(new MapExpector()); 285 testMap(new MapExpector());
254 }); 286 });
255 } 287 }
OLDNEW
« no previous file with comments | « pkg/collection/lib/wrappers.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698