This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/re/regexp_unicode_prop.t: Make sure sub called only once
authorKarl Williamson <khw@cpan.org>
Mon, 6 Aug 2018 23:00:40 +0000 (17:00 -0600)
committerKarl Williamson <khw@cpan.org>
Fri, 15 Feb 2019 05:12:44 +0000 (22:12 -0700)
User-defined properties are supposed to be called just once for /i and
once for non-/i.  This adds tests for that.

It turns out that this was broken in blead.

t/re/regexp_unicode_prop.t

index 06c30e0..ab117d2 100644 (file)
@@ -469,12 +469,25 @@ sub InLatin1 {
 }
 
 sub IsMyUpper {
+    use feature 'state';
+
+    state $cased_count = 0;
+    state $caseless_count = 0;
+    my $ret= "+utf8::";
+
     my $caseless = shift;
-    return "+utf8::"
-           . (($caseless)
-               ? 'Alphabetic'
-               : 'Uppercase')
-           . "\n&utf8::ASCII";
+    if($caseless) {
+        die "Called twice" if $caseless_count;
+        $caseless_count++;
+        $ret .= 'Alphabetic'
+    }
+    else {
+        die "Called twice" if $cased_count;
+        $cased_count++;
+        $ret .= 'Uppercase';
+    }
+
+    return $ret . "\n&utf8::ASCII";
 }
 
 sub pkg1::pkg2::IsMyLower {