Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/CompactNumberFormat/SPIProviderTest.java
41153 views
1
/*
2
* Copyright (c) 2019, 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
* @test
25
* @bug 8222756
26
* @summary Checks the plurals work with SPI provider
27
* @modules jdk.localedata
28
* @library provider
29
* @build provider/module-info provider/test.NumberFormatProviderImpl
30
* @run main/othervm -Djava.locale.providers=SPI,CLDR SPIProviderTest
31
*/
32
33
import java.text.CompactNumberFormat;
34
import java.text.DecimalFormatSymbols;
35
import java.text.NumberFormat;
36
import java.text.ParseException;
37
import java.util.Arrays;
38
import java.util.Locale;
39
40
public class SPIProviderTest {
41
private static final Locale QAA = Locale.forLanguageTag("qaa");
42
private static final Locale QAB = Locale.forLanguageTag("qab");
43
44
public static void main(String... args) {
45
new SPIProviderTest();
46
}
47
48
SPIProviderTest() {
49
Arrays.stream(testData())
50
.forEach(SPIProviderTest::testSPIProvider);
51
}
52
53
Object[][] testData() {
54
return new Object[][]{
55
// Locale, Number, expected
56
{QAA, 1_000, "1K"},
57
{QAA, -1_000, "-1K"},
58
{QAA, 2_000, "2K"},
59
{QAA, -2_000, "-2K"},
60
{QAA, 1_000_000, "1M"},
61
{QAA, -1_000_000, "-1M"},
62
{QAA, 2_000_000, "2M"},
63
{QAA, -2_000_000, "-2M"},
64
65
{QAB, 1_000, "1K"},
66
{QAB, -1_000, "(1K)"},
67
{QAB, 2_000, "2KK"},
68
{QAB, -2_000, "-2KK"},
69
{QAB, 3_000, "3KKK"},
70
{QAB, -3_000, "-3KKK"},
71
{QAB, 5_000, "5KKKK"},
72
{QAB, -5_000, "-5KKKK"},
73
74
{QAB, 10_000, "10000"},
75
{QAB, -10_000, "-10000"},
76
77
{QAB, 1_000_000, "1 M"},
78
{QAB, -1_000_000, "(1 M)"},
79
{QAB, 2_000_000, "2 MM"},
80
{QAB, -2_000_000, "(2 MM)"},
81
{QAB, 3_000_000, "3 MMM"},
82
{QAB, -3_000_000, "-3 MMM"},
83
{QAB, 5_000_000, "5 MMMM"},
84
{QAB, -5_000_000, "-5 MMMM"},
85
86
};
87
}
88
89
public static void testSPIProvider(Object... args) {
90
Locale loc = (Locale)args[0];
91
Number number = (Number)args[1];
92
String expected = (String)args[2];
93
System.out.printf("Testing locale: %s, number: %d, expected: %s\n", loc, number, expected);
94
95
NumberFormat nf =
96
NumberFormat.getCompactNumberInstance(loc, NumberFormat.Style.SHORT);
97
String formatted = nf.format(number);
98
System.out.printf(" formatted: %s\n", formatted);
99
if (!formatted.equals(expected)) {
100
throw new RuntimeException("formatted and expected strings do not match.");
101
}
102
103
try {
104
Number parsed = nf.parse(formatted);
105
System.out.printf(" parsed: %s\n", parsed);
106
if (parsed.intValue() != number.intValue()) {
107
throw new RuntimeException("parsed and input numbers do not match.");
108
}
109
} catch (ParseException pe) {
110
throw new RuntimeException(pe);
111
}
112
}
113
}
114
115