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 17######################### 18 19use Test; 20use strict; 21use warnings; 22BEGIN { plan tests => 14 }; 23use Unicode::Normalize qw(:all); 24ok(1); # If we made it this far, we're ok. 25 26sub _pack_U { Unicode::Normalize::pack_U(@_) } 27sub _unpack_U { Unicode::Normalize::unpack_U(@_) } 28 29######################### 30 31our $proc; # before the last starter 32our $unproc; # the last starter and after 33# If string has no starter, entire string is set to $unproc. 34 35# When you have $normalized string and $unnormalized string following, 36# a simple concatenation 37# C<$concat = $normalized . normalize($form, $unnormalized)> 38# is wrong. Instead of it, like this: 39# 40# ($processed, $unprocessed) = splitOnLastStarter($normalized); 41# $concat = $processed . normalize($form, $unprocessed.$unnormalized); 42 43($proc, $unproc) = splitOnLastStarter(""); 44ok($proc, ""); 45ok($unproc, ""); 46 47($proc, $unproc) = splitOnLastStarter("A"); 48ok($proc, ""); 49ok($unproc, "A"); 50 51($proc, $unproc) = splitOnLastStarter(_pack_U(0x41, 0x300, 0x327, 0x42)); 52ok($proc, _pack_U(0x41, 0x300, 0x327)); 53ok($unproc, "B"); 54 55($proc, $unproc) = splitOnLastStarter(_pack_U(0x4E00, 0x41, 0x301)); 56ok($proc, _pack_U(0x4E00)); 57ok($unproc, _pack_U(0x41, 0x301)); 58 59($proc, $unproc) = splitOnLastStarter(_pack_U(0x302, 0x301, 0x300)); 60ok($proc, ""); 61ok($unproc, _pack_U(0x302, 0x301, 0x300)); 62 63our $ka_grave = _pack_U(0x41, 0, 0x42, 0x304B, 0x300); 64our $dakuten = _pack_U(0x3099); 65our $ga_grave = _pack_U(0x41, 0, 0x42, 0x304C, 0x300); 66 67our ($p, $u) = splitOnLastStarter($ka_grave); 68our $concat = $p . NFC($u.$dakuten); 69 70ok(NFC($ka_grave.$dakuten) eq $ga_grave); 71ok(NFC($ka_grave).NFC($dakuten) ne $ga_grave); 72ok($concat eq $ga_grave); 73 74