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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/core/string.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 main() {
6 test(String s) {
7 Iterable<int> units = s.codeUnits;
8 List<int> expectedUnits = <int>[];
9 for (int i = 0; i < s.length; i++) {
10 expectedUnits.add(s.codeUnitAt(i));
11 }
12
13 Expect.equals(s.length, units.length);
14 for (int i = 0; i < s.length; i++) {
15 Expect.equals(s.codeUnitAt(i), units.elementAt(i));
16 }
17
18 // for-in
19 var res = [];
20 for (int unit in units) {
21 res.add(unit);
22 }
23 Expect.listEquals(expectedUnits, res);
24
25 // .map
26 Expect.listEquals(expectedUnits.map((x) => x.toRadixString(16)).toList(),
27 units.map((x) => x.toRadixString(16)).toList());
28 }
29
30 test("abc");
31 test("\x00\u0000\u{000000}");
32 test("\u{ffff}\u{10000}\u{10ffff}");
33 String string = new String.fromCharCodes(
34 [0xdc00, 0xd800, 61, 0xd800, 0xdc00, 62, 0xdc00, 0xd800]);
35 test(string);
36
37 // Setting position in the middle of a surrogate pair is not allowed.
38 var r = new CodeUnits("\u{10000}");
39 var it = r.iterator;
40 Expect.isTrue(it.moveNext());
41 Expect.equals(0xD800, it.current);
42 Expect.isTrue(it.moveNext());
43 Expect.equals(0xDC00, it.current);
44 }
OLDNEW
« 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