This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Updated Unicode-Collate to CPAN version 0.76
[perl5.git] / cpan / Unicode-Collate / t / cjk_py.t
CommitLineData
68adb2b0
CBW
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;
19265284 15BEGIN { plan tests => 19 };
68adb2b0
CBW
16
17use strict;
18use warnings;
19use Unicode::Collate;
20
21ok(1);
22
23#########################
24
25use Unicode::Collate::CJK::Pinyin;
26
27my $collator = Unicode::Collate->new(
28 table => undef,
29 normalization => undef,
30 overrideCJK => \&Unicode::Collate::CJK::Pinyin::weightPinyin
31);
32
19265284
CBW
33sub hex_sort {
34 my @source = map pack('U', hex $_), split ' ', shift;
35 my @sorted = $collator->sort(@source);
36 return join " ", map sprintf("%04X", unpack 'U', $_), @sorted;
37}
38
39# 1
40
68adb2b0
CBW
41$collator->change(level => 1);
42
19265284
CBW
43ok($collator->lt("\x{963F}", "\x{5730}"));
44ok($collator->lt("\x{5730}", "\x{7ACB}"));
45ok($collator->lt("\x{7ACB}", "\x{4EBA}"));
46ok($collator->lt("\x{4EBA}", "\x{65E5}"));
47ok($collator->lt("\x{65E5}", "\x{4E0A}"));
48ok($collator->lt("\x{4E0A}", "\x{5929}"));
49ok($collator->lt("\x{5929}", "\x{4E0B}"));
50ok($collator->lt("\x{4E0B}", "\x{65BC}"));
51ok($collator->lt("\x{65BC}", "\x{4E2D}"));
52ok($collator->lt("\x{4E2D}", "\x{7AFA}"));
53ok($collator->lt("\x{7AFA}", "\x{5750}"));
68adb2b0
CBW
54
55# Ext.B
56ok($collator->lt("\x{20000}", "\x{20001}"));
57ok($collator->lt("\x{20001}", "\x{20002}"));
58ok($collator->lt("\x{20002}", "\x{20003}"));
59ok($collator->lt("\x{20003}", "\x{20004}"));
60ok($collator->lt("\x{20004}", "\x{20005}"));
61
19265284
CBW
62# 17
63
64ok(hex_sort('4E00 4E8C 4E09 56DB 4E94 516D 4E03 516B 4E5D 5341'),
65 '516B 4E8C 4E5D 516D 4E03 4E09 5341 56DB 4E94 4E00');
66
67ok(hex_sort('4E0C 4E8D 4F5C 5140 554A 5750 57C3 5EA7 963F 9F3D 9F3E 9F44'),
68 '963F 554A 57C3 4E8D 9F3E 4E0C 9F3D 5140 9F44 4F5C 5750 5EA7');
69
70# 19