XS-APItest: Add tests for handy.h
authorKarl Williamson <public@khwilliamson.com>
Mon, 3 Dec 2012 04:34:41 +0000 (21:34 -0700)
committerKarl Williamson <public@khwilliamson.com>
Sun, 9 Dec 2012 17:30:01 +0000 (10:30 -0700)
This adds missing tests for the locale versions of the macros in
handy.h, plus some to make sure that WORDCHAR and ALNUM are synonyms

ext/XS-APItest/APItest.pm
ext/XS-APItest/APItest.xs
ext/XS-APItest/t/handy.t

index 24d5cea..9471ce9 100644 (file)
@@ -5,7 +5,7 @@ use strict;
 use warnings;
 use Carp;
 
-our $VERSION = '0.47';
+our $VERSION = '0.48';
 
 require XSLoader;
 
index 4889acd..4edef93 100644 (file)
@@ -3563,6 +3563,13 @@ test_isBLANK_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isBLANK_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isBLANK_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isBLANK_A(UV ord)
     CODE:
@@ -3577,6 +3584,13 @@ test_isBLANK_L1(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isBLANK_LC(UV ord)
+    CODE:
+        RETVAL = isBLANK_LC(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isBLANK_utf8(unsigned char * p)
     CODE:
@@ -3584,6 +3598,13 @@ test_isBLANK_utf8(unsigned char * p)
     OUTPUT:
         RETVAL
 
+bool
+test_isBLANK_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isBLANK_LC_utf8(p);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isVERTWS_uni(UV ord)
     CODE:
@@ -3605,6 +3626,13 @@ test_isUPPER_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isUPPER_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isUPPER_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isUPPER_A(UV ord)
     CODE:
@@ -3619,6 +3647,13 @@ test_isUPPER_L1(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isUPPER_LC(UV ord)
+    CODE:
+        RETVAL = isUPPER_LC(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isUPPER_utf8(unsigned char * p)
     CODE:
@@ -3626,6 +3661,13 @@ test_isUPPER_utf8(unsigned char * p)
     OUTPUT:
         RETVAL
 
+bool
+test_isUPPER_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isUPPER_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isLOWER_uni(UV ord)
     CODE:
@@ -3633,6 +3675,13 @@ test_isLOWER_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isLOWER_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isLOWER_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isLOWER_A(UV ord)
     CODE:
@@ -3647,6 +3696,13 @@ test_isLOWER_L1(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isLOWER_LC(UV ord)
+    CODE:
+        RETVAL = isLOWER_LC(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isLOWER_utf8(unsigned char * p)
     CODE:
@@ -3654,6 +3710,13 @@ test_isLOWER_utf8(unsigned char * p)
     OUTPUT:
         RETVAL
 
+bool
+test_isLOWER_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isLOWER_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isALPHA_uni(UV ord)
     CODE:
@@ -3661,6 +3724,13 @@ test_isALPHA_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isALPHA_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isALPHA_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isALPHA_A(UV ord)
     CODE:
@@ -3672,6 +3742,13 @@ bool
 test_isALPHA_L1(UV ord)
     CODE:
         RETVAL = isALPHA_L1(ord);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isALPHA_LC(UV ord)
+    CODE:
+        RETVAL = isALPHA_LC(ord);
     OUTPUT:
         RETVAL
 
@@ -3683,26 +3760,131 @@ test_isALPHA_utf8(unsigned char * p)
         RETVAL
 
 bool
-test_isALNUM_uni(UV ord)
+test_isALPHA_LC_utf8(unsigned char * p)
     CODE:
-        RETVAL = isALNUM_uni(ord);
+        RETVAL = isALPHA_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isWORDCHAR_uni(UV ord)
+    CODE:
+        RETVAL = isWORDCHAR_uni(ord);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isWORDCHAR_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isWORDCHAR_LC_uvchr(ord);
     OUTPUT:
         RETVAL
 
 bool
-test_isALNUM_A(UV ord)
+test_isWORDCHAR_A(UV ord)
     CODE:
         RETVAL = isWORDCHAR_A(ord);
     OUTPUT:
         RETVAL
 
 bool
-test_isALNUM_L1(UV ord)
+test_isWORDCHAR_L1(UV ord)
     CODE:
         RETVAL = isWORDCHAR_L1(ord);
     OUTPUT:
         RETVAL
 
+bool
+test_isWORDCHAR_LC(UV ord)
+    CODE:
+        RETVAL = isWORDCHAR_LC(ord);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isWORDCHAR_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isWORDCHAR_utf8( p);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isWORDCHAR_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isWORDCHAR_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isALNUMC_uni(UV ord)
+    CODE:
+        RETVAL = isALNUMC_uni(ord);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isALNUMC_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isALNUMC_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isALNUMC_A(UV ord)
+    CODE:
+        RETVAL = isALNUMC_A(ord);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isALNUMC_L1(UV ord)
+    CODE:
+        RETVAL = isALNUMC_L1(ord);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isALNUMC_LC(UV ord)
+    CODE:
+        RETVAL = isALNUMC_LC(ord);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isALNUMC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isALNUMC_utf8( p);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isALNUMC_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isALNUMC_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isALNUM_uni(UV ord)
+    CODE:
+        RETVAL = isALNUM_uni(ord);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isALNUM_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isALNUM_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isALNUM_LC(UV ord)
+    CODE:
+        RETVAL = isALNUM_LC(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isALNUM_utf8(unsigned char * p)
     CODE:
@@ -3710,6 +3892,13 @@ test_isALNUM_utf8(unsigned char * p)
     OUTPUT:
         RETVAL
 
+bool
+test_isALNUM_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isALNUM_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isDIGIT_uni(UV ord)
     CODE:
@@ -3717,6 +3906,13 @@ test_isDIGIT_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isDIGIT_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isDIGIT_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isDIGIT_utf8(unsigned char * p)
     CODE:
@@ -3724,6 +3920,13 @@ test_isDIGIT_utf8(unsigned char * p)
     OUTPUT:
         RETVAL
 
+bool
+test_isDIGIT_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isDIGIT_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isDIGIT_A(UV ord)
     CODE:
@@ -3738,6 +3941,13 @@ test_isDIGIT_L1(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isDIGIT_LC(UV ord)
+    CODE:
+        RETVAL = isDIGIT_LC(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isIDFIRST_uni(UV ord)
     CODE:
@@ -3745,6 +3955,13 @@ test_isIDFIRST_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isIDFIRST_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isIDFIRST_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isIDFIRST_A(UV ord)
     CODE:
@@ -3759,6 +3976,13 @@ test_isIDFIRST_L1(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isIDFIRST_LC(UV ord)
+    CODE:
+        RETVAL = isIDFIRST_LC(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isIDFIRST_utf8(unsigned char * p)
     CODE:
@@ -3766,6 +3990,13 @@ test_isIDFIRST_utf8(unsigned char * p)
     OUTPUT:
         RETVAL
 
+bool
+test_isIDFIRST_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isIDFIRST_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isSPACE_uni(UV ord)
     CODE:
@@ -3773,6 +4004,13 @@ test_isSPACE_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isSPACE_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isSPACE_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isSPACE_A(UV ord)
     CODE:
@@ -3787,6 +4025,13 @@ test_isSPACE_L1(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isSPACE_LC(UV ord)
+    CODE:
+        RETVAL = isSPACE_LC(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isSPACE_utf8(unsigned char * p)
     CODE:
@@ -3794,6 +4039,13 @@ test_isSPACE_utf8(unsigned char * p)
     OUTPUT:
         RETVAL
 
+bool
+test_isSPACE_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isSPACE_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isASCII_uni(UV ord)
     CODE:
@@ -3801,6 +4053,13 @@ test_isASCII_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isASCII_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isASCII_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isASCII_A(UV ord)
     CODE:
@@ -3815,6 +4074,13 @@ test_isASCII_L1(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isASCII_LC(UV ord)
+    CODE:
+        RETVAL = isASCII_LC(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isASCII_utf8(unsigned char * p)
     CODE:
@@ -3822,6 +4088,13 @@ test_isASCII_utf8(unsigned char * p)
     OUTPUT:
         RETVAL
 
+bool
+test_isASCII_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isASCII_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isCNTRL_uni(UV ord)
     CODE:
@@ -3829,6 +4102,13 @@ test_isCNTRL_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isCNTRL_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isCNTRL_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isCNTRL_A(UV ord)
     CODE:
@@ -3843,6 +4123,13 @@ test_isCNTRL_L1(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isCNTRL_LC(UV ord)
+    CODE:
+        RETVAL = isCNTRL_LC(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isCNTRL_utf8(unsigned char * p)
     CODE:
@@ -3850,6 +4137,13 @@ test_isCNTRL_utf8(unsigned char * p)
     OUTPUT:
         RETVAL
 
+bool
+test_isCNTRL_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isCNTRL_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isPRINT_uni(UV ord)
     CODE:
@@ -3857,6 +4151,13 @@ test_isPRINT_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isPRINT_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isPRINT_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isPRINT_A(UV ord)
     CODE:
@@ -3871,10 +4172,24 @@ test_isPRINT_L1(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isPRINT_LC(UV ord)
+    CODE:
+        RETVAL = isPRINT_LC(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isPRINT_utf8(unsigned char * p)
     CODE:
         RETVAL = isPRINT_utf8( p);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isPRINT_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isPRINT_LC_utf8( p);
     OUTPUT:
         RETVAL
 
@@ -3885,6 +4200,13 @@ test_isGRAPH_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isGRAPH_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isGRAPH_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isGRAPH_A(UV ord)
     CODE:
@@ -3900,23 +4222,23 @@ test_isGRAPH_L1(UV ord)
         RETVAL
 
 bool
-test_isGRAPH_utf8(unsigned char * p)
+test_isGRAPH_LC(UV ord)
     CODE:
-        RETVAL = isGRAPH_utf8( p);
+        RETVAL = isGRAPH_LC(ord);
     OUTPUT:
         RETVAL
 
 bool
-test_isALNUMC_A(UV ord)
+test_isGRAPH_utf8(unsigned char * p)
     CODE:
-        RETVAL = isALNUMC_A(ord);
+        RETVAL = isGRAPH_utf8( p);
     OUTPUT:
         RETVAL
 
 bool
-test_isALNUMC_L1(UV ord)
+test_isGRAPH_LC_utf8(unsigned char * p)
     CODE:
-        RETVAL = isALNUMC_L1(ord);
+        RETVAL = isGRAPH_LC_utf8( p);
     OUTPUT:
         RETVAL
 
@@ -3927,6 +4249,13 @@ test_isPUNCT_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isPUNCT_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isPUNCT_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isPUNCT_A(UV ord)
     CODE:
@@ -3941,6 +4270,13 @@ test_isPUNCT_L1(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isPUNCT_LC(UV ord)
+    CODE:
+        RETVAL = isPUNCT_LC(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isPUNCT_utf8(unsigned char * p)
     CODE:
@@ -3948,6 +4284,13 @@ test_isPUNCT_utf8(unsigned char * p)
     OUTPUT:
         RETVAL
 
+bool
+test_isPUNCT_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isPUNCT_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isXDIGIT_uni(UV ord)
     CODE:
@@ -3955,6 +4298,13 @@ test_isXDIGIT_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isXDIGIT_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isXDIGIT_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isXDIGIT_A(UV ord)
     CODE:
@@ -3969,6 +4319,13 @@ test_isXDIGIT_L1(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isXDIGIT_LC(UV ord)
+    CODE:
+        RETVAL = isXDIGIT_LC(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isXDIGIT_utf8(unsigned char * p)
     CODE:
@@ -3976,6 +4333,13 @@ test_isXDIGIT_utf8(unsigned char * p)
     OUTPUT:
         RETVAL
 
+bool
+test_isXDIGIT_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isXDIGIT_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isPSXSPC_uni(UV ord)
     CODE:
@@ -3983,6 +4347,13 @@ test_isPSXSPC_uni(UV ord)
     OUTPUT:
         RETVAL
 
+bool
+test_isPSXSPC_LC_uvchr(UV ord)
+    CODE:
+        RETVAL = isPSXSPC_LC_uvchr(ord);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isPSXSPC_A(UV ord)
     CODE:
@@ -3994,6 +4365,13 @@ bool
 test_isPSXSPC_L1(UV ord)
     CODE:
         RETVAL = isPSXSPC_L1(ord);
+    OUTPUT:
+        RETVAL
+
+bool
+test_isPSXSPC_LC(UV ord)
+    CODE:
+        RETVAL = isPSXSPC_LC(ord);
     OUTPUT:
         RETVAL
 
@@ -4004,6 +4382,13 @@ test_isPSXSPC_utf8(unsigned char * p)
     OUTPUT:
         RETVAL
 
+bool
+test_isPSXSPC_LC_utf8(unsigned char * p)
+    CODE:
+        RETVAL = isPSXSPC_LC_utf8( p);
+    OUTPUT:
+        RETVAL
+
 bool
 test_isQUOTEMETA(UV ord)
     CODE:
index 4c852c5..d674b5f 100644 (file)
@@ -11,9 +11,25 @@ sub truth($) {  # Converts values so is() works
     return (shift) ? 1 : 0;
 }
 
+require POSIX;
+my $locale = POSIX::setlocale( &POSIX::LC_ALL, "C");
+if (defined $locale && $locale eq 'C') {
+    use locale;
+
+    # Some locale implementations don't have the 128-255 characters all
+    # mean nothing.  Skip the locale tests in that situation
+    for my $i (128 .. 255) {
+        if (chr($i) =~ /[[:print:]]/) {
+            undef $locale;
+            last;
+        }
+    }
+}
+
 my %properties = (
                    # name => Lookup-property name
                    alnum => 'Word',
+                   wordchar => 'Word',
                    alnumc => 'Alnum',
                    alpha => 'Alpha',
                    ascii => 'ASCII',
@@ -92,7 +108,12 @@ foreach my $name (sort keys %properties) {
             }
             next;
         }
+
+        # vertws is always all of Unicode; ALNUM_A and ALNUM_L1 are not
+        # defined as they were added later, after WORDCHAR was created to be a
+        # clearer synonym for ALNUM
         if ($name ne 'vertws') {
+            if ($name ne 'alnum') {
             $ret = truth eval "test_is${function}_A($i)";
             if ($@) {
                 fail($@);
@@ -109,8 +130,20 @@ foreach my $name (sort keys %properties) {
                 my $truth = truth($matches && $i < 256);
                 is ($ret, $truth, "is${function}_L1( $display_name ) == $truth");
             }
+            }
+
+            next unless defined $locale;
+            use locale;
+
+            $ret = truth eval "test_is${function}_LC($i)";
+            if ($@) {
+                fail($@);
+            }
+            else {
+                my $truth = truth($matches && $i < 128);
+                is ($ret, $truth, "is${function}_LC( $display_name ) == $truth");
+            }
         }
-        next if $name eq 'alnumc';
 
         $ret = truth eval "test_is${function}_uni($i)";
         if ($@) {
@@ -120,6 +153,19 @@ foreach my $name (sort keys %properties) {
             is ($ret, $matches, "is${function}_uni( $display_name ) == $matches");
         }
 
+        if (defined $locale && $name ne 'vertws') {
+            use locale;
+
+            $ret = truth eval "test_is${function}_LC_uvchr('$i')";
+            if ($@) {
+                fail($@);
+            }
+            else {
+                my $truth = truth($matches && ($i < 128 || $i > 255));
+                is ($ret, $truth, "is${function}_LC_uvchr( $display_name ) == $truth");
+            }
+        }
+
         my $char = chr($i);
         utf8::upgrade($char);
         $char = quotemeta $char if $char eq '\\' || $char eq "'";
@@ -130,6 +176,18 @@ foreach my $name (sort keys %properties) {
         else {
             is ($ret, $matches, "is${function}_utf8( $display_name ) == $matches");
         }
+
+        next if $name eq 'vertws' || ! defined $locale;
+        use locale;
+
+        $ret = truth eval "test_is${function}_LC_utf8('$char')";
+        if ($@) {
+            fail($@);
+        }
+        else {
+            my $truth = truth($matches && ($i < 128 || $i > 255));
+            is ($ret, $truth, "is${function}_LC_utf8( $display_name ) == $truth");
+        }
     }
 }