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_ko.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 => 52 };
16
17 use strict;
18 use warnings;
19 use Unicode::Collate;
20
21 ok(1);
22
23 #########################
24
25 use Unicode::Collate::CJK::Korean;
26
27 my $collator = Unicode::Collate->new(
28     normalization => undef,
29     overrideCJK => \&Unicode::Collate::CJK::Korean::weightKorean
30 );
31
32 sub hex_sort {
33     my @source = map pack('U', hex $_), split ' ', shift;
34     my @sorted = $collator->sort(@source);
35     return join " ", map sprintf("%04X", unpack 'U', $_), @sorted;
36 }
37
38 # 1
39
40 $collator->change(level => 1);
41
42 ok($collator->eq("\x{AC00}", "\x{4F3D}"));
43 ok($collator->eq("\x{4F3D}", "\x{4F73}"));
44 ok($collator->eq("\x{4F73}", "\x{5047}"));
45 ok($collator->eq("\x{5047}", "\x{50F9}"));
46 ok($collator->eq("\x{50F9}", "\x{52A0}"));
47 ok($collator->eq("\x{52A0}", "\x{53EF}"));
48 ok($collator->lt("\x{53EF}", "\x{AC01}"));
49
50 ok($collator->eq("\x{AC1D}", "\x{5580}"));
51 ok($collator->eq("\x{5580}", "\x{5BA2}"));
52 ok($collator->lt("\x{5BA2}", "\x{AC31}"));
53
54 ok($collator->eq("\x{C77C}", "\x{4E00}"));
55 ok($collator->eq("\x{4E00}", "\x{4F5A}"));
56 ok($collator->eq("\x{4F5A}", "\x{4F7E}"));
57
58 ok($collator->lt("\x{993C}", "\x{D790}"));
59 ok($collator->eq("\x{D790}", "\x{8A70}"));
60 ok($collator->eq("\x{8A70}", "\x{72B5}"));
61 ok($collator->eq("\x{72B5}", "\x{7E88}"));
62 ok($collator->eq("\x{7E88}", "\x{896D}"));
63 ok($collator->eq("\x{896D}", "\x{9821}"));
64 ok($collator->eq("\x{9821}", "\x{9EE0}"));
65
66 # Ext.B
67 ok($collator->lt("\x{20000}", "\x{20001}"));
68 ok($collator->lt("\x{20001}", "\x{20002}"));
69 ok($collator->lt("\x{20002}", "\x{20003}"));
70 ok($collator->lt("\x{20003}", "\x{20004}"));
71 ok($collator->lt("\x{20004}", "\x{20005}"));
72
73 # 26
74
75 $collator->change(level => 2);
76
77 ok($collator->lt("\x{AC00}", "\x{4F3D}"));
78 ok($collator->lt("\x{4F3D}", "\x{4F73}"));
79 ok($collator->lt("\x{4F73}", "\x{5047}"));
80 ok($collator->lt("\x{5047}", "\x{50F9}"));
81 ok($collator->lt("\x{50F9}", "\x{52A0}"));
82 ok($collator->lt("\x{52A0}", "\x{53EF}"));
83 ok($collator->lt("\x{53EF}", "\x{AC01}"));
84
85 ok($collator->lt("\x{AC1D}", "\x{5580}"));
86 ok($collator->lt("\x{5580}", "\x{5BA2}"));
87 ok($collator->lt("\x{5BA2}", "\x{AC31}"));
88
89 ok($collator->lt("\x{C77C}", "\x{4E00}"));
90 ok($collator->lt("\x{4E00}", "\x{4F5A}"));
91 ok($collator->lt("\x{4F5A}", "\x{4F7E}"));
92
93 ok($collator->lt("\x{993C}", "\x{D790}"));
94 ok($collator->lt("\x{D790}", "\x{8A70}"));
95 ok($collator->lt("\x{8A70}", "\x{72B5}"));
96 ok($collator->lt("\x{72B5}", "\x{7E88}"));
97 ok($collator->lt("\x{7E88}", "\x{896D}"));
98 ok($collator->lt("\x{896D}", "\x{9821}"));
99 ok($collator->lt("\x{9821}", "\x{9EE0}"));
100
101 # Ext.B
102 ok($collator->lt("\x{20000}", "\x{20001}"));
103 ok($collator->lt("\x{20001}", "\x{20002}"));
104 ok($collator->lt("\x{20002}", "\x{20003}"));
105 ok($collator->lt("\x{20003}", "\x{20004}"));
106 ok($collator->lt("\x{20004}", "\x{20005}"));
107
108 # 51
109
110 ok(hex_sort('4E00 4E8C 4E09 56DB 4E94 516D 4E03 516B 4E5D 5341'),
111             '4E5D 516D 56DB 4E09 5341 4E94 4E8C 4E00 4E03 516B');
112
113 # 52