| 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:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| 11 import 'package:http/src/byte_stream.dart'; | 11 import 'package:http/http.dart'; |
| 12 import 'package:http/src/utils.dart'; | 12 import 'package:http/src/utils.dart'; |
| 13 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 14 | 14 |
| 15 /// The current server instance. | 15 /// The current server instance. |
| 16 HttpServer _server; | 16 HttpServer _server; |
| 17 | 17 |
| 18 /// The URL for the current server instance. | 18 /// The URL for the current server instance. |
| 19 Uri get serverUrl => Uri.parse('http://localhost:${_server.port}'); | 19 Uri get serverUrl => Uri.parse('http://localhost:${_server.port}'); |
| 20 | 20 |
| 21 /// A dummy URL for constructing requests that won't be sent. | 21 /// A dummy URL for constructing requests that won't be sent. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 167 |
| 168 return _matcher.matches(parsed, matchState); | 168 return _matcher.matches(parsed, matchState); |
| 169 } | 169 } |
| 170 | 170 |
| 171 Description describe(Description description) { | 171 Description describe(Description description) { |
| 172 return description.add('parses to a value that ') | 172 return description.add('parses to a value that ') |
| 173 .addDescriptionOf(_matcher); | 173 .addDescriptionOf(_matcher); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 /// A matcher for HttpExceptions. | |
| 178 const isHttpException = const _HttpException(); | |
| 179 | |
| 180 /// A matcher for functions that throw HttpException. | 177 /// A matcher for functions that throw HttpException. |
| 181 const Matcher throwsHttpException = | 178 Matcher get throwsClientException => |
| 182 const Throws(isHttpException); | 179 throwsA(new isInstanceOf<ClientException>()); |
| 183 | |
| 184 class _HttpException extends TypeMatcher { | |
| 185 const _HttpException() : super("HttpException"); | |
| 186 bool matches(item, Map matchState) => item is HttpException; | |
| 187 } | |
| 188 | 180 |
| 189 /// A matcher for RedirectLimitExceededExceptions. | 181 /// A matcher for RedirectLimitExceededExceptions. |
| 190 const isRedirectLimitExceededException = | 182 const isRedirectLimitExceededException = |
| 191 const _RedirectLimitExceededException(); | 183 const _RedirectLimitExceededException(); |
| 192 | 184 |
| 193 /// A matcher for functions that throw RedirectLimitExceededException. | 185 /// A matcher for functions that throw RedirectLimitExceededException. |
| 194 const Matcher throwsRedirectLimitExceededException = | 186 const Matcher throwsRedirectLimitExceededException = |
| 195 const Throws(isRedirectLimitExceededException); | 187 const Throws(isRedirectLimitExceededException); |
| 196 | 188 |
| 197 class _RedirectLimitExceededException extends TypeMatcher { | 189 class _RedirectLimitExceededException extends TypeMatcher { |
| 198 const _RedirectLimitExceededException() : | 190 const _RedirectLimitExceededException() : |
| 199 super("RedirectLimitExceededException"); | 191 super("RedirectLimitExceededException"); |
| 200 | 192 |
| 201 bool matches(item, Map matchState) => | 193 bool matches(item, Map matchState) => |
| 202 item is RedirectException && item.message == "Redirect limit exceeded"; | 194 item is RedirectException && item.message == "Redirect limit exceeded"; |
| 203 } | 195 } |
| 204 | 196 |
| 205 /// A matcher for SocketExceptions. | 197 /// A matcher for SocketExceptions. |
| 206 const isSocketException = const _SocketException(); | 198 const isSocketException = const _SocketException(); |
| 207 | 199 |
| 208 /// A matcher for functions that throw SocketException. | 200 /// A matcher for functions that throw SocketException. |
| 209 const Matcher throwsSocketException = | 201 const Matcher throwsSocketException = |
| 210 const Throws(isSocketException); | 202 const Throws(isSocketException); |
| 211 | 203 |
| 212 class _SocketException extends TypeMatcher { | 204 class _SocketException extends TypeMatcher { |
| 213 const _SocketException() : super("SocketException"); | 205 const _SocketException() : super("SocketException"); |
| 214 bool matches(item, Map matchState) => item is SocketException; | 206 bool matches(item, Map matchState) => item is SocketException; |
| 215 } | 207 } |
| OLD | NEW |