Skip to content

Commit 53f063f

Browse files
authored
ICU4J collation: use strength correctly. Apply "backwards" as locale "fr-CA" (#483)
1 parent 60293a7 commit 53f063f

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

executors/icu4j/74/executor-icu4j/src/main/java/org/unicode/conformance/testtype/collator/CollatorInputJson.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class CollatorInputJson implements ITestTypeInputJson {
1818

1919
public Integer line;
2020

21+
public String strength;
22+
2123
public String compare_type;
2224

2325
public String test_description;
@@ -26,6 +28,12 @@ public class CollatorInputJson implements ITestTypeInputJson {
2628

2729
public String rules;
2830

31+
public String reorder;
32+
33+
public String case_first;
34+
35+
public String backwards;
36+
2937
public String compare_comment;
3038

3139
public String warning;

executors/icu4j/74/executor-icu4j/src/main/java/org/unicode/conformance/testtype/collator/CollatorTester.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public ITestTypeInputJson inputMapToJson(Map<String, Object> inputMapData) {
3939
}
4040

4141
result.locale = (String) inputMapData.get("locale", null);
42+
result.strength = (String) inputMapData.get("strength", null);
4243

4344
result.ignorePunctuation = (boolean) inputMapData.get("ignorePunctuation", false);
4445
result.line = (int) ((double) inputMapData.get("line", 0.0));
@@ -68,6 +69,8 @@ public ITestTypeInputJson inputMapToJson(Map<String, Object> inputMapData) {
6869
result.compare_comment = (String) inputMapData.get("compare_comment", null);
6970
result.warning = (String) inputMapData.get("warning", null);
7071

72+
result.backwards = (String) inputMapData.get("backwards", null);
73+
7174
return result;
7275
}
7376

@@ -98,20 +101,20 @@ public ITestTypeOutputJson execute(ITestTypeInputJson inputJson) {
98101
}
99102

100103
// Use the compare_type field to set the strength of collation test.
101-
if (input.compare_type != null){
102-
if (input.compare_type.equals("=")) {
104+
if (input.strength != null) {
105+
if (input.strength.equals("identical")) {
103106
coll.setStrength(Collator.IDENTICAL);
104107
} else
105-
if (input.compare_type.equals("<1")) {
108+
if (input.strength.equals("primary")) {
106109
coll.setStrength(Collator.PRIMARY);
107110
} else
108-
if (input.compare_type.equals("<2")) {
111+
if (input.strength.equals("secondary")) {
109112
coll.setStrength(Collator.SECONDARY);
110113
} else
111-
if (input.compare_type.equals("<3")) {
114+
if (input.strength.equals("tertiary")) {
112115
coll.setStrength(Collator.TERTIARY);
113116
} else
114-
if (input.compare_type.equals("<4")) {
117+
if (input.strength.equals("quaternary")) {
115118
coll.setStrength(Collator.QUATERNARY);
116119
}
117120
}
@@ -166,7 +169,13 @@ public String formatOutputJson(ITestTypeOutputJson outputJson) {
166169
public Collator getCollatorForInput(CollatorInputJson input) {
167170
RuleBasedCollator result = null;
168171

172+
// Special case: Reset the locale to fr-CA in special case of backwards diacritics
173+
if (input.backwards != null && input.backwards.equals("on")) {
174+
input.locale = "fr-CA";
175+
}
176+
169177
if (input.locale == null || input.locale == "root") {
178+
// Review this logic
170179
if (input.rules == null) {
171180
result = (RuleBasedCollator) Collator.getInstance(ULocale.ROOT);
172181
} else {

executors/icu4j/74/executor-icu4j/src/test/java/org/unicode/conformance/collator/icu74/CollatorTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,13 @@ public void test00002() {
110110

111111
assertTrue(output.result);
112112
}
113+
114+
@Test
115+
public void testBackwards() {
116+
String testInput = "{\"test_type\": \"collation\", \"strength\": \"secondary\", \"compare_type\":\"<2\",\"s1\":\"côte\",\"s2\":\"coté\",\"source_file\":\"collationtest.txt\",\"line\":347,\"label\":\"00153\",\"locale\":\"fr-CA\",\"test_description\":\"côté with backwards secondary\",\"backwards\":\"on\",\"hexhash\":\"0054321a336610ec2eabc4e824736e7e886bab4d\"}";
117+
CollatorOutputJson output =
118+
(CollatorOutputJson) CollatorTester.INSTANCE.getStructuredOutputFromInputStr(testInput);
119+
120+
assertTrue(output.result);
121+
}
113122
}

0 commit comments

Comments
 (0)