This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Unicode-Collate to CPAN version 0.71
[perl5.git] / cpan / Unicode-Collate / t / loc_test.t
CommitLineData
68adb2b0
CBW
1
2BEGIN {
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
14use Test;
211cc501 15BEGIN { plan tests => 120 };
68adb2b0 16
00e00351
CBW
17use strict;
18use warnings;
19use Unicode::Collate::Locale;
20
68adb2b0 21ok(1);
00e00351 22
68adb2b0
CBW
23#########################
24
25our (@listEs, @listEsT, @listFr);
00e00351
CBW
26
27@listEs = qw(
28 cambio camella camello camelo Camerún
29 chico chile Chile CHILE chocolate
30 cielo curso espacio espanto español esperanza lama líquido
31 llama Llama LLAMA llamar luz nos nueve ñu ojo
32);
33
34@listEsT = qw(
35 cambio camelo camella camello Camerún cielo curso
36 chico chile Chile CHILE chocolate
37 espacio espanto español esperanza lama líquido luz
38 llama Llama LLAMA llamar nos nueve ñu ojo
39);
40
41@listFr = (
42 qw(
43 cadurcien cæcum cÆCUM CæCUM CÆCUM caennais cæsium cafard
44 coercitif cote côte Côte coté Coté côté Côté coter
45 élève élevé gène gêne MÂCON maçon
46 pèche PÈCHE pêche PÊCHE péché PÉCHÉ pécher pêcher
47 relève relevé révèle révélé
48 surélévation sûrement suréminent sûreté
49 vice-consul vicennal vice-président vice-roi vicésimal),
50 "vice versa", "vice-versa",
51);
52
68adb2b0
CBW
53ok(@listEs, 27);
54ok(@listEsT, 27);
55ok(@listFr, 46);
00e00351 56
00e00351
CBW
57ok(Unicode::Collate::Locale::_locale('es_MX'), 'es');
58ok(Unicode::Collate::Locale::_locale('en_CA'), 'default');
59
68adb2b0
CBW
60# 6
61
00e00351
CBW
62my $Collator = Unicode::Collate::Locale->
63 new(normalization => undef);
64ok($Collator->getlocale, 'default');
65
66ok(
67 join(':', $Collator->sort(
68 qw/ lib strict Carp ExtUtils CGI Time warnings Math overload Pod CPAN /
69 ) ),
70 join(':',
71 qw/ Carp CGI CPAN ExtUtils lib Math overload Pod strict Time warnings /
72 ),
73);
74
75ok($Collator->cmp("", ""), 0);
76ok($Collator->eq("", ""));
77ok($Collator->cmp("", "perl"), -1);
78ok($Collator->gt("PERL", "perl"));
79
68adb2b0
CBW
80# 12
81
00e00351
CBW
82$Collator->change(level => 2);
83
84ok($Collator->eq("PERL", "perl"));
85
86my $objEs = Unicode::Collate::Locale->new
87 (normalization => undef, locale => 'ES');
88ok($objEs->getlocale, 'es');
89
90my $objEsT = Unicode::Collate::Locale->new
91 (normalization => undef, locale => 'es_ES_traditional');
92ok($objEsT->getlocale, 'es__traditional');
93
94my $objFr = Unicode::Collate::Locale->new
95 (normalization => undef, locale => 'FR');
96ok($objFr->getlocale, 'fr');
97
68adb2b0
CBW
98# 16
99
00e00351
CBW
100sub randomize { my %hash; @hash{@_} = (); keys %hash; } # ?!
101
102for (my $i = 0; $i < $#listEs; $i++) {
103 ok($objEs->lt($listEs[$i], $listEs[$i+1]));
104}
68adb2b0 105# 42
00e00351
CBW
106
107for (my $i = 0; $i < $#listEsT; $i++) {
108 ok($objEsT->lt($listEsT[$i], $listEsT[$i+1]));
109}
68adb2b0 110# 68
00e00351
CBW
111
112for (my $i = 0; $i < $#listFr; $i++) {
113 ok($objFr->lt($listFr[$i], $listFr[$i+1]));
114}
68adb2b0 115# 113
00e00351
CBW
116
117our @randEs = randomize(@listEs);
118our @sortEs = $objEs->sort(@randEs);
119ok("@sortEs" eq "@listEs");
120
121our @randEsT = randomize(@listEsT);
122our @sortEsT = $objEsT->sort(@randEsT);
123ok("@sortEsT" eq "@listEsT");
124
125our @randFr = randomize(@listFr);
126our @sortFr = $objFr->sort(@randFr);
127ok("@sortFr" eq "@listFr");
128
68adb2b0 129# 116
211cc501
CBW
130
131{
132 my $keyXS = '__useXS'; # see Unicode::Collate internal
cac3df65
CBW
133 my $noLoc = Unicode::Collate->new(normalization => undef);
134 my $UseXS = ref($noLoc->{$keyXS});
211cc501
CBW
135 ok(ref($Collator->{$keyXS}), $UseXS);
136 ok(ref($objFr ->{$keyXS}), $UseXS);
137 ok(ref($objEs ->{$keyXS}), $UseXS);
138 ok(ref($objEsT ->{$keyXS}), $UseXS);
139}
140# 120