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

Unified Diff: recipes/test/core/strings/processing_a_string_one_character_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/processing_a_string_one_character_test.dart
diff --git a/recipes/test/core/strings/processing_a_string_one_character_test.dart b/recipes/test/core/strings/processing_a_string_one_character_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ac000d04717fec9ea16d19a706519af47a040236
--- /dev/null
+++ b/recipes/test/core/strings/processing_a_string_one_character_test.dart
@@ -0,0 +1,62 @@
+library processing_a_string_one_character_test;
+
+import 'package:unittest/unittest.dart';
+
+print(obj) {
+ return obj;
+}
+
+void main() {
+
+ group('processing a string one character at a time', () {
+ var clef = '\u{1F3BC}';
+ var lang= 'Dart';
+
+ group('using split', () {
+ test('on code-unit boundary', () {
+ expect(lang.split('').map((char) => '*${char}*').toList(),
+ equals(['*D*', '*a*', '*r*', '*t*']));
+
+ var smileyFace = '\u263A';
+ var happy = 'I am $smileyFace';
+ expect(print(happy.split('')), equals(['I', ' ', 'a', 'm', ' ', '☺']));
+ expect(clef.split('').length, equals(2));
+ });
+ });
+
+ group('indexing the string in a loop', () {
+ test('', () {
+ var list = [];
+ for(var i = 0; i < lang.length; i++) {
+ list.add('*${lang[i]}*');
+ }
+ expect(list, equals(['*D*', '*a*', '*r*', '*t*']));
+ });
+
+ test('with an extended character', () {
+ var list = [];
+ for(var i = 0; i < clef.length; i++) {
+ list.add([clef[i], clef[i].runes.first]);
+ }
+ // Because we are dealing with invalid strings, this test can never pass.
+ // expect(print(list.last), equals([[?, 55356], [?, 57276]]));
+ });
+ });
+
+ group('mapping runes', () {
+ test('', () {
+ expect(lang.runes.map((rune) => '*${new String.fromCharCode(rune)}*').toList(),
+ equals(['*D*', '*a*', '*r*', '*t*']));
+
+ var smileyFace = '\u263A';
+ var happy = 'I am $smileyFace';
+ expect(happy.runes.map((rune) => [rune, new String.fromCharCode(rune)]).toList(),
+ equals([ [73, 'I'], [32, ' '], [97, 'a'], [109, 'm'], [32, ' '], [9786, '☺'] ]));
+
+ var subject = '$clef list:';
+ expect(subject.runes.map((rune) => new String.fromCharCode(rune)).toList(),
+ equals(['🎼', ' ', 'l', 'i', 's', 't', ':']));
+ });
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698