| 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 import 'interfaces.dart'; | 5 import 'interfaces.dart'; |
| 6 | 6 |
| 7 /// Returns a matcher which matches if the match argument is a string and | 7 /// Returns a matcher which matches if the match argument is a string and |
| 8 /// is equal to [value] when compared case-insensitively. | 8 /// is equal to [value] when compared case-insensitively. |
| 9 Matcher equalsIgnoringCase(String value) => new _IsEqualIgnoringCase(value); | 9 Matcher equalsIgnoringCase(String value) => new _IsEqualIgnoringCase(value); |
| 10 | 10 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 Matcher stringContainsInOrder(List<String> substrings) => | 112 Matcher stringContainsInOrder(List<String> substrings) => |
| 113 new _StringContainsInOrder(substrings); | 113 new _StringContainsInOrder(substrings); |
| 114 | 114 |
| 115 class _StringContainsInOrder extends _StringMatcher { | 115 class _StringContainsInOrder extends _StringMatcher { |
| 116 final List<String> _substrings; | 116 final List<String> _substrings; |
| 117 | 117 |
| 118 const _StringContainsInOrder(this._substrings); | 118 const _StringContainsInOrder(this._substrings); |
| 119 | 119 |
| 120 bool matches(item, Map matchState) { | 120 bool matches(item, Map matchState) { |
| 121 if (!(item is String)) { | 121 if (item is String) { |
| 122 var from_index = 0; |
| 123 for (var s in _substrings) { |
| 124 from_index = item.indexOf(s, from_index); |
| 125 if (from_index < 0) return false; |
| 126 } |
| 127 return true; |
| 128 } else { |
| 122 return false; | 129 return false; |
| 123 } | 130 } |
| 124 var from_index = 0; | |
| 125 for (var s in _substrings) { | |
| 126 from_index = item.indexOf(s, from_index); | |
| 127 if (from_index < 0) return false; | |
| 128 } | |
| 129 return true; | |
| 130 } | 131 } |
| 131 | 132 |
| 132 Description describe(Description description) => description.addAll( | 133 Description describe(Description description) => description.addAll( |
| 133 'a string containing ', ', ', ' in order', _substrings); | 134 'a string containing ', ', ', ' in order', _substrings); |
| 134 } | 135 } |
| 135 | 136 |
| 136 /// Returns a matcher that matches if the match argument is a string and | 137 /// Returns a matcher that matches if the match argument is a string and |
| 137 /// matches the regular expression given by [re]. | 138 /// matches the regular expression given by [re]. |
| 138 /// | 139 /// |
| 139 /// [re] can be a [RegExp] instance or a [String]; in the latter case it will be | 140 /// [re] can be a [RegExp] instance or a [String]; in the latter case it will be |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 } else { | 191 } else { |
| 191 result.write(character); | 192 result.write(character); |
| 192 skipSpace = false; | 193 skipSpace = false; |
| 193 } | 194 } |
| 194 } | 195 } |
| 195 return result.toString().trim(); | 196 return result.toString().trim(); |
| 196 } | 197 } |
| 197 | 198 |
| 198 bool _isWhitespace(String ch) => | 199 bool _isWhitespace(String ch) => |
| 199 ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; | 200 ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; |
| OLD | NEW |