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