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

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

Issue 12335109: Strings recipes for the Dart Cookbook (Closed) Base URL: https://github.com/dart-lang/cookbook.git@master
Patch Set: Fixed typos. Created 7 years, 10 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/splitting_strings_test.dart
diff --git a/recipes/test/core/strings/splitting_strings_test.dart b/recipes/test/core/strings/splitting_strings_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1c892dbd86370a77db34d379844e09e17e4290d4
--- /dev/null
+++ b/recipes/test/core/strings/splitting_strings_test.dart
@@ -0,0 +1,40 @@
+library splitting_strings_test;
+
+import 'package:unittest/unittest.dart';
+
+void main() {
+ group('splitting a string', () {
+ var clef = '\u{1F3BC}';
+ var smileyFace = '\u263A';
+ var happy = 'I am $smileyFace';
+
+ group('using split(string)', () {
+ test('on code-unit boundary', () {
+ expect('Dart'.split(''), equals(['D', 'a', 'r', 't']));
+ expect(smileyFace.split('').length, equals(1));
+ expect(clef.split('').length, equals(2));
+ });
+
+ test('on rune boundary', () {
+ expect(happy.runes.map((charCode) => new String.fromCharCode(charCode)).toList(),
+ equals(['I', ' ', 'a', 'm', ' ', '\u263A']));
+ });
+ });
+
+ group('using split(regExp)', () {
+ var nums = "2/7 3 4/5 3~/5";
+ var numsRegExp = new RegExp(r'(\s|/|~/)');
+ test('', () {
+ expect(nums.split(numsRegExp),
+ equals(['2', '7', '3', '4', '5', '3', '5']));
+ });
+ });
+
+ group('using splitMapJoin(regExp)', () {
+ expect('Eats SHOOTS leaves'.splitMapJoin((new RegExp(r'SHOOTS')),
+ onMatch: (m) => '*${m.group(0).toLowerCase()}*',
+ onNonMatch: (n) => n.toUpperCase()
+ ), equals('EATS *shoots* LEAVES'));
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698