@@ -10,8 +10,8 @@ my $run_slow_tests = $ENV{PERL_RUN_SLOW_TESTS} || 0;
1010my $RUN_SLOW_TESTS_EVERY_CODE_POINT = 100;
1111
1212# If $ENV{PERL_RUN_SLOW_TESTS} is at least 1 and less than the number above,
13- # all code points with names are tested. If it is at least that number, all
14- # 1,114,112 Unicode code points are tested.
13+ # all code points with names are tested, including wildcard search names. If
14+ # it is at least that number, all 1,114,112 Unicode code points are tested.
1515
1616# Because \N{} is compile time, any warnings will get generated before
1717# execution, so have to have an array, and arrange things so no warning
@@ -114,6 +114,7 @@ sub get_loose_name ($) { # Modify name to stress the loose tests.
114114}
115115
116116sub test_vianame ($$$) {
117+ CORE::state $wildcard_count = 0;
117118
118119 # Run the vianame tests on a code point, both loose and full
119120
@@ -126,23 +127,54 @@ sub test_vianame ($$$) {
126127 # Get a copy of the name modified to stress the loose tests.
127128 my $loose_name = get_loose_name($name );
128129
130+ my $right_anchor ;
131+
129132 # Switch loose and full in vianame vs string_vianame half the time
130133 if (rand () < .5) {
131134 use charnames " :full" ;
132135 $all_pass &= is(charnames::vianame($name ), $i , " Verify vianame(\" $name \" ) is 0x$hex " );
133136 use charnames " :loose" ;
134137 $all_pass &= is(charnames::string_vianame($loose_name ), chr ($i ), " Verify string_vianame(\" $loose_name \" ) is chr(0x$hex )" );
138+ $right_anchor = ' \\ Z' ;
135139 }
136140 else {
137141 use charnames " :loose" ;
138142 $all_pass &= is(charnames::vianame($loose_name ), $i , " Verify vianame(\" $loose_name \" ) is 0x$hex " );
139143 use charnames " :full" ;
140144 $all_pass &= is(charnames::string_vianame($name ), chr ($i ), " Verify string_vianame(\" $name \" ) is chr(0x$hex )" );
145+ $right_anchor = ' \\ z' ;
141146 }
142147
148+ my $left_anchor = (rand () < .5) ? ' ^' : ' \\ A' ;
149+
143150 # \p{name=} is always loose matching
144151 $all_pass &= like(chr ($i ), qr / ^\p {name=$loose_name }$ / , " Verify /\p {name=$loose_name }/ matches chr(0x$hex )" );
145152
153+ $wildcard_count ++;
154+
155+ # Because wildcard name matching is so real-time intensive, do it less
156+ # frequently than the others
157+ if ($wildcard_count >= 10) {
158+ $wildcard_count = 0;
159+
160+ # A few control characters have anomalous names containing
161+ # parentheses, which need to be escaped.
162+ my $name_ref = \$name ;
163+ my $mod_name ;
164+ if ($i <= 0x85) { # NEL in ASCII; affected controls are lower than
165+ # this in EBCDIC
166+ $mod_name = $name =~ s / ([()])/ \\ $1 / gr ;
167+ $name_ref = \$mod_name ;
168+ }
169+
170+ # We anchor the name, randomly with the possible anchors.
171+ my $assembled = $left_anchor . $$name_ref . $right_anchor ;
172+
173+ # \p{name=/.../} is always full matching
174+ $all_pass &= like(chr ($i ), qr ! ^\p {name=/$assembled /}! ,
175+ " Verify /\p {name=/$assembled /} matches chr(0x$hex )" );
176+ }
177+
146178 return $all_pass ;
147179}
148180
@@ -352,6 +384,10 @@ is(charnames::viacode("U+00000000000FEED"), "ARABIC LETTER WAW ISOLATED FORM", '
352384
353385test_vianame(0x116C, " 116C" , " HANGUL JUNGSEONG OE" );
354386test_vianame(0x1180, " 1180" , " HANGUL JUNGSEONG O-E" );
387+ like(chr (0x59C3), qr /\p {name=\/\A CJK UNIFIED IDEOGRAPH-59C3\z\/ }/ ,
388+ ' Verify name wildcards delimitters can be escaped' );
389+ like(chr (0xD800), qr !\p {name=/\A\z /}! ,
390+ ' Verify works on matching an empty name' );
355391
356392{
357393 no warnings ' deprecated' ;
0 commit comments