forked from unicode-org/conformance
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:unicode-org/conformance
- Loading branch information
Showing
7 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
.../src/main/java/org/unicode/conformance/testtype/likelysubtags/LikelySubtagsInputJson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.unicode.conformance.testtype.likelysubtags; | ||
|
||
import org.unicode.conformance.testtype.ITestTypeInputJson; | ||
|
||
public class LikelySubtagsInputJson implements ITestTypeInputJson { | ||
|
||
public String test_type; | ||
|
||
public String label; | ||
|
||
public String locale; | ||
|
||
public LikelySubtagsTestOption option; | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...src/main/java/org/unicode/conformance/testtype/likelysubtags/LikelySubtagsOutputJson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.unicode.conformance.testtype.likelysubtags; | ||
|
||
import org.unicode.conformance.testtype.ITestTypeOutputJson; | ||
|
||
public class LikelySubtagsOutputJson implements ITestTypeOutputJson { | ||
|
||
public String label; | ||
|
||
public String locale; | ||
|
||
public LikelySubtagsTestOption option; | ||
|
||
public String result; | ||
|
||
public String error; | ||
|
||
public String error_message; | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...src/main/java/org/unicode/conformance/testtype/likelysubtags/LikelySubtagsTestOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.unicode.conformance.testtype.likelysubtags; | ||
|
||
public enum LikelySubtagsTestOption { | ||
maximize, | ||
minimize, | ||
minimizeFavorScript, | ||
minimizeFavorRegion | ||
} |
72 changes: 72 additions & 0 deletions
72
...u4j/src/main/java/org/unicode/conformance/testtype/likelysubtags/LikelySubtagsTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.unicode.conformance.testtype.likelysubtags; | ||
|
||
import com.ibm.icu.util.ULocale; | ||
import io.lacuna.bifurcan.Map; | ||
import org.unicode.conformance.ExecutorUtils; | ||
import org.unicode.conformance.testtype.ITestType; | ||
import org.unicode.conformance.testtype.ITestTypeInputJson; | ||
import org.unicode.conformance.testtype.ITestTypeOutputJson; | ||
|
||
public class LikelySubtagsTester implements ITestType { | ||
|
||
public static LikelySubtagsTester INSTANCE = new LikelySubtagsTester(); | ||
|
||
@Override | ||
public ITestTypeInputJson inputMapToJson(Map<String, String> inputMapData) { | ||
LikelySubtagsInputJson result = new LikelySubtagsInputJson(); | ||
|
||
result.test_type = inputMapData.get("test_type", null); | ||
result.label = inputMapData.get("label", null); | ||
result.locale = inputMapData.get("locale", null); | ||
result.option = LikelySubtagsTestOption.valueOf( | ||
inputMapData.get("option", null) | ||
); | ||
|
||
return result; | ||
} | ||
|
||
@Override | ||
public ITestTypeOutputJson execute(ITestTypeInputJson inputJson) { | ||
LikelySubtagsInputJson input = (LikelySubtagsInputJson) inputJson; | ||
|
||
// partially construct output | ||
LikelySubtagsOutputJson output = new LikelySubtagsOutputJson(); | ||
output.label = input.label; | ||
|
||
try { | ||
output.result = getLikelySubtagString(input); | ||
} catch (Exception e) { | ||
output.error = "error running test"; | ||
output.error = e.getMessage(); | ||
return output; | ||
} | ||
|
||
// If we get here, it's a pass/fail result (supported options and no runtime errors/exceptions) | ||
return output; | ||
} | ||
|
||
@Override | ||
public String formatOutputJson(ITestTypeOutputJson outputJson) { | ||
return ExecutorUtils.GSON.toJson((LikelySubtagsOutputJson) outputJson); | ||
} | ||
|
||
public String getLikelySubtagString(LikelySubtagsInputJson input) { | ||
String localeID = input.locale; | ||
ULocale locale = ULocale.forLanguageTag(localeID); | ||
|
||
LikelySubtagsTestOption option = input.option; | ||
|
||
switch (option) { | ||
case maximize: | ||
return ULocale.addLikelySubtags(locale).toLanguageTag(); | ||
case minimize: | ||
case minimizeFavorRegion: | ||
return ULocale.minimizeSubtags(locale).toLanguageTag(); | ||
case minimizeFavorScript: | ||
throw new UnsupportedOperationException( | ||
"Likely Subtags test option `minimizeFavorScript` not supported"); | ||
default: | ||
throw new UnsupportedOperationException("Likely Subtags test option not supported"); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...executor-icu4j/src/test/java/org/unicode/conformance/likelysubtags/LikelySubtagsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.unicode.conformance.likelysubtags; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
import org.unicode.conformance.testtype.likelysubtags.LikelySubtagsOutputJson; | ||
import org.unicode.conformance.testtype.likelysubtags.LikelySubtagsTester; | ||
|
||
public class LikelySubtagsTest { | ||
|
||
@Test | ||
public void testMinimizeSubtags() { | ||
String testInput = | ||
"{\"test_type\":\"likely_subtags\", \"option\":\"minimize\", \"locale\":\"fr-Latn-FR\", \"label\":\"1\"}"; | ||
|
||
LikelySubtagsOutputJson output = | ||
(LikelySubtagsOutputJson) LikelySubtagsTester.INSTANCE.getStructuredOutputFromInputStr(testInput); | ||
|
||
assertEquals("fr", output.result); | ||
} | ||
|
||
@Test | ||
public void testMaximizeSubtags() { | ||
String testInput = | ||
"{\"test_type\":\"likely_subtags\", \"option\":\"maximize\", \"locale\":\"fr\", \"label\":\"1\"}"; | ||
|
||
LikelySubtagsOutputJson output = | ||
(LikelySubtagsOutputJson) LikelySubtagsTester.INSTANCE.getStructuredOutputFromInputStr(testInput); | ||
|
||
assertEquals("fr-Latn-FR", output.result); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters