OLD | NEW |
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:io'; | 9 import 'dart:io'; |
10 | 10 |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 /// The error it throws. | 509 /// The error it throws. |
510 static const ERROR = "I am a bad transformer!"; | 510 static const ERROR = "I am a bad transformer!"; |
511 | 511 |
512 /// The list of asset names that it should output. | 512 /// The list of asset names that it should output. |
513 final List<String> outputs; | 513 final List<String> outputs; |
514 | 514 |
515 BadTransformer(this.outputs); | 515 BadTransformer(this.outputs); |
516 | 516 |
517 Future<bool> isPrimary(Asset asset) => new Future.value(true); | 517 Future<bool> isPrimary(Asset asset) => new Future.value(true); |
518 Future apply(Transform transform) { | 518 Future apply(Transform transform) { |
519 return new Future(() { | 519 return newFuture(() { |
520 // Create the outputs first. | 520 // Create the outputs first. |
521 for (var output in outputs) { | 521 for (var output in outputs) { |
522 var id = new AssetId.parse(output); | 522 var id = new AssetId.parse(output); |
523 transform.addOutput(new MockAsset(id, output)); | 523 transform.addOutput(new MockAsset(id, output)); |
524 } | 524 } |
525 | 525 |
526 // Then fail. | 526 // Then fail. |
527 throw ERROR; | 527 throw ERROR; |
528 }); | 528 }); |
529 } | 529 } |
530 } | 530 } |
531 | 531 |
532 /// A transformer that outputs an asset with the given id. | 532 /// A transformer that outputs an asset with the given id. |
533 class CreateAssetTransformer extends Transformer { | 533 class CreateAssetTransformer extends Transformer { |
534 final String output; | 534 final String output; |
535 | 535 |
536 CreateAssetTransformer(this.output); | 536 CreateAssetTransformer(this.output); |
537 | 537 |
538 Future<bool> isPrimary(Asset asset) => new Future.value(true); | 538 Future<bool> isPrimary(Asset asset) => new Future.value(true); |
539 | 539 |
540 Future apply(Transform transform) { | 540 Future apply(Transform transform) { |
541 return new Future(() { | 541 return newFuture(() { |
542 transform.addOutput(new MockAsset(new AssetId.parse(output), output)); | 542 transform.addOutput(new MockAsset(new AssetId.parse(output), output)); |
543 }); | 543 }); |
544 } | 544 } |
545 } | 545 } |
546 | 546 |
547 /// An implementation of [Asset] that never hits the file system. | 547 /// An implementation of [Asset] that never hits the file system. |
548 class MockAsset implements Asset { | 548 class MockAsset implements Asset { |
549 final AssetId id; | 549 final AssetId id; |
550 String contents; | 550 String contents; |
551 | 551 |
552 MockAsset(this.id, this.contents); | 552 MockAsset(this.id, this.contents); |
553 | 553 |
554 Future<String> readAsString({Encoding encoding}) => | 554 Future<String> readAsString({Encoding encoding}) => |
555 new Future.value(contents); | 555 new Future.value(contents); |
556 | 556 |
557 Stream<List<int>> read() => throw new UnimplementedError(); | 557 Stream<List<int>> read() => throw new UnimplementedError(); |
558 | 558 |
559 String toString() => "MockAsset $id $contents"; | 559 String toString() => "MockAsset $id $contents"; |
560 } | 560 } |
OLD | NEW |