Fri, 24 Apr 2020 03:58:51 +0100
Merge
jlahoda@2413 | 1 | /* |
jlahoda@2415 | 2 | * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
jlahoda@2413 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jlahoda@2413 | 4 | * |
jlahoda@2413 | 5 | * This code is free software; you can redistribute it and/or modify it |
jlahoda@2413 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jlahoda@2413 | 7 | * published by the Free Software Foundation. |
jlahoda@2413 | 8 | * |
jlahoda@2413 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jlahoda@2413 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jlahoda@2413 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jlahoda@2413 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jlahoda@2413 | 13 | * accompanied this code). |
jlahoda@2413 | 14 | * |
jlahoda@2413 | 15 | * You should have received a copy of the GNU General Public License version |
jlahoda@2413 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jlahoda@2413 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jlahoda@2413 | 18 | * |
jlahoda@2413 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jlahoda@2413 | 20 | * or visit www.oracle.com if you need additional information or have any |
jlahoda@2413 | 21 | * questions. |
jlahoda@2413 | 22 | */ |
jlahoda@2413 | 23 | |
jlahoda@2413 | 24 | /** |
jlahoda@2413 | 25 | * @test |
jlahoda@2415 | 26 | * @bug 8029800 8043186 |
jlahoda@2413 | 27 | * @summary Unit test StringUtils |
jlahoda@2413 | 28 | * @run main StringUtilsTest |
jlahoda@2413 | 29 | */ |
jlahoda@2413 | 30 | |
jlahoda@2413 | 31 | import java.util.Locale; |
jlahoda@2413 | 32 | import java.util.Objects; |
jlahoda@2413 | 33 | import com.sun.tools.javac.util.StringUtils; |
jlahoda@2413 | 34 | |
jlahoda@2413 | 35 | public class StringUtilsTest { |
jlahoda@2413 | 36 | public static void main(String... args) throws Exception { |
jlahoda@2413 | 37 | new StringUtilsTest().run(); |
jlahoda@2413 | 38 | } |
jlahoda@2413 | 39 | |
jlahoda@2413 | 40 | void run() throws Exception { |
jlahoda@2413 | 41 | Locale.setDefault(new Locale("tr", "TR")); |
jlahoda@2413 | 42 | |
jlahoda@2413 | 43 | //verify the properties of the default locale: |
jlahoda@2413 | 44 | assertEquals("\u0131", "I".toLowerCase()); |
jlahoda@2413 | 45 | assertEquals("\u0130", "i".toUpperCase()); |
jlahoda@2413 | 46 | |
jlahoda@2415 | 47 | //verify the StringUtils.toLowerCase/toUpperCase do what they should: |
jlahoda@2413 | 48 | assertEquals("i", StringUtils.toLowerCase("I")); |
jlahoda@2413 | 49 | assertEquals("I", StringUtils.toUpperCase("i")); |
jlahoda@2413 | 50 | |
jlahoda@2415 | 51 | //verify StringUtils.caseInsensitiveIndexOf works: |
jlahoda@2415 | 52 | assertEquals(2, StringUtils.indexOfIgnoreCase(" lookFor", "lookfor")); |
jlahoda@2415 | 53 | assertEquals(11, StringUtils.indexOfIgnoreCase(" lookFor LOOKfor", "lookfor", 11)); |
jlahoda@2415 | 54 | assertEquals(2, StringUtils.indexOfIgnoreCase("\u0130\u0130lookFor", "lookfor")); |
jlahoda@2413 | 55 | } |
jlahoda@2413 | 56 | |
jlahoda@2413 | 57 | void assertEquals(String expected, String actual) { |
jlahoda@2413 | 58 | if (!Objects.equals(expected, actual)) { |
jlahoda@2413 | 59 | throw new IllegalStateException("expected=" + expected + "; actual=" + actual); |
jlahoda@2413 | 60 | } |
jlahoda@2413 | 61 | } |
jlahoda@2413 | 62 | |
jlahoda@2413 | 63 | void assertEquals(int expected, int actual) { |
jlahoda@2413 | 64 | if (expected != actual) { |
jlahoda@2413 | 65 | throw new IllegalStateException("expected=" + expected + "; actual=" + actual); |
jlahoda@2413 | 66 | } |
jlahoda@2413 | 67 | } |
jlahoda@2413 | 68 | } |