test/java/util/regex/RegExTest.java

Print this page




  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /**
  27  * @test
  28  * @summary tests RegExp framework
  29  * @author Mike McCloskey
  30  * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345
  31  * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962
  32  * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
  33  * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
  34  * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
  35  * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
  36  * 7067045 7014640 7189363
  37  */
  38 
  39 import java.util.regex.*;
  40 import java.util.Random;
  41 import java.io.*;
  42 import java.util.*;
  43 import java.nio.CharBuffer;
  44 
  45 /**
  46  * This is a test class created to check the operation of
  47  * the Pattern and Matcher classes.
  48  */
  49 public class RegExTest {
  50 
  51     private static Random generator = new Random();
  52     private static boolean failure = false;
  53     private static int failCount = 0;
  54     private static String firstFailure = null;
  55 
  56     /**


 127         regionTest();
 128         toStringTest();
 129         negatedCharClassTest();
 130         findFromTest();
 131         boundsTest();
 132         unicodeWordBoundsTest();
 133         caretAtEndTest();
 134         wordSearchTest();
 135         hitEndTest();
 136         toMatchResultTest();
 137         surrogatesInClassTest();
 138         removeQEQuotingTest();
 139         namedGroupCaptureTest();
 140         nonBmpClassComplementTest();
 141         unicodePropertiesTest();
 142         unicodeHexNotationTest();
 143         unicodeClassesTest();
 144         horizontalAndVerticalWSTest();
 145         linebreakTest();
 146         branchTest();

 147         if (failure) {
 148             throw new
 149                 RuntimeException("RegExTest failed, 1st failure: " +
 150                                  firstFailure);
 151         } else {
 152             System.err.println("OKAY: All tests passed.");
 153         }
 154     }
 155 
 156     // Utility functions
 157 
 158     private static String getRandomAlphaString(int length) {
 159         StringBuffer buf = new StringBuffer(length);
 160         for (int i=0; i<length; i++) {
 161             char randChar = (char)(97 + generator.nextInt(26));
 162             buf.append(randChar);
 163         }
 164         return buf.toString();
 165     }
 166 


3930             !Pattern.compile("(a)?+bc|d").matcher("d").find() ||    // possessive
3931             !Pattern.compile("(a)++bc|d").matcher("d").find() ||
3932             !Pattern.compile("(a)*+bc|d").matcher("d").find() ||
3933             !Pattern.compile("(a)?bc|d").matcher("d").matches() ||  // greedy
3934             !Pattern.compile("(a)+bc|d").matcher("d").matches() ||
3935             !Pattern.compile("(a)*bc|d").matcher("d").matches() ||
3936             !Pattern.compile("(a)??bc|d").matcher("d").matches() || // reluctant
3937             !Pattern.compile("(a)+?bc|d").matcher("d").matches() ||
3938             !Pattern.compile("(a)*?bc|d").matcher("d").matches() ||
3939             !Pattern.compile("(a)?+bc|d").matcher("d").matches() || // possessive
3940             !Pattern.compile("(a)++bc|d").matcher("d").matches() ||
3941             !Pattern.compile("(a)*+bc|d").matcher("d").matches() ||
3942             !Pattern.compile("(a)?bc|de").matcher("de").find() ||   // others
3943             !Pattern.compile("(a)??bc|de").matcher("de").find() ||
3944             !Pattern.compile("(a)?bc|de").matcher("de").matches() ||
3945             !Pattern.compile("(a)??bc|de").matcher("de").matches())
3946             failCount++;
3947         report("branchTest");
3948     }
3949 























3950 }


  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /**
  27  * @test
  28  * @summary tests RegExp framework
  29  * @author Mike McCloskey
  30  * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345
  31  * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962
  32  * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
  33  * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
  34  * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
  35  * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
  36  * 7067045 7014640 7189363 8007395
  37  */
  38 
  39 import java.util.regex.*;
  40 import java.util.Random;
  41 import java.io.*;
  42 import java.util.*;
  43 import java.nio.CharBuffer;
  44 
  45 /**
  46  * This is a test class created to check the operation of
  47  * the Pattern and Matcher classes.
  48  */
  49 public class RegExTest {
  50 
  51     private static Random generator = new Random();
  52     private static boolean failure = false;
  53     private static int failCount = 0;
  54     private static String firstFailure = null;
  55 
  56     /**


 127         regionTest();
 128         toStringTest();
 129         negatedCharClassTest();
 130         findFromTest();
 131         boundsTest();
 132         unicodeWordBoundsTest();
 133         caretAtEndTest();
 134         wordSearchTest();
 135         hitEndTest();
 136         toMatchResultTest();
 137         surrogatesInClassTest();
 138         removeQEQuotingTest();
 139         namedGroupCaptureTest();
 140         nonBmpClassComplementTest();
 141         unicodePropertiesTest();
 142         unicodeHexNotationTest();
 143         unicodeClassesTest();
 144         horizontalAndVerticalWSTest();
 145         linebreakTest();
 146         branchTest();
 147         groupCurlyNotFoundSuppTest();
 148         if (failure) {
 149             throw new
 150                 RuntimeException("RegExTest failed, 1st failure: " +
 151                                  firstFailure);
 152         } else {
 153             System.err.println("OKAY: All tests passed.");
 154         }
 155     }
 156 
 157     // Utility functions
 158 
 159     private static String getRandomAlphaString(int length) {
 160         StringBuffer buf = new StringBuffer(length);
 161         for (int i=0; i<length; i++) {
 162             char randChar = (char)(97 + generator.nextInt(26));
 163             buf.append(randChar);
 164         }
 165         return buf.toString();
 166     }
 167 


3931             !Pattern.compile("(a)?+bc|d").matcher("d").find() ||    // possessive
3932             !Pattern.compile("(a)++bc|d").matcher("d").find() ||
3933             !Pattern.compile("(a)*+bc|d").matcher("d").find() ||
3934             !Pattern.compile("(a)?bc|d").matcher("d").matches() ||  // greedy
3935             !Pattern.compile("(a)+bc|d").matcher("d").matches() ||
3936             !Pattern.compile("(a)*bc|d").matcher("d").matches() ||
3937             !Pattern.compile("(a)??bc|d").matcher("d").matches() || // reluctant
3938             !Pattern.compile("(a)+?bc|d").matcher("d").matches() ||
3939             !Pattern.compile("(a)*?bc|d").matcher("d").matches() ||
3940             !Pattern.compile("(a)?+bc|d").matcher("d").matches() || // possessive
3941             !Pattern.compile("(a)++bc|d").matcher("d").matches() ||
3942             !Pattern.compile("(a)*+bc|d").matcher("d").matches() ||
3943             !Pattern.compile("(a)?bc|de").matcher("de").find() ||   // others
3944             !Pattern.compile("(a)??bc|de").matcher("de").find() ||
3945             !Pattern.compile("(a)?bc|de").matcher("de").matches() ||
3946             !Pattern.compile("(a)??bc|de").matcher("de").matches())
3947             failCount++;
3948         report("branchTest");
3949     }
3950 
3951     // This test is for 8007395
3952     private static void groupCurlyNotFoundSuppTest() throws Exception {
3953         String input = "test this as \ud83d\ude0d";
3954         for (String pStr : new String[] { "test(.)+(@[a-zA-Z.]+)",
3955                                           "test(.)*(@[a-zA-Z.]+)",
3956                                           "test([^B])+(@[a-zA-Z.]+)",
3957                                           "test([^B])*(@[a-zA-Z.]+)",
3958                                           "test(\\P{IsControl})+(@[a-zA-Z.]+)",
3959                                           "test(\\P{IsControl})*(@[a-zA-Z.]+)",
3960                                         }) {
3961             Matcher m = Pattern.compile(pStr, Pattern.CASE_INSENSITIVE)
3962                                .matcher(input);
3963             try {
3964                 if (m.find()) {
3965                     failCount++;
3966                 }
3967             } catch (Exception x) {
3968                 failCount++;
3969             }
3970         }
3971         report("GroupCurly NotFoundSupp");
3972     }
3973 
3974 }