1
2BEGIN {
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
10BEGIN {
11    if ($ENV{PERL_CORE}) {
12        chdir('t') if -d 't';
13        @INC = $^O eq 'MacOS' ? qw(::lib) : qw(../lib);
14    }
15}
16
17BEGIN {
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
27use Test;
28use strict;
29use warnings;
30BEGIN { plan tests => 14 };
31use Unicode::Normalize qw(:all);
32ok(1); # If we made it this far, we're ok.
33
34sub _pack_U   { Unicode::Normalize::pack_U(@_) }
35sub _unpack_U { Unicode::Normalize::unpack_U(@_) }
36
37#########################
38
39our $proc;    # before the last starter
40our $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("");
52ok($proc,   "");
53ok($unproc, "");
54
55($proc, $unproc) = splitOnLastStarter("A");
56ok($proc,   "");
57ok($unproc, "A");
58
59($proc, $unproc) = splitOnLastStarter(_pack_U(0x41, 0x300, 0x327, 0x42));
60ok($proc,   _pack_U(0x41, 0x300, 0x327));
61ok($unproc, "B");
62
63($proc, $unproc) = splitOnLastStarter(_pack_U(0x4E00, 0x41, 0x301));
64ok($proc,   _pack_U(0x4E00));
65ok($unproc, _pack_U(0x41, 0x301));
66
67($proc, $unproc) = splitOnLastStarter(_pack_U(0x302, 0x301, 0x300));
68ok($proc,   "");
69ok($unproc, _pack_U(0x302, 0x301, 0x300));
70
71our $ka_grave = _pack_U(0x41, 0, 0x42, 0x304B, 0x300);
72our $dakuten  = _pack_U(0x3099);
73our $ga_grave = _pack_U(0x41, 0, 0x42, 0x304C, 0x300);
74
75our ($p, $u) = splitOnLastStarter($ka_grave);
76our $concat = $p . NFC($u.$dakuten);
77
78ok(NFC($ka_grave.$dakuten) eq $ga_grave);
79ok(NFC($ka_grave).NFC($dakuten) ne $ga_grave);
80ok($concat eq $ga_grave);
81
82