Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/NumberFormat/MultipleNumberScriptTest.java
41152 views
1
/*
2
* Copyright (c) 2012, 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 7073852 8008577
27
* @summary Support multiple scripts for digits and decimal symbols per locale
28
* @run main/othervm -Djava.locale.providers=JRE,SPI MultipleNumberScriptTest
29
*/
30
31
import java.text.*;
32
import java.util.*;
33
34
public class MultipleNumberScriptTest {
35
36
static Locale[] locales = {
37
new Locale("ar"),
38
new Locale("ar", "EG"),
39
new Locale("ar", "DZ"),
40
Locale.forLanguageTag("ar-EG-u-nu-arab"),
41
Locale.forLanguageTag("ar-EG-u-nu-latn"),
42
Locale.forLanguageTag("ar-DZ-u-nu-arab"),
43
Locale.forLanguageTag("ar-DZ-u-nu-latn"),
44
Locale.forLanguageTag("ee"),
45
Locale.forLanguageTag("ee-GH"),
46
Locale.forLanguageTag("ee-GH-u-nu-latn"),
47
new Locale("th", "TH", "TH"),
48
Locale.forLanguageTag("th-TH"),
49
Locale.forLanguageTag("th-TH-u-nu-thai"),
50
Locale.forLanguageTag("th-TH-u-nu-hoge"),
51
};
52
53
// expected numbering system for each locale
54
static String[] expectedNumSystem = {
55
"latn", // ar
56
"latn", // ar-EG
57
"latn", // ar-DZ
58
"arab", // ar-EG-u-nu-arab
59
"latn", // ar-EG-u-nu-latn
60
"arab", // ar-DZ-u-nu-arab
61
"latn", // ar-DZ-u-nu-latn
62
"latn", // ee
63
"latn", // ee-GH
64
"latn", // ee-GH-u-nu-latn
65
"thai", // th_TH_TH
66
"latn", // th-TH
67
"thai", // th-TH-u-nu-thai
68
"latn", // th-TH-u-nu-hoge (invalid)
69
};
70
71
public static void main(String[] args) {
72
int num = 123456;
73
74
for (int i = 0; i < locales.length; i++) {
75
NumberFormat nf = NumberFormat.getIntegerInstance(locales[i]);
76
String formatted = nf.format(num);
77
System.out.printf("%s is %s in %s locale (expected in %s script).\n",
78
num, formatted, locales[i], expectedNumSystem[i]);
79
if (!checkResult(formatted, expectedNumSystem[i])) {
80
throw new RuntimeException("test failed. expected number system was not returned.");
81
}
82
}
83
}
84
85
static boolean checkResult(String formatted, String numSystem) {
86
switch (numSystem) {
87
case "arab":
88
return formatted.charAt(0) == '\u0661';
89
case "latn":
90
return formatted.charAt(0) == '1';
91
case "thai":
92
return formatted.charAt(0) == '\u0e51';
93
default:
94
return false;
95
}
96
}
97
}
98
99