• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.unicode.cldr.unittest;
2 
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.Collection;
6 import java.util.Collections;
7 import java.util.LinkedHashSet;
8 import java.util.Map.Entry;
9 import java.util.Set;
10 
11 import org.unicode.cldr.util.CLDRConfig;
12 
13 import com.google.common.collect.ImmutableSet;
14 import com.google.common.collect.Multimap;
15 import com.google.common.collect.TreeMultimap;
16 import com.ibm.icu.dev.test.TestFmwk;
17 import com.ibm.icu.util.ICUUncheckedIOException;
18 
19 public class TestLdml2IcuCompleteness extends TestFmwk {
20 
21     private static final String CLDR_BASE = CLDRConfig.getInstance().getCldrBaseDirectory() + "/common";
22     private static final String ICU_BASE = CLDRConfig.getInstance().getCldrBaseDirectory() + "/../icu4c/data/"; // "/Users/markdavis/workspace/icu4c/data";
23 
24     static Multimap<String, File> icuFiles = TreeMultimap.create();
25     static Multimap<String, File> cldrFiles = TreeMultimap.create();
26 
27     static Set<String> SKIP_DIRS = ImmutableSet.of(
28         "transforms", "translit", // temp
29         "unidata",
30         "sprep",
31         "mappings");
32     static Set<String> SKIP_FILES = ImmutableSet.of(
33         "attributeValueValidity",
34         "tzdbNames");
35 
36     static {
fillMap(new File(ICU_BASE), ".txt", icuFiles)37         fillMap(new File(ICU_BASE), ".txt", icuFiles);
38 //        for (Entry<String, Collection<File>> s : icuFiles.asMap().entrySet()) {
39 //            System.out.println(s.getKey() + "\t\t" + s.getValue());
40 //        }
41 
fillMap(new File(CLDR_BASE), ".xml", cldrFiles)42         fillMap(new File(CLDR_BASE), ".xml", cldrFiles);
43         for (Entry<String, Collection<File>> s : cldrFiles.asMap().entrySet()) {
44             System.out.println(s.getKey() + "\t\t" + s.getValue());
45         }
46     }
47 
fillMap(File file, String suffix, Multimap<String, File> fileList)48     static void fillMap(File file, String suffix, Multimap<String, File> fileList) {
49         try {
50             for (File f : file.listFiles()) {
51                 String name = f.getName();
52                 if (f.isDirectory()) {
53                     if (SKIP_DIRS.contains(name)) {
54                         continue;
55                     }
56                     fillMap(f, suffix, fileList);
57                 } else {
58                     if (!name.endsWith(suffix)) {
59                         continue;
60                     }
61                     // hack
62                     if (name.endsWith("dict.txt") || name.contains("readme")) {
63                         continue;
64                     }
65                     name = name.substring(0, name.length() - suffix.length());
66                     if (SKIP_FILES.contains(name)) {
67                         continue;
68                     }
69                     fileList.put(name, f.getParentFile().getCanonicalFile());
70                 }
71             }
72         } catch (IOException e) {
73             throw new ICUUncheckedIOException(e);
74         }
75     }
76 
main(String[] args)77     public static void main(String[] args) {
78         new TestLdml2IcuCompleteness().run(args);
79     }
80 
TestFiles()81     public void TestFiles() {
82         verifySuperset("cldrFiles-icuFiles", cldrFiles.keySet(), icuFiles.keySet());
83         verifySuperset("icuFiles-cldrFiles", icuFiles.keySet(), cldrFiles.keySet());
84     }
85 
verifySuperset(String title, Set<String> set1, Set<String> set2)86     private void verifySuperset(String title, Set<String> set1, Set<String> set2) {
87         LinkedHashSet<String> diff = new LinkedHashSet<>(set1);
88         diff.removeAll(set2);
89         assertEquals(title, Collections.EMPTY_SET, diff);
90     }
91 
TestLocales()92     public void TestLocales() {
93         for (Entry<String, Collection<File>> entry : cldrFiles.asMap().entrySet()) {
94             String file = entry.getKey();
95             Set<String> values = collectCldrValues(file, entry.getValue());
96         }
97     }
98 
99     // TODO flesh out
collectCldrValues(String file, Collection<File> value)100     private Set<String> collectCldrValues(String file, Collection<File> value) {
101         for (File f : value) {
102             //org.unicode.cldr.util.XMLFileReader.loadPathValues(filename, data, validating)
103         }
104         return null;
105     }
106 }
107