1/*
2 * Copyright (c) 2013, 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 * @bug 8029800 8043186
27 * @summary Unit test StringUtils
28 * @modules jdk.compiler/com.sun.tools.javac.util
29 * @run main StringUtilsTest
30 */
31
32import java.util.Locale;
33import java.util.Objects;
34import com.sun.tools.javac.util.StringUtils;
35
36public class StringUtilsTest {
37    public static void main(String... args) throws Exception {
38        new StringUtilsTest().run();
39    }
40
41    void run() throws Exception {
42        Locale.setDefault(new Locale("tr", "TR"));
43
44        //verify the properties of the default locale:
45        assertEquals("\u0131", "I".toLowerCase());
46        assertEquals("\u0130", "i".toUpperCase());
47
48        //verify the StringUtils.toLowerCase/toUpperCase do what they should:
49        assertEquals("i", StringUtils.toLowerCase("I"));
50        assertEquals("I", StringUtils.toUpperCase("i"));
51
52        //verify StringUtils.caseInsensitiveIndexOf works:
53        assertEquals(2, StringUtils.indexOfIgnoreCase("  lookFor", "lookfor"));
54        assertEquals(11, StringUtils.indexOfIgnoreCase("  lookFor  LOOKfor", "lookfor", 11));
55        assertEquals(2, StringUtils.indexOfIgnoreCase("\u0130\u0130lookFor", "lookfor"));
56    }
57
58    void assertEquals(String expected, String actual) {
59        if (!Objects.equals(expected, actual)) {
60            throw new IllegalStateException("expected=" + expected + "; actual=" + actual);
61        }
62    }
63
64    void assertEquals(int expected, int actual) {
65        if (expected != actual) {
66            throw new IllegalStateException("expected=" + expected + "; actual=" + actual);
67        }
68    }
69}
70