Home | History | Annotate | Download | only in unittest
      1 package org.unicode.cldr.unittest;
      2 
      3 import java.util.Map;
      4 import java.util.Map.Entry;
      5 import java.util.TreeMap;
      6 
      7 import org.unicode.cldr.test.OutdatedPaths;
      8 import org.unicode.cldr.util.CLDRConfig;
      9 import org.unicode.cldr.util.CLDRFile;
     10 import org.unicode.cldr.util.PathHeader;
     11 
     12 public class TestOutdatedPaths extends TestFmwkPlus {
     13 
     14     static CLDRConfig testInfo = CLDRConfig.getInstance();
     15 
     16     public static void main(String[] args) {
     17         new TestOutdatedPaths().run(args);
     18     }
     19 
     20     OutdatedPaths outdatedPaths = new OutdatedPaths();
     21 
     22     public void TestBasic() {
     23         assertEquals("English should have none", 0,
     24             outdatedPaths.countOutdated("en"));
     25 
     26         // Update the number when GenerateBirth is rerun.
     27 
     28         assertTrue("French should have at least one",
     29             outdatedPaths.countOutdated("fr") > 10);
     30 
     31         // If this path is not outdated, find another one
     32 
     33         // assertTrue(
     34         // "Test one path known to be outdated. Use TestShow -v to find a path, and verify that it is outdated",
     35         // outdatedPaths
     36         // .isOutdated(
     37         // "fr",
     38         // "//ldml/dates/fields/field[@type=\"week\"]/relative[@type=\"-1\"]"));
     39     }
     40 
     41     // use for debugging
     42     public void TestShow() {
     43         if (isVerbose()) {
     44             PathHeader.Factory pathHeaders = PathHeader.getFactory(testInfo.getEnglish());
     45             checkShow(pathHeaders, "fr");
     46             checkShow(pathHeaders, "de");
     47         }
     48     }
     49 
     50     private void checkShow(PathHeader.Factory pathHeaders, String locale) {
     51         CLDRFile cldrFile = testInfo.getMainAndAnnotationsFactory().make(locale, true);
     52 
     53         Map<PathHeader, String> sorted = new TreeMap<PathHeader, String>();
     54         logln("Count:\t" + outdatedPaths.countOutdated(locale));
     55         for (String spath : cldrFile) {
     56             if (outdatedPaths.isOutdated(locale, spath)) {
     57                 sorted.put(pathHeaders.fromPath(spath), "");
     58             }
     59         }
     60         for (Entry<PathHeader, String> entry : sorted.entrySet()) {
     61             PathHeader p = entry.getKey();
     62             String originalPath = p.getOriginalPath();
     63             logln("Eng: "
     64                 + outdatedPaths.getPreviousEnglish(originalPath)
     65                 + "\t=>\t"
     66                 + CLDRConfig.getInstance().getEnglish()
     67                     .getStringValue(originalPath)
     68                 + "\tNative(" + locale
     69                 + "): "
     70                 + cldrFile.getStringValue(originalPath) + "\tPath: "
     71                 + p.toString() + "\tXML Path: " + originalPath);
     72         }
     73     }
     74 
     75 }
     76