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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
#!perl -T
use strict;
use warnings;
use Test::More tests => 28;
BEGIN { use_ok('String::Truncate'); }
package String::Truncate::ELIDE;
eval { String::Truncate->import(qw(elide)); };
main::ok(__PACKAGE__->can('elide'), "elide is exported on request");
main::ok(!__PACKAGE__->can('trunc'), "trunc is not exported sans request");
package String::Truncate::TRUNC;
String::Truncate->import(qw(trunc));
main::ok(__PACKAGE__->can('trunc'), "trunc is exported on request");
main::ok(!__PACKAGE__->can('elide'), "elide is not exported sans request");
package String::Truncate::BOTH;
String::Truncate->import(qw(trunc elide));
main::ok(__PACKAGE__->can('trunc'), "trunc is exported on request");
main::ok(__PACKAGE__->can('elide'), "elide is exported on request");
package String::Truncate::ALL;
eval { String::Truncate->import(qw(:all)); };
main::ok(__PACKAGE__->can('trunc'), "trunc is exported for ':all'");
main::ok(__PACKAGE__->can('elide'), "elide is exported for ':all'");
package String::Truncate::JUNK;
eval { String::Truncate->import(qw(huggalugga)); };
main::like(
$@,
qr/"huggalugga" is not exported by the String::Truncate module/,
"don't accept bogus exports"
);
package String::Truncate::DEFAULT_ELIDE;
String::Truncate->import(elide => defaults => { marker => '--', length => 10 });
main::ok(__PACKAGE__->can('elide'), "elide is exported on request");
main::ok(!__PACKAGE__->can('trunc'), "trunc is not exported sans request");
main::is(
elide("123456789ABCDEF"),
"12345678--",
"elide with default marker/length",
);
package String::Truncate::DEFAULT_TRUNC;
String::Truncate->import(
trunc => defaults => { truncate => 'left', length => 10 }
);
main::ok(__PACKAGE__->can('trunc'), "trunc is exported on request");
main::ok(!__PACKAGE__->can('elide'), "elide is not exported sans request");
main::is(
trunc("123456789ABCDEF"),
"6789ABCDEF",
"trunc with default truncate/length",
);
package String::Truncate::DEFAULT_ALL;
String::Truncate->import(
':all' => defaults => { truncate => 'left', length => 10, marker => '--' }
);
main::ok(__PACKAGE__->can('trunc'), "trunc is exported on request");
main::ok(__PACKAGE__->can('elide'), "elide is exported on request");
main::is(
elide("123456789ABCDEF"),
"--89ABCDEF",
"elide with default truncate/length",
);
main::is(
elide("123456789ABCDEF", 11),
"--789ABCDEF",
"elide with overridden default length",
);
main::is(
elide("123456789ABCDEF", undef, { truncate => 'right' }),
"12345678--",
"elide with overridden default truncate",
);
main::is(
trunc("123456789ABCDEF"),
"6789ABCDEF",
"trunc with default truncate/length",
);
package String::Truncate::DEFAULT_ARG;
String::Truncate->import(
-all => { truncate => 'left', length => 10, marker => '--' }
);
main::ok(__PACKAGE__->can('trunc'), "trunc is exported on request");
main::ok(__PACKAGE__->can('elide'), "elide is exported on request");
main::is(
elide("123456789ABCDEF"),
"--89ABCDEF",
"elide with default truncate/length",
);
main::is(
elide("123456789ABCDEF", 11),
"--789ABCDEF",
"elide with overridden default length",
);
main::is(
elide("123456789ABCDEF", undef, { truncate => 'right' }),
"12345678--",
"elide with overridden default truncate",
);
main::is(
trunc("123456789ABCDEF"),
"6789ABCDEF",
"trunc with default truncate/length",
);
|