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}
9
10BEGIN {
11    if ($ENV{PERL_CORE}) {
12        chdir('t') if -d 't';
13        @INC = $^O eq 'MacOS' ? qw(::lib) : qw(../lib);
14    }
15}
16
17use Test;
18BEGIN { plan tests => 23 };
19
20use strict;
21use warnings;
22use Unicode::Collate;
23
24ok(1);
25
26#########################
27
28my $Collator = Unicode::Collate->new(
29  table => 'keys.txt',
30  normalization => undef,
31);
32
33# rearrange : 0x0E40..0x0E44, 0x0EC0..0x0EC4 (default)
34
35##### 2..9
36
37my %old_rearrange = $Collator->change(rearrange => undef);
38
39ok($Collator->gt("\x{0E41}A", "\x{0E40}B"));
40ok($Collator->gt("A\x{0E41}A", "A\x{0E40}B"));
41
42$Collator->change(rearrange => [ 0x61 ]);
43 # U+0061, 'a': This is a Unicode value, never a native value.
44
45ok($Collator->gt("ab", "AB")); # as 'ba' > 'AB'
46
47$Collator->change(%old_rearrange);
48
49ok($Collator->lt("ab", "AB"));
50ok($Collator->lt("\x{0E40}", "\x{0E41}"));
51ok($Collator->lt("\x{0E40}A", "\x{0E41}B"));
52ok($Collator->lt("\x{0E41}A", "\x{0E40}B"));
53ok($Collator->lt("A\x{0E41}A", "A\x{0E40}B"));
54
55##### 10..13
56
57my $all_undef_8 = Unicode::Collate->new(
58  table => undef,
59  normalization => undef,
60  overrideCJK => undef,
61  overrideHangul => undef,
62  UCA_Version => 8,
63);
64
65ok($all_undef_8->lt("\x{0E40}", "\x{0E41}"));
66ok($all_undef_8->lt("\x{0E40}A", "\x{0E41}B"));
67ok($all_undef_8->lt("\x{0E41}A", "\x{0E40}B"));
68ok($all_undef_8->lt("A\x{0E41}A", "A\x{0E40}B"));
69
70##### 14..18
71
72my $no_rearrange = Unicode::Collate->new(
73  table => undef,
74  normalization => undef,
75  rearrange => [],
76);
77
78ok($no_rearrange->lt("A", "B"));
79ok($no_rearrange->lt("\x{0E40}", "\x{0E41}"));
80ok($no_rearrange->lt("\x{0E40}A", "\x{0E41}B"));
81ok($no_rearrange->gt("\x{0E41}A", "\x{0E40}B"));
82ok($no_rearrange->gt("A\x{0E41}A", "A\x{0E40}B"));
83
84##### 19..23
85
86my $undef_rearrange = Unicode::Collate->new(
87  table => undef,
88  normalization => undef,
89  rearrange => undef,
90);
91
92ok($undef_rearrange->lt("A", "B"));
93ok($undef_rearrange->lt("\x{0E40}", "\x{0E41}"));
94ok($undef_rearrange->lt("\x{0E40}A", "\x{0E41}B"));
95ok($undef_rearrange->gt("\x{0E41}A", "\x{0E40}B"));
96ok($undef_rearrange->gt("A\x{0E41}A", "A\x{0E40}B"));
97
98