| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import "dart:typed_data"; | 6 import "dart:typed_data"; |
| 7 | 7 |
| 8 main() { | 8 main() { |
| 9 iter(count, [values]) => values is List | 9 iter(count, [values]) => values is List |
| 10 ? new Iterable.generate(count, (x) => values[x]) | 10 ? new Iterable.generate(count, (x) => values[x]) |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 test("AB", iterable, 0, 2); | 142 test("AB", iterable, 0, 2); |
| 143 test("GH", iterable, 6, 8); | 143 test("GH", iterable, 6, 8); |
| 144 test("DE", iterable, 3, 5); | 144 test("DE", iterable, 3, 5); |
| 145 test("", iterable, 3, 3); | 145 test("", iterable, 3, 3); |
| 146 } | 146 } |
| 147 // Can split surrogates in input, but not a single big code point. | 147 // Can split surrogates in input, but not a single big code point. |
| 148 test(leadSurrogate, [0xDBFF, 0xDFFF], 0, 1); | 148 test(leadSurrogate, [0xDBFF, 0xDFFF], 0, 1); |
| 149 test(tailSurrogate, [0xDBFF, 0xDFFF], 1); | 149 test(tailSurrogate, [0xDBFF, 0xDFFF], 1); |
| 150 test("\u{10FFFF}", [0x10FFFF], 0, 1); | 150 test("\u{10FFFF}", [0x10FFFF], 0, 1); |
| 151 | 151 |
| 152 void testThrowsRange(iterable, [start = 0, end]) { |
| 153 Expect.throws(() => new String.fromCharCodes(iterable, start, end), |
| 154 (e) => e is RangeError); |
| 155 } |
| 156 |
| 152 // Test varying slices of the code units of a string. | 157 // Test varying slices of the code units of a string. |
| 153 testSubstring(string) { | 158 testSubstring(string) { |
| 154 var codes = string.codeUnits; | 159 var codes = string.codeUnits; |
| 155 int length = string.length; | 160 int length = string.length; |
| 156 for (var iterable in [ | 161 for (var iterable in [ |
| 157 iter(length, codes), | 162 iter(length, codes), |
| 158 codes.toList(growable: true), | 163 codes.toList(growable: true), |
| 159 codes.toList(growable: false), | 164 codes.toList(growable: false), |
| 160 new Uint16List(length)..setRange(0, length, codes), | 165 new Uint16List(length)..setRange(0, length, codes), |
| 161 new Int32List(length)..setRange(0, length, codes), | 166 new Int32List(length)..setRange(0, length, codes), |
| 162 new Uint32List(length)..setRange(0, length, codes), | 167 new Uint32List(length)..setRange(0, length, codes), |
| 163 codes, | 168 codes, |
| 164 ]) { | 169 ]) { |
| 165 var newString = new String.fromCharCodes(iterable); | 170 var newString = new String.fromCharCodes(iterable); |
| 166 Expect.equals(string, newString); | 171 Expect.equals(string, newString); |
| 167 for (int i = 0; i < length; i = i * 2 + 1) { | 172 for (int i = 0; i < length; i = i * 2 + 1) { |
| 168 test(string.substring(i), iterable, i); | 173 test(string.substring(i), iterable, i); |
| 169 test(string.substring(0, i), iterable, 0, i); | 174 test(string.substring(0, i), iterable, 0, i); |
| 170 for (int j = 0; i + j < length; j = j * 2 + 1) { | 175 for (int j = 0; i + j < length; j = j * 2 + 1) { |
| 171 test(string.substring(i, i + j), iterable, i, i + j); | 176 test(string.substring(i, i + j), iterable, i, i + j); |
| 172 } | 177 } |
| 173 } | 178 } |
| 174 | 179 |
| 175 Expect.throws(() => new String.fromCharCodes(iterable, -1)); | 180 testThrowsRange(iterable, -1); |
| 176 Expect.throws(() => new String.fromCharCodes(iterable, 0, -1)); | 181 testThrowsRange(iterable, 0, -1); |
| 177 Expect.throws(() => new String.fromCharCodes(iterable, 2, 1)); | 182 testThrowsRange(iterable, 2, 1); |
| 178 Expect.throws(() => new String.fromCharCodes(iterable, 0, length + 1)); | 183 testThrowsRange(iterable, 0, length + 1); |
| 179 Expect.throws(() => new String.fromCharCodes(iterable, length + 1)); | 184 testThrowsRange(iterable, length + 1); |
| 180 Expect.throws(() => new String.fromCharCodes(iterable, length + 1, | 185 testThrowsRange(iterable, length + 1, length + 2); |
| 181 length + 2)); | |
| 182 } | 186 } |
| 183 } | 187 } |
| 184 | 188 |
| 185 testSubstring(""); | 189 testSubstring(""); |
| 186 testSubstring("ABCDEFGH"); | 190 testSubstring("ABCDEFGH"); |
| 187 // length > 128 | 191 // length > 128 |
| 188 testSubstring("ABCDEFGH" * 33); | 192 testSubstring("ABCDEFGH" * 33); |
| 189 testSubstring("\x00" * 357); | 193 testSubstring("\x00" * 357); |
| 190 // length > 128 and non-ASCII. | 194 // length > 128 and non-ASCII. |
| 191 testSubstring("\uFFFD\uFFFE\u{10000}\u{10ffff}c\x00" * 37); | 195 testSubstring("\uFFFD\uFFFE\u{10000}\u{10ffff}c\x00" * 37); |
| 192 } | 196 } |
| OLD | NEW |