File: WordDecoder.t

package info (click to toggle)
libmime-tools-perl 5.515-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,612 kB
  • sloc: perl: 6,349; makefile: 8
file content (45 lines) | stat: -rw-r--r-- 1,198 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
41
42
43
44
45
#!/usr/bin/perl -w
use strict;
use warnings;
use Test::More tests => 22;

use MIME::QuotedPrint qw(decode_qp);
use MIME::WordDecoder;

use utf8;

binmode STDOUT, ":utf8";
binmode STDERR, ":utf8";

my $mwd = (new MIME::WordDecoder::ISO_8859 1);
{
    local($/) = '';
    open WORDS, "<testin/words.txt" or die "open: $!";
    while (<WORDS>) {
	s{\A\s+|\s+\Z}{}g;    # trim

	my ($isgood, $expect, $enc) = split /\n/, $_, 3;

	# Create the expected data
	$expect = eval $expect;

	my $dec = $mwd->decode($enc);
	if( $isgood eq 'GOOD' ) {
		ok( ! $@, 'No exceptions');
		is( $dec, $expect, "$enc produced correct output");
	} else {
		ok( $@, 'Got an exception as expected');
	}

    }
    close WORDS;
}

my $wd = supported MIME::WordDecoder 'UTF-8';
my $perl_string = $wd->decode('To: =?ISO-8859-1?Q?J=F8rn?= <keld>');
is($perl_string, "To: J\x{00f8}rn <keld>", 'Got back expected UTF-8 string');
is(utf8::is_utf8($perl_string), 1, 'Converted string has UTF-8 flag on');

$perl_string = mime_to_perl_string('To: =?ISO-8859-1?Q?J=F8rn?= <keld>');
is($perl_string, "To: J\x{00f8}rn <keld>", 'Got back expected UTF-8 string');
is(utf8::is_utf8($perl_string), 1, 'Converted string has UTF-8 flag on');