| 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:convert' show Encoding; | 9 import 'dart:convert' show Encoding; |
| 10 | 10 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 242 |
| 243 Future<LogEntry> _getNextLog(String description) { | 243 Future<LogEntry> _getNextLog(String description) { |
| 244 var result = currentSchedule.wrapFuture( | 244 var result = currentSchedule.wrapFuture( |
| 245 _barback.log.elementAt(_nextLog++)); | 245 _barback.log.elementAt(_nextLog++)); |
| 246 return schedule(() => result, description); | 246 return schedule(() => result, description); |
| 247 } | 247 } |
| 248 | 248 |
| 249 /// Schedules an expectation that the graph will deliver an asset matching | 249 /// Schedules an expectation that the graph will deliver an asset matching |
| 250 /// [name] and [contents]. | 250 /// [name] and [contents]. |
| 251 /// | 251 /// |
| 252 /// [contents] may be a [String] or a [Matcher] that matches a string. If | 252 /// If [contents] is omitted, defaults to the asset's filename without an |
| 253 /// [contents] is omitted, defaults to the asset's filename without an extension | 253 /// extension (which is the same default that [initGraph] uses). |
| 254 /// (which is the same default that [initGraph] uses). | 254 void expectAsset(String name, [String contents]) { |
| 255 void expectAsset(String name, [contents]) { | |
| 256 var id = new AssetId.parse(name); | 255 var id = new AssetId.parse(name); |
| 257 | 256 |
| 258 if (contents == null) { | 257 if (contents == null) { |
| 259 contents = pathos.basenameWithoutExtension(id.path); | 258 contents = pathos.basenameWithoutExtension(id.path); |
| 260 } | 259 } |
| 261 | 260 |
| 262 schedule(() { | 261 schedule(() { |
| 263 return _barback.getAssetById(id).then((asset) { | 262 return _barback.getAssetById(id).then((asset) { |
| 264 // TODO(rnystrom): Make an actual Matcher class for this. | 263 // TODO(rnystrom): Make an actual Matcher class for this. |
| 265 expect(asset.id, equals(id)); | 264 expect(asset.id, equals(id)); |
| 266 expect(asset.readAsString(), completion(contents)); | 265 expect(asset.readAsString(), completion(equals(contents))); |
| 267 }); | 266 }); |
| 268 }, "get asset $name"); | 267 }, "get asset $name"); |
| 269 } | 268 } |
| 270 | 269 |
| 271 /// Schedules an expectation that the graph will not find an asset matching | 270 /// Schedules an expectation that the graph will not find an asset matching |
| 272 /// [name]. | 271 /// [name]. |
| 273 void expectNoAsset(String name) { | 272 void expectNoAsset(String name) { |
| 274 var id = new AssetId.parse(name); | 273 var id = new AssetId.parse(name); |
| 275 | 274 |
| 276 // Make sure the future gets the error. | 275 // Make sure the future gets the error. |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 | 564 |
| 566 _MockAsset(this.id, this.contents); | 565 _MockAsset(this.id, this.contents); |
| 567 | 566 |
| 568 Future<String> readAsString({Encoding encoding}) => | 567 Future<String> readAsString({Encoding encoding}) => |
| 569 new Future.value(contents); | 568 new Future.value(contents); |
| 570 | 569 |
| 571 Stream<List<int>> read() => throw new UnimplementedError(); | 570 Stream<List<int>> read() => throw new UnimplementedError(); |
| 572 | 571 |
| 573 String toString() => "MockAsset $id $contents"; | 572 String toString() => "MockAsset $id $contents"; |
| 574 } | 573 } |
| OLD | NEW |