summaryrefslogtreecommitdiff
path: root/t/mailto.t
blob: 8a9cd3e47dda78441ecc6724bc5b2e0cadab6292 (plain)
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
use strict;
use warnings;

use Test::More;

use URI ();

my $u = URI->new('mailto:gisle@aas.no');
is $u->to, 'gisle@aas.no', 'parsing normal URI sets to()';
is $u, 'mailto:gisle@aas.no', '... and stringification works';

my $old = $u->to('larry@wall.org');
is $old, 'gisle@aas.no', 'to() returns old value';
is $u->to, 'larry@wall.org', '... and sets new value';
is $u, 'mailto:larry@wall.org', '... and stringification works';

$u->to("?/#");
is $u->to, "?/#", 'to() accepts chars that need escaping';
is $u, 'mailto:%3F/%23', '... and stringification escapes them';

my @h = $u->headers;
ok @h == 2 && "@h" eq "to ?/#", '... and headers() returns the correct values';

$u->headers(
    to      => 'gisle@aas.no',
    cc      => 'gisle@ActiveState.com,larry@wall.org',
    Subject => 'How do you do?',
    garbage => '/;?#=&',
);

@h = $u->headers;
ok @h == 8
  && "@h" eq
'to gisle@aas.no cc gisle@ActiveState.com,larry@wall.org Subject How do you do? garbage /;?#=&',
  'setting multiple headers at once works';
is $u->to, 'gisle@aas.no', '... and to() returns the new value';

#print "$u\n";
is $u,
'mailto:gisle@aas.no?cc=gisle%40ActiveState.com%2Clarry%40wall.org&Subject=How+do+you+do%3F&garbage=%2F%3B%3F%23%3D%26',
  '... and stringification works';

$u = URI->new("mailto:");
$u->to("gisle");
is $u, 'mailto:gisle', 'starting with an empty URI and setting to() works';

done_testing;