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 141 142
|
#!perl
use strict;
use Test::More tests => 16;
use_ok('Email::Simple');
my $email_text = <<END_MESSAGE;
Alpha: this header comes first
Bravo: this header comes second
Alpha: this header comes third
The body is irrelevant.
END_MESSAGE
my $email = Email::Simple->new($email_text);
isa_ok($email, "Email::Simple");
is_deeply(
[ $email->header('alpha') ],
[ 'this header comes first', 'this header comes third' ],
"we get both values, in order, for a multi-entry header",
);
is_deeply(
[ $email->header_pairs ],
[
Alpha => 'this header comes first',
Bravo => 'this header comes second',
Alpha => 'this header comes third',
],
"and we get everything in order for header_pairs",
);
my @rv = $email->header_set(alpha => ('header one', 'header three'));
is_deeply(
\@rv,
[ 'header one', 'header three' ],
"header_set in list context returns all set values",
);
is_deeply(
[ $email->header('alpha') ],
[ 'header one', 'header three' ],
"headers are replaced in order",
);
is_deeply(
[ $email->header_pairs ],
[
Alpha => 'header one',
Bravo => 'this header comes second',
Alpha => 'header three',
],
"and we still get everything in order for header_pairs",
);
my $rv = $email->header_set(alpha => qw(h1 h3 h4));
is($rv, 'h1', "header_set in scalar context returns first set header");
is_deeply(
[ $email->header('alpha') ],
[ qw(h1 h3 h4) ],
"headers are replaced in order, extras appended",
);
is_deeply(
[ $email->header_pairs ],
[
Alpha => 'h1',
Bravo => 'this header comes second',
Alpha => 'h3',
alpha => 'h4',
],
"and we still get everything in order for header_pairs",
);
$email->header_set(alpha => 'one is the loneliest header');
is_deeply(
[ $email->header('alpha') ],
[ 'one is the loneliest header' ],
"and we drop down to one value for alpha header ok",
);
is_deeply(
[ $email->header_pairs ],
[
Alpha => 'one is the loneliest header',
Bravo => 'this header comes second',
],
"and we still get everything in order for header_pairs",
);
$email->header_set(Gamma => 'gammalon');
is_deeply(
[ $email->header_pairs ],
[
Alpha => 'one is the loneliest header',
Bravo => 'this header comes second',
Gamma => 'gammalon',
],
"a third header goes in at the end",
);
$email->header_set(alpha => ('header one', 'header omega'));
is_deeply(
[ $email->header_pairs ],
[
Alpha => 'header one',
Bravo => 'this header comes second',
Gamma => 'gammalon',
alpha => 'header omega',
],
"and re-adding to the previously third header puts it fourth",
);
$email->header_set('Bravo');
is_deeply(
[ $email->header_pairs ],
[
Alpha => 'header one',
Gamma => 'gammalon',
alpha => 'header omega',
],
"Bravo header gets completely removed",
);
$email->header_set('Omega');
is_deeply(
[ $email->header_pairs ],
[
Alpha => 'header one',
Gamma => 'gammalon',
alpha => 'header omega',
],
"nothing weird happens when deleting absent headers",
);
|