Debian Codegraph @

t/head.t

raw
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use MIME::Lite;
6 use Test::More;
7
8 # Make a tester... here are 3 different alternatives:
9 $MIME::Lite::VANILLA = 1;
10 $MIME::Lite::PARANOID = 1;
11
12 # New:
13 my $from = '[email protected]';
14 my $me = MIME::Lite->build(From => $from,
15 To => '[email protected]',
16 Subject => 'Me!',
17 Type => 'text/plain',
18 Data => "Hello!\n");
19
20 # Test "get" [4 tests]:
21 is($me->get('From'), $from, "get: simple get of 'From'");
22 is($me->get('From',0), $from, "get: indexed get(0) of 'From' gets first");
23 is($me->get('From',-1),
24 $from,
25 "get: indexed get(-1) of 'From' gets first");
26 is($me->get('FROM',0),
27 $from,
28 "get: indexed get(0) of 'FROM' gets From");
29
30 # Test "add": add one, then two [6 tests]:
31 $me->add('Received', 'sined');
32 $me->add('Received', ['seeled', 'delivered']);
33 is(scalar($me->get('Received')),
34 'sined',
35 "add: scalar context get of 'Received'");
36 is($me->get('Received',0),
37 'sined',
38 "add: scalar context get(0) of 'Received'");
39 is($me->get('Received',1),
40 'seeled',
41 "add: scalar context get(1) of 'Received'");
42 is($me->get('Received',2),
43 'delivered',
44 "add: scalar context get(2) of 'Received'");
45 is($me->get('Received',-1),
46 'delivered',
47 "add: scalar context get(-1) of 'Received'");
48 is(($me->get('Received'))[1],
49 'seeled',
50 "add: array context get of 'Received', indexed to 1'th elem");
51
52 # Test "delete" [1 test]:
53 $me->delete('RECEIVED');
54 ok(!defined($me->get('Received')),
55 "delete: deletion of RECEIVED worked");
56
57 # Test "replace" [1 test]:
58 $me->replace('subject', "Hellooooo, nurse!");
59 is($me->get('SUBJECT'),
60 "Hellooooo, nurse!",
61 "replace: replace of SUBJECT worked");
62
63 # Test "attr" [2 tests]:
64 $me->attr('content-type.charset', 'US-ASCII');
65 is($me->attr('content-type.charset'),
66 'US-ASCII',
67 "attr: replace of charset worked");
68 #
69 my ($ct) = map {($_->[0] eq 'content-type') ? $_->[1] : ()} @{$me->fields};
70
71 is($ct,
72 'text/plain; charset="US-ASCII"',
73 "attr: replace of charset worked on whole line");
74
75 done_testing;