OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:io'; | 8 import 'dart:io'; |
9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
10 import 'dart:uri'; | 10 import 'dart:uri'; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 }); | 102 }); |
103 }); | 103 }); |
104 } | 104 } |
105 | 105 |
106 /// Stops the current HTTP server. | 106 /// Stops the current HTTP server. |
107 void stopServer() { | 107 void stopServer() { |
108 _server.close(); | 108 _server.close(); |
109 _server = null; | 109 _server = null; |
110 } | 110 } |
111 | 111 |
| 112 /// Removes eight spaces of leading indentation from a multiline string. |
| 113 /// |
| 114 /// Note that this is very sensitive to how the literals are styled. They should |
| 115 /// be: |
| 116 /// ''' |
| 117 /// Text starts on own line. Lines up with subsequent lines. |
| 118 /// Lines are indented exactly 8 characters from the left margin. |
| 119 /// Close is on the same line.''' |
| 120 /// |
| 121 /// This does nothing if text is only a single line. |
| 122 // TODO(nweiz): Make this auto-detect the indentation level from the first |
| 123 // non-whitespace line. |
| 124 String cleanUpLiteral(String text) { |
| 125 var lines = text.split('\n'); |
| 126 if (lines.length <= 1) return text; |
| 127 |
| 128 for (var j = 0; j < lines.length; j++) { |
| 129 if (lines[j].length > 8) { |
| 130 lines[j] = lines[j].substring(8, lines[j].length); |
| 131 } else { |
| 132 lines[j] = ''; |
| 133 } |
| 134 } |
| 135 |
| 136 return lines.join('\n'); |
| 137 } |
| 138 |
112 /// A matcher that matches JSON that parses to a value that matches the inner | 139 /// A matcher that matches JSON that parses to a value that matches the inner |
113 /// matcher. | 140 /// matcher. |
114 Matcher parse(matcher) => new _Parse(matcher); | 141 Matcher parse(matcher) => new _Parse(matcher); |
115 | 142 |
116 class _Parse extends BaseMatcher { | 143 class _Parse extends BaseMatcher { |
117 final Matcher _matcher; | 144 final Matcher _matcher; |
118 | 145 |
119 _Parse(this._matcher); | 146 _Parse(this._matcher); |
120 | 147 |
121 bool matches(item, MatchState matchState) { | 148 bool matches(item, MatchState matchState) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 const isSocketIOException = const _SocketIOException(); | 196 const isSocketIOException = const _SocketIOException(); |
170 | 197 |
171 /// A matcher for functions that throw SocketIOException. | 198 /// A matcher for functions that throw SocketIOException. |
172 const Matcher throwsSocketIOException = | 199 const Matcher throwsSocketIOException = |
173 const Throws(isSocketIOException); | 200 const Throws(isSocketIOException); |
174 | 201 |
175 class _SocketIOException extends TypeMatcher { | 202 class _SocketIOException extends TypeMatcher { |
176 const _SocketIOException() : super("SocketIOException"); | 203 const _SocketIOException() : super("SocketIOException"); |
177 bool matches(item, MatchState matchState) => item is SocketIOException; | 204 bool matches(item, MatchState matchState) => item is SocketIOException; |
178 } | 205 } |
OLD | NEW |