-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
24 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ void main() { | |
final pattern = const EmailMatcher().pattern; | ||
final regExp = RegExp(pattern); | ||
|
||
test('matches email address despite no letters around it', () { | ||
test('matches email address when there are no letters around it', () { | ||
const address = '[email protected]'; | ||
final matches = regExp.allMatches(address); | ||
expect(matches, hasLength(1)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,11 +28,8 @@ void main() { | |
expect(stopwatch.elapsedMicroseconds, lessThan(1000)); | ||
}); | ||
|
||
test('parsed correctly with default matchers', () async { | ||
test('parsed correctly with preset matchers', () async { | ||
final elements = await parser.parse( | ||
// "john.doe" in the email address is parsed as URL | ||
// mistakenly if UrlMatcher is specified before | ||
// EmailMatcher in the list of default matchers. | ||
'abc https://example.com/sample.jpg. def\n' | ||
'[email protected] 911', | ||
); | ||
|
@@ -64,6 +61,27 @@ void main() { | |
expect(elements[5].matcherType, TelMatcher); | ||
}); | ||
|
||
test('earlier matcher is used if multiple ones match a string', () async { | ||
final elements1 = await TextParser( | ||
matchers: const [EmailMatcher(), UrlLikeMatcher()], | ||
).parse('abc [email protected]'); | ||
|
||
expect(elements1, hasLength(2)); | ||
expect(elements1[1].matcherType, EmailMatcher); | ||
|
||
final elements2 = await TextParser( | ||
matchers: const [UrlLikeMatcher(), EmailMatcher()], | ||
).parse('abc [email protected]'); | ||
|
||
expect(elements2, hasLength(4)); | ||
expect(elements2[1].text, 'john.doe'); | ||
expect(elements2[1].matcherType, UrlLikeMatcher); | ||
expect(elements2[2].text, '@'); | ||
expect(elements2[2].matcherType, TextMatcher); | ||
expect(elements2[3].text, 'example.com'); | ||
expect(elements2[3].matcherType, UrlLikeMatcher); | ||
}); | ||
|
||
test('parsed into a single element if there is no match', () async { | ||
final elements = await parser.parse('abcde'); | ||
|
||
|