< prev index next >

test/jdk/java/util/regex/RegExTest.java

Print this page
rev 54580 : [mq]: 8214245-Case-insensitive-matching-doesnt-work-correctly-for-POSIX-character-classes
   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @summary tests RegExp framework (use -Dseed=X to set PRNG seed)
  27  * @author Mike McCloskey
  28  * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345
  29  * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962
  30  * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
  31  * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
  32  * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
  33  * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
  34  * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
  35  * 8027645 8035076 8039124 8035975 8074678 6854417 8143854 8147531 7071819
  36  * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895
  37  * 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706
  38  * 8194667 8197462 8184692
  39  *
  40  * @library /test/lib
  41  * @build jdk.test.lib.RandomFactory
  42  * @run main RegExTest
  43  * @key randomness
  44  */
  45 
  46 import java.util.function.Function;
  47 import java.util.regex.*;
  48 import java.util.Random;
  49 import java.util.Scanner;
  50 import java.io.*;
  51 import java.nio.file.*;
  52 import java.util.*;
  53 import java.nio.CharBuffer;
  54 import java.util.function.Predicate;
  55 import jdk.test.lib.RandomFactory;
  56 
  57 /**
  58  * This is a test class created to check the operation of


 153         surrogatesInClassTest();
 154         removeQEQuotingTest();
 155         namedGroupCaptureTest();
 156         nonBmpClassComplementTest();
 157         unicodePropertiesTest();
 158         unicodeHexNotationTest();
 159         unicodeClassesTest();
 160         unicodeCharacterNameTest();
 161         horizontalAndVerticalWSTest();
 162         linebreakTest();
 163         branchTest();
 164         groupCurlyNotFoundSuppTest();
 165         groupCurlyBackoffTest();
 166         patternAsPredicate();
 167         patternAsMatchPredicate();
 168         invalidFlags();
 169         embeddedFlags();
 170         grapheme();
 171         expoBacktracking();
 172         invalidGroupName();

 173 
 174         if (failure) {
 175             throw new
 176                 RuntimeException("RegExTest failed, 1st failure: " +
 177                                  firstFailure);
 178         } else {
 179             System.err.println("OKAY: All tests passed.");
 180         }
 181     }
 182 
 183     // Utility functions
 184 
 185     private static String getRandomAlphaString(int length) {
 186         StringBuffer buf = new StringBuffer(length);
 187         for (int i=0; i<length; i++) {
 188             char randChar = (char)(97 + generator.nextInt(26));
 189             buf.append(randChar);
 190         }
 191         return buf.toString();
 192     }


4914                 }
4915             }
4916         }
4917         // Invalid char in a group name
4918         for (String groupName : List.of("a.", "b\u0040", "c\u005b",
4919                 "d\u0060", "e\u007b", "f\u0416")) {
4920             for (String pat : List.of("(?<" + groupName + ">)",
4921                     "\\k<" + groupName + ">")) {
4922                 try {
4923                     Pattern.compile(pat);
4924                     failCount++;
4925                 } catch (PatternSyntaxException e) {
4926                     if (!e.getMessage().startsWith(
4927                             "named capturing group is missing trailing '>'")) {
4928                         failCount++;
4929                     }
4930                 }
4931             }
4932         }
4933         report("Invalid capturing group names");




























































4934     }
4935 }
   1 /*
   2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @summary tests RegExp framework (use -Dseed=X to set PRNG seed)
  27  * @author Mike McCloskey
  28  * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345
  29  * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962
  30  * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
  31  * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
  32  * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
  33  * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
  34  * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
  35  * 8027645 8035076 8039124 8035975 8074678 6854417 8143854 8147531 7071819
  36  * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895
  37  * 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706
  38  * 8194667 8197462 8184692 8214245
  39  *
  40  * @library /test/lib
  41  * @build jdk.test.lib.RandomFactory
  42  * @run main RegExTest
  43  * @key randomness
  44  */
  45 
  46 import java.util.function.Function;
  47 import java.util.regex.*;
  48 import java.util.Random;
  49 import java.util.Scanner;
  50 import java.io.*;
  51 import java.nio.file.*;
  52 import java.util.*;
  53 import java.nio.CharBuffer;
  54 import java.util.function.Predicate;
  55 import jdk.test.lib.RandomFactory;
  56 
  57 /**
  58  * This is a test class created to check the operation of


 153         surrogatesInClassTest();
 154         removeQEQuotingTest();
 155         namedGroupCaptureTest();
 156         nonBmpClassComplementTest();
 157         unicodePropertiesTest();
 158         unicodeHexNotationTest();
 159         unicodeClassesTest();
 160         unicodeCharacterNameTest();
 161         horizontalAndVerticalWSTest();
 162         linebreakTest();
 163         branchTest();
 164         groupCurlyNotFoundSuppTest();
 165         groupCurlyBackoffTest();
 166         patternAsPredicate();
 167         patternAsMatchPredicate();
 168         invalidFlags();
 169         embeddedFlags();
 170         grapheme();
 171         expoBacktracking();
 172         invalidGroupName();
 173         caseInsensitivePMatch();
 174 
 175         if (failure) {
 176             throw new
 177                 RuntimeException("RegExTest failed, 1st failure: " +
 178                                  firstFailure);
 179         } else {
 180             System.err.println("OKAY: All tests passed.");
 181         }
 182     }
 183 
 184     // Utility functions
 185 
 186     private static String getRandomAlphaString(int length) {
 187         StringBuffer buf = new StringBuffer(length);
 188         for (int i=0; i<length; i++) {
 189             char randChar = (char)(97 + generator.nextInt(26));
 190             buf.append(randChar);
 191         }
 192         return buf.toString();
 193     }


4915                 }
4916             }
4917         }
4918         // Invalid char in a group name
4919         for (String groupName : List.of("a.", "b\u0040", "c\u005b",
4920                 "d\u0060", "e\u007b", "f\u0416")) {
4921             for (String pat : List.of("(?<" + groupName + ">)",
4922                     "\\k<" + groupName + ">")) {
4923                 try {
4924                     Pattern.compile(pat);
4925                     failCount++;
4926                 } catch (PatternSyntaxException e) {
4927                     if (!e.getMessage().startsWith(
4928                             "named capturing group is missing trailing '>'")) {
4929                         failCount++;
4930                     }
4931                 }
4932             }
4933         }
4934         report("Invalid capturing group names");
4935     }
4936 
4937     private static void caseInsensitivePMatch() {
4938         for (String input : List.of("abcd", "AbCd", "ABCD")) {
4939             for (String pattern : List.of("abcd", "aBcD", "[a-z]{4}",
4940                     "\\p{Lower}{4}", "\\p{Ll}{4}", "\\p{IsLl}{4}", "\\p{gc=Ll}{4}",
4941                     "\\p{general_category=Ll}{4}", "\\p{IsLowercase}{4}",
4942                     "\\p{javaLowerCase}{4}", "\\p{Upper}{4}", "\\p{Lu}{4}",
4943                     "\\p{IsLu}{4}", "\\p{gc=Lu}{4}", "\\p{general_category=Lu}{4}",
4944                     "\\p{IsUppercase}{4}", "\\p{javaUpperCase}{4}",
4945                     "\\p{Lt}{4}", "\\p{IsLt}{4}", "\\p{gc=Lt}{4}",
4946                     "\\p{general_category=Lt}{4}", "\\p{IsTitlecase}{4}",
4947                     "\\p{javaTitleCase}{4}", "[\\p{Lower}]{4}", "[\\p{Ll}]{4}",
4948                     "[\\p{IsLl}]{4}", "[\\p{gc=Ll}]{4}",
4949                     "[\\p{general_category=Ll}]{4}", "[\\p{IsLowercase}]{4}",
4950                     "[\\p{javaLowerCase}]{4}", "[\\p{Upper}]{4}", "[\\p{Lu}]{4}",
4951                     "[\\p{IsLu}]{4}", "[\\p{gc=Lu}]{4}",
4952                     "[\\p{general_category=Lu}]{4}", "[\\p{IsUppercase}]{4}",
4953                     "[\\p{javaUpperCase}]{4}", "[\\p{Lt}]{4}", "[\\p{IsLt}]{4}",
4954                     "[\\p{gc=Lt}]{4}", "[\\p{general_category=Lt}]{4}",
4955                     "[\\p{IsTitlecase}]{4}", "[\\p{javaTitleCase}]{4}"))
4956             {
4957                 if (!Pattern.compile(pattern, Pattern.CASE_INSENSITIVE)
4958                             .matcher(input)
4959                             .matches())
4960                 {
4961                     failCount++;
4962                 }
4963             }
4964         }
4965 
4966         for (String input : List.of("\u01c7", "\u01c8", "\u01c9")) {
4967             for (String pattern : List.of("\u01c7", "\u01c8", "\u01c9",
4968                     "\\p{Lower}", "\\p{Ll}", "\\p{IsLl}", "\\p{gc=Ll}",
4969                     "\\p{general_category=Ll}", "\\p{IsLowercase}",
4970                     "\\p{javaLowerCase}", "\\p{Upper}", "\\p{Lu}",
4971                     "\\p{IsLu}", "\\p{gc=Lu}", "\\p{general_category=Lu}",
4972                     "\\p{IsUppercase}", "\\p{javaUpperCase}",
4973                     "\\p{Lt}", "\\p{IsLt}", "\\p{gc=Lt}",
4974                     "\\p{general_category=Lt}", "\\p{IsTitlecase}",
4975                     "\\p{javaTitleCase}", "[\\p{Lower}]", "[\\p{Ll}]",
4976                     "[\\p{IsLl}]", "[\\p{gc=Ll}]",
4977                     "[\\p{general_category=Ll}]", "[\\p{IsLowercase}]",
4978                     "[\\p{javaLowerCase}]", "[\\p{Upper}]", "[\\p{Lu}]",
4979                     "[\\p{IsLu}]", "[\\p{gc=Lu}]",
4980                     "[\\p{general_category=Lu}]", "[\\p{IsUppercase}]",
4981                     "[\\p{javaUpperCase}]", "[\\p{Lt}]", "[\\p{IsLt}]",
4982                     "[\\p{gc=Lt}]", "[\\p{general_category=Lt}]",
4983                     "[\\p{IsTitlecase}]", "[\\p{javaTitleCase}]"))
4984             {
4985                 if (!Pattern.compile(pattern, Pattern.CASE_INSENSITIVE
4986                                             | Pattern.UNICODE_CHARACTER_CLASS)
4987                             .matcher(input)
4988                             .matches())
4989                 {
4990                     failCount++;
4991                 }
4992             }
4993         }
4994         report("Case-insensitive property matching");
4995     }
4996 }
< prev index next >