-
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
2 changed files
with
50 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:test/test.dart'; | ||
|
||
import 'package:text_parser/text_parser.dart'; | ||
|
||
extension on ExactMatcher { | ||
RegExp toRegExp() { | ||
return RegExp(pattern); | ||
} | ||
} | ||
|
||
void main() { | ||
test('Strings using reserved characters match exactly same strings', () { | ||
const input = 'Assembly BASIC C++? Dart (^*^)/'; | ||
final regExp = ExactMatcher(const ['(^*^)/', 'C++']).toRegExp(); | ||
final matches = regExp.allMatches(input).toList(); | ||
expect(matches, hasLength(2)); | ||
expect(input.substring(matches[0].start, matches[0].end), 'C++?'); | ||
expect(input.substring(matches[1].start, matches[1].end), '(^*^)/'); | ||
}); | ||
|
||
test('Reserved characters are escaped and used as ordinary characters', () { | ||
const input = 'ABCDEF AB.DE+'; | ||
final regExp = ExactMatcher(const ['B.D', 'E+']).toRegExp(); | ||
final matches = regExp.allMatches(input).toList(); | ||
expect(matches, hasLength(2)); | ||
expect(input.substring(matches[0].start, matches[0].end), 'B.D'); | ||
expect(input.substring(matches[1].start, matches[1].end), 'E+'); | ||
}); | ||
} |