Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: tests/standalone/typed_data_test.dart

Issue 856053002: Let Uint16List.setRange detect a String.codeUnits object, and copy directly from the string. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/internal/internal.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Dart test program for testing typed data. 5 // Dart test program for testing typed data.
6 6
7 // VMOptions=--optimization_counter_threshold=10 7 // VMOptions=--optimization_counter_threshold=10
8 8
9 // Library tag to be able to run in html test framework. 9 // Library tag to be able to run in html test framework.
10 library TypedDataTest; 10 library TypedDataTest;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 typed_data.setRange(1, 3, const [8, 9]); 141 typed_data.setRange(1, 3, const [8, 9]);
142 Expect.equals(20, typed_data[0]); 142 Expect.equals(20, typed_data[0]);
143 Expect.equals(8, typed_data[1]); 143 Expect.equals(8, typed_data[1]);
144 Expect.equals(9, typed_data[2]); 144 Expect.equals(9, typed_data[2]);
145 } 145 }
146 146
147 void testSetRange() { 147 void testSetRange() {
148 testSetRangeHelper(new Uint8List(3)); 148 testSetRangeHelper(new Uint8List(3));
149 testSetRangeHelper(new Uint8ClampedList(3)); 149 testSetRangeHelper(new Uint8ClampedList(3));
150 testSetRangeHelper(new Uint16List(3));
151 testSetRangeHelper(new Int16List(3));
152
153 var list = new Uint8List(4);
154 list.setRange(0, 4, "abcd".codeUnits, 0);
155 Expect.listEquals(list, "abcd".codeUnits);
156 list = new Uint16List(4);
157 list.setRange(0, 4, "abcd".codeUnits, 0);
158 Expect.listEquals(list, "abcd".codeUnits);
159 list.setRange(0, 4, "\xff\u0100\uffff\x00".codeUnits, 0);
160 Expect.listEquals(list, "\xff\u0100\uffff\x00".codeUnits);
161 list = new Int16List(4);
162 list.setRange(0, 4, "abcd".codeUnits, 0);
163 Expect.listEquals(list, "abcd".codeUnits);
164 list.setRange(0, 4, "\xff\u0100\u7fff\x00".codeUnits, 0);
165 Expect.listEquals(list, "\xff\u0100\u7fff\x00".codeUnits);
150 } 166 }
151 167
152 class C { 168 class C {
153 final x; 169 final x;
154 C(this.x); 170 C(this.x);
155 operator<(o) => false; 171 operator<(o) => false;
156 operator>=(o) => false; 172 operator>=(o) => false;
157 operator*(o) => x; 173 operator*(o) => x;
158 } 174 }
159 175
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 doubleLists.add(new Float32List.fromList(doubleList)); 438 doubleLists.add(new Float32List.fromList(doubleList));
423 doubleLists.add(new Float64List.fromList(doubleList)); 439 doubleLists.add(new Float64List.fromList(doubleList));
424 for (var ints in intLists) { 440 for (var ints in intLists) {
425 for (var doubles in doubleLists) { 441 for (var doubles in doubleLists) {
426 Expect.throws(() => ints[0] = doubles[0]); 442 Expect.throws(() => ints[0] = doubles[0]);
427 Expect.throws(() => doubles[0] = ints[0]); 443 Expect.throws(() => doubles[0] = ints[0]);
428 } 444 }
429 } 445 }
430 } 446 }
431 447
448 void testStrings() {
449 test(list) {
450 Uint16List uints = new Uint16List(list.length)..setAll(0, list);
451 String string = new String.fromCharCodes(list);
452 for (int i = 0; i < string.length; i++) {
453 for (int j = i; j < string.length; j++) {
454 int length = j - i;
455 {
456 Uint16List copy = new Uint16List(length);
457 copy.setRange(0, length, string.codeUnits, i);
458 Expect.listEquals(uints.sublist(i, j), copy);
459 }
460 {
461 Uint8List buffer = new Uint8List(length * 2 + 8);
462 Uint16List copy = new Uint16List.view(buffer.buffer, 4, length);
463 copy.setRange(0, length, string.codeUnits, i);
464 Expect.listEquals(uints.sublist(i, j), copy);
465 }
466 {
467 String copy = new String.fromCharCodes(uints, i, j);
468 Expect.equals(string.substring(i, j), copy);
469 }
470 }
471 }
472 }
473 test([]);
474 test([0x00, 0x7f, 0xff]);
475 test([0x00, 0xdfff, 0xffff]);
476 test([0xd800, 0xdc00, 0x20, 0xdbff, 0xdfff]);
477 }
478
432 main() { 479 main() {
433 for (int i = 0; i < 20; i++) { 480 for (int i = 0; i < 20; i++) {
434 testCreateUint8TypedData(); 481 testCreateUint8TypedData();
435 testCreateClampedUint8TypedData(); 482 testCreateClampedUint8TypedData();
436 testTypedDataRange(false); 483 testTypedDataRange(false);
437 testUnsignedTypedDataRange(false); 484 testUnsignedTypedDataRange(false);
438 testClampedUnsignedTypedDataRange(false); 485 testClampedUnsignedTypedDataRange(false);
439 testSetRange(); 486 testSetRange();
440 testIndexOutOfRange(); 487 testIndexOutOfRange();
441 testIndexOf(); 488 testIndexOf();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 525
479 var float64list = new Float64List(16); 526 var float64list = new Float64List(16);
480 testSetAtIndex(float64list, 1.4260258159703532e-105, true); 527 testSetAtIndex(float64list, 1.4260258159703532e-105, true);
481 testGetAtIndex(float64list, 1.4260258159703532e-105); 528 testGetAtIndex(float64list, 1.4260258159703532e-105);
482 } 529 }
483 testTypedDataRange(true); 530 testTypedDataRange(true);
484 testUnsignedTypedDataRange(true); 531 testUnsignedTypedDataRange(true);
485 testViewCreation(); 532 testViewCreation();
486 testWhere(); 533 testWhere();
487 testCreationFromList(); 534 testCreationFromList();
535 testStrings();
536 testSetRange();
488 } 537 }
OLDNEW
« no previous file with comments | « sdk/lib/internal/internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698