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

Side by Side Diff: pkg/analyzer/test/utils.dart

Issue 2623283002: Replace same() with equals() in TypeAssertions. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « pkg/analyzer/test/generated/strong_mode_test.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 library analyzer.test.utils; 5 library analyzer.test.utils;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 Asserter<DartType> get isDynamic => isType(_typeProvider.dynamicType); 214 Asserter<DartType> get isDynamic => isType(_typeProvider.dynamicType);
215 215
216 /** 216 /**
217 * Primitive assertion for the int type 217 * Primitive assertion for the int type
218 */ 218 */
219 Asserter<DartType> get isInt => isType(_typeProvider.intType); 219 Asserter<DartType> get isInt => isType(_typeProvider.intType);
220 220
221 /** 221 /**
222 * Primitive assertion for the list type 222 * Primitive assertion for the list type
223 */ 223 */
224 Asserter<DartType> get isList => sameElement(_typeProvider.listType); 224 Asserter<DartType> get isList => hasElementOf(_typeProvider.listType);
225 225
226 /** 226 /**
227 * Primitive assertion for the map type 227 * Primitive assertion for the map type
228 */ 228 */
229 Asserter<DartType> get isMap => sameElement(_typeProvider.mapType); 229 Asserter<DartType> get isMap => hasElementOf(_typeProvider.mapType);
230 230
231 /** 231 /**
232 * Primitive assertion for the num type 232 * Primitive assertion for the num type
233 */ 233 */
234 Asserter<DartType> get isNum => isType(_typeProvider.numType); 234 Asserter<DartType> get isNum => isType(_typeProvider.numType);
235 235
236 /** 236 /**
237 * Primitive assertion for the string type 237 * Primitive assertion for the string type
238 */ 238 */
239 Asserter<DartType> get isString => isType(_typeProvider.stringType); 239 Asserter<DartType> get isString => isType(_typeProvider.stringType);
240 240
241 /** 241 /**
242 * Given a type, produce an assertion that a type has the same element. 242 * Assert that a type has the element that is equal to the [expected].
243 */ 243 */
244 Asserter<DartType> hasElement(Element element) => 244 Asserter<DartType> hasElement(Element expected) =>
245 (DartType type) => expect(element, same(type.element)); 245 (DartType type) => expect(expected, type.element);
246
247 /**
248 * Assert that a type has the element that is equal to the element of the
249 * given [type].
250 */
251 Asserter<DartType> hasElementOf(DartType type) => hasElement(type.element);
246 252
247 /** 253 /**
248 * Given assertions for the argument and return types, produce an 254 * Given assertions for the argument and return types, produce an
249 * assertion over unary function types. 255 * assertion over unary function types.
250 */ 256 */
251 Asserter<DartType> isFunction2Of( 257 Asserter<DartType> isFunction2Of(
252 Asserter<DartType> argType, Asserter<DartType> returnType) => 258 Asserter<DartType> argType, Asserter<DartType> returnType) =>
253 (DartType type) { 259 (DartType type) {
254 FunctionType fType = (type as FunctionType); 260 FunctionType fType = (type as FunctionType);
255 argType(fType.normalParameterTypes[0]); 261 argType(fType.normalParameterTypes[0]);
256 returnType(fType.returnType); 262 returnType(fType.returnType);
257 }; 263 };
258 264
259 /** 265 /**
260 * Given an assertion for the base type and assertions over the type 266 * Given an assertion for the base type and assertions over the type
261 * parameters, produce an assertion over instantations. 267 * parameters, produce an assertion over instantiations.
262 */ 268 */
263 AsserterBuilder<List<Asserter<DartType>>, DartType> isInstantiationOf( 269 AsserterBuilder<List<Asserter<DartType>>, DartType> isInstantiationOf(
264 Asserter<DartType> baseAssert) => 270 Asserter<DartType> baseAssert) =>
265 (List<Asserter<DartType>> argAsserts) => (DartType type) { 271 (List<Asserter<DartType>> argAsserts) => (DartType type) {
266 InterfaceType t = (type as InterfaceType); 272 InterfaceType t = (type as InterfaceType);
267 baseAssert(t); 273 baseAssert(t);
268 List<DartType> typeArguments = t.typeArguments; 274 List<DartType> typeArguments = t.typeArguments;
269 expect(typeArguments, hasLength(argAsserts.length)); 275 expect(typeArguments, hasLength(argAsserts.length));
270 for (int i = 0; i < typeArguments.length; i++) { 276 for (int i = 0; i < typeArguments.length; i++) {
271 argAsserts[i](typeArguments[i]); 277 argAsserts[i](typeArguments[i]);
272 } 278 }
273 }; 279 };
274 280
275 /** 281 /**
276 * Assert that a type is the List type, and that the given assertion holds 282 * Assert that a type is the List type, and that the given assertion holds
277 * over the type parameter. 283 * over the type parameter.
278 */ 284 */
279 Asserter<InterfaceType> isListOf(Asserter<DartType> argAssert) => 285 Asserter<InterfaceType> isListOf(Asserter<DartType> argAssert) =>
280 isInstantiationOf(isList)([argAssert]); 286 isInstantiationOf(isList)([argAssert]);
281 287
282 /** 288 /**
283 * Assert that a type is the Map type, and that the given assertions hold 289 * Assert that a type is the Map type, and that the given assertions hold
284 * over the type parameters. 290 * over the type parameters.
285 */ 291 */
286 Asserter<InterfaceType> isMapOf( 292 Asserter<InterfaceType> isMapOf(
287 Asserter<DartType> argAssert0, Asserter<DartType> argAssert1) => 293 Asserter<DartType> argAssert0, Asserter<DartType> argAssert1) =>
288 isInstantiationOf(isMap)([argAssert0, argAssert1]); 294 isInstantiationOf(isMap)([argAssert0, argAssert1]);
289 295
290 /** 296 /**
291 * Assert that one type is the same as another 297 * Assert that a type is equal to the [expected].
292 */ 298 */
293 Asserter<DartType> isType(DartType argument) => (DartType t) { 299 Asserter<DartType> isType(DartType expected) => (DartType t) {
294 expect(t, same(argument)); 300 expect(t, expected);
295 }; 301 };
296
297 /**
298 * Given a type, produce an assertion that a type has the same element.
299 */
300 Asserter<DartType> sameElement(DartType elementType) =>
301 hasElement(elementType.element);
302 } 302 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/strong_mode_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698