Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: tests/corelib/string_pattern_test.dart

Issue 15709018: Proof-of-concept matchPrefix on Pattern. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed other comments. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/core/pattern.dart ('k') | tests/language/reg_exp_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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() {
11 testNoMatch(); 11 testNoMatch();
12 testOneMatch(); 12 testOneMatch();
13 testTwoMatches(); 13 testTwoMatches();
14 testEmptyPattern(); 14 testEmptyPattern();
15 testEmptyString(); 15 testEmptyString();
16 testEmptyPatternAndString(); 16 testEmptyPatternAndString();
17 testMatchAsPrefix();
17 } 18 }
18 19
19 testNoMatch() { 20 testNoMatch() {
20 // Also tests that RegExp groups don't work. 21 // Also tests that RegExp groups don't work.
21 String helloPattern = "with (hello)"; 22 String helloPattern = "with (hello)";
22 Iterable<Match> matches = helloPattern.allMatches(str); 23 Iterable<Match> matches = helloPattern.allMatches(str);
23 Expect.isFalse(matches.iterator.moveNext()); 24 Expect.isFalse(matches.iterator.moveNext());
24 } 25 }
25 26
26 testOneMatch() { 27 testOneMatch() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 Iterable<Match> matches = pattern.allMatches(str); 71 Iterable<Match> matches = pattern.allMatches(str);
71 Expect.isFalse(matches.iterator.moveNext()); 72 Expect.isFalse(matches.iterator.moveNext());
72 } 73 }
73 74
74 testEmptyPatternAndString() { 75 testEmptyPatternAndString() {
75 String pattern = ""; 76 String pattern = "";
76 String str = ""; 77 String str = "";
77 Iterable<Match> matches = pattern.allMatches(str); 78 Iterable<Match> matches = pattern.allMatches(str);
78 Expect.isTrue(matches.iterator.moveNext()); 79 Expect.isTrue(matches.iterator.moveNext());
79 } 80 }
81
82 testMatchAsPrefix() {
83 String pattern = "an";
84 String str = "banana";
85 Expect.isNull(pattern.matchAsPrefix(str));
86 Expect.isNull(pattern.matchAsPrefix(str, 0));
87 var m = pattern.matchAsPrefix(str, 1);
88 Expect.equals("an", m[0]);
89 Expect.equals(1, m.start);
90 Expect.isNull(pattern.matchAsPrefix(str, 2));
91 m = pattern.matchAsPrefix(str, 3);
92 Expect.equals("an", m[0]);
93 Expect.equals(3, m.start);
94 Expect.isNull(pattern.matchAsPrefix(str, 4));
95 Expect.isNull(pattern.matchAsPrefix(str, 5));
96 Expect.isNull(pattern.matchAsPrefix(str, 6));
97 Expect.throws(() => pattern.matchAsPrefix(str, -1));
98 Expect.throws(() => pattern.matchAsPrefix(str, 7));
99 }
OLDNEW
« no previous file with comments | « sdk/lib/core/pattern.dart ('k') | tests/language/reg_exp_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698