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 String str = "this is a string with hello here and hello there"; | 6 String str = "this is a string with hello here and hello there"; |
7 | 7 |
8 main() { | 8 main() { |
9 testNoMatch(); | 9 testNoMatch(); |
10 testOneMatch(); | 10 testOneMatch(); |
11 testTwoMatches(); | 11 testTwoMatches(); |
12 testEmptyPattern(); | 12 testEmptyPattern(); |
13 testEmptyString(); | 13 testEmptyString(); |
14 testEmptyPatternAndString(); | 14 testEmptyPatternAndString(); |
15 } | 15 } |
16 | 16 |
17 testNoMatch() { | 17 testNoMatch() { |
18 // Also tests that RegExp groups don't work. | 18 // Also tests that RegExp groups don't work. |
19 String helloPattern = "with (hello)"; | 19 String helloPattern = "with (hello)"; |
20 Iterable<Match> matches = helloPattern.allMatches(str); | 20 Iterable<Match> matches = helloPattern.allMatches(str); |
21 Expect.isFalse(matches.iterator().hasNext); | 21 Expect.isFalse(matches.iterator.moveNext()); |
22 } | 22 } |
23 | 23 |
24 testOneMatch() { | 24 testOneMatch() { |
25 String helloPattern = "with hello"; | 25 String helloPattern = "with hello"; |
26 Iterable<Match> matches = helloPattern.allMatches(str); | 26 Iterable<Match> matches = helloPattern.allMatches(str); |
27 var iterator = matches.iterator(); | 27 var iterator = matches.iterator; |
28 Match match = iterator.next(); | 28 Expect.isTrue(iterator.moveNext()); |
29 Expect.isFalse(iterator.hasNext); | 29 Match match = iterator.current; |
| 30 Expect.isFalse(iterator.moveNext()); |
30 Expect.equals(str.indexOf('with', 0), match.start); | 31 Expect.equals(str.indexOf('with', 0), match.start); |
31 Expect.equals(str.indexOf('with', 0) + helloPattern.length, match.end); | 32 Expect.equals(str.indexOf('with', 0) + helloPattern.length, match.end); |
32 Expect.equals(helloPattern, match.pattern); | 33 Expect.equals(helloPattern, match.pattern); |
33 Expect.equals(str, match.str); | 34 Expect.equals(str, match.str); |
34 Expect.equals(helloPattern, match[0]); | 35 Expect.equals(helloPattern, match[0]); |
35 Expect.equals(0, match.groupCount); | 36 Expect.equals(0, match.groupCount); |
36 } | 37 } |
37 | 38 |
38 testTwoMatches() { | 39 testTwoMatches() { |
39 String helloPattern = "hello"; | 40 String helloPattern = "hello"; |
(...skipping 11 matching lines...) Expand all Loading... |
51 Expect.equals(helloPattern, match[0]); | 52 Expect.equals(helloPattern, match[0]); |
52 Expect.equals(0, match.groupCount); | 53 Expect.equals(0, match.groupCount); |
53 start = match.end; | 54 start = match.end; |
54 } | 55 } |
55 Expect.equals(2, count); | 56 Expect.equals(2, count); |
56 } | 57 } |
57 | 58 |
58 testEmptyPattern() { | 59 testEmptyPattern() { |
59 String pattern = ""; | 60 String pattern = ""; |
60 Iterable<Match> matches = pattern.allMatches(str); | 61 Iterable<Match> matches = pattern.allMatches(str); |
61 Expect.isTrue(matches.iterator().hasNext); | 62 Expect.isTrue(matches.iterator.moveNext()); |
62 } | 63 } |
63 | 64 |
64 testEmptyString() { | 65 testEmptyString() { |
65 String pattern = "foo"; | 66 String pattern = "foo"; |
66 String str = ""; | 67 String str = ""; |
67 Iterable<Match> matches = pattern.allMatches(str); | 68 Iterable<Match> matches = pattern.allMatches(str); |
68 Expect.isFalse(matches.iterator().hasNext); | 69 Expect.isFalse(matches.iterator.moveNext()); |
69 } | 70 } |
70 | 71 |
71 testEmptyPatternAndString() { | 72 testEmptyPatternAndString() { |
72 String pattern = ""; | 73 String pattern = ""; |
73 String str = ""; | 74 String str = ""; |
74 Iterable<Match> matches = pattern.allMatches(str); | 75 Iterable<Match> matches = pattern.allMatches(str); |
75 Expect.isTrue(matches.iterator().hasNext); | 76 Expect.isTrue(matches.iterator.moveNext()); |
76 } | 77 } |
OLD | NEW |