public void TestCountTokensNoCoalesce()
        {
            // jitterbug 5207
            String str = "\"\"";
            String del = "\"";

            IBM.ICU.Util.StringTokenizer st = new IBM.ICU.Util.StringTokenizer(str, del, true);
            int count = 0;

            while (st.HasMoreTokens())
            {
                String t = st.NextToken();
                Logln("[" + count + "] '" + t + "'");
                ++count;
            }
            st = new IBM.ICU.Util.StringTokenizer(str, del, true);
            int ncount = st.CountTokens();
            int xcount = 0;

            while (st.HasMoreTokens())
            {
                String t_0 = st.NextToken();
                Logln("[" + xcount + "] '" + t_0 + "'");
                ++xcount;
            }
            if (count != ncount || count != xcount)
            {
                Errln("inconsistent counts " + count + ", " + ncount + ", "
                      + xcount);
            }
        }
        public void TestCountTokens()
        {
            String str       = "this\tis\na\rstring\ftesting\tStringTokenizer\nconstructors!";
            String delimiter = " \t\n\r\f";

            String[] expected = { "this",            "is", "a", "string", "testing",
                                  "StringTokenizer", "constructors!" };
            String[] expectedreturn = { "this",   "\t", "is",      "\n", "a",               "\r",
                                        "string", "\f", "testing", "\t", "StringTokenizer", "\n",
                                        "constructors!" };
            IBM.ICU.Util.StringTokenizer st       = new IBM.ICU.Util.StringTokenizer(str, delimiter);
            IBM.ICU.Util.StringTokenizer streturn = new IBM.ICU.Util.StringTokenizer(str, delimiter, true);
            if (st.CountTokens() != expected.Length)
            {
                Errln("CountTokens failed for non-delimiter tokens");
            }
            if (streturn.CountTokens() != expectedreturn.Length)
            {
                Errln("CountTokens failed for delimiter tokens");
            }
            for (int i = 0; i < expected.Length; i++)
            {
                if (!st.NextToken().Equals(expected[i]) ||
                    st.CountTokens() != expected.Length - i - 1)
                {
                    Errln("CountTokens default delimiter gives wrong results");
                }
            }
            for (int i_0 = 0; i_0 < expectedreturn.Length; i_0++)
            {
                if (!streturn.NextToken().Equals(expectedreturn[i_0]) ||
                    streturn.CountTokens() != expectedreturn.Length - i_0 - 1)
                {
                    Errln("CountTokens with default delimiter and delimiter tokens gives wrong results");
                }
            }
        }
        public void TestNextNewDelimiters()
        {
            String str = "abc0def1ghi2jkl3mno4pqr0stu1vwx2yza3bcd4efg0hij1klm2nop3qrs4tuv";

            String[]   delimiter = { "0", "1", "2", "3", "4" };
            String[][] expected  = { new String[] { "abc", "pqr", "efg" },
                                     new String[]  { "def", "stu", "hij" },
                                     new String[]  { "ghi", "vwx", "klm" },
                                     new String[]  { "jkl", "yza", "nop" },
                                     new String[]  { "mno", "bcd", "qrs" } };
            IBM.ICU.Util.StringTokenizer st = new IBM.ICU.Util.StringTokenizer(str);
            int size = expected[0].Length;

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < delimiter.Length; j++)
                {
                    if (!st.NextToken(delimiter[j]).Equals(expected[j][i]))
                    {
                        Errln("nextToken() with delimiters error " + i + " " + j);
                    }
                    if (st.CountTokens() != expected[j].Length - i)
                    {
                        Errln("countTokens() after nextToken() with delimiters error"
                              + i + " " + j);
                    }
                }
            }
            st = new IBM.ICU.Util.StringTokenizer(str);
            String[] delimiter1 = { "0", "2", "4" };
            String[] expected1  = { "abc",    "def1ghi", "jkl3mno", "pqr",     "stu1vwx",
                                    "yza3bcd", "efg",     "hij1klm", "nop3qrs", "tuv" };
            for (int i_0 = 0; i_0 < expected1.Length; i_0++)
            {
                if (!st.NextToken(delimiter1[i_0 % delimiter1.Length]).Equals(
                        expected1[i_0]))
                {
                    Errln("nextToken() with delimiters error " + i_0);
                }
            }
        }
        public void TestBug4423()
        {
            // bug 4423: a bad interaction between countTokens() and
            // hasMoreTokens().
            //
            String s1 = "This is a test";

            IBM.ICU.Util.StringTokenizer tzr = new IBM.ICU.Util.StringTokenizer(s1);
            int tokenCount = 0;

            int t = tzr.CountTokens();

            if (t != 4)
            {
                Errln("tzr.countTokens() returned " + t + ".  Expected 4");
            }
            while (tzr.HasMoreTokens())
            {
                String tok = tzr.NextToken();
                if (tok.Length == 0)
                {
                    Errln("token with length == 0");
                }
                tokenCount++;
            }
            if (tokenCount != 4)
            {
                Errln("Incorrect number of tokens found = " + tokenCount);
            }

            // Precomputed tokens arrays can grow. Check for edge cases around
            // boundary where growth is forced. Array grows in increments of 100
            // tokens.
            String s2 = "";

            for (int i = 1; i < 250; i++)
            {
                s2 = s2 + " " + i;
                IBM.ICU.Util.StringTokenizer tzb = new IBM.ICU.Util.StringTokenizer(s2);
                int t2 = tzb.CountTokens();
                if (t2 != i)
                {
                    Errln("tzb.countTokens() returned " + t + ".  Expected " + i);
                    break;
                }
                int j = 0;
                while (tzb.HasMoreTokens())
                {
                    String tok_0 = tzb.NextToken();
                    j++;
                    if (tok_0.Equals(ILOG.J2CsMapping.Util.IlNumber.ToString(j)) == false)
                    {
                        Errln("Wrong token string.  Expected \"" + j + "\", got \""
                              + tok_0 + "\".");
                        break;
                    }
                }
                if (j != i)
                {
                    Errln("Wrong number of tokens.  Expected " + i + ".  Got " + j
                          + ".");
                    break;
                }
            }
        }