This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Refactor die_exit.t to loop over a list, rather than iterate on an hash.
[perl5.git] / cpan / Unicode-Collate / t / override.t
1
2 BEGIN {
3     unless ("A" eq pack('U', 0x41)) {
4         print "1..0 # Unicode::Collate " .
5             "cannot stringify a Unicode code point\n";
6         exit 0;
7     }
8     if ($ENV{PERL_CORE}) {
9         chdir('t') if -d 't';
10         @INC = $^O eq 'MacOS' ? qw(::lib) : qw(../lib);
11     }
12 }
13
14 use Test;
15 BEGIN { plan tests => 35 };
16
17 use strict;
18 use warnings;
19 use Unicode::Collate;
20
21 ok(1);
22
23 #########################
24
25 ##### 2..6
26
27 my $all_undef_8 = Unicode::Collate->new(
28   table => undef,
29   normalization => undef,
30   overrideCJK => undef,
31   overrideHangul => undef,
32   UCA_Version => 8,
33 );
34
35 # All in the Unicode code point order.
36 # No hangul decomposition.
37
38 ok($all_undef_8->lt("\x{3402}", "\x{4E00}"));
39 ok($all_undef_8->lt("\x{4DFF}", "\x{4E00}"));
40 ok($all_undef_8->lt("\x{4E00}", "\x{AC00}"));
41 ok($all_undef_8->gt("\x{AC00}", "\x{1100}\x{1161}"));
42 ok($all_undef_8->gt("\x{AC00}", "\x{ABFF}"));
43
44
45 ##### 7..11
46
47 my $all_undef_9 = Unicode::Collate->new(
48   table => undef,
49   normalization => undef,
50   overrideCJK => undef,
51   overrideHangul => undef,
52   UCA_Version => 9,
53 );
54
55 # CJK Ideo. < CJK ext A/B < Others.
56 # No hangul decomposition.
57
58 ok($all_undef_9->lt("\x{4E00}", "\x{3402}"));
59 ok($all_undef_9->lt("\x{3402}", "\x{20000}"));
60 ok($all_undef_9->lt("\x{20000}", "\x{AC00}"));
61 ok($all_undef_9->gt("\x{AC00}", "\x{1100}\x{1161}"));
62 ok($all_undef_9->gt("\x{AC00}", "\x{ABFF}")); # U+ABFF: not assigned
63
64 ##### 12..16
65
66 my $ignoreHangul = Unicode::Collate->new(
67   table => undef,
68   normalization => undef,
69   overrideHangul => sub {()},
70   entry => <<'ENTRIES',
71 AE00 ; [.0100.0020.0002.AE00]  # Hangul GEUL
72 ENTRIES
73 );
74
75 # All Hangul Syllables except U+AE00 are ignored.
76
77 ok($ignoreHangul->eq("\x{AC00}", ""));
78 ok($ignoreHangul->lt("\x{AC00}", "\0"));
79 ok($ignoreHangul->lt("\x{AC00}", "\x{AE00}"));
80 ok($ignoreHangul->lt("\x{AC00}", "\x{1100}\x{1161}")); # Jamo are not ignored.
81 ok($ignoreHangul->lt("Pe\x{AE00}rl", "Perl")); # 'r' is unassigned.
82
83 ##### 17..21
84
85 my $undefHangul = Unicode::Collate->new(
86   table => undef,
87   normalization => undef,
88   overrideHangul => sub {
89     my $u = shift;
90     return $u == 0xAE00 ? 0x100 : undef;
91   }
92 );
93
94 # All Hangul Syllables except U+AE00 are undefined.
95
96 ok($undefHangul->lt("\x{AE00}", "r"));
97 ok($undefHangul->gt("\x{AC00}", "r"));
98 ok($undefHangul->gt("\x{AC00}", "\x{1100}\x{1161}"));
99 ok($undefHangul->lt("Pe\x{AE00}rl", "Perl")); # 'r' is unassigned.
100 ok($undefHangul->lt("\x{AC00}", "\x{B000}"));
101
102 ##### 22..25
103
104 my $undefCJK = Unicode::Collate->new(
105   table => undef,
106   normalization => undef,
107   overrideCJK => sub {
108     my $u = shift;
109     return $u == 0x4E00 ? 0x100 : undef;
110   }
111 );
112
113 # All CJK Ideographs except U+4E00 are undefined.
114
115 ok($undefCJK->lt("\x{4E00}", "r"));
116 ok($undefCJK->lt("\x{5000}", "r")); # still CJK < unassigned
117 ok($undefCJK->lt("Pe\x{4E00}rl", "Perl")); # 'r' is unassigned.
118 ok($undefCJK->lt("\x{5000}", "\x{6000}"));
119
120 ##### 26..30
121
122 my $cpHangul = Unicode::Collate->new(
123   table => undef,
124   normalization => undef,
125   overrideHangul => sub { shift }
126 );
127
128 ok($cpHangul->lt("\x{AC00}", "\x{AC01}"));
129 ok($cpHangul->lt("\x{AC01}", "\x{D7A3}"));
130 ok($cpHangul->lt("\x{D7A3}", "r")); # 'r' is unassigned.
131 ok($cpHangul->lt("r", "\x{D7A4}"));
132 ok($cpHangul->lt("\x{D7A3}", "\x{4E00}"));
133
134 ##### 31..35
135
136 my $arrayHangul = Unicode::Collate->new(
137   table => undef,
138   normalization => undef,
139   overrideHangul => sub {
140     my $u = shift;
141     return [$u, 0x20, 0x2, $u];
142   }
143 );
144
145 ok($arrayHangul->lt("\x{AC00}", "\x{AC01}"));
146 ok($arrayHangul->lt("\x{AC01}", "\x{D7A3}"));
147 ok($arrayHangul->lt("\x{D7A3}", "r")); # 'r' is unassigned.
148 ok($arrayHangul->lt("r", "\x{D7A4}"));
149 ok($arrayHangul->lt("\x{D7A3}", "\x{4E00}"));
150