diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestUnits.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestUnits.java index 87e9e7c06fe..f61f8c9db1b 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestUnits.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestUnits.java @@ -152,10 +152,14 @@ public class TestUnits extends TestFmwkPlus { /** Flag for generating test: TODO move to separate file */ private static final boolean GENERATE_TESTS = getFlag("TestUnits:GENERATE_TESTS"); + private static final Validity VALIDITY = Validity.getInstance(); + private static final Map> UNIT_STATUS_TO_CODES = + VALIDITY.getStatusToCodes(LstrType.unit); + private static final Set VALID_REGULAR_UNITS = - Validity.getInstance().getStatusToCodes(LstrType.unit).get(Validity.Status.regular); + UNIT_STATUS_TO_CODES.get(Validity.Status.regular); private static final Set DEPRECATED_REGULAR_UNITS = - Validity.getInstance().getStatusToCodes(LstrType.unit).get(Validity.Status.deprecated); + UNIT_STATUS_TO_CODES.get(Validity.Status.deprecated); public static final CLDRConfig CLDR_CONFIG = CLDRConfig.getInstance(); private static final Factory CLDR_FACTORY = CLDR_CONFIG.getCldrFactory(); private static final Integer INTEGER_ONE = 1; @@ -836,8 +840,7 @@ public void TestRationalParse() { static final Multimap TYPE_TO_CORE; static { - Set VALID_UNITS = - Validity.getInstance().getStatusToCodes(LstrType.unit).get(Status.regular); + Set VALID_UNITS = UNIT_STATUS_TO_CODES.get(Status.regular); Map coreToType = new TreeMap<>(); TreeMultimap typeToCore = TreeMultimap.create(); @@ -3396,8 +3399,7 @@ public void TestUnitsToTranslate() { final UnitConverter converter = config.getSupplementalDataInfo().getUnitConverter(); Map shortUnitToTranslationStatus40 = new TreeMap<>(converter.getShortUnitIdComparator()); - for (String longUnit : - Validity.getInstance().getStatusToCodes(LstrType.unit).get(Status.regular)) { + for (String longUnit : UNIT_STATUS_TO_CODES.get(Status.regular)) { String shortUnit = converter.getShortId(longUnit); shortUnitToTranslationStatus40.put(shortUnit, TranslationStatus.skip_trans); } @@ -4936,4 +4938,39 @@ public void testComposedNames() { } } } + + public void testOrder() { + MapComparator canonicalOrder = (MapComparator) converter.getLongUnitIdComparator(); + TreeSet ordered = new TreeSet(canonicalOrder); + + ordered.addAll(VALID_REGULAR_UNITS); + Map normalizedToDenormalizedLong = new TreeMap<>(); + for (String denormalized : DEPRECATED_REGULAR_UNITS) { + String fixed = converter.fixDenormalized(converter.getShortId(denormalized)); + normalizedToDenormalizedLong.put( + converter.getLongId(fixed), converter.getLongId(denormalized)); + } + MapComparator dtdOrder = DtdData.getUnitOrder(); + Set> differences = new LinkedHashSet<>(); + for (String longUnit : ordered) { + Integer cOrder = canonicalOrder.getNumericOrder(longUnit); + Integer dOrder = dtdOrder.getNumericOrder(longUnit); + if (!Objects.equals(cOrder, dOrder)) { + differences.add(List.of(cOrder, dOrder, longUnit)); + } + } + if (!differences.isEmpty()) { + warnln("DtdData order is not canonical. Use -DTestUnits:SHOW_UNITS to see replacement"); + if (SHOW_UNITS) { + System.out.println("Replacement for DtdData.UnitOrderHolder list:"); + for (String norm : ordered) { + System.out.println("\t\"" + norm + "\","); + String denorm = normalizedToDenormalizedLong.get(norm); + if (denorm != null) { + System.out.println("\t\"" + denorm + "\",\t// deprecated"); + } + } + } + } + } }