Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/CompactNumberFormat/TestPlurals.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 Tests plurals support in CompactNumberFormat
27
* @run testng/othervm TestPlurals
28
*/
29
30
import java.text.CompactNumberFormat;
31
import java.text.DecimalFormatSymbols;
32
import java.util.Locale;
33
34
import static org.testng.Assert.*;
35
import org.testng.annotations.DataProvider;
36
import org.testng.annotations.Test;
37
38
public class TestPlurals {
39
40
private final static DecimalFormatSymbols DFS = DecimalFormatSymbols.getInstance(Locale.ROOT);
41
private final static String[] PATTERN = {
42
"{zero:0->zero one:0->one two:0->two few:0->few many:0->many other:0->other}"};
43
private final static String RULE_1 = "zero:n = 0; one:n = 1; two:n = 2; few:n = 3..4; many:n = 5..6,8";
44
private final static String RULE_2 = "one:n % 2 = 1 or n / 3 = 2;";
45
private final static String RULE_3 = "one:n%2=0andn/3=2;";
46
47
48
@DataProvider
49
Object[][] pluralRules() {
50
return new Object[][]{
51
// rules, number, expected
52
{RULE_1, 0, "0->zero"},
53
{RULE_1, 1, "1->one"},
54
{RULE_1, 2, "2->two"},
55
{RULE_1, 3, "3->few"},
56
{RULE_1, 4, "4->few"},
57
{RULE_1, 5, "5->many"},
58
{RULE_1, 6, "6->many"},
59
{RULE_1, 7, "7->other"},
60
{RULE_1, 8, "8->many"},
61
{RULE_1, 9, "9->other"},
62
63
{RULE_2, 0, "0->other"},
64
{RULE_2, 1, "1->one"},
65
{RULE_2, 2, "2->other"},
66
{RULE_2, 3, "3->one"},
67
{RULE_2, 4, "4->other"},
68
{RULE_2, 5, "5->one"},
69
{RULE_2, 6, "6->one"},
70
71
{RULE_3, 0, "0->other"},
72
{RULE_3, 1, "1->other"},
73
{RULE_3, 2, "2->other"},
74
{RULE_3, 3, "3->other"},
75
{RULE_3, 4, "4->other"},
76
{RULE_3, 5, "5->other"},
77
{RULE_3, 6, "6->one"},
78
};
79
}
80
81
@DataProvider
82
Object[][] invalidRules() {
83
return new Object [][] {
84
{"one:a = 1"},
85
{"on:n = 1"},
86
{"one:n = 1...2"},
87
{"one:n = 1.2"},
88
{"one:n = 1..2,"},
89
{"one:n = 1;one:n = 2"},
90
{"foo:n = 1"},
91
{"one:n = 1..2 andor v % 10 != 0"},
92
};
93
}
94
95
@Test(expectedExceptions = NullPointerException.class)
96
public void testNullPluralRules() {
97
String[] pattern = {""};
98
new CompactNumberFormat("#", DFS, PATTERN, null);
99
}
100
101
@Test(dataProvider = "pluralRules")
102
public void testPluralRules(String rules, Number n, String expected) {
103
var cnp = new CompactNumberFormat("#", DFS, PATTERN, rules);
104
assertEquals(cnp.format(n), expected);
105
}
106
107
@Test(dataProvider = "invalidRules", expectedExceptions = IllegalArgumentException.class)
108
public void testInvalidRules(String rules) {
109
new CompactNumberFormat("#", DFS, PATTERN, rules);
110
}
111
112
@Test(expectedExceptions = IllegalArgumentException.class)
113
public void testLimitExceedingRules() {
114
String andCond = " and n = 1";
115
String invalid = "one: n = 1" + andCond.repeat(2_048 / andCond.length());
116
new CompactNumberFormat("#", DFS, PATTERN, invalid);
117
}
118
}
119
120