File: mailcap.t

package info (click to toggle)
libmailtools-perl 2.22-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 432 kB
  • sloc: perl: 2,224; makefile: 18
file content (63 lines) | stat: -rw-r--r-- 1,408 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/env perl

require Mail::Cap;
use warnings;
use strict;

use Test::More tests => 6;

# First we create a mailcap file to test
my $mcfile = "mailcap-$$";

open MAILCAP, '>', $mcfile
    or die "Can't create $mcfile: $!";

print MAILCAP <<EOT;

# This is a comment and should be ignored

image/*; xv %s \\; echo "Showing image %s"; description=Simple image format

text/plain; cat %s;\\
  test=$^X -e "exit (!(q{%{charset}} =~ /^iso-8859-1\$/i))";\\
  copiousoutput

text/plain; smartcat %s; copiousoutput

local;cat %s;print=lpr %{foo} %{bar} %t %s

video/example; echo \\"; none

EOT
close MAILCAP;

# OK, lets parse it
my $mc = Mail::Cap->new($mcfile);
unlink($mcfile);  # no more need for this file

my $desc = $mc->description('image/gif');

print "GIF desc: $desc\n";
is($desc, "Simple image format");

my $cmd1 = $mc->viewCmd('text/plain; charset=iso-8859-1', 'file.txt');
print "$cmd1\n";
is($cmd1, "cat file.txt");

my $cmd2 = $mc->viewCmd('text/plain; charset=iso-8859-2', 'file.txt');
print "$cmd2\n";
is($cmd2, "smartcat file.txt");

my $cmd3 = $mc->viewCmd('image/gif', 'gisle.gif');
print "$cmd3\n";
is($cmd3, qq(xv gisle.gif ; echo "Showing image gisle.gif"));

my $cmd4 = $mc->printCmd('local; foo=bar', 'myfile');
print "$cmd4\n";
like($cmd4, qr/^lpr\s+bar\s+local\s+myfile$/);

my $cmd5 = $mc->viewCmd('video/example', 'myfile');
print "$cmd5\n";
is($cmd5, 'echo \"');

#$mc->dump;