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_st.t
1
2 BEGIN {
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
14 use Test;
15 BEGIN { plan tests => 26 };
16
17 use strict;
18 use warnings;
19 use Unicode::Collate;
20
21 ok(1);
22
23 #########################
24
25 use Unicode::Collate::CJK::Stroke;
26
27 my $collator = Unicode::Collate->new(
28     table => undef,
29     normalization => undef,
30     overrideCJK => \&Unicode::Collate::CJK::Stroke::weightStroke
31 );
32
33 sub 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
41 $collator->change(level => 1);
42
43 ok($collator->lt("\x{4E00}", "\x{4E59}"));
44 ok($collator->lt("\x{4E59}", "\x{4E01}"));
45 ok($collator->lt("\x{4E01}", "\x{4E03}"));
46 ok($collator->lt("\x{4E03}", "\x{4E43}"));
47 ok($collator->lt("\x{4E43}", "\x{4E5D}"));
48 ok($collator->lt("\x{4E5D}", "\x{4E86}"));
49 ok($collator->lt("\x{4E86}", "\x{4E8C}"));
50 ok($collator->lt("\x{4E8C}", "\x{4EBA}"));
51 ok($collator->lt("\x{4EBA}", "\x{513F}"));
52 ok($collator->lt("\x{513F}", "\x{5165}"));
53
54 ok($collator->lt("\x{9E1D}", "\x{7069}"));
55 ok($collator->lt("\x{7069}", "\x{706A}"));
56 ok($collator->lt("\x{706A}", "\x{7C72}"));
57 ok($collator->lt("\x{7C72}", "\x{7229}"));
58 ok($collator->lt("\x{7229}", "\x{9EA4}"));
59 ok($collator->lt("\x{9EA4}", "\x{9F7E}"));
60 ok($collator->lt("\x{9F7E}", "\x{9F49}"));
61 ok($collator->lt("\x{9F49}", "\x{9F98}"));
62
63 # Ext.B
64 ok($collator->lt("\x{20000}", "\x{20001}"));
65 ok($collator->lt("\x{20001}", "\x{20002}"));
66 ok($collator->lt("\x{20002}", "\x{20003}"));
67 ok($collator->lt("\x{20003}", "\x{20004}"));
68 ok($collator->lt("\x{20004}", "\x{20005}"));
69
70 # 24
71
72 ok(hex_sort('4E00 4E8C 4E09 56DB 4E94 516D 4E03 516B 4E5D 5341'),
73             '4E00 4E03 4E5D 4E8C 516B 5341 4E09 4E94 516D 56DB');
74
75 ok(hex_sort('4E0C 4E8D 4F5C 5140 554A 5750 57C3 5EA7 963F 9F3D 9F3E 9F44'),
76             '4E0C 4E8D 5140 4F5C 5750 963F 57C3 5EA7 554A 9F3D 9F3E 9F44');
77
78 # 26