1BEGIN {
2    unless ("A" eq pack('U', 0x41)) {
3	print "1..0 # Unicode::Collate " .
4	    "cannot stringify a Unicode code point\n";
5	exit 0;
6    }
7    if ($ENV{PERL_CORE}) {
8	chdir('t') if -d 't';
9	@INC = $^O eq 'MacOS' ? qw(::lib) : qw(../lib);
10    }
11}
12
13use Test;
14BEGIN { plan tests => 40 };
15
16use strict;
17use warnings;
18use Unicode::Collate;
19
20our $kjeEntry = <<'ENTRIES';
210301  ; [.0000.0032.0002.0301] # COMBINING ACUTE ACCENT
220334  ; [.0000.008B.0002.0334] # COMBINING TILDE OVERLAY
23043A  ; [.0D31.0020.0002.043A] # CYRILLIC SMALL LETTER KA
24041A  ; [.0D31.0020.0008.041A] # CYRILLIC CAPITAL LETTER KA
25045C  ; [.0DA1.0020.0002.045C] # CYRILLIC SMALL LETTER KJE
26043A 0301 ; [.0DA1.0020.0002.045C] # CYRILLIC SMALL LETTER KJE
27040C  ; [.0DA1.0020.0008.040C] # CYRILLIC CAPITAL LETTER KJE
28041A 0301 ; [.0DA1.0020.0008.040C] # CYRILLIC CAPITAL LETTER KJE
29ENTRIES
30
31our $aaEntry = <<'ENTRIES';
320304  ; [.0000.005A.0002.0304] # COMBINING MACRON (cc = 230)
33030A  ; [.0000.0043.0002.030A] # COMBINING RING ABOVE (cc = 230)
340327  ; [.0000.0055.0002.0327] # COMBINING CEDILLA (cc = 202)
35031A  ; [.0000.006B.0002.031A] # COMBINING LEFT ANGLE ABOVE (cc = 232)
360061  ; [.0A15.0020.0002.0061] # LATIN SMALL LETTER A
370041  ; [.0A15.0020.0008.0041] # LATIN CAPITAL LETTER A
38007A  ; [.0C13.0020.0002.007A] # LATIN SMALL LETTER Z
39005A  ; [.0C13.0020.0008.005A] # LATIN CAPITAL LETTER Z
4000E5  ; [.0C25.0020.0002.00E5] # LATIN SMALL LETTER A WITH RING ABOVE; QQCM
4100C5  ; [.0C25.0020.0008.00C5] # LATIN CAPITAL LETTER A WITH RING ABOVE; QQCM
420061 030A ; [.0C25.0020.0002.0061] # LATIN SMALL LETTER A WITH RING ABOVE
430041 030A ; [.0C25.0020.0008.0041] # LATIN CAPITAL LETTER A WITH RING ABOVE
44ENTRIES
45
46#########################
47
48ok(1);
49
50my $kjeNoN = Unicode::Collate->new(
51    level => 1,
52    table => undef,
53    normalization => undef,
54    entry => $kjeEntry,
55);
56
57ok($kjeNoN->lt("\x{043A}", "\x{043A}\x{0301}"));
58ok($kjeNoN->gt("\x{045C}", "\x{043A}\x{0334}\x{0301}"));
59ok($kjeNoN->eq("\x{043A}", "\x{043A}\x{0334}\x{0301}"));
60ok($kjeNoN->eq("\x{045C}", "\x{043A}\x{0301}\x{0334}"));
61
62our %sortkeys;
63
64$sortkeys{'KAac'} = $kjeNoN->viewSortKey("\x{043A}\x{0301}");
65$sortkeys{'KAta'} = $kjeNoN->viewSortKey("\x{043A}\x{0334}\x{0301}");
66$sortkeys{'KAat'} = $kjeNoN->viewSortKey("\x{043A}\x{0301}\x{0334}");
67
68eval { require Unicode::Normalize };
69if (!$@) {
70    my $kjeNFD = Unicode::Collate->new(
71	level => 1,
72	table => undef,
73	entry => $kjeEntry,
74    );
75ok($kjeNFD->lt("\x{043A}", "\x{043A}\x{0301}"));
76ok($kjeNFD->eq("\x{045C}", "\x{043A}\x{0334}\x{0301}"));
77ok($kjeNFD->lt("\x{043A}", "\x{043A}\x{0334}\x{0301}"));
78ok($kjeNFD->eq("\x{045C}", "\x{043A}\x{0301}\x{0334}"));
79
80    my $aaNFD = Unicode::Collate->new(
81	level => 1,
82	table => undef,
83	entry => $aaEntry,
84    );
85
86ok($aaNFD->lt("Z", "A\x{30A}\x{304}"));
87ok($aaNFD->eq("A", "A\x{304}\x{30A}"));
88ok($aaNFD->eq(pack('U', 0xE5), "A\x{30A}\x{304}"));
89ok($aaNFD->eq("A\x{304}", "A\x{304}\x{30A}"));
90ok($aaNFD->lt("Z", "A\x{327}\x{30A}"));
91ok($aaNFD->lt("Z", "A\x{30A}\x{327}"));
92ok($aaNFD->lt("Z", "A\x{31A}\x{30A}"));
93ok($aaNFD->lt("Z", "A\x{30A}\x{31A}"));
94
95    my $aaPre = Unicode::Collate->new(
96	level => 1,
97	normalization => "prenormalized",
98	table => undef,
99	entry => $aaEntry,
100    );
101
102ok($aaPre->lt("Z", "A\x{30A}\x{304}"));
103ok($aaPre->eq("A", "A\x{304}\x{30A}"));
104ok($aaPre->eq(pack('U', 0xE5), "A\x{30A}\x{304}"));
105ok($aaPre->eq("A\x{304}", "A\x{304}\x{30A}"));
106ok($aaPre->lt("Z", "A\x{327}\x{30A}"));
107ok($aaPre->lt("Z", "A\x{30A}\x{327}"));
108ok($aaPre->lt("Z", "A\x{31A}\x{30A}"));
109ok($aaPre->lt("Z", "A\x{30A}\x{31A}"));
110}
111else {
112  ok(1) for 1..20;
113}
114
115# again: loading Unicode::Normalize should not affect $kjeNoN.
116ok($kjeNoN->lt("\x{043A}", "\x{043A}\x{0301}"));
117ok($kjeNoN->gt("\x{045C}", "\x{043A}\x{0334}\x{0301}"));
118ok($kjeNoN->eq("\x{043A}", "\x{043A}\x{0334}\x{0301}"));
119ok($kjeNoN->eq("\x{045C}", "\x{043A}\x{0301}\x{0334}"));
120
121ok($sortkeys{'KAac'}, $kjeNoN->viewSortKey("\x{043A}\x{0301}"));
122ok($sortkeys{'KAta'}, $kjeNoN->viewSortKey("\x{043A}\x{0334}\x{0301}"));
123ok($sortkeys{'KAat'}, $kjeNoN->viewSortKey("\x{043A}\x{0301}\x{0334}"));
124
125my $aaNoN = Unicode::Collate->new(
126    level => 1,
127    table => undef,
128    entry => $aaEntry,
129    normalization => undef,
130);
131
132ok($aaNoN->lt("Z", "A\x{30A}\x{304}"));
133ok($aaNoN->eq("A", "A\x{304}\x{30A}"));
134ok($aaNoN->eq(pack('U', 0xE5), "A\x{30A}\x{304}"));
135ok($aaNoN->eq("A\x{304}", "A\x{304}\x{30A}"));
136ok($aaNoN->eq("A", "A\x{327}\x{30A}"));
137ok($aaNoN->lt("Z", "A\x{30A}\x{327}"));
138ok($aaNoN->eq("A", "A\x{31A}\x{30A}"));
139ok($aaNoN->lt("Z", "A\x{30A}\x{31A}"));
140
141