| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use autobox::Core; |
| 4 | |
| 5 | use Test::More tests => 25; |
| 6 | |
| 7 | my $hello = 'hello'; |
| 8 | |
| 9 | is( $hello->center(7), ' hello ', |
| 10 | '->center() with even length has equal whitespace on both sides' ); |
| 11 | is( $hello->center(7,'-'), '-hello-', |
| 12 | '->center() with even length has equal whitespace on both sides' ); |
| 13 | |
| 14 | is( $hello->center(8), ' hello ', |
| 15 | '->center() with odd length pads left' ); |
| 16 | |
| 17 | is( $hello->center(4), 'hello', |
| 18 | '->center() with too-short length returns the string unmodified' ); |
| 19 | |
| 20 | is( $hello->center(0), 'hello', |
| 21 | '->center(0)' ); |
| 22 | |
| 23 | is( $hello->center(-1), 'hello', |
| 24 | '->center(-1)' ); |
| 25 | |
| 26 | is( "even"->center(6, "-"), '-even-', |
| 27 | '->center(6, "-")' ); |
| 28 | |
| 29 | is( "even"->center(7, "-"), '--even-', |
| 30 | '->center(7, "-")' ); |
| 31 | |
| 32 | is( "even"->center(0, "-"), 'even', |
| 33 | '->center(0, "-")' ); |
| 34 | |
| 35 | # Test that center() always returns the correct length |
| 36 | for my $size ($hello->length..20) { |
| 37 | is( $hello->center($size)->length, $size, "center($size) returns that size" ); |
| 38 | } |