< prev index next >

test/jdk/java/lang/Character/CheckProp.java

Print this page
rev 56092 : imported patch 8229831


   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 /**
  26  * @test
  27  * @bug 7037261 7070436 7198195 8032446 8072600 8221431
  28  * @summary  Check j.l.Character.isLowerCase/isUppercase/isAlphabetic/isIdeographic

  29  * @library /lib/testlibrary/java/lang
  30  */
  31 
  32 import java.util.regex.*;
  33 import java.util.*;
  34 import java.io.*;
  35 import static java.lang.Character.*;
  36 
  37 public class CheckProp {
  38 
  39     public static void main(String[] args) throws IOException {
  40         File fPropList = UCDFiles.PROP_LIST.toFile();
  41         int i, j;
  42         BufferedReader sbfr = new BufferedReader(new FileReader(fPropList));
  43         Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s*;\\s+(\\w+)\\s+#.*").matcher("");
  44         Map<String, ArrayList<Integer>> propMap =  new LinkedHashMap<>();
  45 
  46         String line = null;
  47         int lineNo = 0;
  48         while ((line = sbfr.readLine()) != null) {
  49             lineNo++;
  50             if (line.length() <= 1 || line.charAt(0) == '#') {
  51                 continue;
  52             }
  53             m.reset(line);
  54             if (m.matches()) {
  55                 int start = Integer.parseInt(m.group(1), 16);
  56                 int end = (m.group(2)==null)?start
  57                           :Integer.parseInt(m.group(2), 16);
  58                 String name = m.group(3);
  59 
  60                 ArrayList<Integer> list = propMap.get(name);
  61                 if (list == null) {
  62                     list = new ArrayList<Integer>();
  63                     propMap.put(name, list);
  64                 }
  65                 while (start <= end)
  66                     list.add(start++);
  67             } else {
  68                 System.out.printf("Warning: Unrecognized line %d <%s>%n", lineNo, line);
  69             }
  70         }
  71         sbfr.close();
  72         //for (String name: propMap.keySet()) {
  73         //    System.out.printf("%s    %d%n", name, propMap.get(name).size());
  74         //}
  75 
  76         Integer[] otherLowercase = propMap.get("Other_Lowercase").toArray(new Integer[0]);
  77         Integer[] otherUppercase = propMap.get("Other_Uppercase").toArray(new Integer[0]);
  78         Integer[] otherAlphabetic = propMap.get("Other_Alphabetic").toArray(new Integer[0]);
  79         Integer[] ideographic = propMap.get("Ideographic").toArray(new Integer[0]);


  80 
  81         int fails = 0;
  82         for (int cp = MIN_CODE_POINT; cp < MAX_CODE_POINT; cp++) {
  83             int type = getType(cp);
  84             if (isLowerCase(cp) !=
  85                 (type == LOWERCASE_LETTER ||
  86                  Arrays.binarySearch(otherLowercase, cp) >= 0))
  87             {
  88                 fails++;
  89                 System.err.printf("Wrong isLowerCase(U+%04x)\n", cp);
  90             }
  91             if (isUpperCase(cp) !=
  92                 (type == UPPERCASE_LETTER ||
  93                  Arrays.binarySearch(otherUppercase, cp) >= 0))
  94             {
  95                 fails++;
  96                 System.err.printf("Wrong isUpperCase(U+%04x)\n", cp);
  97             }
  98             if (isAlphabetic(cp) !=
  99                 (type == UPPERCASE_LETTER || type == LOWERCASE_LETTER ||
 100                  type == TITLECASE_LETTER || type == MODIFIER_LETTER  ||
 101                  type == OTHER_LETTER     || type == OTHER_LETTER ||
 102                  type == LETTER_NUMBER ||
 103                  Arrays.binarySearch(otherAlphabetic, cp) >=0))
 104             {
 105                 fails++;
 106                 System.err.printf("Wrong isAlphabetic(U+%04x)\n", cp);
 107             }
 108             if (isIdeographic(cp) !=
 109                 (Arrays.binarySearch(ideographic, cp) >= 0))
 110             {
 111                 fails++;
 112                 System.err.printf("Wrong isIdeographic(U+%04x)\n", cp);
 113             }















 114         }
 115         if (fails != 0)
 116             throw new RuntimeException("CheckProp failed=" + fails);
 117     }








































 118 }


   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 /**
  26  * @test
  27  * @bug 7037261 7070436 7198195 8032446 8072600 8221431 8229831
  28  * @summary  Check j.l.Character.isLowerCase/isUppercase/isAlphabetic/isIdeographic/
  29  *              isUnicodeIdentifierStart/isUnicodeIdentifierPart
  30  * @library /lib/testlibrary/java/lang
  31  */
  32 
  33 import java.util.regex.*;
  34 import java.util.*;
  35 import java.io.*;
  36 import static java.lang.Character.*;
  37 
  38 public class CheckProp {
  39 
  40     public static void main(String[] args) {
  41         Map<String, List<Integer>> propMap =  new LinkedHashMap<>();
  42         List.of(UCDFiles.PROP_LIST.toFile(), UCDFiles.DERIVED_PROPS.toFile()).stream()
  43             .forEach(f -> readPropMap(propMap, f));
































  44 
  45         Integer[] otherLowercase = propMap.get("Other_Lowercase").toArray(new Integer[0]);
  46         Integer[] otherUppercase = propMap.get("Other_Uppercase").toArray(new Integer[0]);
  47         Integer[] otherAlphabetic = propMap.get("Other_Alphabetic").toArray(new Integer[0]);
  48         Integer[] ideographic = propMap.get("Ideographic").toArray(new Integer[0]);
  49         Integer[] IDStart = propMap.get("ID_Start").toArray(new Integer[0]);
  50         Integer[] IDContinue = propMap.get("ID_Continue").toArray(new Integer[0]);
  51 
  52         int fails = 0;
  53         for (int cp = MIN_CODE_POINT; cp < MAX_CODE_POINT; cp++) {
  54             int type = getType(cp);
  55             if (isLowerCase(cp) !=
  56                 (type == LOWERCASE_LETTER ||
  57                  Arrays.binarySearch(otherLowercase, cp) >= 0))
  58             {
  59                 fails++;
  60                 System.err.printf("Wrong isLowerCase(U+%04x)\n", cp);
  61             }
  62             if (isUpperCase(cp) !=
  63                 (type == UPPERCASE_LETTER ||
  64                  Arrays.binarySearch(otherUppercase, cp) >= 0))
  65             {
  66                 fails++;
  67                 System.err.printf("Wrong isUpperCase(U+%04x)\n", cp);
  68             }
  69             if (isAlphabetic(cp) !=
  70                 (type == UPPERCASE_LETTER || type == LOWERCASE_LETTER ||
  71                  type == TITLECASE_LETTER || type == MODIFIER_LETTER  ||
  72                  type == OTHER_LETTER     || type == OTHER_LETTER ||
  73                  type == LETTER_NUMBER ||
  74                  Arrays.binarySearch(otherAlphabetic, cp) >=0))
  75             {
  76                 fails++;
  77                 System.err.printf("Wrong isAlphabetic(U+%04x)\n", cp);
  78             }
  79             if (isIdeographic(cp) !=
  80                 (Arrays.binarySearch(ideographic, cp) >= 0))
  81             {
  82                 fails++;
  83                 System.err.printf("Wrong isIdeographic(U+%04x)\n", cp);
  84             }
  85             if (isUnicodeIdentifierStart(cp) !=
  86                 (cp == 0x2E2F ||
  87                  Arrays.binarySearch(IDStart, cp) >= 0))
  88             {
  89                 fails++;
  90                 System.err.printf("Wrong isUnicodeIdentifierStart(U+%04x)\n", cp);
  91             }
  92             if (isUnicodeIdentifierPart(cp) !=
  93                 (isIdentifierIgnorable(cp) ||
  94                  cp == 0x2E2F ||
  95                  Arrays.binarySearch(IDContinue, cp) >= 0))
  96             {
  97                 fails++;
  98                 System.err.printf("Wrong isUnicodeIdentifierPart(U+%04x)\n", cp);
  99             }
 100         }
 101         if (fails != 0)
 102             throw new RuntimeException("CheckProp failed=" + fails);
 103     }
 104 
 105     private static void readPropMap(Map<String, List<Integer>> propMap, File fPropList) {
 106         try {
 107             BufferedReader sbfr = new BufferedReader(new FileReader(fPropList));
 108             Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s*;\\s+(\\w+)\\s+#.*").matcher("");
 109  
 110             String line = null;
 111             int lineNo = 0;
 112             while ((line = sbfr.readLine()) != null) {
 113                 lineNo++;
 114                 if (line.length() <= 1 || line.charAt(0) == '#') {
 115                     continue;
 116                 }
 117                 m.reset(line);
 118                 if (m.matches()) {
 119                     int start = Integer.parseInt(m.group(1), 16);
 120                     int end = (m.group(2)==null)?start
 121                               :Integer.parseInt(m.group(2), 16);
 122                     String name = m.group(3);
 123  
 124                     List<Integer> list = propMap.get(name);
 125                     if (list == null) {
 126                         list = new ArrayList<Integer>();
 127                         propMap.put(name, list);
 128                     }
 129                     while (start <= end)
 130                         list.add(start++);
 131                 } else {
 132                     System.out.printf("Warning: Unrecognized line %d <%s>%n", lineNo, line);
 133                 }
 134             }
 135             sbfr.close();
 136         } catch (IOException ioe) {
 137             throw new UncheckedIOException(ioe);
 138         }
 139         
 140         //for (String name: propMap.keySet()) {
 141         //    System.out.printf("%s    %d%n", name, propMap.get(name).size());
 142         //}
 143     }
 144 }
< prev index next >