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