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 matcher.string_matchers; | 5 library matcher.string_matchers; |
6 | 6 |
7 import 'interfaces.dart'; | 7 import 'interfaces.dart'; |
8 | 8 |
9 /// Returns a matcher which matches if the match argument is a string and | 9 /// Returns a matcher which matches if the match argument is a string and |
10 /// is equal to [value] when compared case-insensitively. | 10 /// is equal to [value] when compared case-insensitively. |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 /// Returns a matcher which matches if the match argument is a string and | 28 /// Returns a matcher which matches if the match argument is a string and |
29 /// is equal to [value], ignoring whitespace. | 29 /// is equal to [value], ignoring whitespace. |
30 /// | 30 /// |
31 /// In this matcher, "ignoring whitespace" means comparing with all runs of | 31 /// In this matcher, "ignoring whitespace" means comparing with all runs of |
32 /// whitespace collapsed to single space characters and leading and trailing | 32 /// whitespace collapsed to single space characters and leading and trailing |
33 /// whitespace removed. | 33 /// whitespace removed. |
34 /// | 34 /// |
35 /// For example, the following will all match successfully: | 35 /// For example, the following will all match successfully: |
36 /// | 36 /// |
37 /// expect("hello world", equalsIgnoringCase("hello world")); | 37 /// expect("hello world", equalsIgnoringWhitespace("hello world")); |
38 /// expect(" hello world", equalsIgnoringCase("hello world")); | 38 /// expect(" hello world", equalsIgnoringWhitespace("hello world")); |
39 /// expect("hello world ", equalsIgnoringCase("hello world")); | 39 /// expect("hello world ", equalsIgnoringWhitespace("hello world")); |
40 /// | 40 /// |
41 /// The following will not match: | 41 /// The following will not match: |
42 /// | 42 /// |
43 /// expect("helloworld", equalsIgnoringCase("hello world")); | 43 /// expect("helloworld", equalsIgnoringWhitespace("hello world")); |
44 /// expect("he llo world", equalsIgnoringCase("hello world")); | 44 /// expect("he llo world", equalsIgnoringWhitespace("hello world")); |
45 Matcher equalsIgnoringWhitespace(String value) => | 45 Matcher equalsIgnoringWhitespace(String value) => |
46 new _IsEqualIgnoringWhitespace(value); | 46 new _IsEqualIgnoringWhitespace(value); |
47 | 47 |
48 class _IsEqualIgnoringWhitespace extends _StringMatcher { | 48 class _IsEqualIgnoringWhitespace extends _StringMatcher { |
49 final String _value; | 49 final String _value; |
50 final String _matchValue; | 50 final String _matchValue; |
51 | 51 |
52 _IsEqualIgnoringWhitespace(String value) | 52 _IsEqualIgnoringWhitespace(String value) |
53 : _value = value, | 53 : _value = value, |
54 _matchValue = collapseWhitespace(value); | 54 _matchValue = collapseWhitespace(value); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } else { | 192 } else { |
193 result.write(character); | 193 result.write(character); |
194 skipSpace = false; | 194 skipSpace = false; |
195 } | 195 } |
196 } | 196 } |
197 return result.toString().trim(); | 197 return result.toString().trim(); |
198 } | 198 } |
199 | 199 |
200 bool _isWhitespace(String ch) => | 200 bool _isWhitespace(String ch) => |
201 ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; | 201 ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; |
OLD | NEW |