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

Side by Side Diff: lib/src/utils.dart

Issue 1116443002: Support future matchers and expectAsync in tearDowns. (Closed) Base URL: git@github.com:dart-lang/unittest.git@master
Patch Set: Created 5 years, 7 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
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 test.utils; 5 library test.utils;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:math' as math; 8 import 'dart:math' as math;
9 9
10 import 'package:crypto/crypto.dart'; 10 import 'package:crypto/crypto.dart';
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 /// Returns a sink that maps events sent to [original] using [fn]. 132 /// Returns a sink that maps events sent to [original] using [fn].
133 StreamSink mapSink(StreamSink original, fn(event)) { 133 StreamSink mapSink(StreamSink original, fn(event)) {
134 var controller = new StreamController(sync: true); 134 var controller = new StreamController(sync: true);
135 controller.stream.listen( 135 controller.stream.listen(
136 (event) => original.add(fn(event)), 136 (event) => original.add(fn(event)),
137 onError: (error, stackTrace) => original.addError(error, stackTrace), 137 onError: (error, stackTrace) => original.addError(error, stackTrace),
138 onDone: () => original.close()); 138 onDone: () => original.close());
139 return controller.sink; 139 return controller.sink;
140 } 140 }
141 141
142 /// Like [runZoned], but [zoneValues] are set for the callbacks in
143 /// [zoneSpecification] and [onError].
144 runZonedWithValues(Function body(), {Map zoneValues,
145 ZoneSpecification zoneSpecification, Function onError}) {
146 return runZoned(() {
147 return runZoned(body,
148 zoneSpecification: zoneSpecification, onError: onError);
149 }, zoneValues: zoneValues);
150 }
151
142 /// Truncates [text] to fit within [maxLength]. 152 /// Truncates [text] to fit within [maxLength].
143 /// 153 ///
144 /// This will try to truncate along word boundaries and preserve words both at 154 /// This will try to truncate along word boundaries and preserve words both at
145 /// the beginning and the end of [text]. 155 /// the beginning and the end of [text].
146 String truncate(String text, int maxLength) { 156 String truncate(String text, int maxLength) {
147 // Return the full message if it fits. 157 // Return the full message if it fits.
148 if (text.length <= maxLength) return text; 158 if (text.length <= maxLength) return text;
149 159
150 // If we can fit the first and last three words, do so. 160 // If we can fit the first and last three words, do so.
151 var words = text.split(' '); 161 var words = text.split(' ');
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 314 }
305 } 315 }
306 316
307 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. 317 /// Returns middleware that nests all requests beneath the URL prefix [beneath].
308 shelf.Middleware nestingMiddleware(String beneath) { 318 shelf.Middleware nestingMiddleware(String beneath) {
309 return (handler) { 319 return (handler) {
310 var pathHandler = new PathHandler()..add(beneath, handler); 320 var pathHandler = new PathHandler()..add(beneath, handler);
311 return pathHandler.handler; 321 return pathHandler.handler;
312 }; 322 };
313 } 323 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698