| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 main() { | 5 main() { |
| 6 test(String s) { | 6 test(String s) { |
| 7 Iterable<int> units = s.codeUnits; | 7 Iterable<int> units = s.codeUnits; |
| 8 List<int> expectedUnits = <int>[]; | 8 List<int> expectedUnits = <int>[]; |
| 9 for (int i = 0; i < s.length; i++) { | 9 for (int i = 0; i < s.length; i++) { |
| 10 expectedUnits.add(s.codeUnitAt(i)); | 10 expectedUnits.add(s.codeUnitAt(i)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 // .map | 25 // .map |
| 26 Expect.listEquals(expectedUnits.map((x) => x.toRadixString(16)).toList(), | 26 Expect.listEquals(expectedUnits.map((x) => x.toRadixString(16)).toList(), |
| 27 units.map((x) => x.toRadixString(16)).toList()); | 27 units.map((x) => x.toRadixString(16)).toList()); |
| 28 | 28 |
| 29 if (s == "") { | 29 if (s == "") { |
| 30 Expect.throws(() => units.first, (e) => e is StateError); | 30 Expect.throws(() => units.first, (e) => e is StateError); |
| 31 Expect.throws(() => units.last, (e) => e is StateError); | 31 Expect.throws(() => units.last, (e) => e is StateError); |
| 32 Expect.throws(() => units[0], (e) => e is RangeError); | 32 Expect.throws(() => units[0], (e) => e is RangeError); |
| 33 Expect.throws(() => units[0] = 499, (e) => e is UnsupportedError); | 33 Expect.throws(() => units[0] = 499, (e) => e is UnsupportedError); |
| 34 Expect.listEquals([], units.getRange(0, 0)); | 34 Expect.listEquals([], units.sublist(0, 0)); |
| 35 Expect.equals(-1, units.indexOf(42)); | 35 Expect.equals(-1, units.indexOf(42)); |
| 36 Expect.equals(-1, units.lastIndexOf(499)); | 36 Expect.equals(-1, units.lastIndexOf(499)); |
| 37 } else { | 37 } else { |
| 38 Expect.equals(s.codeUnitAt(0), units.first); | 38 Expect.equals(s.codeUnitAt(0), units.first); |
| 39 Expect.equals(s.codeUnitAt(s.length - 1), units.last); | 39 Expect.equals(s.codeUnitAt(s.length - 1), units.last); |
| 40 Expect.equals(s.codeUnitAt(0), units[0]); | 40 Expect.equals(s.codeUnitAt(0), units[0]); |
| 41 Expect.throws(() { units[0] = 499; }, (e) => e is UnsupportedError); | 41 Expect.throws(() { units[0] = 499; }, (e) => e is UnsupportedError); |
| 42 List<int> sub = units.getRange(1, units.length - 1); | 42 List<int> sub = units.sublist(1); |
| 43 Expect.listEquals(s.substring(1, s.length).codeUnits, sub); | 43 Expect.listEquals(s.substring(1, s.length).codeUnits, sub); |
| 44 Expect.equals(-1, units.indexOf(-1)); | 44 Expect.equals(-1, units.indexOf(-1)); |
| 45 Expect.equals(0, units.indexOf(units[0])); | 45 Expect.equals(0, units.indexOf(units[0])); |
| 46 Expect.equals(-1, units.lastIndexOf(-1)); | 46 Expect.equals(-1, units.lastIndexOf(-1)); |
| 47 Expect.equals(units.length - 1, units.lastIndexOf(units[units.length - 1])
); | 47 Expect.equals(units.length - 1, units.lastIndexOf(units[units.length - 1])
); |
| 48 } | 48 } |
| 49 | 49 |
| 50 Iterable reversed = units.reversed; | 50 Iterable reversed = units.reversed; |
| 51 int i = units.length - 1; | 51 int i = units.length - 1; |
| 52 for (int codeUnit in reversed) { | 52 for (int codeUnit in reversed) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 66 test(string); | 66 test(string); |
| 67 | 67 |
| 68 // Reading each unit of a surrogate pair works. | 68 // Reading each unit of a surrogate pair works. |
| 69 var r = "\u{10000}".codeUnits; | 69 var r = "\u{10000}".codeUnits; |
| 70 var it = r.iterator; | 70 var it = r.iterator; |
| 71 Expect.isTrue(it.moveNext()); | 71 Expect.isTrue(it.moveNext()); |
| 72 Expect.equals(0xD800, it.current); | 72 Expect.equals(0xD800, it.current); |
| 73 Expect.isTrue(it.moveNext()); | 73 Expect.isTrue(it.moveNext()); |
| 74 Expect.equals(0xDC00, it.current); | 74 Expect.equals(0xDC00, it.current); |
| 75 } | 75 } |
| OLD | NEW |