File: 05jp.t

package info (click to toggle)
libmime-charset-perl 1.011.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 316 kB
  • sloc: perl: 2,665; makefile: 2
file content (89 lines) | stat: -rw-r--r-- 2,413 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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use strict;
use Test::More;
eval "use Encode::EUCJPASCII";
if ($@) {
    plan skip_all => "Encode::EUCJPASCII required";
} else {
    plan tests => 18;
}

use MIME::Charset qw(:trans);

my ($converted, $charset, $encoding);
my $src = "\x5C\x7E\xA1\xB1\xA1\xBD\xA1\xC0\xA1\xC1\xA1\xC2\xA1\xDD\xA1\xEF\xA1\xF1\xA1\xF2\xA2\xCC\xA1\xC1\x8F\xA2\xC3";
my $dst = "\x5c\x7e\e\x24\x42\x21\x31\x21\x3d\x21\x40\x21\x41\x21\x42\x21\x5d\x21\x6f\x21\x71\x21\x72\x22\x4c\x21\x41\e\x24\x28\x44\x22\x43\e\x28\x42";

# test get encodings for body
($converted, $charset, $encoding) = body_encode($src, "euc-jp");
if (MIME::Charset::USE_ENCODE) {
    is($converted, $dst);
    is($charset, "ISO-2022-JP");
    is($encoding, "7BIT");
} else {
    is($converted, $src);
    is($charset, "EUC-JP");
    is($encoding, "8BIT");
}

# test get encodings for body with auto-detection of 7-bit
($converted, $charset, $encoding) = body_encode($dst);
if (MIME::Charset::USE_ENCODE) {
    is($converted, $dst);
    is($charset, "ISO-2022-JP");
    is($encoding, "7BIT");
} else {
    is($converted, $dst);
    is($charset, "US-ASCII");
    is($encoding, "7BIT");
}

# test get encodings for header
($converted, $charset, $encoding) = header_encode($src, "euc-jp");
if (MIME::Charset::USE_ENCODE) {
    is($converted, $dst);
    is($charset, "ISO-2022-JP");
    is($encoding, "B");
} else {
    is($converted, $src);
    is($charset, "EUC-JP");
    is($encoding, "B");
}

# test get encodings for header with auto-detection of 7-bit
($converted, $charset, $encoding) = header_encode($dst);
if (MIME::Charset::USE_ENCODE) {
    is($converted, $dst);
    is($charset, "ISO-2022-JP");
    is($encoding, "B");
} else {
    is($converted, $dst);
    is($charset, "US-ASCII");
    is($encoding, undef);
}

$src = $dst;

# test get encodings for body
($converted, $charset, $encoding) = body_encode($src, "iso-2022-jp");
if (MIME::Charset::USE_ENCODE) {
    is($converted, $dst);
    is($charset, "ISO-2022-JP");
    is($encoding, "7BIT");
} else {
    is($converted, $src);
    is($charset, "ISO-2022-JP");
    is($encoding, "7BIT");
}

# test get encodings for header
($converted, $charset, $encoding) = header_encode($src, "iso-2022-jp");
if (MIME::Charset::USE_ENCODE) {
    is($converted, $dst);
    is($charset, "ISO-2022-JP");
    is($encoding, "B");
} else {
    is($converted, $src);
    is($charset, "ISO-2022-JP");
    is($encoding, "B");
}