Skip to content

Commit

Permalink
CLDR-17560 CheckCLDR separate out entireLocale checks
Browse files Browse the repository at this point in the history
- add an isEntireLocale status to CheckStatus
- make CheckStatus comparable
- set the isEntireLocale for all possibleErrors and deferred (handleCheck)
- update ConsoleCheckCLDR
  • Loading branch information
srl295 committed Apr 19, 2024
1 parent 26de8b7 commit 277e98c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package org.unicode.cldr.test;

import com.google.common.collect.ComparisonChain;
import com.google.common.collect.ImmutableSet;
import com.ibm.icu.dev.util.ElapsedTimer;
import com.ibm.icu.impl.Row.R3;
Expand Down Expand Up @@ -763,6 +764,8 @@ protected boolean accept(List<CheckStatus> result) {
cachedPossibleErrors.clear();
// call into the subclass
handleSetCldrFileToCheck(this.cldrFileToCheck, cachedOptions, cachedPossibleErrors);
// all of these are entireLocale
cachedPossibleErrors.forEach(e -> e.setEntireLocale());
initted = true;
}
// unconditionally append all cached possible errors
Expand All @@ -782,7 +785,7 @@ protected boolean accept(List<CheckStatus> result) {
Options cachedOptions = null;

/** Status value returned from check */
public static class CheckStatus {
public static class CheckStatus implements Comparable<CheckStatus> {
public static final Type alertType = Type.Comment,
warningType = Type.Warning,
errorType = Type.Error,
Expand Down Expand Up @@ -1117,6 +1120,38 @@ public static boolean hasType(List<CheckStatus> result, Type type) {
}
return false;
}

/**
* @returns true if this status applies to the entire locale, not a single path
*/
public boolean isEntireLocale() {
return entireLocale;
}

/** Mark this CheckStatus as isEntireLocale */
CheckStatus setEntireLocale() {
entireLocale = true;
return this;
}

private boolean entireLocale = false;

@Override
public int compareTo(CheckStatus o) {
if (this == o) return 0;
return ComparisonChain.start()
.compare(getType(), o.getType())
.compare(getSubtype(), o.getSubtype())
.compare(getMessage(), o.getMessage())
.result();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof CheckStatus) return false;
return compareTo((CheckStatus) o) == 0;
}
}

public abstract static class SimpleDemo {
Expand Down Expand Up @@ -1488,6 +1523,8 @@ public void handleCheckPossibleErrors(
}
}
if (SHOW_TIMES) System.out.println("Overall: " + testOverallTime + ": {0}");
// all of these are entire locale
possibleErrors.forEach(e -> e.setEntireLocale());
}

public Matcher getFilter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ public static void main(String[] args) throws Throwable {
return; // get out, it's an error.
}

List<CheckStatus> result = new ArrayList<>();
Set<PathHeader> paths = new TreeSet<>(); // CLDRFile.ldmlComparator);
Map<String, String> m = new TreeMap<>();
Map<String, String> options = new HashMap<>();
Expand Down Expand Up @@ -653,40 +652,12 @@ public static void main(String[] args) throws Throwable {
parent = new CLDRFile.TestUser(parent, user, isLanguageLocale);
}
}
// checkCldr.setCldrFileToCheck(file, new Options(options), result);

subtotalCount.clear();

for (Iterator<CheckStatus> it3 = result.iterator(); it3.hasNext(); ) {
CheckStatus status = it3.next();
String statusString = status.toString(); // com.ibm.icu.impl.Utility.escape(
CheckStatus.Type statusType = status.getType();
final Set<CheckStatus> possibleProblems = new TreeSet<>();
possibleProblems.addAll(bundle.getPossibleProblems());

if (errorsOnly) {
if (!statusType.equals(CheckStatus.errorType)) continue;
}

if (subtypeFilter != null) {
if (!subtypeFilter.contains(status.getSubtype())) {
continue;
}
}

if (checkOnSubmit) {
if (!status.isCheckOnSubmit()
|| !statusType.equals(CheckStatus.errorType)) continue;
}
showValue(
file,
null,
localeID,
null,
null,
null,
null,
statusString,
status.getSubtype());
}
paths.clear();

CoverageInfo covInfo = cldrConf.getCoverageInfo();
Expand Down Expand Up @@ -796,6 +767,7 @@ public static void main(String[] args) throws Throwable {
}
int limit = 1;
for (int jj = 0; jj < limit; ++jj) {
final List<CheckStatus> result = new ArrayList<>();
if (jj == 0) {
bundle.check(path, result, value);
} else {
Expand All @@ -805,6 +777,10 @@ public static void main(String[] args) throws Throwable {
boolean showedOne = false;
for (Iterator<CheckStatus> it3 = result.iterator(); it3.hasNext(); ) {
CheckStatus status = it3.next();
if (status.isEntireLocale()) {
possibleProblems.add(status);
continue;
}
String statusString =
status.toString(); // com.ibm.icu.impl.Utility.escape(
CheckStatus.Type statusType = status.getType();
Expand Down Expand Up @@ -890,6 +866,42 @@ public static void main(String[] args) throws Throwable {
}
}

// handle possibleProblems (non path-based errors)
{
for (Iterator<CheckStatus> it3 = possibleProblems.iterator();
it3.hasNext(); ) {
CheckStatus status = it3.next();
String statusString =
status.toString(); // com.ibm.icu.impl.Utility.escape(
CheckStatus.Type statusType = status.getType();

if (errorsOnly) {
if (!statusType.equals(CheckStatus.errorType)) continue;
}

if (subtypeFilter != null) {
if (!subtypeFilter.contains(status.getSubtype())) {
continue;
}
}

if (checkOnSubmit) {
if (!status.isCheckOnSubmit()
|| !statusType.equals(CheckStatus.errorType)) continue;
}
showValue(
file,
null,
localeID,
null,
null,
null,
null,
statusString,
status.getSubtype());
}
}

if (resolveVotesDirectory != null) {
LocaleVotingData.resolveErrors(localeID);
}
Expand Down

0 comments on commit 277e98c

Please sign in to comment.