public void GetSortRules_English() { var locale = new Locale("en-US"); var tailoredRules = Collator.GetCollationRules(locale); var collationRules = Collator.GetCollationRules(locale, UColRuleOption.UCOL_FULL_RULES); Assert.IsEmpty(tailoredRules); Assert.IsNotNullOrEmpty(collationRules); }
public void GetSortRules_Serbian() { if (string.CompareOrdinal(Wrapper.IcuVersion, "55.1") < 0) { Assert.Ignore("This test requires ICU 55 or higher"); } const string rules = "[reorder Cyrl][suppressContractions [Ии]]"; const string language = "sr"; var locale = new Locale(language); var collationRules = Collator.GetCollationRules(locale); var collationRules2 = Collator.GetCollationRules(language); Assert.AreEqual(rules, collationRules); Assert.AreEqual(collationRules, collationRules2); }
public virtual void TestCustomRules() { // It is possible not to have the collator rules for a specific // country, fallback to the language if that is the case. var possiblelocales = new[] { new Locale("de-DE"), new Locale("de") }; var allRules = RuleBasedCollator.GetAvailableCollationLocales(); var localeToUse = possiblelocales.FirstOrDefault(locl => allRules.Contains(locl.Id)); Assert.True(localeToUse != default, "Should have found a matching collation locale given the two locales to use."); const string DIN5007_2_tailorings = "& ae , a\u0308 & AE , A\u0308" + "& oe , o\u0308 & OE , O\u0308" + "& ue , u\u0308 & UE , u\u0308"; var collationRules = Collator.GetCollationRules(localeToUse.Id); Assert.IsNotNull(collationRules, $"Rules should have been fetched for {localeToUse.Id}"); string tailoredRules = collationRules + DIN5007_2_tailorings; RuleBasedCollator tailoredCollator = new RuleBasedCollator(tailoredRules); // at this point, you would save these tailoredRules to a file, // and use the custom parameter. string germanUmlaut = "Töne"; string germanOE = "Toene"; IDictionary <string, string> args = new Dictionary <string, string>(); args["custom"] = "rules.txt"; args["strength"] = "primary"; #pragma warning disable 612, 618 CollationKeyFilterFactory factory = new CollationKeyFilterFactory(args); #pragma warning restore 612, 618 factory.Inform(new StringMockResourceLoader(tailoredRules)); TokenStream tsUmlaut = factory.Create(new MockTokenizer(new StringReader(germanUmlaut), MockTokenizer.KEYWORD, false)); TokenStream tsOE = factory.Create(new MockTokenizer(new StringReader(germanOE), MockTokenizer.KEYWORD, false)); AssertCollatesToSame(tsUmlaut, tsOE); }