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_gb.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 => 25 };
16
17 use strict;
18 use warnings;
19 use Unicode::Collate;
20
21 ok(1);
22
23 #########################
24
25 use Unicode::Collate::CJK::GB2312;
26
27 my $collator = Unicode::Collate->new(
28     table => undef,
29     normalization => undef,
30     overrideCJK => \&Unicode::Collate::CJK::GB2312::weightGB2312
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{554A}", "\x{963F}"));
44 ok($collator->lt("\x{963F}", "\x{57C3}"));
45 ok($collator->lt("\x{57C3}", "\x{6328}"));
46 ok($collator->lt("\x{6328}", "\x{54CE}"));
47 ok($collator->lt("\x{54CE}", "\x{5509}"));
48 ok($collator->lt("\x{5509}", "\x{54C0}"));
49 ok($collator->lt("\x{54C0}", "\x{7691}"));
50 ok($collator->lt("\x{7691}", "\x{764C}"));
51 ok($collator->lt("\x{764C}", "\x{853C}"));
52 ok($collator->lt("\x{853C}", "\x{77EE}"));
53
54 ok($collator->lt("\x{77EE}", "\x{4E00}"));
55 ok($collator->lt("\x{4E00}", "\x{9F2F}"));
56
57 ok($collator->lt("\x{9F2F}", "\x{9F39}"));
58 ok($collator->lt("\x{9F39}", "\x{9F37}"));
59 ok($collator->lt("\x{9F37}", "\x{9F3D}"));
60 ok($collator->lt("\x{9F3D}", "\x{9F3E}"));
61 ok($collator->lt("\x{9F3E}", "\x{9F44}"));
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 # 23
71
72 ok(hex_sort('4E00 4E8C 4E09 56DB 4E94 516D 4E03 516B 4E5D 5341'),
73             '516B 4E8C 4E5D 516D 4E03 4E09 5341 56DB 4E94 4E00');
74
75 ok(hex_sort('4E0C 4E8D 4F5C 5140 554A 5750 57C3 5EA7 963F 9F3D 9F3E 9F44'),
76             '554A 963F 57C3 4F5C 5750 5EA7 4E8D 4E0C 5140 9F3D 9F3E 9F44');
77
78 # 25