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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
(Empty)
1 library splitting_strings_test;
2
3 import 'package:unittest/unittest.dart';
4
5 void main() {
6 group('splitting a string', () {
7 var clef = '\u{1F3BC}';
8 var smileyFace = '\u263A';
9 var happy = 'I am $smileyFace';
10
11 group('using split(string)', () {
12 test('on code-unit boundary', () {
13 expect('Dart'.split(''), equals(['D', 'a', 'r', 't']));
14 expect(smileyFace.split('').length, equals(1));
15 expect(clef.split('').length, equals(2));
16 });
17
18 test('on rune boundary', () {
19 expect(happy.runes.map((charCode) => new String.fromCharCode(charCode)). toList(),
20 equals(['I', ' ', 'a', 'm', ' ', '\u263A']));
21 });
22 });
23
24 group('using split(regExp)', () {
25 var nums = "2/7 3 4/5 3~/5";
26 var numsRegExp = new RegExp(r'(\s|/|~/)');
27 test('', () {
28 expect(nums.split(numsRegExp),
29 equals(['2', '7', '3', '4', '5', '3', '5']));
30 });
31 });
32
33 group('using splitMapJoin(regExp)', () {
34 expect('Eats SHOOTS leaves'.splitMapJoin((new RegExp(r'SHOOTS')),
35 onMatch: (m) => '*${m.group(0).toLowerCase()}*',
36 onNonMatch: (n) => n.toUpperCase()
37 ), equals('EATS *shoots* LEAVES'));
38 });
39 });
40 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698