OLD | NEW |
(Empty) | |
| 1 library finding_regexp_matches; |
| 2 |
| 3 import 'package:unittest/unittest.dart'; |
| 4 |
| 5 void main() { |
| 6 group('finding regExp matches', () { |
| 7 var neverEatingThat = 'Not with a fox, not in a box'; |
| 8 var regExp = new RegExp(r'[fb]ox'); |
| 9 |
| 10 test('using allMatches()', () { |
| 11 List matches = regExp.allMatches(neverEatingThat); |
| 12 expect(matches.map((match) => match.group(0)).toList(), equals(['fox', 'bo
x'])); |
| 13 // Finding the number of occurences of a subneverEatingThat. |
| 14 expect(matches.length, equals(2)); |
| 15 }); |
| 16 |
| 17 test('using firstMatch()', () { |
| 18 expect(regExp.firstMatch(neverEatingThat).group(0), equals('fox')); |
| 19 }); |
| 20 |
| 21 test('using neverEatingThatMatch', () { |
| 22 expect(regExp.stringMatch(neverEatingThat), equals('fox')); |
| 23 expect(regExp.stringMatch('I like bagels and lox'), isNull); |
| 24 }); |
| 25 }); |
| 26 } |
| 27 |
OLD | NEW |