File: 01decode.t

package info (click to toggle)
libmime-encwords-perl 1.014.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 348 kB
  • ctags: 48
  • sloc: perl: 872; makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,600 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
use strict;
use Test;

BEGIN { plan tests => ($] >= 5.007003)? 48: 16 }

use MIME::EncWords qw(decode_mimewords);
$MIME::EncWords::Config = {
    Detect7bit => 'YES',
    Mapping => 'EXTENDED',
    Replacement => 'DEFAULT',
    Charset => 'ISO-8859-1',
    Encoding => 'A',
    Field => undef,
    Folding => "\n",
    MaxLineLen => 76,
    Minimal => 'YES',
};
if (&MIME::Charset::USE_ENCODE && $] < 5.008) {
    require Encode::KR;
}

my @testins = qw(decode-singlebyte decode-multibyte decode-ascii);

{
  local($/) = '';
  foreach my $in (@testins) {
    open WORDS, "<testin/$in.txt" or die "open: $!";
    while (<WORDS>) {
	s{\A\s+|\s+\Z}{}g;    # trim

	my ($isgood, $expect, $enc) = split /\n/, $_, 3;
	my ($charset, $ucharset);
	$isgood = (uc($isgood) eq 'GOOD');
	($expect, $charset, $ucharset) = eval $expect;

	# Convert to raw data...
	my $dec = decode_mimewords($enc);
	ok((($isgood && !$@) or (!$isgood && $@)) and
           ($isgood ? ($dec eq $expect) : 1));
	if (MIME::Charset::USE_ENCODE ne '') {
	    my $u;
	    # Convert to other charset (or no conversion)...
	    $u = $expect;
	    Encode::from_to($u, $charset, "utf-8") if $charset;
	    $dec = decode_mimewords($enc, Charset => $charset? "utf-8": "");
	    ok((($isgood && !$@) or (!$isgood && $@)) and
		($isgood ? ($dec eq $u) : 1));
	    # Convert to Unicode...
	    $u = Encode::decode($charset || $ucharset || "us-ascii", $expect);
	    $dec = decode_mimewords($enc, Charset => "_UNICODE_");
	    ok((($isgood && !$@) or (!$isgood && $@)) and
		($isgood ? ($dec eq $u) : 1));
	}
    }
    close WORDS;
  }
}    

1;