| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 // Dart test for testing String.allMatches. | |
| 5 | |
| 6 String str = "this is a string with hello here and hello there"; | |
| 7 | |
| 8 main() { | |
| 9 testNoMatch(); | |
| 10 testOneMatch(); | |
| 11 testTwoMatches(); | |
| 12 testEmptyPattern(); | |
| 13 testEmptyString(); | |
| 14 testEmptyPatternAndString(); | |
| 15 } | |
| 16 | |
| 17 testNoMatch() { | |
| 18 // Also tests that RegExp groups don't work. | |
| 19 String helloPattern = "with (hello)"; | |
| 20 Iterable<Match> matches = helloPattern.allMatches(str); | |
| 21 Expect.isFalse(matches.iterator().hasNext()); | |
| 22 } | |
| 23 | |
| 24 testOneMatch() { | |
| 25 String helloPattern = "with hello"; | |
| 26 Iterable<Match> matches = helloPattern.allMatches(str); | |
| 27 var iterator = matches.iterator(); | |
| 28 Match match = iterator.next(); | |
| 29 Expect.isFalse(iterator.hasNext()); | |
| 30 Expect.equals(str.indexOf('with', 0), match.start()); | |
| 31 Expect.equals(str.indexOf('with', 0) + helloPattern.length, match.end()); | |
| 32 Expect.equals(helloPattern, match.pattern); | |
| 33 Expect.equals(str, match.str); | |
| 34 Expect.equals(helloPattern, match[0]); | |
| 35 Expect.equals(0, match.groupCount()); | |
| 36 } | |
| 37 | |
| 38 testTwoMatches() { | |
| 39 String helloPattern = "hello"; | |
| 40 Iterable<Match> matches = helloPattern.allMatches(str); | |
| 41 | |
| 42 int count = 0; | |
| 43 int start = 0; | |
| 44 for (var match in matches) { | |
| 45 count++; | |
| 46 Expect.equals(str.indexOf('hello', start), match.start()); | |
| 47 Expect.equals( | |
| 48 str.indexOf('hello', start) + helloPattern.length, match.end()); | |
| 49 Expect.equals(helloPattern, match.pattern); | |
| 50 Expect.equals(str, match.str); | |
| 51 Expect.equals(helloPattern, match[0]); | |
| 52 Expect.equals(0, match.groupCount()); | |
| 53 start = match.end(); | |
| 54 } | |
| 55 Expect.equals(2, count); | |
| 56 } | |
| 57 | |
| 58 testEmptyPattern() { | |
| 59 String pattern = ""; | |
| 60 Iterable<Match> matches = pattern.allMatches(str); | |
| 61 Expect.isTrue(matches.iterator().hasNext()); | |
| 62 } | |
| 63 | |
| 64 testEmptyString() { | |
| 65 String pattern = "foo"; | |
| 66 String str = ""; | |
| 67 Iterable<Match> matches = pattern.allMatches(str); | |
| 68 Expect.isFalse(matches.iterator().hasNext()); | |
| 69 } | |
| 70 | |
| 71 testEmptyPatternAndString() { | |
| 72 String pattern = ""; | |
| 73 String str = ""; | |
| 74 Iterable<Match> matches = pattern.allMatches(str); | |
| 75 Expect.isTrue(matches.iterator().hasNext()); | |
| 76 } | |
| OLD | NEW |