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

Side by Side Diff: tests/corelib/string_runes_test.dart

Issue 12094056: Runes, a bi-directional code-point iterator/iterable. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make rawIndex return null if there is no current rune. 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, List<int> expectedRunes) {
7 Runes runes = s.runes;
8 Expect.identical(s, runes.string);
9
10 // for-in
11 var res = [];
12 for (int rune in runes) {
13 res.add(rune);
14 }
15 Expect.listEquals(expectedRunes, res);
16
17 // manual iteration, backwards.
18 res = [];
19 for (var it = runes.iterator..reset(s.length); it.movePrevious();) {
20 res.add(it.current);
21 }
22 Expect.listEquals(expectedRunes.reversed.toList(), res);
23
24 // Setting rawIndex.
25 RuneIterator it = runes.iterator;
26 it.rawIndex = 1;
27 Expect.equals(expectedRunes[1], it.current);
28
29 it = runes.iterator;
30 it.moveNext();
31 Expect.equals(0, it.rawIndex);
32 it.moveNext();
33 Expect.equals(1, it.rawIndex);
34 it.moveNext();
35 Expect.isTrue(1 < it.rawIndex);
36 it.rawIndex = 1;
37 Expect.equals(1, it.rawIndex);
38 Expect.equals(expectedRunes[1], it.current);
39
40 // Reset, moveNext.
41 it.reset(1);
42 Expect.equals(null, it.rawIndex);
43 Expect.equals(null, it.current);
44 it.moveNext();
45 Expect.equals(1, it.rawIndex);
46 Expect.equals(expectedRunes[1], it.current);
47
48 // Reset, movePrevious.
49 it.reset(1);
50 Expect.equals(null, it.rawIndex);
51 Expect.equals(null, it.current);
52 it.movePrevious();
53 Expect.equals(0, it.rawIndex);
54 Expect.equals(expectedRunes[0], it.current);
55
56 // .map
57 Expect.listEquals(expectedRunes.map((x) => x.toRadixString(16)).toList(),
58 runes.map((x) => x.toRadixString(16)).toList());
59 }
60
61 // First character must be single-code-unit for test.
62 test("abc", [0x61, 0x62, 0x63]);
63 test("\x00\u0000\u{000000}", [0, 0, 0]);
64 test("\u{ffff}\u{10000}\u{10ffff}", [0xffff, 0x10000, 0x10ffff]);
erikcorry 2013/02/13 08:58:54 Can we have at least one test case where the 10 bi
65 String string = new String.fromCharCodes(
66 [0xdc00, 0xd800, 61, 0xd800, 0xdc00, 62, 0xdc00, 0xd800]);
67 test(string, [0xdc00, 0xd800, 61, 0x10000, 62, 0xdc00, 0xd800]);
68
69 // Setting position in the middle of a surrogate pair is not allowed.
70 var r = new Runes("\u{10000}");
71 var it = r.iterator;
72 it.moveNext();
73 Expect.equals(0x10000, it.current);
74
75 // Setting rawIndex inside surrogate pair.
76 Expect.throws(() { it.rawIndex = 1; }, (e) => e is Error);
77 Expect.throws(() { it.reset(1); }, (e) => e is Error);
78 }
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