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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 } | 187 } |
187 } | 188 } |
188 | 189 |
189 testSubstring(""); | 190 testSubstring(""); |
190 testSubstring("ABCDEFGH"); | 191 testSubstring("ABCDEFGH"); |
191 // length > 128 | 192 // length > 128 |
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); |
197 | |
198 const cLatin1 = const [0x00, 0xff]; | |
199 const cUtf16 = const [0x00, 0xffff, 0xdfff, 0xdbff, 0xdfff, 0xdbff]; | |
200 const cCodepoints = const [0x00, 0xffff, 0xdfff, 0x10ffff, 0xdbff]; | |
201 List gLatin1 = cLatin1.toList(growable: true); | |
202 List gUtf16 = cUtf16.toList(growable: true); | |
203 List gCodepoints = cCodepoints.toList(growable: true); | |
204 List fLatin1 = cLatin1.toList(growable: false); | |
205 List fUtf16 = cUtf16.toList(growable: false); | |
206 List fCodepoints = cCodepoints.toList(growable: false); | |
207 Uint8List bLatin1 = new Uint8List(2)..setRange(0, 2, cLatin1); | |
208 Uint16List wLatin1 = new Uint16List(2)..setRange(0, 2, cLatin1); | |
209 Uint16List wUtf16 = new Uint16List(6)..setRange(0, 6, cUtf16); | |
210 Uint32List lLatin1 = new Uint32List(2)..setRange(0, 2, cLatin1); | |
211 Uint32List lUtf16 = new Uint32List(6)..setRange(0, 6, cUtf16); | |
212 Uint32List lCodepoints = new Uint32List(5)..setRange(0, 5, cCodepoints); | |
213 String sLatin1 = "\x00\xff"; | |
214 String sUnicode = | |
215 "\x00\uffff$tailSurrogate$leadSurrogate$tailSurrogate$leadSurrogate"; | |
216 for (int i = 0; i < 2; i++) { | |
217 for (int j = i + 1; j < 2; j++) { | |
218 test(sLatin1.substring(i, j), cLatin1, i, j); | |
219 test(sLatin1.substring(i, j), gLatin1, i, j); | |
220 test(sLatin1.substring(i, j), fLatin1, i, j); | |
221 test(sLatin1.substring(i, j), bLatin1, i, j); | |
222 test(sLatin1.substring(i, j), wLatin1, i, j); | |
223 test(sLatin1.substring(i, j), lLatin1, i, j); | |
224 } | |
225 } | |
226 for (int i = 0; i < 6; i++) { | |
227 for (int j = i + 1; j < 6; j++) { | |
228 test(sUnicode.substring(i, j), cUtf16, i, j); | |
229 test(sUnicode.substring(i, j), gUtf16, i, j); | |
230 test(sUnicode.substring(i, j), fUtf16, i, j); | |
231 test(sUnicode.substring(i, j), wUtf16, i, j); | |
232 test(sUnicode.substring(i, j), lUtf16, i, j); | |
233 } | |
234 } | |
235 for (int i = 0; i < 5; i++) { | |
236 for (int j = i + 1; j < 5; j++) { | |
237 int stringEnd = j < 4 ? j : j + 1; | |
238 test(sUnicode.substring(i, stringEnd), cCodepoints, i, j); | |
239 test(sUnicode.substring(i, stringEnd), gCodepoints, i, j); | |
240 test(sUnicode.substring(i, stringEnd), fCodepoints, i, j); | |
241 test(sUnicode.substring(i, stringEnd), lCodepoints, i, j); | |
242 } | |
243 } | |
siva
2015/01/20 23:50:26
Does this also test the ExternalTypedData and Uint
Lasse Reichstein Nielsen
2015/01/22 07:16:33
No. I'll add Uint16ListViev. Is there a way to cre
siva
2015/01/23 01:06:33
You would have to create it in native code and pas
| |
196 } | 244 } |
OLD | NEW |