• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.unicode.cldr.unittest;
2 
3 import java.util.ArrayList;
4 import java.util.HashSet;
5 import java.util.List;
6 import java.util.Set;
7 
8 import org.unicode.cldr.util.CLDRConfig;
9 import org.unicode.cldr.util.CLDRFile;
10 import org.unicode.cldr.util.Factory;
11 import org.unicode.cldr.util.LanguageTagCanonicalizer;
12 import org.unicode.cldr.util.LanguageTagParser;
13 
14 import com.ibm.icu.dev.test.TestFmwk;
15 
16 public class TestIdentity extends TestFmwk {
17     static CLDRConfig testInfo = CLDRConfig.getInstance();
18 
main(String[] args)19     public static void main(String[] args) {
20         new TestIdentity().run(args);
21     }
22 
TestIdentityVsFilename()23     public void TestIdentityVsFilename() {
24 
25         LanguageTagParser ltp = new LanguageTagParser();
26         LanguageTagCanonicalizer ltc = new LanguageTagCanonicalizer();
27 
28         List<Factory> factories = new ArrayList<Factory>();
29         factories.add(testInfo.getFullCldrFactory());
30         factories.add(testInfo.getExemplarsFactory());
31         factories.add(testInfo.getCollationFactory());
32         factories.add(testInfo.getRBNFFactory());
33         factories.add(testInfo.getAnnotationsFactory());
34         for (Factory factory : factories) {
35             for (String locale : factory.getAvailable()) {
36                 String canonicalLocaleID = ltc.transform(locale);
37                 ltp.set(locale);
38                 String fLanguage = ltp.getLanguage();
39                 String fScript = ltp.getScript().length() > 0 ? ltp.getScript()
40                     : "<missing>";
41                 String fTerritory = ltp.getRegion().length() > 0 ? ltp
42                     .getRegion() : "<missing>";
43                 Set<String> fVariants = new HashSet<String>(ltp.getVariants());
44                 CLDRFile localeData;
45                 if (factory.equals(testInfo.getFullCldrFactory())) {
46                     localeData = testInfo.getCLDRFile(locale, false);
47                 } else {
48                     localeData = factory.make(locale, false);
49                 }
50                 String identity = localeData.getLocaleIDFromIdentity();
51                 ltp.set(identity);
52                 String iLanguage = ltp.getLanguage();
53                 if (!fLanguage.equals(iLanguage)) {
54                     errln("Language code for locale \""
55                         + locale
56                         + "\" does not match the identity section."
57                         + "\n\tLocated in : "
58                         + factory.getSourceDirectoryForLocale(locale)
59                             .getPath()
60                         + "\n\tValue in file name is: "
61                         + fLanguage + "\n\tValue in identity section is: "
62                         + iLanguage);
63                 }
64                 String iScript = ltp.getScript().length() > 0 ? ltp.getScript()
65                     : "<missing>";
66                 if (!fScript.equals(iScript)) {
67                     errln("Script code for locale \""
68                         + locale
69                         + "\" does not match the identity section."
70                         + "\n\tLocated in : "
71                         + factory.getSourceDirectoryForLocale(locale)
72                             .getPath()
73                         + "\n\tValue in file name is: "
74                         + fScript + "\n\tValue in identity section is: "
75                         + iScript);
76                 }
77                 String iTerritory = ltp.getRegion().length() > 0 ? ltp
78                     .getRegion() : "<missing>";
79                 if (!fTerritory.equals(iTerritory)) {
80                     errln("Territory code for locale \""
81                         + locale
82                         + "\" does not match the identity section."
83                         + "\n\tLocated in : "
84                         + factory.getSourceDirectoryForLocale(locale)
85                             .getPath()
86                         + "\n\tValue in file name is: "
87                         + fTerritory + "\n\tValue in identity section is: "
88                         + iTerritory);
89                 }
90                 Set<String> iVariants = new HashSet<String>(ltp.getVariants());
91                 if (!fVariants.equals(iVariants)) {
92                     errln("Variants for locale \""
93                         + locale
94                         + "\" do not match the identity section."
95                         + "\n\tLocated in : "
96                         + factory.getSourceDirectoryForLocale(locale)
97                             .getPath()
98                         + "\n\tValue in file name is: "
99                         + fVariants.toString()
100                         + "\n\tValue in identity section is: "
101                         + iVariants.toString());
102                 }
103                 if (canonicalLocaleID != null) {
104                     ltp.set(canonicalLocaleID);
105                     String canonicalLanguage = ltp.getLanguage();
106                     if (!fLanguage.equals(canonicalLanguage)) {
107                         errln("Locale \""
108                             + locale
109                             + "\" uses a non-canonical language tag: "
110                             + fLanguage
111                             + "\n\tLocated in : "
112                             + factory.getSourceDirectoryForLocale(locale)
113                                 .getPath()
114                             + "\n\tCanonical form would be : "
115                             + canonicalLanguage);
116                     }
117                 }
118             }
119         }
120     }
121 }
122