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

Unified Diff: recipes/test/core/strings/finding_regexp_matches_test.dart

Issue 12335109: Strings recipes for the Dart Cookbook (Closed) Base URL: https://github.com/dart-lang/cookbook.git@master
Patch Set: Made most changes requested my Kathy. Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: recipes/test/core/strings/finding_regexp_matches_test.dart
diff --git a/recipes/test/core/strings/finding_regexp_matches_test.dart b/recipes/test/core/strings/finding_regexp_matches_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..757c69cfef5a668c086f3e4077e961e9bbc571bd
--- /dev/null
+++ b/recipes/test/core/strings/finding_regexp_matches_test.dart
@@ -0,0 +1,27 @@
+library finding_regexp_matches;
+
+import 'package:unittest/unittest.dart';
+
+void main() {
+ group('finding regExp matches', () {
+ var neverEatingThat = 'Not with a fox, not in a box';
+ var regExp = new RegExp(r'[fb]ox');
+
+ test('using allMatches()', () {
+ List matches = regExp.allMatches(neverEatingThat);
+ expect(matches.map((match) => match.group(0)).toList(), equals(['fox', 'box']));
+ // Finding the number of occurences of a subneverEatingThat.
+ expect(matches.length, equals(2));
+ });
+
+ test('using firstMatch()', () {
+ expect(regExp.firstMatch(neverEatingThat).group(0), equals('fox'));
+ });
+
+ test('using neverEatingThatMatch', () {
+ expect(regExp.stringMatch(neverEatingThat), equals('fox'));
+ expect(regExp.stringMatch('I like bagels and lox'), isNull);
+ });
+ });
+}
+

Powered by Google App Engine
This is Rietveld 408576698