| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Dart test for testing String.allMatches. | 4 // Dart test for testing String.allMatches. |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 String str = "this is a string with hello here and hello there"; | 8 String str = "this is a string with hello here and hello there"; |
| 9 | 9 |
| 10 main() { | 10 main() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 testOneMatch() { | 27 testOneMatch() { |
| 28 String helloPattern = "with hello"; | 28 String helloPattern = "with hello"; |
| 29 Iterable<Match> matches = helloPattern.allMatches(str); | 29 Iterable<Match> matches = helloPattern.allMatches(str); |
| 30 var iterator = matches.iterator; | 30 var iterator = matches.iterator; |
| 31 Expect.isTrue(iterator.moveNext()); | 31 Expect.isTrue(iterator.moveNext()); |
| 32 Match match = iterator.current; | 32 Match match = iterator.current; |
| 33 Expect.isFalse(iterator.moveNext()); | 33 Expect.isFalse(iterator.moveNext()); |
| 34 Expect.equals(str.indexOf('with', 0), match.start); | 34 Expect.equals(str.indexOf('with', 0), match.start); |
| 35 Expect.equals(str.indexOf('with', 0) + helloPattern.length, match.end); | 35 Expect.equals(str.indexOf('with', 0) + helloPattern.length, match.end); |
| 36 Expect.equals(helloPattern, match.pattern); | 36 Expect.equals(helloPattern, match.pattern); |
| 37 Expect.equals(str, match.str); | 37 Expect.equals(str, match.input); |
| 38 Expect.equals(helloPattern, match[0]); | 38 Expect.equals(helloPattern, match[0]); |
| 39 Expect.equals(0, match.groupCount); | 39 Expect.equals(0, match.groupCount); |
| 40 } | 40 } |
| 41 | 41 |
| 42 testTwoMatches() { | 42 testTwoMatches() { |
| 43 String helloPattern = "hello"; | 43 String helloPattern = "hello"; |
| 44 Iterable<Match> matches = helloPattern.allMatches(str); | 44 Iterable<Match> matches = helloPattern.allMatches(str); |
| 45 | 45 |
| 46 int count = 0; | 46 int count = 0; |
| 47 int start = 0; | 47 int start = 0; |
| 48 for (var match in matches) { | 48 for (var match in matches) { |
| 49 count++; | 49 count++; |
| 50 Expect.equals(str.indexOf('hello', start), match.start); | 50 Expect.equals(str.indexOf('hello', start), match.start); |
| 51 Expect.equals( | 51 Expect.equals( |
| 52 str.indexOf('hello', start) + helloPattern.length, match.end); | 52 str.indexOf('hello', start) + helloPattern.length, match.end); |
| 53 Expect.equals(helloPattern, match.pattern); | 53 Expect.equals(helloPattern, match.pattern); |
| 54 Expect.equals(str, match.str); | 54 Expect.equals(str, match.input); |
| 55 Expect.equals(helloPattern, match[0]); | 55 Expect.equals(helloPattern, match[0]); |
| 56 Expect.equals(0, match.groupCount); | 56 Expect.equals(0, match.groupCount); |
| 57 start = match.end; | 57 start = match.end; |
| 58 } | 58 } |
| 59 Expect.equals(2, count); | 59 Expect.equals(2, count); |
| 60 } | 60 } |
| 61 | 61 |
| 62 testEmptyPattern() { | 62 testEmptyPattern() { |
| 63 String pattern = ""; | 63 String pattern = ""; |
| 64 Iterable<Match> matches = pattern.allMatches(str); | 64 Iterable<Match> matches = pattern.allMatches(str); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 90 Expect.isNull(pattern.matchAsPrefix(str, 2)); | 90 Expect.isNull(pattern.matchAsPrefix(str, 2)); |
| 91 m = pattern.matchAsPrefix(str, 3); | 91 m = pattern.matchAsPrefix(str, 3); |
| 92 Expect.equals("an", m[0]); | 92 Expect.equals("an", m[0]); |
| 93 Expect.equals(3, m.start); | 93 Expect.equals(3, m.start); |
| 94 Expect.isNull(pattern.matchAsPrefix(str, 4)); | 94 Expect.isNull(pattern.matchAsPrefix(str, 4)); |
| 95 Expect.isNull(pattern.matchAsPrefix(str, 5)); | 95 Expect.isNull(pattern.matchAsPrefix(str, 5)); |
| 96 Expect.isNull(pattern.matchAsPrefix(str, 6)); | 96 Expect.isNull(pattern.matchAsPrefix(str, 6)); |
| 97 Expect.throws(() => pattern.matchAsPrefix(str, -1)); | 97 Expect.throws(() => pattern.matchAsPrefix(str, -1)); |
| 98 Expect.throws(() => pattern.matchAsPrefix(str, 7)); | 98 Expect.throws(() => pattern.matchAsPrefix(str, 7)); |
| 99 } | 99 } |
| OLD | NEW |