This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Merge branch 'blead' of ssh://perl5.git.perl.org/gitroot/perl into blead
[perl5.git] / cpan / Unicode-Collate / t / rearrang.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 => 23 };
16
17 use strict;
18 use warnings;
19 use Unicode::Collate;
20
21 ok(1);
22
23 #########################
24
25 my $Collator = Unicode::Collate->new(
26   table => 'keys.txt',
27   normalization => undef,
28   UCA_Version => 9,
29 );
30
31 # rearrange : 0x0E40..0x0E44, 0x0EC0..0x0EC4 (default)
32
33 ##### 2..9
34
35 my %old_rearrange = $Collator->change(rearrange => undef);
36
37 ok($Collator->gt("\x{0E41}A", "\x{0E40}B"));
38 ok($Collator->gt("A\x{0E41}A", "A\x{0E40}B"));
39
40 $Collator->change(rearrange => [ 0x61 ]);
41  # U+0061, 'a': This is a Unicode value, never a native value.
42
43 ok($Collator->gt("ab", "AB")); # as 'ba' > 'AB'
44
45 $Collator->change(%old_rearrange);
46
47 ok($Collator->lt("ab", "AB"));
48 ok($Collator->lt("\x{0E40}", "\x{0E41}"));
49 ok($Collator->lt("\x{0E40}A", "\x{0E41}B"));
50 ok($Collator->lt("\x{0E41}A", "\x{0E40}B"));
51 ok($Collator->lt("A\x{0E41}A", "A\x{0E40}B"));
52
53 ##### 10..13
54
55 my $all_undef_8 = Unicode::Collate->new(
56   table => undef,
57   normalization => undef,
58   overrideCJK => undef,
59   overrideHangul => undef,
60   UCA_Version => 8,
61 );
62
63 ok($all_undef_8->lt("\x{0E40}", "\x{0E41}"));
64 ok($all_undef_8->lt("\x{0E40}A", "\x{0E41}B"));
65 ok($all_undef_8->lt("\x{0E41}A", "\x{0E40}B"));
66 ok($all_undef_8->lt("A\x{0E41}A", "A\x{0E40}B"));
67
68 ##### 14..18
69
70 my $no_rearrange = Unicode::Collate->new(
71   table => undef,
72   normalization => undef,
73   rearrange => [],
74   UCA_Version => 9,
75 );
76
77 ok($no_rearrange->lt("A", "B"));
78 ok($no_rearrange->lt("\x{0E40}", "\x{0E41}"));
79 ok($no_rearrange->lt("\x{0E40}A", "\x{0E41}B"));
80 ok($no_rearrange->gt("\x{0E41}A", "\x{0E40}B"));
81 ok($no_rearrange->gt("A\x{0E41}A", "A\x{0E40}B"));
82
83 ##### 19..23
84
85 my $undef_rearrange = Unicode::Collate->new(
86   table => undef,
87   normalization => undef,
88   rearrange => undef,
89   UCA_Version => 9,
90 );
91
92 ok($undef_rearrange->lt("A", "B"));
93 ok($undef_rearrange->lt("\x{0E40}", "\x{0E41}"));
94 ok($undef_rearrange->lt("\x{0E40}A", "\x{0E41}B"));
95 ok($undef_rearrange->gt("\x{0E41}A", "\x{0E40}B"));
96 ok($undef_rearrange->gt("A\x{0E41}A", "A\x{0E40}B"));
97