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

Unified Diff: recipes/test/core/strings/removing_leading_trailing_whitespace_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/removing_leading_trailing_whitespace_test.dart
diff --git a/recipes/test/core/strings/removing_leading_trailing_whitespace_test.dart b/recipes/test/core/strings/removing_leading_trailing_whitespace_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..659f50bfd1028e08c3c33756e7b8ded497bb0a64
--- /dev/null
+++ b/recipes/test/core/strings/removing_leading_trailing_whitespace_test.dart
@@ -0,0 +1,24 @@
+library removing_leading_trailing_whitespace_test;
+
+import "package:unittest/unittest.dart";
+
+void main() {
+ group('trimming whitespace from a string', () {
+ var space = '\n\r\f\t\v';
+ var string = '$space X $space';
+
+ test('', () {
+ expect(string.trim(), equals('X'));
+ });
+
+ test('leading whitespace', () {
+ expect(string.replaceFirst(new RegExp(r'^\s+'), ''), equals('X $space'));
+ });
+
+ test('trailing whitespace', () {
+ expect(string.replaceFirst(new RegExp(r'\s+$'), ''), equals('$space X'));
+ });
+ });
+
+}
+

Powered by Google App Engine
This is Rietveld 408576698