File: 10string.t

package info (click to toggle)
libmail-box-perl 2.068-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,576 kB
  • ctags: 1,493
  • sloc: perl: 22,358; makefile: 49
file content (70 lines) | stat: -rw-r--r-- 1,540 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
#!/usr/bin/perl -T
#
# Test processing of message bodies which have their content stored
# in a single string.  This does not test the reading of the bodies
# from file.
#

use strict;
use warnings;

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

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

use Mail::Message::Body::String;

# Test to read a scalar from file.
# Let's fake the file, for simplicity.

my $filedata = <<'SIMULATED_FILE';
This is a file
with five lines, and it
is used to test whether
the reading into a scalar body
would work (or not)
SIMULATED_FILE

my @filedata = split /^/, $filedata;
cmp_ok(@filedata, '==', 5);

my $f = IO::Scalar->new(\$filedata);
my $body = Mail::Message::Body::String->new(file => $f);
ok(defined $body);
is($body->string, $filedata);
cmp_ok($body->nrLines, '==', 5);
cmp_ok($body->size, '==', length $filedata);

my $fakeout;
my $g = IO::Scalar->new(\$fakeout);
$body->print($g);
is($fakeout, $filedata);

my @lines = $body->lines;
cmp_ok(@lines, '==', 5);
foreach (0..4) { is($lines[$_], $filedata[$_]) }

# Reading data from lines.

$body = Mail::Message::Body::String->new(data => [@filedata]);
ok($body);
is($body->string, $filedata);
cmp_ok($body->nrLines, '==', 5);
cmp_ok($body->size, '==', length $filedata);

$fakeout = '';
$body->print($g);
is($fakeout, $filedata);

@lines = $body->lines;
cmp_ok(@lines, '==', 5);
foreach (0..4) { is($lines[$_], $filedata[$_]) }

# Test overloading

is("$body", $filedata);
@lines = @$body;
cmp_ok(@lines, '==', 5);
foreach (0..4) { is($lines[$_], $filedata[$_]) }