File: ParserPreamble.t

package info (click to toggle)
libmime-tools-perl 5.508-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,552 kB
  • ctags: 413
  • sloc: perl: 6,174; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 980 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl -w
use strict;
use warnings;
use Test::More tests => 7;
use Test::Deep;

my %files = (
	'testmsgs/empty-preamble.msg' => [ '' ],
	'testmsgs/multi-simple.msg'   => [
		"This is the preamble.  It is to be ignored, though it\n",
		"is a handy place for mail composers to include an\n",
		"explanatory note to non-MIME conformant readers."
	],
	'testmsgs/ticket-60931.msg'   => [ ],
);

#-- Load MIME::Parser
use_ok("MIME::Parser");

#-- Prepare parser
my $parser = MIME::Parser->new();
$parser->output_to_core(1);
$parser->decode_bodies(0);

foreach my $file (keys %files) {
	#-- Parse quoted-printable encoded file
	open (my $fh, $file)
		or die "can't open testmsgs/empty-preamble.msg: $!";
	my $entity = $parser->parse($fh);

	$fh->seek(0,0);
	my $expected = do { local $/; <$fh> };
	close $fh;

	cmp_deeply( $entity->preamble(), $files{$file}, 'Preamble is as expected');

	is( $entity->as_string(), $expected, 'File with preamble roundtripped correctly');
}

1;