Upgrade to Unicode-Normalize-1.00
[p5sagit/p5-mst-13.2.git] / ext / Unicode / Normalize / t / split.t
1
2 BEGIN {
3     unless ("A" eq pack('U', 0x41)) {
4         print "1..0 # Unicode::Normalize " .
5             "cannot stringify a Unicode code point\n";
6         exit 0;
7     }
8 }
9
10 BEGIN {
11     if ($ENV{PERL_CORE}) {
12         chdir('t') if -d 't';
13         @INC = $^O eq 'MacOS' ? qw(::lib) : qw(../lib);
14     }
15 }
16
17 BEGIN {
18     unless (5.006001 <= $]) {
19         print "1..0 # skipped: Perl 5.6.1 or later".
20                 " needed for this test\n";
21         exit;
22     }
23 }
24
25 #########################
26
27 use Test;
28 use strict;
29 use warnings;
30 BEGIN { plan tests => 14 };
31 use Unicode::Normalize qw(:all);
32 ok(1); # If we made it this far, we're ok.
33
34 sub _pack_U   { Unicode::Normalize::pack_U(@_) }
35 sub _unpack_U { Unicode::Normalize::unpack_U(@_) }
36
37 #########################
38
39 our $proc;    # before the last starter
40 our $unproc;  # the last starter and after
41 # If string has no starter, entire string is set to $unproc.
42
43 # When you have $normalized string and $unnormalized string following,
44 # a simple concatenation
45 #   C<$concat = $normalized . normalize($form, $unnormalized)>
46 # is wrong. Instead of it, like this:
47 #
48 #       ($processed, $unprocessed) = splitOnLastStarter($normalized);
49 #       $concat = $processed . normalize($form, $unprocessed.$unnormalized);
50
51 ($proc, $unproc) = splitOnLastStarter("");
52 ok($proc,   "");
53 ok($unproc, "");
54
55 ($proc, $unproc) = splitOnLastStarter("A");
56 ok($proc,   "");
57 ok($unproc, "A");
58
59 ($proc, $unproc) = splitOnLastStarter(_pack_U(0x41, 0x300, 0x327, 0x42));
60 ok($proc,   _pack_U(0x41, 0x300, 0x327));
61 ok($unproc, "B");
62
63 ($proc, $unproc) = splitOnLastStarter(_pack_U(0x4E00, 0x41, 0x301));
64 ok($proc,   _pack_U(0x4E00));
65 ok($unproc, _pack_U(0x41, 0x301));
66
67 ($proc, $unproc) = splitOnLastStarter(_pack_U(0x302, 0x301, 0x300));
68 ok($proc,   "");
69 ok($unproc, _pack_U(0x302, 0x301, 0x300));
70
71 our $ka_grave = _pack_U(0x41, 0, 0x42, 0x304B, 0x300);
72 our $dakuten  = _pack_U(0x3099);
73 our $ga_grave = _pack_U(0x41, 0, 0x42, 0x304C, 0x300);
74
75 our ($p, $u) = splitOnLastStarter($ka_grave);
76 our $concat = $p . NFC($u.$dakuten);
77
78 ok(NFC($ka_grave.$dakuten) eq $ga_grave);
79 ok(NFC($ka_grave).NFC($dakuten) ne $ga_grave);
80 ok($concat eq $ga_grave);
81