OLD | NEW |
(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 } |
OLD | NEW |