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

Unified Diff: recipes/test/core/strings/handling_extended_characters_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/handling_extended_characters_test.dart
diff --git a/recipes/test/core/strings/handling_extended_characters_test.dart b/recipes/test/core/strings/handling_extended_characters_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..385135cabd49a929bc7c5c50a9bcf33077bd1187
--- /dev/null
+++ b/recipes/test/core/strings/handling_extended_characters_test.dart
@@ -0,0 +1,41 @@
+library handling_extended_characters_test;
+
+import 'package:unittest/unittest.dart';
+
+print(obj) => obj;
+
+void main() {
+ var clef = '\u{1F3BC}';
+ group('creating an extended character', () {
+ test('using a rune', () {
+ expect(print(clef), equals('🎼'));
+ });
+ });
+
+ group('accessing runes and code units', () {
+ test('', () {
+ expect(clef.codeUnits.map((codeUnit) => codeUnit.toRadixString(16)), equals(['d83c', 'dfbc']));
+ expect(clef.runes.map((rune) => rune.toRadixString(16)).toList(), equals(['1f3bc']));
+ });
+ });
+
+ group('accessing length', () {
+ test('', () {
+ expect(print(clef.length), equals(2));
+ expect(print(clef.codeUnits.length), equals(2));
+ expect(print(clef.runes.length), equals(1));
+ });
+ });
+
+ group('subscripting', () {
+ test('', () {
+ expect(print(clef.runes.first.toRadixString(16)), equals('1f3bc'));
+ expect(print(clef.runes.toList()[0].toRadixString(16)), equals('1f3bc'));
+ // This test will never pass because clef[0] is an illegal string.
+ // expect(print(clef[0]), equals('?'));
+ expect(print(clef.codeUnits[0]), equals(55356));
+ expect(clef.runes.toList()[0], equals(127932));
+ });
+ });
+}
+
« no previous file with comments | « recipes/test/core/strings/finding_regexp_matches_test.dart ('k') | recipes/test/core/strings/incrementally_building_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698