summaryrefslogtreecommitdiff
path: root/cpan/Unicode-Collate/t/iglevel2.t
blob: f9fdbe0658279dd43d9e5a04493c44a92aa313b9 (plain)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218

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 => 42 };

use strict;
use warnings;
use Unicode::Collate;

ok(1);

#########################

my $Collator = Unicode::Collate->new(
  table => 'keys.txt',
  normalization => undef,
  ignore_level2 => 1,
  entry => << 'ENTRIES',
1B00  ; [.0000.00FF.0002.1B00] # BALINESE SIGN ULU RICEM
1B01  ; [.0000.0100.0002.1B01] # BALINESE SIGN ULU CANDRA
1B02  ; [.0000.0101.0002.1B02] # BALINESE SIGN CECEK
03C6  ; [.1900.0020.0002.03C6] # GREEK SMALL LETTER PHI
03D5  ; [.1900.0020.0004.03D5] # GREEK PHI SYMBOL; QQK
03A6  ; [.1900.0020.0008.03A6] # GREEK CAPITAL LETTER PHI
ENTRIES
);

ok($Collator->eq("camel", "came\x{300}l"));
ok($Collator->eq("camel", "ca\x{300}me\x{301}l"));
ok($Collator->lt("camel", "Camel"));

# 4

$Collator->change(ignore_level2 => 0);

ok($Collator->lt("camel", "came\x{300}l"));
ok($Collator->lt("camel", "ca\x{300}me\x{301}l"));
ok($Collator->lt("camel", "Camel"));

$Collator->change(level => 1);

ok($Collator->eq("camel", "came\x{300}l"));
ok($Collator->eq("camel", "ca\x{300}me\x{301}l"));
ok($Collator->eq("camel", "Camel"));

$Collator->change(level => 2);

ok($Collator->lt("camel", "came\x{300}l"));
ok($Collator->lt("camel", "ca\x{300}me\x{301}l"));
ok($Collator->eq("camel", "Camel"));

# 13

$Collator->change(ignore_level2 => 1);

ok($Collator->eq("camel", "came\x{300}l"));
ok($Collator->eq("camel", "ca\x{300}me\x{301}l"));
ok($Collator->eq("camel", "Camel"));

$Collator->change(level => 3);

ok($Collator->eq("camel", "came\x{300}l"));
ok($Collator->eq("camel", "ca\x{300}me\x{301}l"));
ok($Collator->lt("camel", "Camel"));

#  secondary: neither 00FF nor 0100 is zero
ok($Collator->eq("camel", "came\x{1B00}l"));
ok($Collator->eq("camel", "came\x{1B01}l"));
ok($Collator->eq("camel", "came\x{1B02}l"));

#  primary: 1900 isn't zero
ok($Collator->lt("\x{03C6}", "\x{03D5}"));
ok($Collator->lt("\x{03D5}", "\x{03A6}"));

# 24

{
    my $s;
    my $txt = "Camel donkey zebra came\x{301}l CAMEL horse cAm\0E\0L.";

    $Collator->change(ignore_level2 => 0, level => 1);

    $s = $txt;
    $Collator->gsubst($s, "camel", sub { "=$_[0]=" });
    ok($s, "=Camel= donkey zebra =came\x{301}l= =CAMEL= horse =cAm\0E\0L=.");

    $Collator->change(level => 2);

    $s = $txt;
    $Collator->gsubst($s, "camel", sub { "=$_[0]=" });
    ok($s, "=Camel= donkey zebra came\x{301}l =CAMEL= horse =cAm\0E\0L=.");

    $Collator->change(level => 3);

    $s = $txt;
    $Collator->gsubst($s, "camel", sub { "=$_[0]=" });
    ok($s, "Camel donkey zebra came\x{301}l CAMEL horse cAm\0E\0L.");

    $Collator->change(ignore_level2 => 1);

    $s = $txt;
    $Collator->gsubst($s, "camel", sub { "=$_[0]=" });
    ok($s, "Camel donkey zebra =came\x{301}l= CAMEL horse cAm\0E\0L.");

    $Collator->change(level => 2);
    $s = $txt;
    $Collator->gsubst($s, "camel", sub { "=$_[0]=" });
    ok($s, "=Camel= donkey zebra =came\x{301}l= =CAMEL= horse =cAm\0E\0L=.");

    $Collator->change(level => 1);
    $s = $txt;
    $Collator->gsubst($s, "camel", sub { "=$_[0]=" });
    ok($s, "=Camel= donkey zebra =came\x{301}l= =CAMEL= horse =cAm\0E\0L=.");

}

# 30

{
    my $c = Unicode::Collate->new(
        table => 'keys.txt', normalization => undef, level => 1,
    );
    my $str = "Camel donkey zebra came\x{301}l CAMEL horse cam\0e\0l...";
    $c->gsubst($str, "camel", sub { "<b>$_[0]</b>" });
    ok($str, "<b>Camel</b> donkey zebra <b>came\x{301}l</b> <b>CAMEL</b> horse <b>cam\0e\0l</b>...");
}

{
    my $c = Unicode::Collate->new(
        table => 'keys.txt', normalization => undef, level => 2,
    );
    my $str = "Camel donkey zebra came\x{301}l CAMEL horse cam\0e\0l...";
    $c->gsubst($str, "camel", sub { "<b>$_[0]</b>" });
    ok($str, "<b>Camel</b> donkey zebra came\x{301}l <b>CAMEL</b> horse <b>cam\0e\0l</b>...");
}

{
    my $c = Unicode::Collate->new(
        table => 'keys.txt', normalization => undef, ignore_level2 => 1,
    );
    my $str = "Camel donkey zebra came\x{301}l CAMEL horse cam\0e\0l...";
    $c->gsubst($str, "camel", sub { "<b>$_[0]</b>" });
    ok($str, "Camel donkey zebra <b>came\x{301}l</b> CAMEL horse <b>cam\0e\0l</b>...");
}

{
    my $c = Unicode::Collate->new(
        table => 'keys.txt', normalization => undef, level => 3,
    );
    my $str = "Camel donkey zebra came\x{301}l CAMEL horse cam\0e\0l...";
    $c->gsubst($str, "camel", sub { "<b>$_[0]</b>" });
    ok($str, "Camel donkey zebra came\x{301}l CAMEL horse <b>cam\0e\0l</b>...");
}

# 34

{
    my $str;
    my $camel = "camel Camel came\x{301}l c-a-m-e-l cam\0e\0l";

    $Collator->change(ignore_level2 => 0);

    $Collator->change(level => 1);
    $str = $camel;
    $Collator->gsubst($str, "camel", sub { "=$_[0]=" });
    ok($str, "=camel= =Camel= =came\x{301}l= =c-a-m-e-l= =cam\0e\0l=");

    $Collator->change(level => 2);
    $str = $camel;
    $Collator->gsubst($str, "camel", sub { "=$_[0]=" });
    ok($str, "=camel= =Camel= came\x{301}l =c-a-m-e-l= =cam\0e\0l=");

    $Collator->change(level => 3);
    $str = $camel;
    $Collator->gsubst($str, "camel", sub { "=$_[0]=" });
    ok($str, "=camel= Camel came\x{301}l =c-a-m-e-l= =cam\0e\0l=");

    $Collator->change(level => 4);
    $str = $camel;
    $Collator->gsubst($str, "camel", sub { "=$_[0]=" });
    ok($str, "=camel= Camel came\x{301}l c-a-m-e-l =cam\0e\0l=");

    $Collator->change(ignore_level2 => 1);

    $Collator->change(level => 1);
    $str = $camel;
    $Collator->gsubst($str, "camel", sub { "=$_[0]=" });
    ok($str, "=camel= =Camel= =came\x{301}l= =c-a-m-e-l= =cam\0e\0l=");

    $Collator->change(level => 2);
    $str = $camel;
    $Collator->gsubst($str, "camel", sub { "=$_[0]=" });
    ok($str, "=camel= =Camel= =came\x{301}l= =c-a-m-e-l= =cam\0e\0l=");

    $Collator->change(level => 3);
    $str = $camel;
    $Collator->gsubst($str, "camel", sub { "=$_[0]=" });
    ok($str, "=camel= Camel =came\x{301}l= =c-a-m-e-l= =cam\0e\0l=");

    $Collator->change(level => 4);
    $str = $camel;
    $Collator->gsubst($str, "camel", sub { "=$_[0]=" });
    ok($str, "=camel= Camel =came\x{301}l= c-a-m-e-l =cam\0e\0l=");
}

# 42