#pragma warning restore 612, 618 /// <summary> /// Returns the locales for which we have plurals data. Utility for testing. /// </summary> #pragma warning disable 672 public override ULocale[] GetAvailableULocales() #pragma warning restore 672 { ICollection <string> keys = GetLocaleIdToRulesIdMap(PluralType.Cardinal).Keys; ULocale[] locales = new ULocale[keys.Count]; int n = 0; foreach (var key in keys) { locales[n++] = ULocale.CreateCanonical(key); } return(locales); }
public void TestThaiDictionaryBreakIterator() { int position; int index; int[] result = { 1, 2, 5, 10, 11, 12, 11, 10, 5, 2, 1, 0 }; char[] ctext = { (char)0x0041, (char)0x0020, (char)0x0E01, (char)0x0E32,(char)0x0E23, (char)0x0E17, (char)0x0E14, (char)0x0E25, (char)0x0E2D, (char)0x0E07, (char)0x0020, (char)0x0041 }; String text = new String(ctext); ULocale locale = ULocale.CreateCanonical("th"); BreakIterator b = BreakIterator.GetWordInstance(locale); b.SetText(text); index = 0; // Test forward iteration while ((position = b.Next()) != BreakIterator.Done) { if (position != result[index++]) { Errln("Error with ThaiDictionaryBreakIterator forward iteration test at " + position + ".\nShould have been " + result[index - 1]); } } // Test backward iteration while ((position = b.Previous()) != BreakIterator.Done) { if (position != result[index++]) { Errln("Error with ThaiDictionaryBreakIterator backward iteration test at " + position + ".\nShould have been " + result[index - 1]); } } //Test invalid sequence and spaces char[] text2 = { (char)0x0E01, (char)0x0E39, (char)0x0020, (char)0x0E01, (char)0x0E34, (char)0x0E19, (char)0x0E01, (char)0x0E38, (char)0x0E49, (char)0x0E07, (char)0x0020, (char)0x0E1B, (char)0x0E34, (char)0x0E49, (char)0x0E48, (char)0x0E07, (char)0x0E2D, (char)0x0E22, (char)0x0E39, (char)0x0E48, (char)0x0E43, (char)0x0E19, (char)0x0E16, (char)0x0E49, (char)0x0E33 }; int[] expectedWordResult = { 2, 3, 6, 10, 11, 15, 17, 20, 22 }; int[] expectedLineResult = { 3, 6, 11, 15, 17, 20, 22 }; BreakIterator brk = BreakIterator.GetWordInstance(new ULocale("th")); brk.SetText(new String(text2)); position = index = 0; while ((position = brk.Next()) != BreakIterator.Done && position < text2.Length) { if (position != expectedWordResult[index++]) { Errln("Incorrect break given by thai word break iterator. Expected: " + expectedWordResult[index - 1] + " Got: " + position); } } brk = BreakIterator.GetLineInstance(new ULocale("th")); brk.SetText(new String(text2)); position = index = 0; while ((position = brk.Next()) != BreakIterator.Done && position < text2.Length) { if (position != expectedLineResult[index++]) { Errln("Incorrect break given by thai line break iterator. Expected: " + expectedLineResult[index - 1] + " Got: " + position); } } // Improve code coverage if (brk.Preceding(expectedLineResult[1]) != expectedLineResult[0]) { Errln("Incorrect preceding position."); } if (brk.Following(expectedLineResult[1]) != expectedLineResult[2]) { Errln("Incorrect following position."); } int[] fillInArray = new int[2]; if (((RuleBasedBreakIterator)brk).GetRuleStatusVec(fillInArray) != 1 || fillInArray[0] != 0) { Errln("Error: Since getRuleStatusVec is not supported in DictionaryBasedBreakIterator, it should return 1 and fillInArray[0] == 0."); } }