File: Encode-Mapper-1.t

package info (click to toggle)
libencode-arabic-perl 14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 584 kB
  • ctags: 119
  • sloc: perl: 4,515; makefile: 11
file content (79 lines) | stat: -rw-r--r-- 2,757 bytes parent folder | download | duplicates (5)
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
#########################

use Test::More tests => 9;

BEGIN {

    use_ok 'Encode::Mapper';
}

require_ok 'Encode';
require_ok 'Data::Dumper';

#########################

# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

can_ok 'Encode::Mapper', qw 'new compile process recover compute dumper',
       qw 'encode decode', qw 'options import';

my $mapper = Encode::Mapper->new (

            map {

                (chr $_) x 2,

            } 0x00..0xFF

        );

my @tokens = (

            "\x{060C}",  ",",           "\x{0637}",  ".t",
            "\x{061B}",  ";",           "\x{0638}",  ".z",
            "\x{061F}",  "?",           "\x{0639}",  "`",
            "\x{0621}",  "'",           "\x{063A}",  ".g",
            "\x{0622}",  "'A",          "\x{0640}",  "--",
            "\x{0623}",  "'",           "\x{0641}",  "f",
            "\x{0624}",  "'",           "\x{0642}",  "q",
            "\x{0625}",  "'",           "\x{0643}",  "k",
            "\x{0626}",  "'",           "\x{0644}",  "l",
            "\x{0627}",  "A",           "\x{0645}",  "m",
            "\x{0628}",  "b",           "\x{0646}",  "n",
            "\x{0629}",  "T",           "\x{0647}",  "h",
            "\x{062A}",  "t",           "\x{0648}",  "w",
            "\x{062B}",  "_t",          "\x{0649}",  "Y",
            "\x{062C}",  "^g",          "\x{064A}",  "y",
            "\x{062D}",  ".h",          "\x{064B}",  "aN",
            "\x{062E}",  "_h",          "\x{064C}",  "uN",
            "\x{062F}",  "d",           "\x{064D}",  "iN",
            "\x{0630}",  "_d",          "\x{064E}",  "a",
            "\x{0631}",  "r",           "\x{064F}",  "u",
            "\x{0632}",  "z",           "\x{0650}",  "i",
            "\x{0633}",  "s",           "\x{0651}",  "\\shadda{}",
            "\x{0634}",  "^s",          "\x{0652}",  "\\sukuun{}",
            "\x{0635}",  ".s",          "\x{0670}",  "_a",
            "\x{0636}",  ".d",          "\x{0671}",  "A",

        );

push @tokens, qw 'ě š č ř ž ý á í é = ů ú';


ok defined $mapper,                 "use compile() as the constructor";
ok $mapper->isa('Encode::Mapper'),  "constructs the right class";

is  Encode::decode_utf8(join "", map {
                 UNIVERSAL::isa($_, 'CODE') ? $_->() : $_
             } $mapper->process(@tokens), $mapper->recover()),

   join("", map { Encode::is_utf8($_) ? $_ : Encode::decode_utf8($_) } @tokens),

   "identity mapping, bytes oriented";

is_deeply [ my @x = split //, "\x{c4}\x{80}"],
          [ split //, Encode::encode("utf8", "\x{0100}") ],
          'unicodeness test';

is_deeply [ map { ord } @x ], [ 0xC4, 0x80 ], 'byte comparison';