• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.unicode.cldr.unittest;
2 
3 import java.util.Collection;
4 import java.util.Map;
5 import java.util.Map.Entry;
6 import java.util.TreeMap;
7 
8 import org.unicode.cldr.test.OutdatedPaths;
9 import org.unicode.cldr.tool.CldrVersion;
10 import org.unicode.cldr.util.CLDRConfig;
11 import org.unicode.cldr.util.CLDRFile;
12 import org.unicode.cldr.util.PathHeader;
13 
14 import com.google.common.collect.Multimap;
15 import com.google.common.collect.TreeMultimap;
16 
17 public class TestOutdatedPaths extends TestFmwkPlus {
18 
19     static CLDRConfig testInfo = CLDRConfig.getInstance();
20 
main(String[] args)21     public static void main(String[] args) {
22         new TestOutdatedPaths().run(args);
23     }
24 
25     OutdatedPaths outdatedPaths = new OutdatedPaths();
26 
TestBirths()27     public void TestBirths() {
28         Multimap<CldrVersion, String> birthToPaths = TreeMultimap.create();
29         for (String path : testInfo.getEnglish()) {
30             CldrVersion birth = outdatedPaths.getEnglishBirth(path);
31             if (birth == null) birth = CldrVersion.unknown;
32             birthToPaths.put(birth, path);
33         }
34         int accum = 0;
35         for (Entry<CldrVersion, Collection<String>> entry : birthToPaths.asMap().entrySet()) {
36             int size = entry.getValue().size();
37             accum += size;
38             logln(entry.getKey() + "\t" + size + "\t" + accum);
39         }
40     }
41 
TestBasic()42     public void TestBasic() {
43         assertEquals("English should have none", 0,
44             outdatedPaths.countOutdated("en"));
45 
46         // Update the number when GenerateBirth is rerun.
47 
48         assertTrue("French should have at least one",
49             outdatedPaths.countOutdated("fr") > 10);
50 
51         // If this path is not outdated, find another one
52 
53         // assertTrue(
54         // "Test one path known to be outdated. Use TestShow -v to find a path, and verify that it is outdated",
55         // outdatedPaths
56         // .isOutdated(
57         // "fr",
58         // "//ldml/dates/fields/field[@type=\"week\"]/relative[@type=\"-1\"]"));
59     }
60 
61     // use for debugging, and also just to make sure cycle works.
TestShow()62     public void TestShow() {
63         PathHeader.Factory pathHeaders = PathHeader.getFactory();
64         // checkShow(pathHeaders, "fr");
65         checkShow(pathHeaders, "de");
66     }
67 
checkShow(PathHeader.Factory pathHeaders, String locale)68     private void checkShow(PathHeader.Factory pathHeaders, String locale) {
69         CLDRFile cldrFile = testInfo.getMainAndAnnotationsFactory().make(locale, true);
70 
71         Map<PathHeader, String> sorted = new TreeMap<PathHeader, String>();
72         logln(locale + " total outdated:\t" + outdatedPaths.countOutdated(locale));
73         for (String spath : cldrFile) {
74             if (outdatedPaths.isOutdated(locale, spath)) {
75                 sorted.put(pathHeaders.fromPath(spath), "");
76             }
77         }
78         for (Entry<PathHeader, String> entry : sorted.entrySet()) {
79             PathHeader p = entry.getKey();
80             String originalPath = p.getOriginalPath();
81             logln("English (" + outdatedPaths.getEnglishBirth(originalPath) + "):\\t"
82                 + "«" + outdatedPaths.getPreviousEnglish(originalPath) + "»"
83                 + "\t⇒\\t"
84                 + "«" + CLDRConfig.getInstance().getEnglish().getStringValue(originalPath) + "»"
85                 + "\tNative: «" + cldrFile.getStringValue(originalPath) //
86                 + "»\tPath: " + p.toString() //
87                 + "\tXML-Path: " + originalPath);
88         }
89     }
90 
91 }
92