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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
BEGIN {
unless ("A" eq pack('U', 0x41)) {
print "1..0 # Unicode::Collate " .
"cannot stringify a Unicode code point\n";
exit 0;
}
if ($ENV{PERL_CORE}) {
chdir('t') if -d 't';
@INC = $^O eq 'MacOS' ? qw(::lib) : qw(../lib);
}
}
use Test;
BEGIN { plan tests => 35 };
use strict;
use warnings;
use Unicode::Collate;
ok(1);
#########################
##### 2..6
my $all_undef_8 = Unicode::Collate->new(
table => undef,
normalization => undef,
overrideCJK => undef,
overrideHangul => undef,
UCA_Version => 8,
);
# All in the Unicode code point order.
# No hangul decomposition.
ok($all_undef_8->lt("\x{3402}", "\x{4E00}"));
ok($all_undef_8->lt("\x{4DFF}", "\x{4E00}"));
ok($all_undef_8->lt("\x{4E00}", "\x{AC00}"));
ok($all_undef_8->gt("\x{AC00}", "\x{1100}\x{1161}"));
ok($all_undef_8->gt("\x{AC00}", "\x{ABFF}"));
##### 7..11
my $all_undef_9 = Unicode::Collate->new(
table => undef,
normalization => undef,
overrideCJK => undef,
overrideHangul => undef,
UCA_Version => 9,
);
# CJK Ideo. < CJK ext A/B < Others.
# No hangul decomposition.
ok($all_undef_9->lt("\x{4E00}", "\x{3402}"));
ok($all_undef_9->lt("\x{3402}", "\x{20000}"));
ok($all_undef_9->lt("\x{20000}", "\x{AC00}"));
ok($all_undef_9->gt("\x{AC00}", "\x{1100}\x{1161}"));
ok($all_undef_9->gt("\x{AC00}", "\x{ABFF}")); # U+ABFF: not assigned
##### 12..16
my $ignoreHangul = Unicode::Collate->new(
table => undef,
normalization => undef,
overrideHangul => sub {()},
entry => <<'ENTRIES',
AE00 ; [.0100.0020.0002.AE00] # Hangul GEUL
ENTRIES
);
# All Hangul Syllables except U+AE00 are ignored.
ok($ignoreHangul->eq("\x{AC00}", ""));
ok($ignoreHangul->lt("\x{AC00}", "\0"));
ok($ignoreHangul->lt("\x{AC00}", "\x{AE00}"));
ok($ignoreHangul->lt("\x{AC00}", "\x{1100}\x{1161}")); # Jamo are not ignored.
ok($ignoreHangul->lt("Pe\x{AE00}rl", "Perl")); # 'r' is unassigned.
##### 17..21
my $undefHangul = Unicode::Collate->new(
table => undef,
normalization => undef,
overrideHangul => sub {
my $u = shift;
return $u == 0xAE00 ? 0x100 : undef;
}
);
# All Hangul Syllables except U+AE00 are undefined.
ok($undefHangul->lt("\x{AE00}", "r"));
ok($undefHangul->gt("\x{AC00}", "r"));
ok($undefHangul->gt("\x{AC00}", "\x{1100}\x{1161}"));
ok($undefHangul->lt("Pe\x{AE00}rl", "Perl")); # 'r' is unassigned.
ok($undefHangul->lt("\x{AC00}", "\x{B000}"));
##### 22..25
my $undefCJK = Unicode::Collate->new(
table => undef,
normalization => undef,
overrideCJK => sub {
my $u = shift;
return $u == 0x4E00 ? 0x100 : undef;
}
);
# All CJK Ideographs except U+4E00 are undefined.
ok($undefCJK->lt("\x{4E00}", "r"));
ok($undefCJK->lt("\x{5000}", "r")); # still CJK < unassigned
ok($undefCJK->lt("Pe\x{4E00}rl", "Perl")); # 'r' is unassigned.
ok($undefCJK->lt("\x{5000}", "\x{6000}"));
##### 26..30
my $cpHangul = Unicode::Collate->new(
table => undef,
normalization => undef,
overrideHangul => sub { shift }
);
ok($cpHangul->lt("\x{AC00}", "\x{AC01}"));
ok($cpHangul->lt("\x{AC01}", "\x{D7A3}"));
ok($cpHangul->lt("\x{D7A3}", "r")); # 'r' is unassigned.
ok($cpHangul->lt("r", "\x{D7A4}"));
ok($cpHangul->lt("\x{D7A3}", "\x{4E00}"));
##### 31..35
my $arrayHangul = Unicode::Collate->new(
table => undef,
normalization => undef,
overrideHangul => sub {
my $u = shift;
return [$u, 0x20, 0x2, $u];
}
);
ok($arrayHangul->lt("\x{AC00}", "\x{AC01}"));
ok($arrayHangul->lt("\x{AC01}", "\x{D7A3}"));
ok($arrayHangul->lt("\x{D7A3}", "r")); # 'r' is unassigned.
ok($arrayHangul->lt("r", "\x{D7A4}"));
ok($arrayHangul->lt("\x{D7A3}", "\x{4E00}"));
|