test/java/lang/String/ToLowerCase.java

Print this page




  87         test("I", Locale.US, "i");
  88         test("IABC", turkish, "\u0131abc");
  89         test("IABC", az, "\u0131abc");
  90         test("IABC", Locale.US, "iabc");
  91 
  92         // Supplementary character tests
  93         //
  94         // U+10400 ("\uD801\uDC00"): DESERET CAPITAL LETTER LONG I
  95         // U+10401 ("\uD801\uDC01"): DESERET CAPITAL LETTER LONG E
  96         // U+10402 ("\uD801\uDC02"): DESERET CAPITAL LETTER LONG A
  97         // U+10428 ("\uD801\uDC28"): DESERET SMALL LETTER LONG I
  98         // U+10429 ("\uD801\uDC29"): DESERET SMALL LETTER LONG E
  99         // U+1042A ("\uD801\uDC2A"): DESERET SMALL LETTER LONG A
 100         //
 101         // valid code point tests:
 102         test("\uD801\uDC00\uD801\uDC01\uD801\uDC02", Locale.US, "\uD801\uDC28\uD801\uDC29\uD801\uDC2A");
 103         test("\uD801\uDC00A\uD801\uDC01B\uD801\uDC02C", Locale.US, "\uD801\uDC28a\uD801\uDC29b\uD801\uDC2Ac");
 104         // invalid code point tests:
 105         test("\uD800\uD800\uD801A\uDC00\uDC00\uDC00B", Locale.US, "\uD800\uD800\uD801a\uDC00\uDC00\uDC00b");
 106 
















 107     }
 108 
 109     static void test(String in, Locale locale, String expected) {
 110         String result = in.toLowerCase(locale);
 111         if (!result.equals(expected)) {
 112             System.err.println("input: " + in + ", locale: " + locale +
 113                     ", expected: " + expected + ", actual: " + result);
 114             throw new RuntimeException();
 115         }
 116    }
 117 }


  87         test("I", Locale.US, "i");
  88         test("IABC", turkish, "\u0131abc");
  89         test("IABC", az, "\u0131abc");
  90         test("IABC", Locale.US, "iabc");
  91 
  92         // Supplementary character tests
  93         //
  94         // U+10400 ("\uD801\uDC00"): DESERET CAPITAL LETTER LONG I
  95         // U+10401 ("\uD801\uDC01"): DESERET CAPITAL LETTER LONG E
  96         // U+10402 ("\uD801\uDC02"): DESERET CAPITAL LETTER LONG A
  97         // U+10428 ("\uD801\uDC28"): DESERET SMALL LETTER LONG I
  98         // U+10429 ("\uD801\uDC29"): DESERET SMALL LETTER LONG E
  99         // U+1042A ("\uD801\uDC2A"): DESERET SMALL LETTER LONG A
 100         //
 101         // valid code point tests:
 102         test("\uD801\uDC00\uD801\uDC01\uD801\uDC02", Locale.US, "\uD801\uDC28\uD801\uDC29\uD801\uDC2A");
 103         test("\uD801\uDC00A\uD801\uDC01B\uD801\uDC02C", Locale.US, "\uD801\uDC28a\uD801\uDC29b\uD801\uDC2Ac");
 104         // invalid code point tests:
 105         test("\uD800\uD800\uD801A\uDC00\uDC00\uDC00B", Locale.US, "\uD800\uD800\uD801a\uDC00\uDC00\uDC00b");
 106 
 107         // test bmp + supp1
 108         StringBuilder src = new StringBuilder(0x20000);
 109         StringBuilder exp = new StringBuilder(0x20000);
 110         for (int cp = 0; cp < 0x20000; cp++) {
 111             if (cp >= Character.MIN_HIGH_SURROGATE && cp <= Character.MAX_HIGH_SURROGATE) {
 112                 continue;
 113             }
 114             int lowerCase = Character.toLowerCase(cp);
 115             if (lowerCase == -1) {    //Character.ERROR
 116                 continue;
 117             }
 118             src.appendCodePoint(cp);
 119             exp.appendCodePoint(lowerCase);
 120         }
 121         test(src.toString(), Locale.US, exp.toString());
 122 
 123     }
 124 
 125     static void test(String in, Locale locale, String expected) {
 126         String result = in.toLowerCase(locale);
 127         if (!result.equals(expected)) {
 128             System.err.println("input: " + in + ", locale: " + locale +
 129                     ", expected: " + expected + ", actual: " + result);
 130             throw new RuntimeException();
 131         }
 132    }
 133 }