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]) |
11 : new Iterable.generate(count, (x) => values); | 11 : new Iterable.generate(count, (x) => values); |
12 test(expect, iter, [start = 0, end]) { | 12 test(expect, iter, [start = 0, end]) { |
13 Expect.equals(expect, new String.fromCharCodes(iter, start, end)); | 13 var actual = new String.fromCharCodes(iter, start, end); |
| 14 Expect.equals(expect, actual); |
14 } | 15 } |
15 testThrows(iterable, [start = 0, end]) { | 16 testThrows(iterable, [start = 0, end]) { |
16 Expect.throws(() { new String.fromCharCodes(iterable, start, end); }); | 17 Expect.throws(() { new String.fromCharCodes(iterable, start, end); }); |
17 } | 18 } |
18 | 19 |
19 test("", iter(0)); | 20 test("", iter(0)); |
20 test("", []); | 21 test("", []); |
21 test("", const []); | 22 test("", const []); |
22 test("", new List(0)); | 23 test("", new List(0)); |
23 test("", new Uint8List(0)); | 24 test("", new Uint8List(0)); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 testSubstring("ABCDEFGH" * 33); | 193 testSubstring("ABCDEFGH" * 33); |
193 testSubstring("\x00" * 357); | 194 testSubstring("\x00" * 357); |
194 // length > 128 and non-ASCII. | 195 // length > 128 and non-ASCII. |
195 testSubstring("\uFFFD\uFFFE\u{10000}\u{10ffff}c\x00" * 37); | 196 testSubstring("\uFFFD\uFFFE\u{10000}\u{10ffff}c\x00" * 37); |
196 | 197 |
197 // Large List. | 198 // Large List. |
198 var megaList = ("abcde" * 200000).codeUnits.toList(); | 199 var megaList = ("abcde" * 200000).codeUnits.toList(); |
199 test("abcde" * 199998, megaList, 5, 999995); | 200 test("abcde" * 199998, megaList, 5, 999995); |
200 // Large Uint8List. | 201 // Large Uint8List. |
201 test("abcde" * 199998, new Uint8List.fromList(megaList), 5, 999995); | 202 test("abcde" * 199998, new Uint8List.fromList(megaList), 5, 999995); |
| 203 |
| 204 const cLatin1 = const [0x00, 0xff]; |
| 205 const cUtf16 = const [0x00, 0xffff, 0xdfff, 0xdbff, 0xdfff, 0xdbff]; |
| 206 const cCodepoints = const [0x00, 0xffff, 0xdfff, 0x10ffff, 0xdbff]; |
| 207 List gLatin1 = cLatin1.toList(growable: true); |
| 208 List gUtf16 = cUtf16.toList(growable: true); |
| 209 List gCodepoints = cCodepoints.toList(growable: true); |
| 210 List fLatin1 = cLatin1.toList(growable: false); |
| 211 List fUtf16 = cUtf16.toList(growable: false); |
| 212 List fCodepoints = cCodepoints.toList(growable: false); |
| 213 Uint8List bLatin1 = new Uint8List(2)..setRange(0, 2, cLatin1); |
| 214 Uint16List wLatin1 = new Uint16List(2)..setRange(0, 2, cLatin1); |
| 215 Uint16List wUtf16 = new Uint16List(6)..setRange(0, 6, cUtf16); |
| 216 Uint32List lLatin1 = new Uint32List(2)..setRange(0, 2, cLatin1); |
| 217 Uint32List lUtf16 = new Uint32List(6)..setRange(0, 6, cUtf16); |
| 218 Uint32List lCodepoints = new Uint32List(5)..setRange(0, 5, cCodepoints); |
| 219 Uint8List bvLatin1 = new Uint8List.view(bLatin1.buffer); |
| 220 Uint16List wvLatin1 = new Uint16List.view(wLatin1.buffer); |
| 221 Uint16List wvUtf16 = new Uint16List.view(wUtf16.buffer); |
| 222 Uint32List lvLatin1 = new Uint32List.view(lLatin1.buffer); |
| 223 Uint32List lvUtf16 = new Uint32List.view(lUtf16.buffer); |
| 224 Uint32List lvCodepoints = new Uint32List.view(lCodepoints.buffer); |
| 225 var buffer = new Uint8List(200).buffer; |
| 226 Uint8List bbLatin1 = |
| 227 new Uint8List.view(buffer, 3, 2)..setAll(0, bLatin1); |
| 228 Uint16List wbLatin1 = |
| 229 new Uint16List.view(buffer, 8, 2)..setAll(0, wLatin1); |
| 230 Uint16List wbUtf16 = |
| 231 new Uint16List.view(buffer, 16, 6)..setAll(0, wUtf16); |
| 232 Uint32List lbLatin1 = |
| 233 new Uint32List.view(buffer, 32, 2)..setAll(0, lLatin1); |
| 234 Uint32List lbUtf16 = |
| 235 new Uint32List.view(buffer, 64, 6)..setAll(0, lUtf16); |
| 236 Uint32List lbCodepoints = |
| 237 new Uint32List.view(buffer, 128, 5)..setAll(0, lCodepoints); |
| 238 |
| 239 String sLatin1 = "\x00\xff"; |
| 240 String sUnicode = |
| 241 "\x00\uffff$tailSurrogate$leadSurrogate$tailSurrogate$leadSurrogate"; |
| 242 for (int i = 0; i < 2; i++) { |
| 243 for (int j = i + 1; j < 2; j++) { |
| 244 test(sLatin1.substring(i, j), cLatin1, i, j); |
| 245 test(sLatin1.substring(i, j), gLatin1, i, j); |
| 246 test(sLatin1.substring(i, j), fLatin1, i, j); |
| 247 test(sLatin1.substring(i, j), bLatin1, i, j); |
| 248 test(sLatin1.substring(i, j), wLatin1, i, j); |
| 249 test(sLatin1.substring(i, j), lLatin1, i, j); |
| 250 test(sLatin1.substring(i, j), bvLatin1, i, j); |
| 251 test(sLatin1.substring(i, j), wvLatin1, i, j); |
| 252 test(sLatin1.substring(i, j), lvLatin1, i, j); |
| 253 test(sLatin1.substring(i, j), bbLatin1, i, j); |
| 254 test(sLatin1.substring(i, j), wbLatin1, i, j); |
| 255 test(sLatin1.substring(i, j), lbLatin1, i, j); |
| 256 } |
| 257 } |
| 258 for (int i = 0; i < 6; i++) { |
| 259 for (int j = i + 1; j < 6; j++) { |
| 260 test(sUnicode.substring(i, j), cUtf16, i, j); |
| 261 test(sUnicode.substring(i, j), gUtf16, i, j); |
| 262 test(sUnicode.substring(i, j), fUtf16, i, j); |
| 263 test(sUnicode.substring(i, j), wUtf16, i, j); |
| 264 test(sUnicode.substring(i, j), lUtf16, i, j); |
| 265 test(sUnicode.substring(i, j), wvUtf16, i, j); |
| 266 test(sUnicode.substring(i, j), lvUtf16, i, j); |
| 267 test(sUnicode.substring(i, j), wbUtf16, i, j); |
| 268 test(sUnicode.substring(i, j), lbUtf16, i, j); |
| 269 } |
| 270 } |
| 271 for (int i = 0; i < 5; i++) { |
| 272 for (int j = i + 1; j < 5; j++) { |
| 273 int stringEnd = j < 4 ? j : j + 1; |
| 274 test(sUnicode.substring(i, stringEnd), cCodepoints, i, j); |
| 275 test(sUnicode.substring(i, stringEnd), gCodepoints, i, j); |
| 276 test(sUnicode.substring(i, stringEnd), fCodepoints, i, j); |
| 277 test(sUnicode.substring(i, stringEnd), lCodepoints, i, j); |
| 278 test(sUnicode.substring(i, stringEnd), lvCodepoints, i, j); |
| 279 test(sUnicode.substring(i, stringEnd), lbCodepoints, i, j); |
| 280 } |
| 281 } |
202 } | 282 } |
OLD | NEW |