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