| 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 utils; | 5 library utils; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:json'; | 8 import 'dart:json'; |
| 9 import 'dart:uri'; | 9 import 'dart:uri'; |
| 10 | 10 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 /// A matcher that matches JSON that parses to a value that matches the inner | 88 /// A matcher that matches JSON that parses to a value that matches the inner |
| 89 /// matcher. | 89 /// matcher. |
| 90 Matcher parse(matcher) => new _Parse(matcher); | 90 Matcher parse(matcher) => new _Parse(matcher); |
| 91 | 91 |
| 92 class _Parse extends BaseMatcher { | 92 class _Parse extends BaseMatcher { |
| 93 final Matcher _matcher; | 93 final Matcher _matcher; |
| 94 | 94 |
| 95 _Parse(this._matcher); | 95 _Parse(this._matcher); |
| 96 | 96 |
| 97 bool matches(item, MatchState matchState) { | 97 bool matches(item, MatchState matchState) { |
| 98 print("_Parse.matches [$item]"); |
| 98 if (item is! String) return false; | 99 if (item is! String) return false; |
| 99 | 100 |
| 100 var parsed; | 101 var parsed; |
| 101 try { | 102 try { |
| 102 parsed = JSON.parse(item); | 103 parsed = JSON.parse(item); |
| 103 } catch (e) { | 104 } catch (e) { |
| 104 return false; | 105 return false; |
| 105 } | 106 } |
| 106 | 107 |
| 107 return _matcher.matches(parsed, matchState); | 108 return _matcher.matches(parsed, matchState); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 130 const isHttpException = const _HttpException(); | 131 const isHttpException = const _HttpException(); |
| 131 | 132 |
| 132 /// A matcher for functions that throw HttpException. | 133 /// A matcher for functions that throw HttpException. |
| 133 const Matcher throwsHttpException = | 134 const Matcher throwsHttpException = |
| 134 const Throws(isHttpException); | 135 const Throws(isHttpException); |
| 135 | 136 |
| 136 class _HttpException extends TypeMatcher { | 137 class _HttpException extends TypeMatcher { |
| 137 const _HttpException() : super("HttpException"); | 138 const _HttpException() : super("HttpException"); |
| 138 bool matches(item, MatchState matchState) => item is HttpException; | 139 bool matches(item, MatchState matchState) => item is HttpException; |
| 139 } | 140 } |
| OLD | NEW |