test/java/lang/String/ToLowerCase.java

Print this page




   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     @bug 4217441 4533872 4900935 8020037
  27     @summary toLowerCase should lower-case Greek Sigma correctly depending
  28              on the context (final/non-final).  Also it should handle
  29              Locale specific (lt, tr, and az) lowercasings and supplementary
  30              characters correctly.
  31 */
  32 
  33 import java.util.Locale;
  34 
  35 public class ToLowerCase {
  36 
  37     public static void main(String[] args) {
  38         Locale turkish = new Locale("tr", "TR");
  39         Locale lt = new Locale("lt"); // Lithanian
  40         Locale az = new Locale("az"); // Azeri
  41 
  42         // Greek Sigma final/non-final tests
  43         test("\u03A3", Locale.US, "\u03C3");
  44         test("LAST\u03A3", Locale.US, "last\u03C2");
  45         test("MID\u03A3DLE", Locale.US, "mid\u03C3dle");
  46         test("WORD1 \u03A3 WORD3", Locale.US, "word1 \u03C3 word3");


  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 }


   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     @bug 4217441 4533872 4900935 8020037 8032012
  27     @summary toLowerCase should lower-case Greek Sigma correctly depending
  28              on the context (final/non-final).  Also it should handle
  29              Locale specific (lt, tr, and az) lowercasings and supplementary
  30              characters correctly.
  31 */
  32 
  33 import java.util.Locale;
  34 
  35 public class ToLowerCase {
  36 
  37     public static void main(String[] args) {
  38         Locale turkish = new Locale("tr", "TR");
  39         Locale lt = new Locale("lt"); // Lithanian
  40         Locale az = new Locale("az"); // Azeri
  41 
  42         // Greek Sigma final/non-final tests
  43         test("\u03A3", Locale.US, "\u03C3");
  44         test("LAST\u03A3", Locale.US, "last\u03C2");
  45         test("MID\u03A3DLE", Locale.US, "mid\u03C3dle");
  46         test("WORD1 \u03A3 WORD3", Locale.US, "word1 \u03C3 word3");


  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 }