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