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

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

Issue 149243009: Add support for lazy transformers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review 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/barback/test/transformer/lazy_rewrite.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 barback.test.utils; 5 library barback.test.utils;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:convert' show Encoding; 9 import 'dart:convert' show Encoding;
10 10
11 import 'package:barback/barback.dart'; 11 import 'package:barback/barback.dart';
12 import 'package:barback/src/cancelable_future.dart'; 12 import 'package:barback/src/cancelable_future.dart';
13 import 'package:barback/src/utils.dart'; 13 import 'package:barback/src/utils.dart';
14 import 'package:path/path.dart' as pathos; 14 import 'package:path/path.dart' as pathos;
15 import 'package:scheduled_test/scheduled_test.dart'; 15 import 'package:scheduled_test/scheduled_test.dart';
16 import 'package:stack_trace/stack_trace.dart'; 16 import 'package:stack_trace/stack_trace.dart';
17 import 'package:unittest/compact_vm_config.dart'; 17 import 'package:unittest/compact_vm_config.dart';
18 18
19 export 'transformer/bad.dart'; 19 export 'transformer/bad.dart';
20 export 'transformer/check_content.dart'; 20 export 'transformer/check_content.dart';
21 export 'transformer/check_content_and_rename.dart'; 21 export 'transformer/check_content_and_rename.dart';
22 export 'transformer/create_asset.dart'; 22 export 'transformer/create_asset.dart';
23 export 'transformer/lazy_bad.dart';
24 export 'transformer/lazy_many_to_one.dart';
25 export 'transformer/lazy_rewrite.dart';
23 export 'transformer/many_to_one.dart'; 26 export 'transformer/many_to_one.dart';
24 export 'transformer/mock.dart'; 27 export 'transformer/mock.dart';
25 export 'transformer/one_to_many.dart'; 28 export 'transformer/one_to_many.dart';
26 export 'transformer/rewrite.dart'; 29 export 'transformer/rewrite.dart';
27 30
28 var _configured = false; 31 var _configured = false;
29 32
30 MockProvider _provider; 33 MockProvider _provider;
31 Barback _barback; 34 Barback _barback;
32 35
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 }).catchError((error) { 279 }).catchError((error) {
277 expect(error, new isInstanceOf<AssetNotFoundException>()); 280 expect(error, new isInstanceOf<AssetNotFoundException>());
278 expect(error.id, equals(id)); 281 expect(error.id, equals(id));
279 }); 282 });
280 }, "get asset $name"); 283 }, "get asset $name");
281 } 284 }
282 285
283 /// Schedules an expectation that the graph will output all of the given 286 /// Schedules an expectation that the graph will output all of the given
284 /// assets, and no others. 287 /// assets, and no others.
285 /// 288 ///
286 /// [assets] is a list of strings that can be parsed to [AssetID]s. 289 /// [assets] may be an iterable of asset id strings, in which case this asserts
287 void expectAllAssets(Iterable<String> assets) { 290 /// that the graph outputs exactly the assets with those ids. It may also be a
288 var expected = assets.map((asset) => new AssetId.parse(asset)); 291 /// map from asset id strings to asset contents, in which case the contents must
292 /// also match.
293 void expectAllAssets(assets) {
294 var expected;
295 var expectedString;
296 if (assets is Map) {
297 expected = mapMapKeys(assets, (key, _) => new AssetId.parse(key));
298 expectedString = expected.toString();
299 } else {
300 expected = assets.map((asset) => new AssetId.parse(asset));
301 expectedString = expected.join(', ');
302 }
289 303
290 schedule(() { 304 schedule(() {
291 return _barback.getAllAssets().then((actualAssets) { 305 return _barback.getAllAssets().then((actualAssets) {
292 var actualIds = actualAssets.map((asset) => asset.id).toSet(); 306 var actualIds = actualAssets.map((asset) => asset.id).toSet();
293 307
294 for (var id in expected) { 308 if (expected is Map) {
295 expect(actualIds, contains(id)); 309 expected.forEach((id, contents) {
296 actualIds.remove(id); 310 expect(actualIds, contains(id));
311 actualIds.remove(id);
312 expect(actualAssets[id].readAsString(), completion(equals(contents)));
313 });
314 } else {
315 for (var id in expected) {
316 expect(actualIds, contains(id));
317 actualIds.remove(id);
318 }
297 } 319 }
298 320
299 expect(actualIds, isEmpty); 321 expect(actualIds, isEmpty);
300 }); 322 });
301 }, "get all assets, expecting ${expected.join(', ')}"); 323 }, "get all assets, expecting $expectedString");
302 } 324 }
303 325
304 /// Schedules an expectation that [Barback.getAllAssets] will return a [Future] 326 /// Schedules an expectation that [Barback.getAllAssets] will return a [Future]
305 /// that completes to a error that matches [matcher]. 327 /// that completes to a error that matches [matcher].
306 /// 328 ///
307 /// If [match] is a [List], then it expects the completed error to be an 329 /// If [match] is a [List], then it expects the completed error to be an
308 /// [AggregateException] whose errors match each matcher in the list. Otherwise, 330 /// [AggregateException] whose errors match each matcher in the list. Otherwise,
309 /// [match] should be a single matcher that the error should match. 331 /// [match] should be a single matcher that the error should match.
310 void expectAllAssetsShouldFail(Matcher matcher) { 332 void expectAllAssetsShouldFail(Matcher matcher) {
311 schedule(() { 333 schedule(() {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 564
543 _MockAsset(this.id, this.contents); 565 _MockAsset(this.id, this.contents);
544 566
545 Future<String> readAsString({Encoding encoding}) => 567 Future<String> readAsString({Encoding encoding}) =>
546 new Future.value(contents); 568 new Future.value(contents);
547 569
548 Stream<List<int>> read() => throw new UnimplementedError(); 570 Stream<List<int>> read() => throw new UnimplementedError();
549 571
550 String toString() => "MockAsset $id $contents"; 572 String toString() => "MockAsset $id $contents";
551 } 573 }
OLDNEW
« no previous file with comments | « pkg/barback/test/transformer/lazy_rewrite.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698