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

Unified Diff: tests/corelib/string_codeunits_test.dart

Issue 12261009: Added implementation of String.codeUnits. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix 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
« no previous file with comments | « sdk/lib/core/string.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/string_codeunits_test.dart
diff --git a/tests/corelib/string_codeunits_test.dart b/tests/corelib/string_codeunits_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..81625c5d186c3bd1787ff71a3401ef89bd44191e
--- /dev/null
+++ b/tests/corelib/string_codeunits_test.dart
@@ -0,0 +1,44 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+main() {
+ test(String s) {
+ Iterable<int> units = s.codeUnits;
+ List<int> expectedUnits = <int>[];
+ for (int i = 0; i < s.length; i++) {
+ expectedUnits.add(s.codeUnitAt(i));
+ }
+
+ Expect.equals(s.length, units.length);
+ for (int i = 0; i < s.length; i++) {
+ Expect.equals(s.codeUnitAt(i), units.elementAt(i));
+ }
+
+ // for-in
+ var res = [];
+ for (int unit in units) {
+ res.add(unit);
+ }
+ Expect.listEquals(expectedUnits, res);
+
+ // .map
+ Expect.listEquals(expectedUnits.map((x) => x.toRadixString(16)).toList(),
+ units.map((x) => x.toRadixString(16)).toList());
+ }
+
+ test("abc");
+ test("\x00\u0000\u{000000}");
+ test("\u{ffff}\u{10000}\u{10ffff}");
+ String string = new String.fromCharCodes(
+ [0xdc00, 0xd800, 61, 0xd800, 0xdc00, 62, 0xdc00, 0xd800]);
+ test(string);
+
+ // Setting position in the middle of a surrogate pair is not allowed.
+ var r = new CodeUnits("\u{10000}");
+ var it = r.iterator;
+ Expect.isTrue(it.moveNext());
+ Expect.equals(0xD800, it.current);
+ Expect.isTrue(it.moveNext());
+ Expect.equals(0xDC00, it.current);
+}
« no previous file with comments | « sdk/lib/core/string.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698