jdk/test/java/util/regex/RegExTest.java
changeset 31645 26db68d6758c
parent 30436 17827057ef5a
child 34436 33c20335507c
equal deleted inserted replaced
31644:dbca10d053fd 31645:26db68d6758c
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    30  * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
    30  * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
    31  * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
    31  * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
    32  * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
    32  * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
    33  * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
    33  * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
    34  * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
    34  * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
    35  * 8027645 8035076 8039124 8035975 8074678
    35  * 8027645 8035076 8039124 8035975 8074678 6854417
    36  * @library /lib/testlibrary
    36  * @library /lib/testlibrary
    37  * @build jdk.testlibrary.*
    37  * @build jdk.testlibrary.*
    38  * @run main RegExTest
    38  * @run main RegExTest
    39  * @key intermittent randomness
    39  * @key randomness
    40  */
    40  */
    41 
    41 
    42 import java.util.function.Function;
    42 import java.util.function.Function;
    43 import java.util.regex.*;
    43 import java.util.regex.*;
    44 import java.util.Random;
    44 import java.util.Random;
  3552 
  3552 
  3553         for (int i=0; i<100; i++) {
  3553         for (int i=0; i<100; i++) {
  3554             // Create a short pattern to search for
  3554             // Create a short pattern to search for
  3555             int patternLength = generator.nextInt(7) + 4;
  3555             int patternLength = generator.nextInt(7) + 4;
  3556             StringBuffer patternBuffer = new StringBuffer(patternLength);
  3556             StringBuffer patternBuffer = new StringBuffer(patternLength);
  3557             for (int x=0; x<patternLength; x++) {
  3557             String pattern;
  3558                 int ch = baseCharacter + generator.nextInt(26);
  3558             retry: for (;;) {
  3559                 if (Character.isSupplementaryCodePoint(ch)) {
  3559                 for (int x=0; x<patternLength; x++) {
  3560                     patternBuffer.append(Character.toChars(ch));
  3560                     int ch = baseCharacter + generator.nextInt(26);
  3561                 } else {
  3561                     if (Character.isSupplementaryCodePoint(ch)) {
  3562                     patternBuffer.append((char)ch);
  3562                         patternBuffer.append(Character.toChars(ch));
       
  3563                     } else {
       
  3564                         patternBuffer.append((char)ch);
       
  3565                     }
  3563                 }
  3566                 }
       
  3567                 pattern = patternBuffer.toString();
       
  3568 
       
  3569                 // Avoid patterns that start and end with the same substring
       
  3570                 // See JDK-6854417
       
  3571                 for (int x=1; x <patternLength; x++) {
       
  3572                     if (pattern.startsWith(pattern.substring(x)))
       
  3573                         continue retry;
       
  3574                 }
       
  3575                 break;
  3564             }
  3576             }
  3565             String pattern =  patternBuffer.toString();
       
  3566             Pattern p = Pattern.compile(pattern);
  3577             Pattern p = Pattern.compile(pattern);
  3567 
  3578 
  3568             // Create a buffer with random ASCII chars that does
  3579             // Create a buffer with random ASCII chars that does
  3569             // not match the sample
  3580             // not match the sample
  3570             String toSearch = null;
  3581             String toSearch = null;