< prev index next >

test/java/util/regex/RegExTest.java

Print this page
rev 12216 : imported patch 8169056-StringIndexOutOfBoundsException-in-Pattern-compile-with-CANON_EQ-flag
   1 /*
   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.
   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
  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 6854417
  36  */
  37 
  38 import java.util.regex.*;
  39 import java.util.Random;
  40 import java.io.*;
  41 import java.util.*;
  42 import java.nio.CharBuffer;
  43 import java.util.function.Predicate;
  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 


2126 
2127             // u00b5 when UNICODE_CASE
2128             pattern = Pattern.compile("[ab\u00b5cd]",
2129                                       Pattern.CASE_INSENSITIVE|
2130                                       Pattern.UNICODE_CASE);
2131             check(pattern, "ab\u00b5cd", true);
2132             check(pattern, "Ab\u039cCd", true);
2133         } catch (Exception e) { failCount++; }
2134 
2135         /* Special cases
2136            (1)LatinSmallLetterLongS u+017f
2137            (2)LatinSmallLetterDotlessI u+0131
2138            (3)LatineCapitalLetterIWithDotAbove u+0130
2139            (4)KelvinSign u+212a
2140            (5)AngstromSign u+212b
2141         */
2142         int flags = Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE;
2143         pattern = Pattern.compile("[sik\u00c5]+", flags);
2144         if (!pattern.matcher("\u017f\u0130\u0131\u212a\u212b").matches())
2145             failCount++;








2146 
2147         report("CharClass");
2148     }
2149 
2150     private static void caretTest() throws Exception {
2151         Pattern pattern = Pattern.compile("\\w*");
2152         Matcher matcher = pattern.matcher("a#bc#def##g");
2153         check(matcher, "a");
2154         check(matcher, "");
2155         check(matcher, "bc");
2156         check(matcher, "");
2157         check(matcher, "def");
2158         check(matcher, "");
2159         check(matcher, "");
2160         check(matcher, "g");
2161         check(matcher, "");
2162         if (matcher.find())
2163             failCount++;
2164 
2165         pattern = Pattern.compile("^\\w*");


   1 /*
   2  * Copyright (c) 1999, 2017, 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
  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 6854417 8169056
  36  */
  37 
  38 import java.util.regex.*;
  39 import java.util.Random;
  40 import java.io.*;
  41 import java.util.*;
  42 import java.nio.CharBuffer;
  43 import java.util.function.Predicate;
  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 


2126 
2127             // u00b5 when UNICODE_CASE
2128             pattern = Pattern.compile("[ab\u00b5cd]",
2129                                       Pattern.CASE_INSENSITIVE|
2130                                       Pattern.UNICODE_CASE);
2131             check(pattern, "ab\u00b5cd", true);
2132             check(pattern, "Ab\u039cCd", true);
2133         } catch (Exception e) { failCount++; }
2134 
2135         /* Special cases
2136            (1)LatinSmallLetterLongS u+017f
2137            (2)LatinSmallLetterDotlessI u+0131
2138            (3)LatineCapitalLetterIWithDotAbove u+0130
2139            (4)KelvinSign u+212a
2140            (5)AngstromSign u+212b
2141         */
2142         int flags = Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE;
2143         pattern = Pattern.compile("[sik\u00c5]+", flags);
2144         if (!pattern.matcher("\u017f\u0130\u0131\u212a\u212b").matches())
2145             failCount++;
2146 
2147         try {
2148             Pattern.compile("[", Pattern.CANON_EQ);
2149             failCount++;
2150         } catch (PatternSyntaxException expected) {
2151         } catch (Exception unexpected) {
2152             failCount++;
2153         }
2154 
2155         report("CharClass");
2156     }
2157 
2158     private static void caretTest() throws Exception {
2159         Pattern pattern = Pattern.compile("\\w*");
2160         Matcher matcher = pattern.matcher("a#bc#def##g");
2161         check(matcher, "a");
2162         check(matcher, "");
2163         check(matcher, "bc");
2164         check(matcher, "");
2165         check(matcher, "def");
2166         check(matcher, "");
2167         check(matcher, "");
2168         check(matcher, "g");
2169         check(matcher, "");
2170         if (matcher.find())
2171             failCount++;
2172 
2173         pattern = Pattern.compile("^\\w*");


< prev index next >