@@ -124,7 +124,8 @@ void main() {
124124 final pattern = Nfa .fromString (testData.pattern);
125125 for (final expectData in testData.expects) {
126126 expect (
127- pattern.tryMatch (expectData.input),
127+ pattern.tryMatch (expectData.input, 0 , expectData.input.length) ==
128+ expectData.input.length,
128129 expectData.match,
129130 reason:
130131 '"${testData .pattern }" '
@@ -153,11 +154,40 @@ void main() {
153154 expect (match[0 ], 'aaa' );
154155 expect (match.groups ([0 , 1 ]), ['aaa' , null ]);
155156 });
157+ test ('matchAsPrefix with non-matching input' , () {
158+ final noMatch = pattern.matchAsPrefix ('baaa' );
159+ expect (noMatch, isNull);
160+ });
161+ test ('matchAsPrefix with start index' , () {
162+ final match = pattern.matchAsPrefix ('baaa' , 1 )! ;
163+ expect (match.pattern, pattern);
164+ expect (match.input, 'baaa' );
165+ expect (match.start, 1 );
166+ expect (match.end, 4 );
167+ expect (match.group (0 ), 'aaa' );
168+ });
156169 test ('allMatches' , () {
157- expect (pattern.allMatches ('aaa' ).map ((each) => each[0 ]), [
158- 'aaa' ,
170+ expect (pattern.allMatches ('' ).map ((each) => each[0 ]), []);
171+ expect (pattern.allMatches ('a' ).map ((each) => each[0 ]), ['a' ]);
172+ expect (pattern.allMatches ('aa' ).map ((each) => each[0 ]), ['aa' ]);
173+ expect (pattern.allMatches ('aaa' ).map ((each) => each[0 ]), ['aaa' ]);
174+ expect (pattern.allMatches ('baab' ).map ((each) => each[0 ]), ['aa' ]);
175+ expect (pattern.allMatches ('babaab' ).map ((each) => each[0 ]), ['a' , 'aa' ]);
176+ });
177+ test ('allMatches with start index' , () {
178+ expect (pattern.allMatches ('babaab' , 2 ).map ((each) => each[0 ]), ['aa' ]);
179+ expect (pattern.allMatches ('babaab' , 3 ).map ((each) => each[0 ]), ['aa' ]);
180+ expect (pattern.allMatches ('babaab' , 4 ).map ((each) => each[0 ]), ['a' ]);
181+ });
182+ test ('allMatches with zero-length matches' , () {
183+ final starPattern = Node .fromString (r'a*' ).toNfa ();
184+ expect (starPattern.allMatches ('' ).map ((each) => each[0 ]), ['' ]);
185+ expect (starPattern.allMatches ('b' ).map ((each) => each[0 ]), ['' , '' ]);
186+ expect (starPattern.allMatches ('baab' ).map ((each) => each[0 ]), [
187+ '' ,
159188 'aa' ,
160- 'a' ,
189+ '' ,
190+ '' ,
161191 ]);
162192 });
163193 });
0 commit comments