author | naoto |
Mon, 06 Jun 2016 10:52:21 -0700 | |
changeset 38786 | 8e7b0ac05815 |
child 39134 | be0fe7a4190a |
permissions | -rw-r--r-- |
38786
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
1 |
/* |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
4 |
* |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
8 |
* |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
13 |
* accompanied this code). |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
14 |
* |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
18 |
* |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
21 |
* questions. |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
22 |
*/ |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
23 |
|
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
24 |
/** |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
25 |
* @test |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
26 |
* @bug 8146156 |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
27 |
* @summary test whether uppercasing follows Locale.Category.FORMAT locale. |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
28 |
* @run main/othervm FormatLocale |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
29 |
*/ |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
30 |
|
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
31 |
import java.time.LocalDate; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
32 |
import java.time.Month; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
33 |
import java.util.Formatter; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
34 |
import java.util.List; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
35 |
import java.util.Locale; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
36 |
import java.util.Locale.Category; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
37 |
import java.util.stream.IntStream; |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
38 |
|
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
39 |
public class FormatLocale { |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
40 |
|
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
41 |
static final Locale TURKISH = new Locale("tr"); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
42 |
|
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
43 |
static final List<String> conversions = List.of( |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
44 |
"%S", |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
45 |
"%S", |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
46 |
"%TB", |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
47 |
"%G"); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
48 |
static final List<Object> src = List.of( |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
49 |
"Turkish", |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
50 |
"Turkish", |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
51 |
LocalDate.of(2016, Month.APRIL, 1), |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
52 |
Float.valueOf(100_000_000)); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
53 |
static final List<Locale> formatLocale = List.of( |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
54 |
Locale.ENGLISH, |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
55 |
TURKISH, |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
56 |
TURKISH, |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
57 |
Locale.FRANCE); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
58 |
static final List<String> expected = List.of( |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
59 |
"TURKISH", |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
60 |
"TURK\u0130SH", |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
61 |
"N\u0130SAN", |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
62 |
"1,00000E+08"); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
63 |
|
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
64 |
public static void main(String [] args) { |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
65 |
StringBuilder sb = new StringBuilder(); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
66 |
|
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
67 |
IntStream.range(0, src.size()).forEach(i -> { |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
68 |
sb.setLength(0); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
69 |
Locale.setDefault(Locale.Category.FORMAT, formatLocale.get(i)); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
70 |
new Formatter(sb).format(conversions.get(i), src.get(i)); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
71 |
if (!sb.toString().equals(expected.get(i))) { |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
72 |
throw new RuntimeException( |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
73 |
"Wrong uppercasing with Formatter.format(" + |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
74 |
"\"" + conversions.get(i) + "\"" + |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
75 |
") in locale " |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
76 |
+ formatLocale.get(i) + |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
77 |
". Expected: " + expected.get(i) + |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
78 |
" Returned: " + sb.toString()); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
79 |
} |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
80 |
}); |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
81 |
} |
8e7b0ac05815
8146156: Inconsistent default locale in string formatter methods
naoto
parents:
diff
changeset
|
82 |
} |