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

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

Issue 12282038: Remove deprecated string features. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // TODO(ngeoffray): test String methods with null arguments. 5 // TODO(ngeoffray): test String methods with null arguments.
6 class StringTest { 6 class StringTest {
7 7
8 static testMain() { 8 static testMain() {
9 testOutOfRange(); 9 testOutOfRange();
10 testIllegalArgument(); 10 testIllegalArgument();
11 testConcat(); 11 testConcat();
12 testIndex(); 12 testIndex();
13 testCharCodeAt(); 13 testCodeUnitAt();
14 testEquals(); 14 testEquals();
15 testEndsWith(); 15 testEndsWith();
16 testStartsWith(); 16 testStartsWith();
17 testIndexOf(); 17 testIndexOf();
18 testLastIndexOf(); 18 testLastIndexOf();
19 testContains(); 19 testContains();
20 testReplaceAll(); 20 testReplaceAll();
21 testCompareTo(); 21 testCompareTo();
22 testToList();
23 testCharCodes(); 22 testCharCodes();
24 } 23 }
25 24
26 static void testOutOfRange() { 25 static void testOutOfRange() {
27 String a = "Hello"; 26 String a = "Hello";
28 bool exception_caught = false; 27 bool exception_caught = false;
29 try { 28 try {
30 var c = a[20]; // Throw exception. 29 var c = a[20]; // Throw exception.
31 } on RangeError catch (e) { 30 } on RangeError catch (e) {
32 exception_caught = true; 31 exception_caught = true;
(...skipping 16 matching lines...) Expand all
49 } 48 }
50 49
51 static testIndex() { 50 static testIndex() {
52 String str = "string"; 51 String str = "string";
53 for (int i = 0; i < str.length; i++) { 52 for (int i = 0; i < str.length; i++) {
54 Expect.equals(true, str[i] is String); 53 Expect.equals(true, str[i] is String);
55 Expect.equals(1, str[i].length); 54 Expect.equals(1, str[i].length);
56 } 55 }
57 } 56 }
58 57
59 static testCharCodeAt() { 58 static testCodeUnitAt() {
60 String str = "string"; 59 String str = "string";
61 for (int i = 0; i < str.length; i++) { 60 for (int i = 0; i < str.length; i++) {
62 Expect.equals(true, str.charCodeAt(i) is int); 61 Expect.equals(true, str.codeUnitAt(i) is int);
63 } 62 }
64 } 63 }
65 64
66 static testConcat() { 65 static testConcat() {
67 var a = "One"; 66 var a = "One";
68 var b = "Four"; 67 var b = "Four";
69 var c = a.concat(b); 68 var c = a.concat(b);
70 Expect.equals(7, c.length); 69 Expect.equals(7, c.length);
71 Expect.equals("OneFour", c); 70 Expect.equals("OneFour", c);
72 } 71 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 263
265 static testCompareTo() { 264 static testCompareTo() {
266 Expect.equals(0, "".compareTo("")); 265 Expect.equals(0, "".compareTo(""));
267 Expect.equals(0, "str".compareTo("str")); 266 Expect.equals(0, "str".compareTo("str"));
268 Expect.equals(-1, "str".compareTo("string")); 267 Expect.equals(-1, "str".compareTo("string"));
269 Expect.equals(1, "string".compareTo("str")); 268 Expect.equals(1, "string".compareTo("str"));
270 Expect.equals(1, "string".compareTo("")); 269 Expect.equals(1, "string".compareTo(""));
271 Expect.equals(-1, "".compareTo("string")); 270 Expect.equals(-1, "".compareTo("string"));
272 } 271 }
273 272
274 static testToList() {
275 test(str) {
276 var list = str.splitChars();
277 Expect.equals(str.length, list.length);
278 for (int i = 0; i < str.length; i++) {
279 Expect.equals(str[i], list[i]);
280 }
281 }
282 test("abc");
283 test("");
284 test(" ");
285 }
286
287 static testCharCodes() { 273 static testCharCodes() {
288 test(str) { 274 test(str) {
289 var list = str.charCodes; 275 var list = str.codeUnits;
290 Expect.equals(str.length, list.length); 276 Expect.equals(str.length, list.length);
291 for (int i = 0; i < str.length; i++) { 277 for (int i = 0; i < str.length; i++) {
292 Expect.equals(str.charCodeAt(i), list[i]); 278 Expect.equals(str.codeUnitAt(i), list[i]);
293 } 279 }
294 } 280 }
295 test("abc"); 281 test("abc");
296 test(""); 282 test("");
297 test(" "); 283 test(" ");
298 } 284 }
299 } 285 }
300 286
301 main() { 287 main() {
302 StringTest.testMain(); 288 StringTest.testMain();
303 } 289 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698