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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 /// This is useful for running test files directly and skipping tests as | 44 /// This is useful for running test files directly and skipping tests as |
45 /// appropriate. The only OS-specific information we have is the current path, | 45 /// appropriate. The only OS-specific information we have is the current path, |
46 /// which we try to use to figure out the OS. | 46 /// which we try to use to figure out the OS. |
47 final OperatingSystem currentOSGuess = (() { | 47 final OperatingSystem currentOSGuess = (() { |
48 if (p.style == p.Style.url) return OperatingSystem.none; | 48 if (p.style == p.Style.url) return OperatingSystem.none; |
49 if (p.style == p.Style.windows) return OperatingSystem.windows; | 49 if (p.style == p.Style.windows) return OperatingSystem.windows; |
50 if (_macOSDirectories.any(p.current.startsWith)) return OperatingSystem.macOS; | 50 if (_macOSDirectories.any(p.current.startsWith)) return OperatingSystem.macOS; |
51 return OperatingSystem.linux; | 51 return OperatingSystem.linux; |
52 })(); | 52 })(); |
53 | 53 |
| 54 /// A pair of values. |
| 55 class Pair<E, F> { |
| 56 E first; |
| 57 F last; |
| 58 |
| 59 Pair(this.first, this.last); |
| 60 |
| 61 String toString() => '($first, $last)'; |
| 62 |
| 63 bool operator==(other) { |
| 64 if (other is! Pair) return false; |
| 65 return other.first == first && other.last == last; |
| 66 } |
| 67 |
| 68 int get hashCode => first.hashCode ^ last.hashCode; |
| 69 } |
| 70 |
54 /// Get a string description of an exception. | 71 /// Get a string description of an exception. |
55 /// | 72 /// |
56 /// Many exceptions include the exception class name at the beginning of their | 73 /// Many exceptions include the exception class name at the beginning of their |
57 /// [toString], so we remove that if it exists. | 74 /// [toString], so we remove that if it exists. |
58 String getErrorMessage(error) => | 75 String getErrorMessage(error) => |
59 error.toString().replaceFirst(_exceptionPrefix, ''); | 76 error.toString().replaceFirst(_exceptionPrefix, ''); |
60 | 77 |
61 /// Indent each line in [str] by two spaces. | 78 /// Indent each line in [str] by two spaces. |
62 String indent(String str) => | 79 String indent(String str) => |
63 str.replaceAll(new RegExp("^", multiLine: true), " "); | 80 str.replaceAll(new RegExp("^", multiLine: true), " "); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 } | 304 } |
288 } | 305 } |
289 | 306 |
290 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. | 307 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. |
291 shelf.Middleware nestingMiddleware(String beneath) { | 308 shelf.Middleware nestingMiddleware(String beneath) { |
292 return (handler) { | 309 return (handler) { |
293 var pathHandler = new PathHandler()..add(beneath, handler); | 310 var pathHandler = new PathHandler()..add(beneath, handler); |
294 return pathHandler.handler; | 311 return pathHandler.handler; |
295 }; | 312 }; |
296 } | 313 } |
OLD | NEW |