jlahoda@2413: /* jlahoda@2415: * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. jlahoda@2413: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jlahoda@2413: * jlahoda@2413: * This code is free software; you can redistribute it and/or modify it jlahoda@2413: * under the terms of the GNU General Public License version 2 only, as jlahoda@2413: * published by the Free Software Foundation. jlahoda@2413: * jlahoda@2413: * This code is distributed in the hope that it will be useful, but WITHOUT jlahoda@2413: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jlahoda@2413: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jlahoda@2413: * version 2 for more details (a copy is included in the LICENSE file that jlahoda@2413: * accompanied this code). jlahoda@2413: * jlahoda@2413: * You should have received a copy of the GNU General Public License version jlahoda@2413: * 2 along with this work; if not, write to the Free Software Foundation, jlahoda@2413: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jlahoda@2413: * jlahoda@2413: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jlahoda@2413: * or visit www.oracle.com if you need additional information or have any jlahoda@2413: * questions. jlahoda@2413: */ jlahoda@2413: jlahoda@2413: /** jlahoda@2413: * @test jlahoda@2415: * @bug 8029800 8043186 jlahoda@2413: * @summary Unit test StringUtils jlahoda@2413: * @run main StringUtilsTest jlahoda@2413: */ jlahoda@2413: jlahoda@2413: import java.util.Locale; jlahoda@2413: import java.util.Objects; jlahoda@2413: import com.sun.tools.javac.util.StringUtils; jlahoda@2413: jlahoda@2413: public class StringUtilsTest { jlahoda@2413: public static void main(String... args) throws Exception { jlahoda@2413: new StringUtilsTest().run(); jlahoda@2413: } jlahoda@2413: jlahoda@2413: void run() throws Exception { jlahoda@2413: Locale.setDefault(new Locale("tr", "TR")); jlahoda@2413: jlahoda@2413: //verify the properties of the default locale: jlahoda@2413: assertEquals("\u0131", "I".toLowerCase()); jlahoda@2413: assertEquals("\u0130", "i".toUpperCase()); jlahoda@2413: jlahoda@2415: //verify the StringUtils.toLowerCase/toUpperCase do what they should: jlahoda@2413: assertEquals("i", StringUtils.toLowerCase("I")); jlahoda@2413: assertEquals("I", StringUtils.toUpperCase("i")); jlahoda@2413: jlahoda@2415: //verify StringUtils.caseInsensitiveIndexOf works: jlahoda@2415: assertEquals(2, StringUtils.indexOfIgnoreCase(" lookFor", "lookfor")); jlahoda@2415: assertEquals(11, StringUtils.indexOfIgnoreCase(" lookFor LOOKfor", "lookfor", 11)); jlahoda@2415: assertEquals(2, StringUtils.indexOfIgnoreCase("\u0130\u0130lookFor", "lookfor")); jlahoda@2413: } jlahoda@2413: jlahoda@2413: void assertEquals(String expected, String actual) { jlahoda@2413: if (!Objects.equals(expected, actual)) { jlahoda@2413: throw new IllegalStateException("expected=" + expected + "; actual=" + actual); jlahoda@2413: } jlahoda@2413: } jlahoda@2413: jlahoda@2413: void assertEquals(int expected, int actual) { jlahoda@2413: if (expected != actual) { jlahoda@2413: throw new IllegalStateException("expected=" + expected + "; actual=" + actual); jlahoda@2413: } jlahoda@2413: } jlahoda@2413: }