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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/internal/internal.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/typed_data_test.dart
diff --git a/tests/standalone/typed_data_test.dart b/tests/standalone/typed_data_test.dart
index fa467decae11e43c8abfc4ce8a36144b2e942850..1b44624fee5808fd2f51bcf9ce9911385ee397d8 100644
--- a/tests/standalone/typed_data_test.dart
+++ b/tests/standalone/typed_data_test.dart
@@ -147,6 +147,22 @@ void testSetRangeHelper(typed_data) {
void testSetRange() {
testSetRangeHelper(new Uint8List(3));
testSetRangeHelper(new Uint8ClampedList(3));
+ testSetRangeHelper(new Uint16List(3));
+ testSetRangeHelper(new Int16List(3));
+
+ var list = new Uint8List(4);
+ list.setRange(0, 4, "abcd".codeUnits, 0);
+ Expect.listEquals(list, "abcd".codeUnits);
+ list = new Uint16List(4);
+ list.setRange(0, 4, "abcd".codeUnits, 0);
+ Expect.listEquals(list, "abcd".codeUnits);
+ list.setRange(0, 4, "\xff\u0100\uffff\x00".codeUnits, 0);
+ Expect.listEquals(list, "\xff\u0100\uffff\x00".codeUnits);
+ list = new Int16List(4);
+ list.setRange(0, 4, "abcd".codeUnits, 0);
+ Expect.listEquals(list, "abcd".codeUnits);
+ list.setRange(0, 4, "\xff\u0100\u7fff\x00".codeUnits, 0);
+ Expect.listEquals(list, "\xff\u0100\u7fff\x00".codeUnits);
}
class C {
@@ -429,6 +445,37 @@ testCreationFromList() {
}
}
+void testStrings() {
+ test(list) {
+ Uint16List uints = new Uint16List(list.length)..setAll(0, list);
+ String string = new String.fromCharCodes(list);
+ for (int i = 0; i < string.length; i++) {
+ for (int j = i; j < string.length; j++) {
+ int length = j - i;
+ {
+ Uint16List copy = new Uint16List(length);
+ copy.setRange(0, length, string.codeUnits, i);
+ Expect.listEquals(uints.sublist(i, j), copy);
+ }
+ {
+ Uint8List buffer = new Uint8List(length * 2 + 8);
+ Uint16List copy = new Uint16List.view(buffer.buffer, 4, length);
+ copy.setRange(0, length, string.codeUnits, i);
+ Expect.listEquals(uints.sublist(i, j), copy);
+ }
+ {
+ String copy = new String.fromCharCodes(uints, i, j);
+ Expect.equals(string.substring(i, j), copy);
+ }
+ }
+ }
+ }
+ test([]);
+ test([0x00, 0x7f, 0xff]);
+ test([0x00, 0xdfff, 0xffff]);
+ test([0xd800, 0xdc00, 0x20, 0xdbff, 0xdfff]);
+}
+
main() {
for (int i = 0; i < 20; i++) {
testCreateUint8TypedData();
@@ -485,4 +532,6 @@ main() {
testViewCreation();
testWhere();
testCreationFromList();
+ testStrings();
+ testSetRange();
}
« 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