Skip to content
This repository
Newer
Older
100644 38 lines (26 sloc) 0.972 kb
ac297660 » brunoV
2010-03-18 add test and docs for SCALAR::center(). Found a bug and fixed it
1 #!/usr/bin/perl
2
3 use autobox::Core;
4
dbfec8ae » chocolateboy
2010-10-18 add test plans
5 use Test::More tests => 25;
ac297660 » brunoV
2010-03-18 add test and docs for SCALAR::center(). Found a bug and fixed it
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 }
Something went wrong with that request. Please try again.