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