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 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 helper(element); | 91 helper(element); |
92 } else { | 92 } else { |
93 result.add(element); | 93 result.add(element); |
94 } | 94 } |
95 } | 95 } |
96 } | 96 } |
97 helper(nested); | 97 helper(nested); |
98 return result; | 98 return result; |
99 } | 99 } |
100 | 100 |
| 101 /// Returns a new map with all values in both [map1] and [map2]. |
| 102 /// |
| 103 /// If there are conflicting keys, [map2]'s value wins. |
| 104 Map mergeMaps(Map map1, Map map2) { |
| 105 var result = {}; |
| 106 map1.forEach((key, value) { |
| 107 result[key] = value; |
| 108 }); |
| 109 map2.forEach((key, value) { |
| 110 result[key] = value; |
| 111 }); |
| 112 return result; |
| 113 } |
| 114 |
101 /// Returns a sink that maps events sent to [original] using [fn]. | 115 /// Returns a sink that maps events sent to [original] using [fn]. |
102 StreamSink mapSink(StreamSink original, fn(event)) { | 116 StreamSink mapSink(StreamSink original, fn(event)) { |
103 var controller = new StreamController(sync: true); | 117 var controller = new StreamController(sync: true); |
104 controller.stream.listen( | 118 controller.stream.listen( |
105 (event) => original.add(fn(event)), | 119 (event) => original.add(fn(event)), |
106 onError: (error, stackTrace) => original.addError(error, stackTrace), | 120 onError: (error, stackTrace) => original.addError(error, stackTrace), |
107 onDone: () => original.close()); | 121 onDone: () => original.close()); |
108 return controller.sink; | 122 return controller.sink; |
109 } | 123 } |
110 | 124 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } | 287 } |
274 } | 288 } |
275 | 289 |
276 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. | 290 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. |
277 shelf.Middleware nestingMiddleware(String beneath) { | 291 shelf.Middleware nestingMiddleware(String beneath) { |
278 return (handler) { | 292 return (handler) { |
279 var pathHandler = new PathHandler()..add(beneath, handler); | 293 var pathHandler = new PathHandler()..add(beneath, handler); |
280 return pathHandler.handler; | 294 return pathHandler.handler; |
281 }; | 295 }; |
282 } | 296 } |
OLD | NEW |