Skip to content

Commit 4b08cc9

Browse files
authored
CLDR-16755 Error fixing/testing for links in PathDescriptions (#4978)
1 parent dc8062a commit 4b08cc9

File tree

5 files changed

+62
-27
lines changed

5 files changed

+62
-27
lines changed

tools/cldr-apps/src/test/java/org/unicode/cldr/util/TestCLDRLinks.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ public static Stream<Arguments> pathDescriptionProvider() {
100100

101101
// this gets all URLs in references
102102
PathDescriptionParser pathDescriptionParser = new PathDescriptionParser();
103-
pathDescriptionParser.parse(PathDescription.getPathDescriptionString());
103+
String fileName = PathDescription.pathDescriptionFileName;
104+
pathDescriptionParser.parse(PathDescription.getBigString(fileName));
104105
for (final String url : urlsFromString(pathDescriptionParser.getReferences())) {
105-
urls.putIfAbsent(url, "PathDescriptions.md");
106+
urls.putIfAbsent(url, fileName);
106107
}
107108

108109
assertNotEquals(0, urls.size(), "PathDescription had no urls");

tools/cldr-code/src/main/java/org/unicode/cldr/util/PathDescription.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818

1919
public class PathDescription {
2020
/** Remember to quote any [ character! */
21+
public static final String pathDescriptionFileName = "PathDescriptions.md";
22+
23+
public static final String pathDescriptionHintsFileName = "PathDescriptionHints.md";
24+
2125
private static final String pathDescriptionString =
22-
CldrUtility.getUTF8Data("PathDescriptions.md")
26+
CldrUtility.getUTF8Data(pathDescriptionFileName)
2327
.lines()
2428
.collect(Collectors.joining("\n"));
2529

2630
private static final String pathDescriptionHintsString =
27-
CldrUtility.getUTF8Data("PathDescriptionHints.md")
31+
CldrUtility.getUTF8Data(pathDescriptionHintsFileName)
2832
.lines()
2933
.collect(Collectors.joining("\n"));
3034

@@ -64,8 +68,15 @@ public enum ErrorHandling {
6468
private static final String references = parser.getReferences();
6569

6670
/** for tests, returns the big string */
67-
static String getPathDescriptionString() {
68-
return pathDescriptionString;
71+
static String getBigString(String fileName) {
72+
switch (fileName) {
73+
case pathDescriptionFileName:
74+
return pathDescriptionString;
75+
case pathDescriptionHintsFileName:
76+
return pathDescriptionHintsString;
77+
default:
78+
throw new IllegalArgumentException();
79+
}
6980
}
7081

7182
/** for tests */

tools/cldr-code/src/main/resources/org/unicode/cldr/util/data/PathDescriptionHints.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ warning, see info panel on right
294294

295295
<!--
296296
This section is appended to every markdown fragment.
297-
All links should be https://cldr.unicode.org/translation/
298-
Currently, for hints, there are no reference links.
297+
All links should be cldr.unicode.org/translation/
298+
Currently, for hints, there are no actual reference links yet, but a "Placeholder" reference link is included for testing.
299299
-->
300+
[Placeholder]: https://cldr.unicode.org/translation/units

tools/cldr-code/src/main/resources/org/unicode/cldr/util/data/PathDescriptions.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,19 @@ The name of the language variant with code {0}. For more information, please see
220220

221221
- `^//ldml/characters/exemplarCharacters$`
222222

223-
Defines the set of characters used in your language. _To change this item, you have to flag it for review\!_ See [Changing Protected Items](https://cldr.unicode.org/translation/getting-started/guide#change-protected-items). Before filing any tickets to request changes, be sure to also read [Exemplar Characters].
223+
Defines the set of characters used in your language. _To change this item, you have to flag it for review\!_ See [Changing Protected Items]. Before filing any tickets to request changes, be sure to also read [Exemplar Characters].
224224

225225
###
226226

227227
- `^//ldml/characters/exemplarCharacters\[@type="([^"]*)"]`
228228

229-
Defines the set of characters used in your language for the “{1}” category. _To change this item, you have to flag it for review\!_ See [Changing Protected Items](https://cldr.unicode.org/translation/getting-started/guide#change-protected-items). Before filing any tickets to request changes, be sure to also read [Exemplar Characters].
229+
Defines the set of characters used in your language for the “{1}” category. _To change this item, you have to flag it for review\!_ See [Changing Protected Items]. Before filing any tickets to request changes, be sure to also read [Exemplar Characters].
230230

231231
###
232232

233233
- `^//ldml/characters/parseLenients`
234234

235-
Defines sets of characters that are treated as equivalent in parsing. _To change this item, you have to flag it for review\!_ See [Changing Protected Items](https://cldr.unicode.org/translation/getting-started/guide#change-protected-items). Before filing any tickets to request changes, be sure to also read [Exemplar Characters].
235+
Defines sets of characters that are treated as equivalent in parsing. _To change this item, you have to flag it for review\!_ See [Changing Protected Items]. Before filing any tickets to request changes, be sure to also read [Exemplar Characters].
236236

237237
###
238238

@@ -1087,9 +1087,10 @@ A set of keywords for a character or sequence. For more information, see [Short
10871087

10881088
<!--
10891089
This section is appended to every markdown fragment.
1090-
All links should be https://cldr.unicode.org/translation/
1090+
All links should be cldr.unicode.org/translation/
10911091
-->
10921092

1093+
[Changing Protected Items]: https://cldr.unicode.org/translation/getting-started/guide#change-protected-items
10931094
[Characters]: https://cldr.unicode.org/translation/characters
10941095
[Character Labels]: https://cldr.unicode.org/translation/characters/character-labels
10951096
[Compound Units]: https://cldr.unicode.org/translation/units/unit-names-and-patterns#compound-units

tools/cldr-code/src/test/java/org/unicode/cldr/util/TestPathDescription.java

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,42 @@
1212
public class TestPathDescription {
1313
@Test
1414
public void testParseGiantString() {
15+
parseOneString(PathDescription.pathDescriptionFileName);
16+
parseOneString(PathDescription.pathDescriptionHintsFileName);
17+
}
18+
19+
private void parseOneString(String fileName) {
20+
final String bigString = PathDescription.getBigString(fileName);
1521
final PathDescriptionParser parser = new PathDescriptionParser();
16-
RegexLookup<Pair<String, String>> lookup =
17-
parser.parse(PathDescription.getPathDescriptionString());
22+
final RegexLookup<Pair<String, String>> lookup = parser.parse(bigString);
23+
1824
assertNotNull(lookup);
19-
assertFalse(lookup.size() == 0, "lookup is empty");
25+
assertNotEquals(0, lookup.size(), "lookup is empty");
26+
2027
String references = parser.getReferences();
2128
assertNotNull(references);
22-
assertFalse(parser.getReferences().trim().isEmpty());
23-
29+
assertFalse(references.trim().isEmpty());
2430
// To print out the regex tree:
2531
// System.out.println(lookup.toString());
2632
assertFalse(
27-
parser.getReferences().contains("#h."),
28-
"PathDescriptions.md refers to broken anchor #h.… (old Google Sites)");
33+
references.contains("#h."),
34+
fileName + " refers to broken anchor #h.… (old Google Sites)");
35+
36+
String badLine = containsHttpWithoutLeftBracket(bigString);
37+
assertNull(
38+
badLine,
39+
fileName
40+
+ " contains http in line that does not start with left bracket: "
41+
+ badLine);
42+
}
43+
44+
private String containsHttpWithoutLeftBracket(String s) {
45+
for (String line : s.split("\\R")) {
46+
if (!line.isBlank() && line.charAt(0) != '[' && line.contains("http")) {
47+
return line;
48+
}
49+
}
50+
return null;
2951
}
3052

3153
@ParameterizedTest
@@ -36,7 +58,7 @@ public void testParseGiantString() {
3658
"//ldml/dates/timeZoneNames/zone[@type=\"Asia/Kuching\"]/exemplarCity"
3759
})
3860
public void testPresent(final String xpath) {
39-
assertNotNull(PathDescription.getPathHandling().get(xpath), () -> xpath);
61+
assertNotNull(PathDescription.getPathHandling().get(xpath), xpath);
4062
}
4163

4264
@Test
@@ -73,13 +95,12 @@ void testNoPlaceholders() {
7395
"Remaining placeholders (sampling of xpaths) from PathDescriptions.md:\n"
7496
+ xpathsWithPlaceholders.entrySet().stream()
7597
.map(
76-
e -> {
77-
return urls.forXpath(locale, e.getValue())
78-
+ " "
79-
+ e.getKey()
80-
+ " "
81-
+ e.getValue();
82-
})
98+
e ->
99+
urls.forXpath(locale, e.getValue())
100+
+ " "
101+
+ e.getKey()
102+
+ " "
103+
+ e.getValue())
83104
.collect(Collectors.joining("\n")));
84105
}
85106
}

0 commit comments

Comments
 (0)