Index: recipes/test/core/strings/substituting_strings_test.dart |
diff --git a/recipes/test/core/strings/substituting_strings_test.dart b/recipes/test/core/strings/substituting_strings_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d7eca49bf3e374b8f5e2776ceeaa284aa2b3cc7a |
--- /dev/null |
+++ b/recipes/test/core/strings/substituting_strings_test.dart |
@@ -0,0 +1,25 @@ |
+library substituting_strings_test; |
+ |
+import 'package:unittest/unittest.dart'; |
+ |
+void main() { |
+ group('substituting strings based on regExp matches', () { |
+ test('using replaceAll()', () { |
+ expect('resume'.replaceAll(new RegExp(r'e'), '\u00E9'), equals('résumé')); |
+ }); |
+ |
+ test('using replaceFirst()', () { |
+ expect('0.0001'.replaceFirst(new RegExp(r'0+'), ''), equals('.0001')); |
+ }); |
+ |
+ test('using replaceAllMapped()', () { |
+ var heart = '\u2661'; |
+ var string = "I like Ike but I $heart Lucy"; |
+ var regExp = new RegExp(r'[A-Z]\w+'); |
+ expect(string.replaceAllMapped( |
+ regExp, (match) => match.group(0).toUpperCase()), |
+ equals('I like IKE but I ♡ LUCY')); |
+ }); |
+ |
+ }); |
+} |