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