Skip to content

Commit

Permalink
CLDR-16393 add a test for loading SDI
Browse files Browse the repository at this point in the history
- also, reinstate the 'platform' DtdType as 'removed'
  • Loading branch information
srl295 committed Aug 30, 2023
1 parent 3458c9d commit 0b683a6
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ private static void checkForDtd(Data target) {
M4<String, String, DtdType, Boolean> typeToElements =
ChainedMap.of(new TreeMap(), new TreeMap(), new TreeMap(), Boolean.class);
for (DtdType type : DtdType.values()) {
if (type.getStatus() != DtdType.DtdStatus.active) continue;
if (type == DtdType.ldmlICU) continue;
DtdData dtdData = DtdData.getInstance(type);
Set<Element> elements = dtdData.getElements();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void main(String[] args) throws IOException {
final DTD2Markdown dtd2md = new DTD2Markdown();
// System.setProperty("show_all", "true");
for (DtdType type : DtdType.values()) {
if (type.getStatus() != DtdType.DtdStatus.active) continue;
if (type == DtdType.ldmlICU) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ private static void checkBadAttributes(Relation<String, String> path2value2, Str

SupplementalDataInfo supp = SUPPLEMENTAL_DATA_INFO;
for (DtdType dtdType : DtdType.values()) {
if (dtdType.getStatus() != DtdType.DtdStatus.active) continue;
if (dtdType == DtdType.ldmlICU) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class GenerateReformattedXml {
public static void main(String[] args) {
for (DtdType dtdType : DtdType.values()) {
if (dtdType.getStatus() != DtdType.DtdStatus.active) continue;
if (args.length > 0 && !dtdType.toString().matches(args[0])) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public static void main(String[] args) {
System.out.println("№\tLevel\tStarredPath\tPH Status\t?\tAttributes");
}
for (DtdType dtdType : DtdType.values()) {
if (dtdType.getStatus() != DtdType.DtdStatus.active) continue;
if (dtdTypes != null && !dtdTypes.contains(dtdType)) {
continue;
}
Expand Down
29 changes: 28 additions & 1 deletion tools/cldr-code/src/main/java/org/unicode/cldr/util/DtdType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableSet;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -31,7 +32,10 @@ public enum DtdType {
ldmlBCP47("common/dtd/ldmlBCP47.dtd", "1.7.2", null, "bcp47"),
// keyboard 3.0
keyboard("keyboards/dtd/ldmlKeyboard.dtd", "44.0", null, "../keyboards/3.0"),
keyboardTest("keyboards/dtd/ldmlKeyboardTest.dtd", "44.0", null, "../keyboards/test");
keyboardTest("keyboards/dtd/ldmlKeyboardTest.dtd", "44.0", null, "../keyboards/test"),
// Keyboard 3.0 removes platform
platform(DtdStatus.removed, "44.0");

public static final Set<DtdType> STANDARD_SET =
ImmutableSet.of(ldmlBCP47, supplementalData, ldml, keyboard);

Expand All @@ -42,10 +46,32 @@ public enum DtdType {
public final String firstVersion;
public final Set<String> directories;

private final DtdStatus status;

/** Get the ststus, whether this is an active DTD or not */
public DtdStatus getStatus() {
return status;
}

public enum DtdStatus {
/** DTD active (default) */
active,
/** DTD no longer used */
removed,
};

private DtdType(String dtdPath) {
this(dtdPath, null, null);
}

private DtdType(DtdStatus status, String sinceVersion) {
this.directories = Collections.emptySet();
this.dtdPath = null;
this.rootType = this;
this.firstVersion = sinceVersion;
this.status = status;
}

private DtdType(String dtdPath, DtdType realType) {
this(dtdPath, null, realType);
}
Expand All @@ -55,6 +81,7 @@ private DtdType(String dtdPath, String firstVersion, DtdType realType, String...
this.rootType = realType == null ? this : realType;
this.firstVersion = firstVersion;
this.directories = ImmutableSet.copyOf(directories);
this.status = DtdStatus.active;
}

public static DtdType fromPath(String elementOrPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.unicode.cldr.util.Builder.CBuilder;
import org.unicode.cldr.util.CldrUtility.VariableReplacer;
import org.unicode.cldr.util.DayPeriodInfo.DayPeriod;
import org.unicode.cldr.util.DtdType.DtdStatus;
import org.unicode.cldr.util.GrammarInfo.GrammaticalFeature;
import org.unicode.cldr.util.GrammarInfo.GrammaticalScope;
import org.unicode.cldr.util.GrammarInfo.GrammaticalTarget;
Expand Down Expand Up @@ -4572,6 +4573,10 @@ public MetaZoneRange getMetaZoneRange(String zone, long date) {
}

public boolean isDeprecated(DtdType type, String element, String attribute, String value) {
if (type.getStatus() == DtdStatus.removed) {
// if the DTD was removed, skip
return true;
}
return DtdData.getInstance(type).isDeprecated(element, attribute, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public void showFoundElements(Relation<Row.R2<DtdType, String>, String> foundAtt
Relation<Row.R2<DtdType, String>, String> theoryAttributes =
Relation.of(new TreeMap<Row.R2<DtdType, String>, Set<String>>(), TreeSet.class);
for (DtdType type : DtdType.values()) {
if (type.getStatus() != DtdType.DtdStatus.active) continue;
DtdData dtdData = DtdData.getInstance(type);
for (Element element : dtdData.getElementFromName().values()) {
String name = element.getName();
Expand Down Expand Up @@ -1166,6 +1167,7 @@ private boolean isTopLevel(String localeID) {
/** Tests that every dtd item is connected from root */
public void TestDtdCompleteness() {
for (DtdType type : DtdType.values()) {
if (type.getStatus() != DtdType.DtdStatus.active) continue;
DtdData dtdData = DtdData.getInstance(type);
Set<Element> descendents = new LinkedHashSet<>();
dtdData.getDescendents(dtdData.ROOT, descendents);
Expand Down Expand Up @@ -1225,6 +1227,7 @@ public void TestBasicDTDCompatibility() {

// test all DTDs
for (DtdType dtd : DtdType.values()) {
if (dtd.getStatus() != DtdType.DtdStatus.active) continue;
try {
ElementAttributeInfo oldDtd = ElementAttributeInfo.getInstance(oldCommon, dtd);
ElementAttributeInfo newDtd = ElementAttributeInfo.getInstance(dtd);
Expand Down Expand Up @@ -1333,6 +1336,7 @@ private <T> Set<T> containsInOrder(Set<T> superset, Set<T> subset) {
public void TestDtdCompatibility() {

for (DtdType type : DtdType.values()) {
if (type.getStatus() != DtdType.DtdStatus.active) continue;
DtdData dtdData = DtdData.getInstance(type);
Map<String, Element> currentElementFromName = dtdData.getElementFromName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ private void dtdAttributes() {
// unless FindDtdOrder also checks attributes.
Builder<String> builder = new Builder<String>(Ordering.NATURAL);
for (DtdType dtd : DtdType.values()) {
if (dtd.getStatus() != DtdType.DtdStatus.active) continue;
Relation<String, String> eaInfo =
ElementAttributeInfo.getInstance(dtd).getElement2Attributes();
for (String element : eaInfo.keySet()) {
Expand All @@ -68,6 +69,7 @@ private void dtdAttributes() {

logln("Attribute Ordering:\t" + comp.getOrdering().toString());
for (DtdType dtd : DtdType.values()) {
if (dtd.getStatus() != DtdType.DtdStatus.active) continue;
// check that the ordering is right
Relation<String, String> eaInfo =
ElementAttributeInfo.getInstance(dtd).getElement2Attributes();
Expand All @@ -82,6 +84,7 @@ public void TestDtdElements() {
Set<String> specials =
new HashSet<String>(Arrays.asList(new String[] {"EMPTY", "PCDATA", "ANY"}));
for (DtdType dtd : DtdType.values()) {
if (dtd.getStatus() != DtdType.DtdStatus.active) continue;
if (dtd.rootType != dtd) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private void checkOrdering(DtdType type) {

public void TestDistinguishing() {
for (DtdType type : DtdType.values()) {
if (type.getStatus() != DtdType.DtdStatus.active) continue;
if (type == DtdType.ldmlICU) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public void TestDirectories() throws IOException {
public void TestValueAttributesWithChildren() {
Multimap<String, String> m = TreeMultimap.create();
for (DtdType type : DtdType.values()) {
if (type.getStatus() != DtdType.DtdStatus.active) continue;
if (type == DtdType.ldmlICU) {
continue;
}
Expand Down Expand Up @@ -355,6 +356,7 @@ private String showPath(List<Element> parents) {

public void TestNewDtdData() {
for (DtdType type : DtdType.values()) {
if (type.getStatus() != DtdType.DtdStatus.active) continue;
if (type == DtdType.ldmlICU) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,7 @@ public void TestCompletenessNonLdmlDtd() {
Multimap<String, String> pathValuePairs = LinkedListMultimap.create();
// get all the directories containing non-Ldml dtd files
for (DtdType dtdType : DtdType.values()) {
if (dtdType.getStatus() != DtdType.DtdStatus.active) continue;
if (dtdType == DtdType.ldml
|| dtdType == DtdType.ldmlICU
|| dtdType == DtdType.keyboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ public boolean check(XPathParts parts, String fullName) {

public void show(int inclusion) {
for (DtdType dtdType : DtdType.values()) {
if (dtdType.getStatus() != DtdType.DtdStatus.active) continue;
if (dtdType == DtdType.ldmlICU) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.unicode.cldr.util;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.io.File;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -35,4 +38,13 @@ public static final boolean canUseArchiveDirectory() {
}
return true; // OK to use
}

@Test
void TestReadPrevSDI() {
assumeTrue(canUseArchiveDirectory());
SupplementalDataInfo SDI_LAST =
SupplementalDataInfo.getInstance(
CLDRPaths.LAST_RELEASE_DIRECTORY + "common/supplemental/");
assertNotNull(SDI_LAST);
}
}

0 comments on commit 0b683a6

Please sign in to comment.