public void TestPreceding() { String words3 = "aaa bbb ccc"; BreakIterator e = BreakIterator.GetWordInstance(CultureInfo.CurrentCulture); e.SetText(words3); e.First(); int p1 = e.Next(); int p2 = e.Next(); int p3 = e.Next(); int p4 = e.Next(); int f = e.Following(p2 + 1); int p = e.Preceding(p2 + 1); if (f != p3) { Errln("IntlTestTextBoundary::TestPreceding: f!=p3"); } if (p != p2) { Errln("IntlTestTextBoundary::TestPreceding: p!=p2"); } if (p1 + 1 != p2) { Errln("IntlTestTextBoundary::TestPreceding: p1+1!=p2"); } if (p3 + 1 != p4) { Errln("IntlTestTextBoundary::TestPreceding: p3+1!=p4"); } if (!e.IsBoundary(p2) || e.IsBoundary(p2 + 1) || !e.IsBoundary(p3)) { Errln("IntlTestTextBoundary::TestPreceding: isBoundary err"); } }
public void TestBug12918() { // This test triggered an assertion failure in ICU4C, in dictbe.cpp // The equivalent code in ICU4J is structured slightly differently, // and does not appear vulnerable to the same issue. // // \u3325 decomposes with normalization, then the CJK dictionary // finds a break within the decomposition. String crasherString = "\u3325\u4a16"; BreakIterator iter = BreakIterator.GetWordInstance(ULocale.ENGLISH); iter.SetText(crasherString); iter.First(); int pos = 0; int lastPos = -1; while ((pos = iter.Next()) != BreakIterator.Done) { assertTrue("", pos > lastPos); } }
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."); } }
public void TestExtended() { TestParams tp = new TestParams(); // // Open and read the test data file. // StringBuilder testFileBuf = new StringBuilder(); Stream @is = null; try { @is = typeof(RBBITestExtended).GetTypeInfo().Assembly.GetManifestResourceStream("ICU4N.Dev.Test.Rbbi.rbbitst.txt"); if (@is == null) { Errln("Could not open test data file rbbitst.txt"); return; } StreamReader isr = new StreamReader(@is, Encoding.UTF8); try { int c; int count = 0; for (; ;) { c = isr.Read(); if (c < 0) { break; } count++; if (c == 0xFEFF && count == 1) { // BOM in the test data file. Discard it. continue; } testFileBuf.AppendCodePoint(c); } } finally { isr.Dispose(); } } catch (IOException e) { Errln(e.ToString()); try { @is.Dispose(); } catch (IOException ignored) { } return; } String testString = testFileBuf.ToString(); const int PARSE_COMMENT = 1; const int PARSE_TAG = 2; const int PARSE_DATA = 3; const int PARSE_NUM = 4; const int PARSE_RULES = 5; int parseState = PARSE_TAG; int savedState = PARSE_TAG; int lineNum = 1; int colStart = 0; int column = 0; int charIdx = 0; int i; int tagValue = 0; // The numeric value of a <nnn> tag. StringBuilder rules = new StringBuilder(); // Holds rules from a <rules> ... </rules> block int rulesFirstLine = 0; // Line number of the start of current <rules> block int len = testString.Length; for (charIdx = 0; charIdx < len;) { int c = testString.CodePointAt(charIdx); charIdx++; if (c == '\r' && charIdx < len && testString[charIdx] == '\n') { // treat CRLF as a unit c = '\n'; charIdx++; } if (c == '\n' || c == '\r') { lineNum++; colStart = charIdx; } column = charIdx - colStart + 1; switch (parseState) { case PARSE_COMMENT: if (c == 0x0a || c == 0x0d) { parseState = savedState; } break; case PARSE_TAG: { if (c == '#') { parseState = PARSE_COMMENT; savedState = PARSE_TAG; break; } if (UCharacter.IsWhitespace(c)) { break; } if (testString.StartsWith("<word>", charIdx - 1)) { tp.bi = BreakIterator.GetWordInstance(tp.currentLocale); charIdx += 5; break; } if (testString.StartsWith("<char>", charIdx - 1)) { tp.bi = BreakIterator.GetCharacterInstance(tp.currentLocale); charIdx += 5; break; } if (testString.StartsWith("<line>", charIdx - 1)) { tp.bi = BreakIterator.GetLineInstance(tp.currentLocale); charIdx += 5; break; } if (testString.StartsWith("<sent>", charIdx - 1)) { tp.bi = BreakIterator.GetSentenceInstance(tp.currentLocale); charIdx += 5; break; } if (testString.StartsWith("<title>", charIdx - 1)) { tp.bi = BreakIterator.GetTitleInstance(tp.currentLocale); charIdx += 6; break; } if (testString.StartsWith("<rules>", charIdx - 1) || testString.StartsWith("<badrules>", charIdx - 1)) { charIdx = testString.IndexOf('>', charIdx) + 1; parseState = PARSE_RULES; rules.Length = (0); rulesFirstLine = lineNum; break; } if (testString.StartsWith("<locale ", charIdx - 1)) { int closeIndex = testString.IndexOf(">", charIdx); if (closeIndex < 0) { Errln("line" + lineNum + ": missing close on <locale tag."); break; } String localeName = testString.Substring(charIdx + 6, closeIndex - (charIdx + 6)); // ICU4N: Corrected 2nd parameter localeName = localeName.Trim(); tp.currentLocale = new ULocale(localeName); charIdx = closeIndex + 1; break; } if (testString.StartsWith("<data>", charIdx - 1)) { parseState = PARSE_DATA; charIdx += 5; tp.dataToBreak.Length = (0); Arrays.Fill(tp.expectedBreaks, 0); Arrays.Fill(tp.srcCol, 0); Arrays.Fill(tp.srcLine, 0); break; } Errln("line" + lineNum + ": Tag expected in test file."); return; //parseState = PARSE_COMMENT; //savedState = PARSE_DATA; } case PARSE_RULES: if (testString.StartsWith("</rules>", charIdx - 1)) { charIdx += 7; parseState = PARSE_TAG; try { tp.bi = new RuleBasedBreakIterator(rules.ToString()); } catch (ArgumentException e) { Errln(String.Format("rbbitst.txt:{0} Error creating break iterator from rules. {1}", lineNum, e)); } } else if (testString.StartsWith("</badrules>", charIdx - 1)) { charIdx += 10; parseState = PARSE_TAG; bool goodRules = true; try { new RuleBasedBreakIterator(rules.ToString()); } catch (ArgumentException e) { goodRules = false; } if (goodRules) { Errln(String.Format( "rbbitst.txt:{0} Expected, but did not get, a failure creating break iterator from rules.", lineNum)); } } else { rules.AppendCodePoint(c); } break; case PARSE_DATA: if (c == '•') { int breakIdx = tp.dataToBreak.Length; tp.expectedBreaks[breakIdx] = -1; tp.srcLine[breakIdx] = lineNum; tp.srcCol[breakIdx] = column; break; } if (testString.StartsWith("</data>", charIdx - 1)) { // Add final entry to mappings from break location to source file position. // Need one extra because last break position returned is after the // last char in the data, not at the last char. int idx = tp.dataToBreak.Length; tp.srcLine[idx] = lineNum; tp.srcCol[idx] = column; parseState = PARSE_TAG; charIdx += 6; // RUN THE TEST! executeTest(tp); break; } if (testString.StartsWith("\\N{", charIdx - 1)) { int nameEndIdx = testString.IndexOf('}', charIdx); if (nameEndIdx == -1) { Errln("Error in named character in test file at line " + lineNum + ", col " + column); } // Named character, e.g. \N{COMBINING GRAVE ACCENT} // Get the code point from the name and insert it into the test data. String charName = testString.Substring(charIdx + 2, nameEndIdx - (charIdx + 2)); // ICU4N: Corrected 2nd parameter c = UCharacter.GetCharFromName(charName); if (c == -1) { Errln("Error in named character in test file at line " + lineNum + ", col " + column); } else { // Named code point was recognized. Insert it // into the test data. tp.dataToBreak.AppendCodePoint(c); for (i = tp.dataToBreak.Length - 1; i >= 0 && tp.srcLine[i] == 0; i--) { tp.srcLine[i] = lineNum; tp.srcCol[i] = column; } } if (nameEndIdx > charIdx) { charIdx = nameEndIdx + 1; } break; } if (testString.StartsWith("<>", charIdx - 1)) { charIdx++; int breakIdx = tp.dataToBreak.Length; tp.expectedBreaks[breakIdx] = -1; tp.srcLine[breakIdx] = lineNum; tp.srcCol[breakIdx] = column; break; } if (c == '<') { tagValue = 0; parseState = PARSE_NUM; break; } if (c == '#' && column == 3) { // TODO: why is column off so far? parseState = PARSE_COMMENT; savedState = PARSE_DATA; break; } if (c == '\\') { // Check for \ at end of line, a line continuation. // Advance over (discard) the newline int cp = testString.CodePointAt(charIdx); if (cp == '\r' && charIdx < len && testString.CodePointAt(charIdx + 1) == '\n') { // We have a CR LF // Need an extra increment of the input ptr to move over both of them charIdx++; } if (cp == '\n' || cp == '\r') { lineNum++; column = 0; charIdx++; colStart = charIdx; break; } // Let unescape handle the back slash. int[] charIdxAr = new int[1]; charIdxAr[0] = charIdx; cp = Utility.UnescapeAt(testString, charIdxAr); if (cp != -1) { // Escape sequence was recognized. Insert the char // into the test data. charIdx = charIdxAr[0]; tp.dataToBreak.AppendCodePoint(cp); for (i = tp.dataToBreak.Length - 1; i >= 0 && tp.srcLine[i] == 0; i--) { tp.srcLine[i] = lineNum; tp.srcCol[i] = column; } break; } // Not a recognized backslash escape sequence. // Take the next char as a literal. // TODO: Should this be an error? c = testString.CodePointAt(charIdx); charIdx = testString.OffsetByCodePoints(charIdx, 1); } // Normal, non-escaped data char. tp.dataToBreak.AppendCodePoint(c); // Save the mapping from offset in the data to line/column numbers in // the original input file. Will be used for better error messages only. // If there's an expected break before this char, the slot in the mapping // vector will already be set for this char; don't overwrite it. for (i = tp.dataToBreak.Length - 1; i >= 0 && tp.srcLine[i] == 0; i--) { tp.srcLine[i] = lineNum; tp.srcCol[i] = column; } break; case PARSE_NUM: // We are parsing an expected numeric tag value, like <1234>, // within a chunk of data. if (UCharacter.IsWhitespace(c)) { break; } if (c == '>') { // Finished the number. Add the info to the expected break data, // and switch parse state back to doing plain data. parseState = PARSE_DATA; if (tagValue == 0) { tagValue = -1; } int breakIdx = tp.dataToBreak.Length; tp.expectedBreaks[breakIdx] = tagValue; tp.srcLine[breakIdx] = lineNum; tp.srcCol[breakIdx] = column; break; } if (UCharacter.IsDigit(c)) { tagValue = tagValue * 10 + UCharacter.Digit(c); break; } Errln(String.Format("Syntax Error in rbbitst.txt at line {0}, col {1}", lineNum, column)); return; } } // Reached end of test file. Raise an error if parseState indicates that we are // within a block that should have been terminated. if (parseState == PARSE_RULES) { Errln(String.Format("rbbitst.txt:{0} <rules> block beginning at line {1} is not closed.", lineNum, rulesFirstLine)); } if (parseState == PARSE_DATA) { Errln(String.Format("rbbitst.txt:{0} <data> block not closed.", lineNum)); } }
public void TestRegUnreg() { CultureInfo thailand_locale = new CultureInfo("th-TH"); // ICU4N: Arbitrary locales are not allowed in .NET //CultureInfo foo_locale = new CultureInfo("fu-FU"); BreakIterator jwbi = BreakIterator.GetWordInstance(new CultureInfo("ja")); BreakIterator uwbi = BreakIterator.GetWordInstance(new CultureInfo("en-US")); BreakIterator usbi = BreakIterator.GetSentenceInstance(new CultureInfo("en-US")); BreakIterator twbi = BreakIterator.GetWordInstance(thailand_locale); BreakIterator rwbi = BreakIterator.GetWordInstance(CultureInfo.InvariantCulture); // (new Locale("", "", "")); BreakIterator sbi = (BreakIterator)usbi.Clone(); // todo: this will cause the test to fail, no way to set a breakiterator to null text so can't fix yet. // String text = "This is some test, by golly. Boy, they don't make tests like they used to, do they? This here test ain't worth $2.50. Nope."; // sbi.setText(text); assertTrue(!BreakIterator.Unregister(""), "unregister before register"); // coverage // ICU4N: Arbitrary locales are not allowed in .NET //object key0 = BreakIterator.RegisterInstance((BreakIterator)twbi.Clone(), foo_locale, BreakIterator.KIND_WORD); object key1 = BreakIterator.RegisterInstance(sbi, new CultureInfo("en-US"), BreakIterator.KIND_WORD); object key2 = BreakIterator.RegisterInstance((BreakIterator)twbi.Clone(), new CultureInfo("en-US"), BreakIterator.KIND_WORD); { BreakIterator test0 = BreakIterator.GetWordInstance(new CultureInfo("ja")); BreakIterator test1 = BreakIterator.GetWordInstance(new CultureInfo("en-US")); BreakIterator test2 = BreakIterator.GetSentenceInstance(new CultureInfo("en-US")); BreakIterator test3 = BreakIterator.GetWordInstance(thailand_locale); // ICU4N: Arbitrary locales are not allowed in .NET //BreakIterator test4 = BreakIterator.GetWordInstance(foo_locale); assertEqual(test0, jwbi, "japan word == japan word"); assertEqual(test1, twbi, "us word == thai word"); assertEqual(test2, usbi, "us sentence == us sentence"); assertEqual(test3, twbi, "thai word == thai word"); // ICU4N: Arbitrary locales are not allowed in .NET //assertEqual(test4, twbi, "foo word == thai word"); } //Locale[] locales = BreakIterator.getAvailableLocales(); assertTrue(BreakIterator.Unregister(key2), "unregister us word (thai word)"); assertTrue(!BreakIterator.Unregister(key2), "unregister second time"); bool error = false; try { BreakIterator.Unregister(null); } catch (ArgumentException e) { error = true; } assertTrue(error, "unregister null"); { CharacterIterator sci = BreakIterator.GetWordInstance(new CultureInfo("en-US")).Text; int len = sci.EndIndex - sci.BeginIndex; assertEqual(len, 0, "us word text: " + getString(sci)); } // ICU4N: Arbitrary locales are not allowed in .NET //assertTrue((BreakIterator.GetAvailableLocales().ToList()).Contains(foo_locale), "foo_locale"); //assertTrue(BreakIterator.Unregister(key0), "unregister foo word (thai word)"); //assertTrue(!(BreakIterator.GetAvailableLocales().ToList()).Contains(foo_locale), "no foo_locale"); assertEqual(BreakIterator.GetWordInstance(new CultureInfo("en-US")), usbi, "us word == us sentence"); assertTrue(BreakIterator.Unregister(key1), "unregister us word (us sentence)"); { BreakIterator test0 = BreakIterator.GetWordInstance(new CultureInfo("ja")); BreakIterator test1 = BreakIterator.GetWordInstance(new CultureInfo("en-US")); BreakIterator test2 = BreakIterator.GetSentenceInstance(new CultureInfo("en-US")); BreakIterator test3 = BreakIterator.GetWordInstance(thailand_locale); // ICU4N: Arbitrary locales are not allowed in .NET //BreakIterator test4 = BreakIterator.GetWordInstance(foo_locale); assertEqual(test0, jwbi, "japanese word break"); assertEqual(test1, uwbi, "us sentence-word break"); assertEqual(test2, usbi, "us sentence break"); assertEqual(test3, twbi, "thai word break"); // ICU4N: Arbitrary locales are not allowed in .NET //assertEqual(test4, rwbi, "root word break"); CharacterIterator sci = test1.Text; int len = sci.EndIndex - sci.BeginIndex; assertEqual(len, 0, "us sentence-word break text: " + getString(sci)); } }
public void TestLastPreviousPreceding() { int p, q; String testString = "This is a word break. Isn't it? 2.25 dollars"; Logln("Testing last(),previous(), preceding() with custom rules"); Logln("testing word iteration for string \"" + testString + "\""); RuleBasedBreakIterator wordIter1 = (RuleBasedBreakIterator)BreakIterator.GetWordInstance(new CultureInfo("en")); wordIter1.SetText(testString); p = wordIter1.Last(); if (p != testString.Length) { Errln("ERROR: last() returned" + p + "instead of" + testString.Length); } q = wordIter1.Previous(); doTest(testString, p, q, 37, "dollars"); p = q; q = wordIter1.Previous(); doTest(testString, p, q, 36, " "); q = wordIter1.Preceding(25); doTest(testString, 25, q, 22, "Isn"); p = q; q = wordIter1.Previous(); doTest(testString, p, q, 21, " "); q = wordIter1.Preceding(20); doTest(testString, 20, q, 15, "break"); p = wordIter1.Preceding(wordIter1.First()); if (p != BreakIterator.Done) { Errln("ERROR: preceding() at starting position returned #" + p + " instead of 0"); } testString = "Hello! how are you? I'am fine. Thankyou. How are you doing? This costs $20,00,000."; Logln("testing sentence iter - String:- \"" + testString + "\""); RuleBasedBreakIterator sentIter1 = (RuleBasedBreakIterator)BreakIterator.GetSentenceInstance(CultureInfo.CurrentCulture); sentIter1.SetText(testString); p = sentIter1.Last(); if (p != testString.Length) { Errln("ERROR: last() returned" + p + "instead of " + testString.Length); } q = sentIter1.Previous(); doTest(testString, p, q, 60, "This costs $20,00,000."); p = q; q = sentIter1.Previous(); doTest(testString, p, q, 41, "How are you doing? "); q = sentIter1.Preceding(40); doTest(testString, 40, q, 31, "Thankyou."); q = sentIter1.Preceding(25); doTest(testString, 25, q, 20, "I'am "); sentIter1.First(); p = sentIter1.Previous(); q = sentIter1.Preceding(sentIter1.First()); if (p != BreakIterator.Done || q != BreakIterator.Done) { Errln("ERROR: previous()/preceding() at starting position returned #" + p + " and " + q + " instead of 0\n"); } testString = "Hello! how are you? I'am fine. Thankyou. How are you doing? This\n costs $20,00,000."; Logln("testing line iter - String:- \"" + testString + "\""); RuleBasedBreakIterator lineIter1 = (RuleBasedBreakIterator)BreakIterator.GetLineInstance(CultureInfo.CurrentCulture); lineIter1.SetText(testString); p = lineIter1.Last(); if (p != testString.Length) { Errln("ERROR: last() returned" + p + "instead of " + testString.Length); } q = lineIter1.Previous(); doTest(testString, p, q, 72, "$20,00,000."); p = q; q = lineIter1.Previous(); doTest(testString, p, q, 66, "costs "); q = lineIter1.Preceding(40); doTest(testString, 40, q, 31, "Thankyou."); q = lineIter1.Preceding(25); doTest(testString, 25, q, 20, "I'am "); lineIter1.First(); p = lineIter1.Previous(); q = lineIter1.Preceding(sentIter1.First()); if (p != BreakIterator.Done || q != BreakIterator.Done) { Errln("ERROR: previous()/preceding() at starting position returned #" + p + " and " + q + " instead of 0\n"); } }
public void TestFirstNextFollowing() { int p, q; String testString = "This is a word break. Isn't it? 2.25"; Logln("Testing first() and next(), following() with custom rules"); Logln("testing word iterator - string :- \"" + testString + "\"\n"); RuleBasedBreakIterator wordIter1 = (RuleBasedBreakIterator)BreakIterator.GetWordInstance(CultureInfo.CurrentCulture); wordIter1.SetText(testString); p = wordIter1.First(); if (p != 0) { Errln("ERROR: first() returned" + p + "instead of 0"); } q = wordIter1.Next(9); doTest(testString, p, q, 20, "This is a word break"); p = q; q = wordIter1.Next(); doTest(testString, p, q, 21, "."); p = q; q = wordIter1.Next(3); doTest(testString, p, q, 28, " Isn't "); p = q; q = wordIter1.Next(2); doTest(testString, p, q, 31, "it?"); q = wordIter1.Following(2); doTest(testString, 2, q, 4, "is"); q = wordIter1.Following(22); doTest(testString, 22, q, 27, "Isn't"); wordIter1.Last(); p = wordIter1.Next(); q = wordIter1.Following(wordIter1.Last()); if (p != BreakIterator.Done || q != BreakIterator.Done) { Errln("ERROR: next()/following() at last position returned #" + p + " and " + q + " instead of" + testString.Length + "\n"); } RuleBasedBreakIterator charIter1 = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(CultureInfo.CurrentCulture); testString = "Write hindi here. "; Logln("testing char iter - string:- \"" + testString + "\""); charIter1.SetText(testString); p = charIter1.First(); if (p != 0) { Errln("ERROR: first() returned" + p + "instead of 0"); } q = charIter1.Next(); doTest(testString, p, q, 1, "W"); p = q; q = charIter1.Next(4); doTest(testString, p, q, 5, "rite"); p = q; q = charIter1.Next(12); doTest(testString, p, q, 17, " hindi here."); p = q; q = charIter1.Next(-6); doTest(testString, p, q, 11, " here."); p = q; q = charIter1.Next(6); doTest(testString, p, q, 17, " here."); p = charIter1.Following(charIter1.Last()); q = charIter1.Next(charIter1.Last()); if (p != BreakIterator.Done || q != BreakIterator.Done) { Errln("ERROR: following()/next() at last position returned #" + p + " and " + q + " instead of" + testString.Length); } testString = "Hello! how are you? I'am fine. Thankyou. How are you doing? This costs $20,00,000."; RuleBasedBreakIterator sentIter1 = (RuleBasedBreakIterator)BreakIterator.GetSentenceInstance(CultureInfo.CurrentCulture); Logln("testing sentence iter - String:- \"" + testString + "\""); sentIter1.SetText(testString); p = sentIter1.First(); if (p != 0) { Errln("ERROR: first() returned" + p + "instead of 0"); } q = sentIter1.Next(); doTest(testString, p, q, 7, "Hello! "); p = q; q = sentIter1.Next(2); doTest(testString, p, q, 31, "how are you? I'am fine. "); p = q; q = sentIter1.Next(-2); doTest(testString, p, q, 7, "how are you? I'am fine. "); p = q; q = sentIter1.Next(4); doTest(testString, p, q, 60, "how are you? I'am fine. Thankyou. How are you doing? "); p = q; q = sentIter1.Next(); doTest(testString, p, q, 83, "This costs $20,00,000."); q = sentIter1.Following(1); doTest(testString, 1, q, 7, "ello! "); q = sentIter1.Following(10); doTest(testString, 10, q, 20, " are you? "); q = sentIter1.Following(20); doTest(testString, 20, q, 31, "I'am fine. "); p = sentIter1.Following(sentIter1.Last()); q = sentIter1.Next(sentIter1.Last()); if (p != BreakIterator.Done || q != BreakIterator.Done) { Errln("ERROR: following()/next() at last position returned #" + p + " and " + q + " instead of" + testString.Length); } testString = "Hello! how\r\n (are)\r you? I'am fine- Thankyou. foo\u00a0bar How, are, you? This, costs $20,00,000."; Logln("(UnicodeString)testing line iter - String:- \"" + testString + "\""); RuleBasedBreakIterator lineIter1 = (RuleBasedBreakIterator)BreakIterator.GetLineInstance(CultureInfo.CurrentCulture); lineIter1.SetText(testString); p = lineIter1.First(); if (p != 0) { Errln("ERROR: first() returned" + p + "instead of 0"); } q = lineIter1.Next(); doTest(testString, p, q, 7, "Hello! "); p = q; p = q; q = lineIter1.Next(4); doTest(testString, p, q, 20, "how\r\n (are)\r "); p = q; q = lineIter1.Next(-4); doTest(testString, p, q, 7, "how\r\n (are)\r "); p = q; q = lineIter1.Next(6); doTest(testString, p, q, 30, "how\r\n (are)\r you? I'am "); p = q; q = lineIter1.Next(); doTest(testString, p, q, 36, "fine- "); p = q; q = lineIter1.Next(2); doTest(testString, p, q, 54, "Thankyou. foo\u00a0bar "); q = lineIter1.Following(60); doTest(testString, 60, q, 64, "re, "); q = lineIter1.Following(1); doTest(testString, 1, q, 7, "ello! "); q = lineIter1.Following(10); doTest(testString, 10, q, 12, "\r\n"); q = lineIter1.Following(20); doTest(testString, 20, q, 25, "you? "); p = lineIter1.Following(lineIter1.Last()); q = lineIter1.Next(lineIter1.Last()); if (p != BreakIterator.Done || q != BreakIterator.Done) { Errln("ERROR: following()/next() at last position returned #" + p + " and " + q + " instead of" + testString.Length); } }
private static BreakIterator LoadProto() { lock (syncLock) return(BreakIterator.GetWordInstance(new CultureInfo("th"))); }
public void TestNullLocale() { CultureInfo loc = null; ULocale uloc = null; BreakIterator brk; // Character try { brk = BreakIterator.GetCharacterInstance(loc); Errln("getCharacterInstance((Locale)null) did not throw NPE."); } catch (ArgumentNullException e) { /* OK */ } try { brk = BreakIterator.GetCharacterInstance(uloc); Errln("getCharacterInstance((ULocale)null) did not throw NPE."); } catch (ArgumentNullException e) { /* OK */ } // Line try { brk = BreakIterator.GetLineInstance(loc); Errln("getLineInstance((Locale)null) did not throw NPE."); } catch (ArgumentNullException e) { /* OK */ } try { brk = BreakIterator.GetLineInstance(uloc); Errln("getLineInstance((ULocale)null) did not throw NPE."); } catch (ArgumentNullException e) { /* OK */ } // Sentence try { brk = BreakIterator.GetSentenceInstance(loc); Errln("getSentenceInstance((Locale)null) did not throw NPE."); } catch (ArgumentNullException e) { /* OK */ } try { brk = BreakIterator.GetSentenceInstance(uloc); Errln("getSentenceInstance((ULocale)null) did not throw NPE."); } catch (ArgumentNullException e) { /* OK */ } // Title try { brk = BreakIterator.GetTitleInstance(loc); Errln("getTitleInstance((Locale)null) did not throw NPE."); } catch (ArgumentNullException e) { /* OK */ } try { brk = BreakIterator.GetTitleInstance(uloc); Errln("getTitleInstance((ULocale)null) did not throw NPE."); } catch (ArgumentNullException e) { /* OK */ } // Word try { brk = BreakIterator.GetWordInstance(loc); Errln("getWordInstance((Locale)null) did not throw NPE."); } catch (ArgumentNullException e) { /* OK */ } try { brk = BreakIterator.GetWordInstance(uloc); Errln("getWordInstance((ULocale)null) did not throw NPE."); } catch (ArgumentNullException e) { /* OK */ } }