예제 #1
0
        public void TestHashCode()
        {
            RuleBasedBreakIterator bi1 = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(CultureInfo.CurrentCulture);
            RuleBasedBreakIterator bi3 = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(CultureInfo.CurrentCulture);
            RuleBasedBreakIterator bi2 = (RuleBasedBreakIterator)BreakIterator.GetWordInstance(CultureInfo.CurrentCulture);

            Logln("Testing hashCode()");
            bi1.SetText("Hash code");
            bi2.SetText("Hash code");
            bi3.SetText("Hash code");
            RuleBasedBreakIterator bi1clone = (RuleBasedBreakIterator)bi1.Clone();
            RuleBasedBreakIterator bi2clone = (RuleBasedBreakIterator)bi2.Clone();

            if (bi1.GetHashCode() != bi1clone.GetHashCode() ||
                bi1.GetHashCode() != bi3.GetHashCode() ||
                bi1clone.GetHashCode() != bi3.GetHashCode() ||
                bi2.GetHashCode() != bi2clone.GetHashCode())
            {
                Errln("ERROR: identical objects have different hashcodes");
            }

            if (bi1.GetHashCode() == bi2.GetHashCode() ||
                bi2.GetHashCode() == bi3.GetHashCode() ||
                bi1clone.GetHashCode() == bi2clone.GetHashCode() ||
                bi1clone.GetHashCode() == bi2.GetHashCode())
            {
                Errln("ERROR: different objects have same hashcodes");
            }
        }
예제 #2
0
        public void TestRuledump()
        {
            RuleBasedBreakIterator bi   = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance();
            MemoryStream           bos  = new MemoryStream();
            TextWriter             @out = new StreamWriter(bos);

            bi.Dump(@out);
            assertTrue(null, bos.Length > 100);
        }
예제 #3
0
 public void Init()
 {
     characterBreak = BreakIterator.GetCharacterInstance();
     wordBreak      = BreakIterator.GetWordInstance();
     lineBreak      = BreakIterator.GetLineInstance();
     //Logln("Creating sentence iterator...");
     sentenceBreak = BreakIterator.GetSentenceInstance();
     //Logln("Finished creating sentence iterator...");
     titleBreak = BreakIterator.GetTitleInstance();
 }
예제 #4
0
            public void doTest()
            {
                BreakIterator brkIter;

                switch (type)
                {
                case BreakIterator.KIND_CHARACTER: brkIter = BreakIterator.GetCharacterInstance(locale); break;

                case BreakIterator.KIND_WORD: brkIter = BreakIterator.GetWordInstance(locale); break;

                case BreakIterator.KIND_LINE: brkIter = BreakIterator.GetLineInstance(locale); break;

                case BreakIterator.KIND_SENTENCE: brkIter = BreakIterator.GetSentenceInstance(locale); break;

                default: Errln("Unsupported break iterator type " + type); return;
                }
                brkIter.SetText(text);
                int[] foundOffsets = new int[maxOffsetCount];
                int   offset, foundOffsetsCount = 0;

                // do forwards iteration test
                while (foundOffsetsCount < maxOffsetCount && (offset = brkIter.Next()) != BreakIterator.Done)
                {
                    foundOffsets[foundOffsetsCount++] = offset;
                }
                if (!offsetsMatchExpected(foundOffsets, foundOffsetsCount))
                {
                    // log error for forwards test
                    String textToDisplay = (text.Length <= 16) ? text : text.Substring(0, 16 - 0); // ICU4N: Checked 2nd parameter
                    Errln("For type " + type + " " + locale + ", text \"" + textToDisplay + "...\"" +
                          "; expect " + expectOffsets.Length + " offsets:" + formatOffsets(expectOffsets, expectOffsets.Length) +
                          "; found " + foundOffsetsCount + " offsets fwd:" + formatOffsets(foundOffsets, foundOffsetsCount));
                }
                else
                {
                    // do backwards iteration test
                    --foundOffsetsCount; // back off one from the end offset
                    while (foundOffsetsCount > 0)
                    {
                        offset = brkIter.Previous();
                        if (offset != foundOffsets[--foundOffsetsCount])
                        {
                            // log error for backwards test
                            String textToDisplay = (text.Length <= 16) ? text : text.Substring(0, 16 - 0); // ICU4N: Checked 2nd parameter
                            Errln("For type " + type + " " + locale + ", text \"" + textToDisplay + "...\"" +
                                  "; expect " + expectOffsets.Length + " offsets:" + formatOffsets(expectOffsets, expectOffsets.Length) +
                                  "; found rev offset " + offset + " where expect " + foundOffsets[foundOffsetsCount]);
                            break;
                        }
                    }
                }
            }
예제 #5
0
        public void TestCloneEquals()
        {
            RuleBasedBreakIterator bi1     = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(CultureInfo.CurrentCulture);
            RuleBasedBreakIterator biequal = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(CultureInfo.CurrentCulture);
            RuleBasedBreakIterator bi3     = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(CultureInfo.CurrentCulture);
            RuleBasedBreakIterator bi2     = (RuleBasedBreakIterator)BreakIterator.GetWordInstance(CultureInfo.CurrentCulture);

            string testString = "Testing word break iterators's clone() and equals()";

            bi1.SetText(testString);
            bi2.SetText(testString);
            biequal.SetText(testString);

            bi3.SetText("hello");
            Logln("Testing equals()");
            Logln("Testing == and !=");
            if (!bi1.Equals(biequal) || bi1.Equals(bi2) || bi1.Equals(bi3))
            {
                Errln("ERROR:1 RBBI's == and !- operator failed.");
            }
            if (bi2.Equals(biequal) || bi2.Equals(bi1) || biequal.Equals(bi3))
            {
                Errln("ERROR:2 RBBI's == and != operator  failed.");
            }
            Logln("Testing clone()");
            RuleBasedBreakIterator bi1clone = (RuleBasedBreakIterator)bi1.Clone();
            RuleBasedBreakIterator bi2clone = (RuleBasedBreakIterator)bi2.Clone();

            if (!bi1clone.Equals(bi1) ||
                !bi1clone.Equals(biequal) ||
                bi1clone.Equals(bi3) ||
                bi1clone.Equals(bi2))
            {
                Errln("ERROR:1 RBBI's clone() method failed");
            }

            if (bi2clone.Equals(bi1) ||
                bi2clone.Equals(biequal) ||
                bi2clone.Equals(bi3) ||
                !bi2clone.Equals(bi2))
            {
                Errln("ERROR:2 RBBI's clone() method failed");
            }

            if (!bi1.Text.Equals(bi1clone.Text) ||
                !bi2clone.Text.Equals(bi2.Text) ||
                bi2clone.Equals(bi1clone))
            {
                Errln("ERROR: RBBI's clone() method failed");
            }
        }
예제 #6
0
        public void TestIsBoundary()
        {
            String testString1 = "Write here. \u092d\u0301\u0930\u0924 \u0938\u0941\u0902\u0926\u0930 a\u0301u";
            RuleBasedBreakIterator charIter1 = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(new CultureInfo("en"));

            charIter1.SetText(testString1);
            int[] bounds1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 20, 21, 22, 23, 25, 26 };
            doBoundaryTest(charIter1, testString1, bounds1);
            RuleBasedBreakIterator wordIter2 = (RuleBasedBreakIterator)BreakIterator.GetWordInstance(new CultureInfo("en"));

            wordIter2.SetText(testString1);
            int[] bounds2 = { 0, 5, 6, 10, 11, 12, 16, 17, 22, 23, 26 };
            doBoundaryTest(wordIter2, testString1, bounds2);
        }
예제 #7
0
        public void TestToString()
        {
            RuleBasedBreakIterator bi1 = (RuleBasedBreakIterator)BreakIterator.GetCharacterInstance(CultureInfo.CurrentCulture);
            RuleBasedBreakIterator bi2 = (RuleBasedBreakIterator)BreakIterator.GetWordInstance(CultureInfo.CurrentCulture);

            Logln("Testing toString()");
            bi1.SetText("Hello there");
            RuleBasedBreakIterator bi3 = (RuleBasedBreakIterator)bi1.Clone();
            String temp  = bi1.ToString();
            String temp2 = bi2.ToString();
            String temp3 = bi3.ToString();

            if (temp2.Equals(temp3) || temp.Equals(temp2) || !temp.Equals(temp3))
            {
                Errln("ERROR: error in toString() method");
            }
        }
예제 #8
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));
            }
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
        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 */ }
        }