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

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

Issue 171773003: Allow multi-codeunit padding in String.padLeft/padRight. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Type typo. Created 6 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 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 6
7 void main() { 7 void main() {
8 testOutOfRange(); 8 testOutOfRange();
9 testIllegalArgument(); 9 testIllegalArgument();
10 testConcat(); 10 testConcat();
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 "\u2028", 404 "\u2028",
405 "abcdef\u2028", 405 "abcdef\u2028",
406 "\u{10002}", 406 "\u{10002}",
407 "abcdef\u{10002}" 407 "abcdef\u{10002}"
408 ]; 408 ];
409 List<int> counts = [ 409 List<int> counts = [
410 0, 410 0,
411 1, 411 1,
412 2, 412 2,
413 3, 413 3,
414 4,
415 5,
416 6,
417 7,
418 8,
419 9,
414 10, 420 10,
415 100 421 11,
422 12,
423 13,
424 14,
425 15,
426 16,
427 17,
428 127,
429 128,
430 129
416 ]; 431 ];
417 void testRepeat(str, repeat, sep) { 432 void testRepeat(str, repeat) {
418 String expect; 433 String expect;
419 if (repeat == 0) { 434 if (repeat <= 0) {
420 expect = ""; 435 expect = "";
421 } else if (repeat == 1) { 436 } else if (repeat == 1) {
422 expect = str; 437 expect = str;
423 } else { 438 } else {
424 StringBuffer buf = new StringBuffer(str); 439 StringBuffer buf = new StringBuffer();
425 for (int i = 1; i < repeat; i++) { 440 for (int i = 0; i < repeat; i++) {
426 buf.write(sep);
427 buf.write(str); 441 buf.write(str);
428 } 442 }
429 expect = buf.toString(); 443 expect = buf.toString();
430 } 444 }
431 String actual = str.repeat(repeat, sep); 445 String actual = str * repeat;
432 Expect.equals(expect, actual, 446 Expect.equals(expect, actual,
433 "$str#${str.length}*$repeat/$sep#${sep.length}"); 447 "$str#${str.length} * $repeat");
434 } 448 }
435 for (String str in testStrings) { 449 for (String str in testStrings) {
436 for (String sep in testStrings) { 450 for (int repeat in counts) {
437 for (int repeat in counts) { 451 testRepeat(str, repeat);
438 testRepeat(str, repeat, sep);
439 }
440 } 452 }
441 } 453 }
442 Expect.throws(() { "a".repeat(-1); });
443 } 454 }
444 455
445 void testPadLeft() { 456 void testPadLeft() {
446 Expect.equals(" 1", "1".padLeft(5, ' ')); 457 Expect.equals(" 1", "1".padLeft(5, ' '));
447 Expect.equals(" 11", "11".padLeft(5, ' ')); 458 Expect.equals(" 11", "11".padLeft(5, ' '));
448 Expect.equals(" 111", "111".padLeft(5, ' ')); 459 Expect.equals(" 111", "111".padLeft(5, ' '));
449 Expect.equals(" 1111", "1111".padLeft(5, ' ')); 460 Expect.equals(" 1111", "1111".padLeft(5, ' '));
450 Expect.equals("11111", "11111".padLeft(5, ' ')); 461 Expect.equals("11111", "11111".padLeft(5, ' '));
451 Expect.equals("111111", "111111".padLeft(5, ' ')); 462 Expect.equals("111111", "111111".padLeft(5, ' '));
452 Expect.equals(" \u{10002}", "\u{10002}".padLeft(5, ' ')); 463 Expect.equals(" \u{10002}", "\u{10002}".padLeft(5, ' '));
453 Expect.equals('', ''.padLeft(0, 'a')); 464 Expect.equals('', ''.padLeft(0, 'a'));
454 Expect.equals('a', ''.padLeft(1, 'a')); 465 Expect.equals('a', ''.padLeft(1, 'a'));
455 Expect.equals('aaaaa', ''.padLeft(5, 'a')); 466 Expect.equals('aaaaa', ''.padLeft(5, 'a'));
456 Expect.equals('', ''.padLeft(-2, 'a')); 467 Expect.equals('', ''.padLeft(-2, 'a'));
457 468
458 Expect.throws(() { ' '.padLeft(5, ''); }); 469 Expect.equals('xyzxyzxyzxyzxyz', ''.padLeft(5, 'xyz'));
459 Expect.throws(() { ' '.padLeft(5, 'xx'); }); 470 Expect.equals('xyzxyzxyzxyza', 'a'.padLeft(5, 'xyz'));
460 Expect.throws(() { ' '.padLeft(5, '\u{10002}'); }); 471 Expect.equals('xyzxyzxyzaa', 'aa'.padLeft(5, 'xyz'));
472 Expect.equals('\u{10002}\u{10002}\u{10002}aa', 'aa'.padLeft(5, '\u{10002}'));
473 Expect.equals('a', 'a'.padLeft(10, ''));
461 } 474 }
462 475
463 void testPadRight() { 476 void testPadRight() {
464 Expect.equals("1 ", "1".padRight(5, ' ')); 477 Expect.equals("1 ", "1".padRight(5, ' '));
465 Expect.equals("11 ", "11".padRight(5, ' ')); 478 Expect.equals("11 ", "11".padRight(5, ' '));
466 Expect.equals("111 ", "111".padRight(5, ' ')); 479 Expect.equals("111 ", "111".padRight(5, ' '));
467 Expect.equals("1111 ", "1111".padRight(5, ' ')); 480 Expect.equals("1111 ", "1111".padRight(5, ' '));
468 Expect.equals("11111", "11111".padRight(5, ' ')); 481 Expect.equals("11111", "11111".padRight(5, ' '));
469 Expect.equals("111111", "111111".padRight(5, ' ')); 482 Expect.equals("111111", "111111".padRight(5, ' '));
470 Expect.equals("\u{10002} ", "\u{10002}".padRight(5, ' ')); 483 Expect.equals("\u{10002} ", "\u{10002}".padRight(5, ' '));
471 Expect.equals('', ''.padRight(0, 'a')); 484 Expect.equals('', ''.padRight(0, 'a'));
472 Expect.equals('a', ''.padRight(1, 'a')); 485 Expect.equals('a', ''.padRight(1, 'a'));
473 Expect.equals('aaaaa', ''.padRight(5, 'a')); 486 Expect.equals('aaaaa', ''.padRight(5, 'a'));
474 Expect.equals('', ''.padRight(-2, 'a')); 487 Expect.equals('', ''.padRight(-2, 'a'));
475 488
476 Expect.throws(() { ' '.padRight(5, ''); }); 489 Expect.equals('xyzxyzxyzxyzxyz', ''.padRight(5, 'xyz'));
477 Expect.throws(() { ' '.padRight(5, 'xx'); }); 490 Expect.equals('axyzxyzxyzxyz', 'a'.padRight(5, 'xyz'));
478 Expect.throws(() { ' '.padRight(5, '\u{10002}'); }); 491 Expect.equals('aaxyzxyzxyz', 'aa'.padRight(5, 'xyz'));
492 Expect.equals('aa\u{10002}\u{10002}\u{10002}', 'aa'.padRight(5, '\u{10002}'));
493 Expect.equals('a', 'a'.padRight(10, ''));
479 } 494 }
OLDNEW
« runtime/lib/string_patch.dart ('K') | « tests/corelib/core_runtime_types_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698