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