| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 testTwoMatches() { | 43 testTwoMatches() { |
| 44 String helloPattern = "hello"; | 44 String helloPattern = "hello"; |
| 45 Iterable<Match> matches = helloPattern.allMatches(str); | 45 Iterable<Match> matches = helloPattern.allMatches(str); |
| 46 | 46 |
| 47 int count = 0; | 47 int count = 0; |
| 48 int start = 0; | 48 int start = 0; |
| 49 for (var match in matches) { | 49 for (var match in matches) { |
| 50 count++; | 50 count++; |
| 51 Expect.equals(str.indexOf('hello', start), match.start); | 51 Expect.equals(str.indexOf('hello', start), match.start); |
| 52 Expect.equals( | 52 Expect.equals(str.indexOf('hello', start) + helloPattern.length, match.end); |
| 53 str.indexOf('hello', start) + helloPattern.length, match.end); | |
| 54 Expect.equals(helloPattern, match.pattern); | 53 Expect.equals(helloPattern, match.pattern); |
| 55 Expect.equals(str, match.input); | 54 Expect.equals(str, match.input); |
| 56 Expect.equals(helloPattern, match[0]); | 55 Expect.equals(helloPattern, match[0]); |
| 57 Expect.equals(0, match.groupCount); | 56 Expect.equals(0, match.groupCount); |
| 58 start = match.end; | 57 start = match.end; |
| 59 } | 58 } |
| 60 Expect.equals(2, count); | 59 Expect.equals(2, count); |
| 61 } | 60 } |
| 62 | 61 |
| 63 testEmptyPattern() { | 62 testEmptyPattern() { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 String p = "ass"; | 102 String p = "ass"; |
| 104 String s = "assassin"; | 103 String s = "assassin"; |
| 105 Expect.equals(2, p.allMatches(s).length); | 104 Expect.equals(2, p.allMatches(s).length); |
| 106 Expect.equals(2, p.allMatches(s, 0).length); | 105 Expect.equals(2, p.allMatches(s, 0).length); |
| 107 Expect.equals(1, p.allMatches(s, 1).length); | 106 Expect.equals(1, p.allMatches(s, 1).length); |
| 108 Expect.equals(0, p.allMatches(s, 4).length); | 107 Expect.equals(0, p.allMatches(s, 4).length); |
| 109 Expect.equals(0, p.allMatches(s, s.length).length); | 108 Expect.equals(0, p.allMatches(s, s.length).length); |
| 110 Expect.throws(() => p.allMatches(s, -1)); | 109 Expect.throws(() => p.allMatches(s, -1)); |
| 111 Expect.throws(() => p.allMatches(s, s.length + 1)); | 110 Expect.throws(() => p.allMatches(s, s.length + 1)); |
| 112 } | 111 } |
| OLD | NEW |