1#!/usr/bin/perl -w
2use strict;
3use warnings;
4use Test::More tests => 22;
5
6use MIME::QuotedPrint qw(decode_qp);
7use MIME::WordDecoder;
8
9use utf8;
10
11binmode STDOUT, ":utf8";
12binmode STDERR, ":utf8";
13
14my $mwd = (new MIME::WordDecoder::ISO_8859 1);
15{
16    local($/) = '';
17    open WORDS, "<testin/words.txt" or die "open: $!";
18    while (<WORDS>) {
19	s{\A\s+|\s+\Z}{}g;    # trim
20
21	my ($isgood, $expect, $enc) = split /\n/, $_, 3;
22
23	# Create the expected data
24	$expect = eval $expect;
25
26	my $dec = $mwd->decode($enc);
27	if( $isgood eq 'GOOD' ) {
28		ok( ! $@, 'No exceptions');
29		is( $dec, $expect, "$enc produced correct output");
30	} else {
31		ok( $@, 'Got an exception as expected');
32	}
33
34    }
35    close WORDS;
36}
37
38my $wd = supported MIME::WordDecoder 'UTF-8';
39my $perl_string = $wd->decode('To: =?ISO-8859-1?Q?J=F8rn?= <keld>');
40is($perl_string, "To: J\x{00f8}rn <keld>", 'Got back expected UTF-8 string');
41is(utf8::is_utf8($perl_string), 1, 'Converted string has UTF-8 flag on');
42
43$perl_string = mime_to_perl_string('To: =?ISO-8859-1?Q?J=F8rn?= <keld>');
44is($perl_string, "To: J\x{00f8}rn <keld>", 'Got back expected UTF-8 string');
45is(utf8::is_utf8($perl_string), 1, 'Converted string has UTF-8 flag on');
46