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

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: repeat -> operator*. 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
« sdk/lib/core/string.dart ('K') | « 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) 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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 "\xff", 403 "\xff",
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,
sra1 2014/02/19 23:15:12 I would add some more, at least covering any speci
Lasse Reichstein Nielsen 2014/02/20 07:16:40 Added all numbers in range 0..17 and replaced 100
414 10, 414 10,
415 100 415 100
416 ]; 416 ];
417 void testRepeat(str, repeat, sep) { 417 void testRepeat(str, repeat) {
418 String expect; 418 String expect;
419 if (repeat == 0) { 419 if (repeat <= 0) {
420 expect = ""; 420 expect = "";
421 } else if (repeat == 1) { 421 } else if (repeat == 1) {
422 expect = str; 422 expect = str;
423 } else { 423 } else {
424 StringBuffer buf = new StringBuffer(str); 424 StringBuffer buf = new StringBuffer();
425 for (int i = 1; i < repeat; i++) { 425 for (int i = 0; i < repeat; i++) {
426 buf.write(sep);
427 buf.write(str); 426 buf.write(str);
428 } 427 }
429 expect = buf.toString(); 428 expect = buf.toString();
430 } 429 }
431 String actual = str.repeat(repeat, sep); 430 String actual = str * repeat;
432 Expect.equals(expect, actual, 431 Expect.equals(expect, actual,
433 "$str#${str.length}*$repeat/$sep#${sep.length}"); 432 "$str#${str.length} * $repeat");
434 } 433 }
435 for (String str in testStrings) { 434 for (String str in testStrings) {
436 for (String sep in testStrings) { 435 for (int repeat in counts) {
437 for (int repeat in counts) { 436 testRepeat(str, repeat);
438 testRepeat(str, repeat, sep);
439 }
440 } 437 }
441 } 438 }
442 Expect.throws(() { "a".repeat(-1); });
443 } 439 }
444 440
445 void testPadLeft() { 441 void testPadLeft() {
446 Expect.equals(" 1", "1".padLeft(5, ' ')); 442 Expect.equals(" 1", "1".padLeft(5, ' '));
447 Expect.equals(" 11", "11".padLeft(5, ' ')); 443 Expect.equals(" 11", "11".padLeft(5, ' '));
448 Expect.equals(" 111", "111".padLeft(5, ' ')); 444 Expect.equals(" 111", "111".padLeft(5, ' '));
449 Expect.equals(" 1111", "1111".padLeft(5, ' ')); 445 Expect.equals(" 1111", "1111".padLeft(5, ' '));
450 Expect.equals("11111", "11111".padLeft(5, ' ')); 446 Expect.equals("11111", "11111".padLeft(5, ' '));
451 Expect.equals("111111", "111111".padLeft(5, ' ')); 447 Expect.equals("111111", "111111".padLeft(5, ' '));
452 Expect.equals(" \u{10002}", "\u{10002}".padLeft(5, ' ')); 448 Expect.equals(" \u{10002}", "\u{10002}".padLeft(5, ' '));
453 Expect.equals('', ''.padLeft(0, 'a')); 449 Expect.equals('', ''.padLeft(0, 'a'));
454 Expect.equals('a', ''.padLeft(1, 'a')); 450 Expect.equals('a', ''.padLeft(1, 'a'));
455 Expect.equals('aaaaa', ''.padLeft(5, 'a')); 451 Expect.equals('aaaaa', ''.padLeft(5, 'a'));
456 Expect.equals('', ''.padLeft(-2, 'a')); 452 Expect.equals('', ''.padLeft(-2, 'a'));
457 453
458 Expect.throws(() { ' '.padLeft(5, ''); }); 454 Expect.equals('xyzxyzxyzxyzxyz', ''.padLeft(5, 'xyz'));
459 Expect.throws(() { ' '.padLeft(5, 'xx'); }); 455 Expect.equals('xyzxyzxyzxyza', 'a'.padLeft(5, 'xyz'));
460 Expect.throws(() { ' '.padLeft(5, '\u{10002}'); }); 456 Expect.equals('xyzxyzxyzaa', 'aa'.padLeft(5, 'xyz'));
457 Expect.equals('\u{10002}\u{10002}\u{10002}aa', 'aa'.padLeft(5, '\u{10002}'));
458 Expect.equals('a', 'a'.padLeft(10, ''));
461 } 459 }
462 460
463 void testPadRight() { 461 void testPadRight() {
464 Expect.equals("1 ", "1".padRight(5, ' ')); 462 Expect.equals("1 ", "1".padRight(5, ' '));
465 Expect.equals("11 ", "11".padRight(5, ' ')); 463 Expect.equals("11 ", "11".padRight(5, ' '));
466 Expect.equals("111 ", "111".padRight(5, ' ')); 464 Expect.equals("111 ", "111".padRight(5, ' '));
467 Expect.equals("1111 ", "1111".padRight(5, ' ')); 465 Expect.equals("1111 ", "1111".padRight(5, ' '));
468 Expect.equals("11111", "11111".padRight(5, ' ')); 466 Expect.equals("11111", "11111".padRight(5, ' '));
469 Expect.equals("111111", "111111".padRight(5, ' ')); 467 Expect.equals("111111", "111111".padRight(5, ' '));
470 Expect.equals("\u{10002} ", "\u{10002}".padRight(5, ' ')); 468 Expect.equals("\u{10002} ", "\u{10002}".padRight(5, ' '));
471 Expect.equals('', ''.padRight(0, 'a')); 469 Expect.equals('', ''.padRight(0, 'a'));
472 Expect.equals('a', ''.padRight(1, 'a')); 470 Expect.equals('a', ''.padRight(1, 'a'));
473 Expect.equals('aaaaa', ''.padRight(5, 'a')); 471 Expect.equals('aaaaa', ''.padRight(5, 'a'));
474 Expect.equals('', ''.padRight(-2, 'a')); 472 Expect.equals('', ''.padRight(-2, 'a'));
475 473
476 Expect.throws(() { ' '.padRight(5, ''); }); 474 Expect.equals('xyzxyzxyzxyzxyz', ''.padRight(5, 'xyz'));
477 Expect.throws(() { ' '.padRight(5, 'xx'); }); 475 Expect.equals('axyzxyzxyzxyz', 'a'.padRight(5, 'xyz'));
478 Expect.throws(() { ' '.padRight(5, '\u{10002}'); }); 476 Expect.equals('aaxyzxyzxyz', 'aa'.padRight(5, 'xyz'));
477 Expect.equals('aa\u{10002}\u{10002}\u{10002}', 'aa'.padRight(5, '\u{10002}'));
478 Expect.equals('a', 'a'.padRight(10, ''));
479 } 479 }
OLDNEW
« sdk/lib/core/string.dart ('K') | « sdk/lib/core/string.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698