File: center.t

package info (click to toggle)
libautobox-core-perl 1.2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 328 kB
  • ctags: 161
  • sloc: perl: 567; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 977 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl

use autobox::Core;

use Test::More;

my $hello = 'hello';

is( $hello->center(7), ' hello ',
    '->center() with even length has equal whitespace on both sides' );
is( $hello->center(7,'-'), '-hello-',
    '->center() with even length has equal whitespace on both sides' );

is( $hello->center(8), '  hello ',
    '->center() with odd length pads left' );

is( $hello->center(4), 'hello',
    '->center() with too-short length returns the string unmodified' );

is( $hello->center(0), 'hello',
    '->center(0)' );

is( $hello->center(-1), 'hello',
    '->center(-1)' );

is( "even"->center(6, "-"), '-even-',
    '->center(6, "-")' );

is( "even"->center(7, "-"), '--even-',
    '->center(7, "-")' );

is( "even"->center(0, "-"), 'even',
    '->center(0, "-")' );

# Test that center() always returns the correct length
for my $size ($hello->length..20) {
    is( $hello->center($size)->length, $size, "center($size) returns that size" );
}

done_testing();