File: 10create.t

package info (click to toggle)
libmail-box-perl 2.117-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,828 kB
  • ctags: 1,564
  • sloc: perl: 23,381; makefile: 2
file content (129 lines) | stat: -rw-r--r-- 2,040 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env perl
#
# Test the processing of a whole message header, not the reading of a
# header from file.
#

use strict;
use warnings;

use lib qw(. .. tests);
use Tools;

use Test::More tests => 25;
use IO::Scalar;

use Mail::Message::Head::Complete;

my $h = Mail::Message::Head::Complete->new;
{  my @o = $h->names;
   cmp_ok(scalar @o, '==', 0);
}

# Adding a first.

{  my $a = $h->add(From => 'me@home');
   ok(ref $a);
   isa_ok($a, 'Mail::Message::Field');
}

{  my @o = $h->names;
   cmp_ok(@o, '==', 1);
}

{  my @f = $h->get('From'); # list context
   cmp_ok(@f, '==', 1);
   ok(ref $f[0]);
   isa_ok($f[0], 'Mail::Message::Field');
   is($f[0]->body, 'me@home');
}

{  my $f = $h->get('From'); # scalar context
   is($f->body, 'me@home');
}

# Adding a second.

$h->add(From => 'you2me');
{  my @o = $h->names;
   cmp_ok(@o, '==', 1);
}

{  my @f = $h->get('From'); # list context
   cmp_ok(@f, '==', 2);
   is($f[0]->body, 'me@home');
   is($f[1]->body, 'you2me');
}

{  my $f = $h->get('From'); # scalar context
   is($f->body, 'you2me');
}

# Missing

{  my @f = $h->get('unknown');
   cmp_ok(@f, '==', 0);
}

{  my $f = $h->get('unknown');
   ok(! defined $f);
}

# Set

{
   $h->set(From => 'perl');
   my @f = $h->get('From');
   cmp_ok(@f, '==', 1);
}

{  my @o = $h->names;
   cmp_ok(@o, '==', 1);
}

$h->set(New => 'test');
{  my @o = sort $h->names;
   cmp_ok(@o, '==', 2);
   is($o[0], 'from');
   is($o[1], 'new');
}

# Reset

$h->reset('From');
{  my @f = $h->get('From');
   cmp_ok(@f, '==', 0);
}

{
   my $l = Mail::Message::Field->new(New => 'other');
   $h->reset('NEW', $h->get('new'), $l);
}

{  my @f = $h->get('neW');
   cmp_ok(@f, '==', 2);
}

# Print

$h->add(Subject => 'hallo!');
$h->add(To => 'the world');
$h->add(From => 'me');

my $output;
my $fakefile = new IO::Scalar \$output;

$h->print($fakefile, 0);
my $expected = <<'EXPECTED_OUTPUT';
New: test
New: other
Subject: hallo!
To: the world
From: me

EXPECTED_OUTPUT

is($output, $expected);
is($h->toString, $expected);

$fakefile->close;