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