Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Locale/Bug8179071.java
41149 views
1
/*
2
* Copyright (c) 2018, 2020, 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 8179071 8202537 8231273 8251317
27
* @summary Test that language aliases of CLDR supplemental metadata are handled correctly.
28
* @modules jdk.localedata
29
* @run main/othervm -Djava.locale.providers=CLDR Bug8179071
30
*/
31
32
/**
33
* This fix is dependent on a particular version of CLDR data.
34
*/
35
36
import java.time.Month;
37
import java.time.format.TextStyle;
38
import java.util.Arrays;
39
import java.util.HashSet;
40
import java.util.Locale;
41
import java.util.Map;
42
import java.util.Set;
43
44
public class Bug8179071 {
45
46
// Deprecated and Legacy tags.
47
// As of CLDR 38, language aliases for some of the legacy tags have been removed.
48
private static final Set<String> LegacyAliases = Set.of(
49
"zh-guoyu", "zh-min-nan", "i-klingon", "i-tsu",
50
"sgn-CH-DE", "mo", "i-tay", "scc",
51
"i-hak", "sgn-BE-FR", "i-lux", "tl", "zh-hakka", "i-ami", "aa-SAAHO",
52
"zh-xiang", "i-pwn", "sgn-BE-NL", "jw", "sh", "i-bnn");
53
// expected month format data for locales after language aliases replacement.
54
private static final Map<String, String> shortJanuaryNames = Map.of( "pa-PK", "\u0a1c\u0a28",
55
"uz-AF" , "yan",
56
"sr-ME", "\u0458\u0430\u043d",
57
"scc", "\u0458\u0430\u043d",
58
"sh", "jan",
59
"ha-Latn-NE", "Jan",
60
"i-lux", "Jan.");
61
62
63
private static void test(String tag, String expected) {
64
Locale target = Locale.forLanguageTag(tag);
65
Month day = Month.JANUARY;
66
TextStyle style = TextStyle.SHORT;
67
String actual = day.getDisplayName(style, target);
68
if (!actual.equals(expected)) {
69
throw new RuntimeException("failed for locale " + tag + " actual output " + actual +" does not match with " + expected);
70
}
71
}
72
73
/**
74
* getAvailableLocales() should not contain any deprecated or Legacy language tags
75
*/
76
private static void checkInvalidTags() {
77
Set<String> invalidTags = new HashSet<>();
78
Arrays.asList(Locale.getAvailableLocales()).stream()
79
.map(loc -> loc.toLanguageTag())
80
.forEach( tag -> {if(LegacyAliases.contains(tag)) {invalidTags.add(tag);}});
81
if (!invalidTags.isEmpty()) {
82
throw new RuntimeException("failed: Deprecated and Legacy tags found " + invalidTags + " in AvailableLocales ");
83
}
84
}
85
86
public static void main(String[] args) {
87
shortJanuaryNames.forEach(Bug8179071::test);
88
checkInvalidTags();
89
}
90
}
91
92