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 64 65 66 67 68 69 70 71 72
|
use strict;
use Test;
BEGIN { plan tests => 18 }
use MIME::Charset qw(:trans);
my ($converted, $charset, $encoding);
my $dst = "Perl:\033\$BIBE*\@^CoE*GQJ*=PNO4o\033(B";
my $src = "Perl:\xC9\xC2\xC5\xAA\xC0\xDE\xC3\xEF\xC5\xAA".
"\xC7\xD1\xCA\xAA\xBD\xD0\xCE\xCF\xB4\xEF";
# test get encodings for body
($converted, $charset, $encoding) = body_encode($src, "euc-jp");
if (MIME::Charset::USE_ENCODE) {
ok($converted eq $dst);
ok($charset, "ISO-2022-JP", $charset);
ok($encoding, "7BIT", $encoding);
} else {
ok($converted eq $src);
ok($charset, "EUC-JP", $charset);
ok($encoding, "8BIT", $encoding);
}
# test get encodings for body with auto-detection of 7-bit
($converted, $charset, $encoding) = body_encode($dst);
if (MIME::Charset::USE_ENCODE) {
ok($converted eq $dst);
ok($charset, "ISO-2022-JP", $charset);
ok($encoding, "7BIT", $encoding);
} else {
ok($converted eq $dst);
ok($charset, "US-ASCII", $charset);
ok($encoding, "7BIT", $encoding);
}
# test get encodings for header
($converted, $charset, $encoding) = header_encode($src, "euc-jp");
if (MIME::Charset::USE_ENCODE) {
ok($converted eq $dst);
ok($charset, "ISO-2022-JP", $charset);
ok($encoding, "B", $encoding);
} else {
ok($converted eq $src);
ok($charset, "EUC-JP", $charset);
ok($encoding, "B", $encoding);
}
# test get encodings for header with auto-detection of 7-bit
($converted, $charset, $encoding) = header_encode($dst);
if (MIME::Charset::USE_ENCODE) {
ok($converted eq $dst);
ok($charset, "ISO-2022-JP", $charset);
ok($encoding, "B", $encoding);
} else {
ok($converted eq $dst);
ok($charset, "US-ASCII", $charset);
ok($encoding, undef, $encoding);
}
$src = "~{<:Ky2;S{#,NpJ)l6HK!#~}~";
($converted, $charset, $encoding) = header_encode($src, "hz-gb-2312");
ok($converted eq $src);
ok($charset, "HZ-GB-2312", $charset);
ok($encoding, "B", $encoding);
$src = "This doesn't contain non-ASCII.";
($converted, $charset, $encoding) = header_encode($src, "hz-gb-2312");
ok($converted eq $src);
ok($charset, "US-ASCII", $charset);
ok($encoding, undef, $encoding);
|