Skip to content

(ticket closed) CLDR-14218 Include TestLanguageGroup in TestAll, improve infra #666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/cldr-unittest/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<classpathentry kind="lib" path="/cldr-tools/libs/guava.jar"/>
<classpathentry kind="lib" path="/cldr-tools/libs/failureaccess.jar"/>
<classpathentry kind="lib" path="/cldr-tools/libs/myanmar-tools-1.1.1.jar"/>
<classpathentry kind="lib" path="/cldr-tools/libs/gson.jar"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public TestAll() {
"org.unicode.cldr.unittest.TestIdentity",
"org.unicode.cldr.unittest.TestInheritance",
"org.unicode.cldr.unittest.TestKeyboardModifierSet",
"org.unicode.cldr.unittest.TestLanguageGroup",
"org.unicode.cldr.unittest.TestLdml2ICU",
"org.unicode.cldr.unittest.TestLocalCurrency",
"org.unicode.cldr.unittest.TestLocale",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.unicode.cldr.unittest;

import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
Expand All @@ -9,6 +10,7 @@

import org.unicode.cldr.util.CLDRConfig;
import org.unicode.cldr.util.CLDRFile;
import org.unicode.cldr.util.CldrUtility;
import org.unicode.cldr.util.Containment;
import org.unicode.cldr.util.LanguageGroup;
import org.unicode.cldr.util.LanguageTagParser;
Expand All @@ -23,6 +25,7 @@
import com.ibm.icu.util.ULocale;

public class TestLanguageGroup extends TestFmwk {
private static final String LANGUAGES_ISOLATES_JSON = "languages/isolates.json";
static CLDRConfig CONF = CLDRConfig.getInstance();
static CLDRFile ENGLISH = CONF.getEnglish();
static SupplementalDataInfo SDI = CONF.getSupplementalDataInfo();
Expand All @@ -33,10 +36,9 @@ public static void main(String[] args) {
new TestLanguageGroup().run(args);
}

static final Set<String> ISOLATES = ImmutableSet.of("ko", "qu", "root");

public void TestCodes() {
public void TestCodes() throws IOException {
LanguageTagParser ltp = new LanguageTagParser();
final Set<String> ISOLATES = CldrUtility.readJsonStringSet(LANGUAGES_ISOLATES_JSON);
Set<String> seen = new HashSet<>();
for (String locale : CONF.getCldrFactory().getAvailableLanguages()) {
String lang = ltp.set(locale).getLanguage();
Expand All @@ -51,7 +53,11 @@ public void TestCodes() {
assertEquals(targets.toString(), 1, targets.size());
List<String> target = targets.iterator().next();
if ((target.size() == 1) != ISOLATES.contains(lang)) {
errln(getName(lang) + "\t" + target);
if(ISOLATES.contains(lang)) {
errln(getName(lang) + "\t" + target + "\t - in "+ LANGUAGES_ISOLATES_JSON+" but in languageGroup.xml");
} else {
errln(getName(lang) + "\t" + target + "\t - not in "+LANGUAGES_ISOLATES_JSON+" nor languageGroup.xml");
}
} else {
logln(getName(lang) + "\t" + target);
}
Expand All @@ -72,7 +78,7 @@ public void TestSingleParent() {

public static Set<LanguageGroup> SPECIALS = ImmutableSet.of(LanguageGroup.root, LanguageGroup.cjk, LanguageGroup.other, LanguageGroup.american);

public void TestOldLangaugeGroup() {
public void TestOldLanguageGroup() {
for (LanguageGroup item : LanguageGroup.values()) {
if (SPECIALS.contains(item)) { // special cases
continue;
Expand All @@ -84,9 +90,9 @@ public void TestOldLangaugeGroup() {
logln(parent + ": " + getAllChildren(parent));
for (ULocale child : locales) {
String childString = child.toLanguageTag();
if (!assertTrue(getName(parent) + " contains " + getName(childString), isAncestorOf(parent, childString))) {
System.out.println("superclasses of " + childString + ": " + getAllAncestors(childString));
System.out.println("subclasses of " + parent + ": " + getAllChildren(childString));
if (!assertTrue(getName(parent) + " is not an ancestor of " + getName(childString), isAncestorOf(parent, childString))) {
System.out.println("ancestors of " + childString + ": " + getAllAncestors(childString));
System.out.println("children of " + parent + ": " + getAllChildren(childString));
}
}
}
Expand Down
46 changes: 46 additions & 0 deletions tools/java/org/unicode/cldr/util/CldrUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.text.DateFormat;
import com.ibm.icu.text.SimpleDateFormat;
Expand Down Expand Up @@ -1029,6 +1033,48 @@ public static InputStream getInputStream(Class<?> callingClass, String relativeP
return InputStreamFactory.buffer(is);
}

/**
* Fetch a data item as a JSON file, with an arbitrary class
* @param relativePath relative to the 'data' directory
* @param clazz class of object to return
* @return object
* @throws IOException
*/
public static <T> T readJson(String relativePath, Class <T> clazz) throws IOException {
try (BufferedReader reader = FileReaders.openFile(CldrUtility.class, "data/" + relativePath)) {
Gson gson = new Gson();
return gson.fromJson(reader, clazz);
}
}


/**
* Fetch a data item as a JsonElement
* @param relativePath relative to the 'data' directory
* @return object read
* @throws IOException
*/
public static JsonElement readJson(String relativePath) throws IOException {
try (BufferedReader reader = FileReaders.openFile(CldrUtility.class, "data/" + relativePath)) {
JsonParser jsonParser = new JsonParser();
return jsonParser.parse(reader);
}
}

/**
* Read a JSON file containing only a set of Strings: ["a", "b", "c"]
* @param relativePath JSON path relative to the 'data' directory
* @return
* @throws IOException
*/
public static Set<String> readJsonStringSet(String relativePath) throws IOException {
JsonArray iterator = readJson(relativePath).getAsJsonArray();
Set<String> strs = new TreeSet<>();
iterator.forEach((JsonElement e) -> strs.add(e.getAsString()));
return Collections.unmodifiableSet(strs);

}

/**
* Takes a Map that goes from Object to Set, and fills in the transpose
*
Expand Down
3 changes: 3 additions & 0 deletions tools/java/org/unicode/cldr/util/data/languages/isolates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"ko", "qu", "root"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: what is this for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delayed answer: it's to move static final Set<String> ISOLATES out to a data file.

]