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

Unified Diff: recipes/test/core/strings/substituting_strings_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/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'));
+ });
+
+ });
+}
« no previous file with comments | « recipes/test/core/strings/subscripting_a_string_test.dart ('k') | recipes/test/core/strings/using_raw_strings_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698