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