1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
BEGIN {
unless ("A" eq pack('U', 0x41)) {
print "1..0 # Unicode::Collate " .
"cannot stringify a Unicode code point\n";
exit 0;
}
if ($ENV{PERL_CORE}) {
chdir('t') if -d 't';
@INC = $^O eq 'MacOS' ? qw(::lib) : qw(../lib);
}
}
use Test;
BEGIN { plan tests => 36 };
use strict;
use warnings;
use Unicode::Collate;
ok(1);
# 2..12
{
my $backLevel1 = Unicode::Collate->new(
table => "keys.txt",
normalization => undef,
backwards => [ 1 ],
);
ok($backLevel1->gt("a\x{300}a", "aa\x{300}"));
ok($backLevel1->lt("Ca\x{300}ca\x{302}", "ca\x{302}ca\x{300}"));
ok($backLevel1->lt("ca\x{300}ca\x{302}", "Ca\x{302}ca\x{300}"));
# all strings are reversed at level 1.
ok($backLevel1->gt("AB", "BA"));
ok($backLevel1->gt("\x{3042}\x{3044}", "\x{3044}\x{3042}"));
$backLevel1->change(backwards => []);
ok($backLevel1->lt("AB", "BA"));
ok($backLevel1->lt("\x{3042}\x{3044}", "\x{3044}\x{3042}"));
$backLevel1->change(backwards => 1);
ok($backLevel1->gt("AB", "BA"));
ok($backLevel1->gt("\x{3042}\x{3044}", "\x{3044}\x{3042}"));
$backLevel1->change(backwards => undef);
ok($backLevel1->lt("AB", "BA"));
ok($backLevel1->lt("\x{3042}\x{3044}", "\x{3044}\x{3042}"));
}
# 13..26
{
my $backLevel2 = Unicode::Collate->new(
table => "keys.txt",
normalization => undef,
backwards => 2,
);
ok($backLevel2->lt("AB", "BA"));
ok($backLevel2->lt("\x{3042}\x{3044}", "\x{3044}\x{3042}"));
# all strings are reversed at level 2.
ok($backLevel2->lt("a\x{300}a", "aa\x{300}"));
ok($backLevel2->gt("Ca\x{300}ca\x{302}", "ca\x{302}ca\x{300}"));
ok($backLevel2->gt("ca\x{300}ca\x{302}", "Ca\x{302}ca\x{300}"));
$backLevel2->change(backwards => undef);
ok($backLevel2->gt("a\x{300}a", "aa\x{300}"));
ok($backLevel2->lt("Ca\x{300}ca\x{302}", "ca\x{302}ca\x{300}"));
ok($backLevel2->lt("ca\x{300}ca\x{302}", "Ca\x{302}ca\x{300}"));
$backLevel2->change(backwards => [2]);
ok($backLevel2->lt("a\x{300}a", "aa\x{300}"));
ok($backLevel2->gt("Ca\x{300}ca\x{302}", "ca\x{302}ca\x{300}"));
ok($backLevel2->gt("ca\x{300}ca\x{302}", "Ca\x{302}ca\x{300}"));
$backLevel2->change(backwards => []);
ok($backLevel2->gt("a\x{300}a", "aa\x{300}"));
ok($backLevel2->lt("Ca\x{300}ca\x{302}", "ca\x{302}ca\x{300}"));
ok($backLevel2->lt("ca\x{300}ca\x{302}", "Ca\x{302}ca\x{300}"));
}
# 27..31
{
my $undef = Unicode::Collate->new(
table => "keys.txt",
normalization => undef,
backwards => undef,
);
ok($undef->lt("AB", "BA"));
ok($undef->lt("\x{3042}\x{3044}", "\x{3044}\x{3042}"));
ok($undef->gt("a\x{300}a", "aa\x{300}"));
ok($undef->lt("Ca\x{300}ca\x{302}", "ca\x{302}ca\x{300}"));
ok($undef->lt("ca\x{300}ca\x{302}", "Ca\x{302}ca\x{300}"));
}
# 32..36
{
my $empty = Unicode::Collate->new(
table => "keys.txt",
normalization => undef,
backwards => [ ],
);
ok($empty->lt("AB", "BA"));
ok($empty->lt("\x{3042}\x{3044}", "\x{3044}\x{3042}"));
ok($empty->gt("a\x{300}a", "aa\x{300}"));
ok($empty->lt("Ca\x{300}ca\x{302}", "ca\x{302}ca\x{300}"));
ok($empty->lt("ca\x{300}ca\x{302}", "Ca\x{302}ca\x{300}"));
}
|