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

Side by Side Diff: pkg/analysis_server/test/mocks.dart

Issue 376693002: Extract testing utilities into a separate package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 mocks; 5 library mocks;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 @MirrorsUsed(targets: 'mocks', override: '*') 10 @MirrorsUsed(targets: 'mocks', override: '*')
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 var id = response.id; 297 var id = response.id;
298 RequestError error = response.error; 298 RequestError error = response.error;
299 mismatchDescription.add('has identifier "$id"'); 299 mismatchDescription.add('has identifier "$id"');
300 if (error == null) { 300 if (error == null) {
301 mismatchDescription.add(' and has no error'); 301 mismatchDescription.add(' and has no error');
302 } 302 }
303 return mismatchDescription; 303 return mismatchDescription;
304 } 304 }
305 } 305 }
306 306
307 class MockSdk implements DartSdk {
308
309 final resource.MemoryResourceProvider provider = new resource.MemoryResourcePr ovider();
310
311 MockSdk() {
312 // TODO(paulberry): Add to this as needed.
313 const Map<String, String> pathToContent = const {
314 "/lib/core/core.dart": '''
315 library dart.core;
316 class Object {}
317 class Function {}
318 class StackTrace {}
319 class Symbol {}
320 class Type {}
321
322 class String extends Object {}
323 class bool extends Object {}
324 abstract class num extends Object {
325 num operator +(num other);
326 num operator -(num other);
327 num operator *(num other);
328 num operator /(num other);
329 }
330 abstract class int extends num {
331 int operator -();
332 }
333 class double extends num {}
334 class DateTime extends Object {}
335 class Null extends Object {}
336
337 class Deprecated extends Object {
338 final String expires;
339 const Deprecated(this.expires);
340 }
341 const Object deprecated = const Deprecated("next release");
342
343 abstract class List<E> extends Object {
344 void add(E value);
345 E operator [](int index);
346 void operator []=(int index, E value);
347 }
348 class Map<K, V> extends Object {}
349
350 void print(Object object) {}
351 ''',
352
353 "/lib/html/dartium/html_dartium.dart": '''
354 library dart.html;
355 class HtmlElement {}
356 ''',
357
358 "/lib/math/math.dart": '''
359 library dart.math;
360 '''
361 };
362
363 pathToContent.forEach((String path, String content) {
364 provider.newFile(path, content);
365 });
366 }
367
368 // Not used
369 @override
370 AnalysisContext get context => throw unimplemented;
371
372 @override
373 Source fromEncoding(UriKind kind, Uri uri) {
374 resource.Resource file = provider.getResource(uri.path);
375 if (file is resource.File) {
376 return file.createSource(kind);
377 }
378 return null;
379 }
380
381 UnimplementedError get unimplemented => new UnimplementedError();
382
383 @override
384 SdkLibrary getSdkLibrary(String dartUri) {
385 // getSdkLibrary() is only used to determine whether a library is internal
386 // to the SDK. The mock SDK doesn't have any internals, so it's safe to
387 // return null.
388 return null;
389 }
390
391 @override
392 Source mapDartUri(String dartUri) {
393 const Map<String, String> uriToPath = const {
394 "dart:core": "/lib/core/core.dart",
395 "dart:html": "/lib/html/dartium/html_dartium.dart",
396 "dart:math": "/lib/math/math.dart"
397 };
398
399 String path = uriToPath[dartUri];
400 if (path != null) {
401 resource.File file = provider.getResource(path);
402 return file.createSource(UriKind.DART_URI);
403 }
404
405 // If we reach here then we tried to use a dartUri that's not in the
406 // table above.
407 throw unimplemented;
408 }
409
410 // Not used.
411 @override
412 List<SdkLibrary> get sdkLibraries => throw unimplemented;
413
414 // Not used.
415 @override
416 String get sdkVersion => throw unimplemented;
417
418 // Not used.
419 @override
420 List<String> get uris => throw unimplemented;
421 }
422 307
423 /** 308 /**
424 * A mock [PackageMapProvider]. 309 * A mock [PackageMapProvider].
425 */ 310 */
426 class MockPackageMapProvider implements PackageMapProvider { 311 class MockPackageMapProvider implements PackageMapProvider {
427 /** 312 /**
428 * Package map that will be returned by the next call to [computePackageMap]. 313 * Package map that will be returned by the next call to [computePackageMap].
429 */ 314 */
430 Map<String, List<resource.Folder>> packageMap = <String, List<resource.Folder> >{}; 315 Map<String, List<resource.Folder>> packageMap = <String, List<resource.Folder> >{};
431 316
432 /** 317 /**
433 * Dependency list that will be returned by the next call to [computePackageMa p]. 318 * Dependency list that will be returned by the next call to [computePackageMa p].
434 */ 319 */
435 Set<String> dependencies = new Set<String>(); 320 Set<String> dependencies = new Set<String>();
436 321
437 @override 322 @override
438 PackageMapInfo computePackageMap(resource.Folder folder) { 323 PackageMapInfo computePackageMap(resource.Folder folder) {
439 return new PackageMapInfo(packageMap, dependencies); 324 return new PackageMapInfo(packageMap, dependencies);
440 } 325 }
441 } 326 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698