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

Side by Side Diff: tests/corelib/string_fromcharcodes_test.dart

Issue 605213002: Change restrictions on start/end on String.fromCharCodes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address commments. Created 6 years, 2 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/core/string.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) 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 test(tailSurrogate, new Uint16List(1)..[0] = 0xDFFF); 97 test(tailSurrogate, new Uint16List(1)..[0] = 0xDFFF);
98 test(tailSurrogate, new Uint32List(1)..[0] = 0xDFFF); 98 test(tailSurrogate, new Uint32List(1)..[0] = 0xDFFF);
99 test(tailSurrogate, tailSurrogate.codeUnits); 99 test(tailSurrogate, tailSurrogate.codeUnits);
100 100
101 testThrows(null); 101 testThrows(null);
102 testThrows("not an iterable"); 102 testThrows("not an iterable");
103 testThrows(42); 103 testThrows(42);
104 testThrows([-1]); 104 testThrows([-1]);
105 testThrows(new List(1)..[0] = -1); 105 testThrows(new List(1)..[0] = -1);
106 testThrows(const [-1]); 106 testThrows(const [-1]);
107 //testThrows(new Int8List(1)..[0] = -1); 107 testThrows(new Int8List(1)..[0] = -1);
108 testThrows(new Int16List(1)..[0] = -1); 108 testThrows(new Int16List(1)..[0] = -1);
109 testThrows(new Int32List(1)..[0] = -1); 109 testThrows(new Int32List(1)..[0] = -1);
110 testThrows([0x110000]); 110 testThrows([0x110000]);
111 testThrows(new List(1)..[0] = 0x110000); 111 testThrows(new List(1)..[0] = 0x110000);
112 testThrows(const [0x110000]); 112 testThrows(const [0x110000]);
113 testThrows(new Int32List(1)..[0] = 0x110000); 113 testThrows(new Int32List(1)..[0] = 0x110000);
114 114
115 // Check start/end 115 // Check start/end
116 var list = const[0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48]; 116 var list = const[0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48];
117 for (var iterable in [ 117 for (var iterable in [
118 iter(list.length, list), 118 iter(list.length, list),
119 list.toList(growable: true), 119 list.toList(growable: true),
120 list.toList(growable: false), 120 list.toList(growable: false),
121 list, 121 list,
122 new Uint8List(8)..setRange(0, 8, list), 122 new Uint8List(8)..setRange(0, 8, list),
123 new Uint16List(8)..setRange(0, 8, list), 123 new Uint16List(8)..setRange(0, 8, list),
124 new Uint32List(8)..setRange(0, 8, list), 124 new Uint32List(8)..setRange(0, 8, list),
125 "ABCDEFGH".codeUnits, 125 "ABCDEFGH".codeUnits,
126 ]) { 126 ]) {
127 test("ABCDEFGH", iterable); 127 test("ABCDEFGH", iterable);
128 // start varies, end is null. 128 // start varies, end is null.
129 test("ABCDEFGH", iterable, 0); 129 test("ABCDEFGH", iterable, 0);
130 test("BCDEFGH", iterable, 1); 130 test("BCDEFGH", iterable, 1);
131 test("H", iterable, 7); 131 test("H", iterable, 7);
132 test("", iterable, 8); 132 test("", iterable, 8);
133 test("", iterable, 9);
134 // start = 0, end varies. 133 // start = 0, end varies.
135 test("ABCDEFGH", iterable, 0); 134 test("ABCDEFGH", iterable, 0);
136 test("A", iterable, 0, 1); 135 test("A", iterable, 0, 1);
137 test("AB", iterable, 0, 2); 136 test("AB", iterable, 0, 2);
138 test("ABCDEFG", iterable, 0, 7); 137 test("ABCDEFG", iterable, 0, 7);
139 test("ABCDEFGH", iterable, 0, 8); 138 test("ABCDEFGH", iterable, 0, 8);
140 test("ABCDEFGH", iterable, 0, 9);
141 test("", iterable, 0, 0); 139 test("", iterable, 0, 0);
142 test("", iterable, 0, -1);
143 // Both varying. 140 // Both varying.
144 test("ABCDEFGH", iterable, 0, 8); 141 test("ABCDEFGH", iterable, 0, 8);
145 test("ABCDEFGH", iterable, 0, 9);
146 test("AB", iterable, 0, 2); 142 test("AB", iterable, 0, 2);
147 test("GH", iterable, 6, 8); 143 test("GH", iterable, 6, 8);
148 test("DE", iterable, 3, 5); 144 test("DE", iterable, 3, 5);
149 test("", iterable, 3, 3); 145 test("", iterable, 3, 3);
150 test("", iterable, 5, 3);
151 test("", iterable, 4, -1);
152 test("", iterable, 8, -1);
153 test("", iterable, 0, -1);
154 test("", iterable, 9, 9);
155 } 146 }
156 // 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.
157 test(leadSurrogate, [0xDBFF, 0xDFFF], 0, 1); 148 test(leadSurrogate, [0xDBFF, 0xDFFF], 0, 1);
158 test(tailSurrogate, [0xDBFF, 0xDFFF], 1); 149 test(tailSurrogate, [0xDBFF, 0xDFFF], 1);
159 test("\u{10FFFF}", [0x10FFFF], 0, 1); 150 test("\u{10FFFF}", [0x10FFFF], 0, 1);
160 151
161 // Test varying slices of the code units of a string. 152 // Test varying slices of the code units of a string.
162 testSubstring(string) { 153 testSubstring(string) {
163 var codes = string.codeUnits; 154 var codes = string.codeUnits;
164 int length = string.length; 155 int length = string.length;
165 for (var iterable in [ 156 for (var iterable in [
166 iter(length, codes), 157 iter(length, codes),
167 codes.toList(growable: true), 158 codes.toList(growable: true),
168 codes.toList(growable: false), 159 codes.toList(growable: false),
169 new Uint16List(length)..setRange(0, length, codes), 160 new Uint16List(length)..setRange(0, length, codes),
170 new Int32List(length)..setRange(0, length, codes), 161 new Int32List(length)..setRange(0, length, codes),
171 new Uint32List(length)..setRange(0, length, codes), 162 new Uint32List(length)..setRange(0, length, codes),
172 codes, 163 codes,
173 ]) { 164 ]) {
174 var newString = new String.fromCharCodes(iterable); 165 var newString = new String.fromCharCodes(iterable);
175 Expect.equals(string, newString); 166 Expect.equals(string, newString);
176 for (int i = 0; i < length; i = i * 2 + 1) { 167 for (int i = 0; i < length; i = i * 2 + 1) {
177 test(string.substring(i), iterable, i); 168 test(string.substring(i), iterable, i);
178 test(string.substring(0, i), iterable, 0, i); 169 test(string.substring(0, i), iterable, 0, i);
179 for (int j = 0; i + j < length; j = j * 2 + 1) { 170 for (int j = 0; i + j < length; j = j * 2 + 1) {
180 test(string.substring(i, i + j), iterable, i, i + j); 171 test(string.substring(i, i + j), iterable, i, i + j);
181 } 172 }
182 } 173 }
183 Expect.equals(string, new String.fromCharCodes(iterable, 0, length + 1)); 174
175 Expect.throws(() => new String.fromCharCodes(iterable, -1));
176 Expect.throws(() => new String.fromCharCodes(iterable, 0, -1));
177 Expect.throws(() => new String.fromCharCodes(iterable, 2, 1));
178 Expect.throws(() => new String.fromCharCodes(iterable, 0, length + 1));
179 Expect.throws(() => new String.fromCharCodes(iterable, length + 1));
180 Expect.throws(() => new String.fromCharCodes(iterable, length + 1,
181 length + 2));
184 } 182 }
185 } 183 }
186 184
187 testSubstring(""); 185 testSubstring("");
188 testSubstring("ABCDEFGH"); 186 testSubstring("ABCDEFGH");
189 // length > 128 187 // length > 128
190 testSubstring("ABCDEFGH" * 33); 188 testSubstring("ABCDEFGH" * 33);
191 testSubstring("\x00" * 357); 189 testSubstring("\x00" * 357);
192 // length > 128 and non-ASCII. 190 // length > 128 and non-ASCII.
193 testSubstring("\uFFFD\uFFFE\u{10000}\u{10ffff}c\x00" * 37); 191 testSubstring("\uFFFD\uFFFE\u{10000}\u{10ffff}c\x00" * 37);
194 } 192 }
OLDNEW
« no previous file with comments | « sdk/lib/core/string.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698