Example #1
0
        public void Test41GetNextChars()
        {
            CharsTrie     trie   = buildMonthsTrie(TrieBuilderOption.Small);
            StringBuilder buffer = new StringBuilder();
            int           count  = trie.GetNextChars(buffer);

            if (count != 2 || !"aj".ContentEquals(buffer))
            {
                Errln("months getNextChars()!=[aj] at root");
            }
            trie.Next('j');
            trie.Next('a');
            trie.Next('n');
            // getNextChars() directly after next()
            buffer.Length = (0);
            count         = trie.GetNextChars(buffer);
            if (count != 20 || !".abcdefghijklmnopqru".ContentEquals(buffer))
            {
                Errln("months getNextChars()!=[.abcdefghijklmnopqru] after \"jan\"");
            }
            // getNextChars() after getValue()
            trie.GetValue();  // next() had returned BytesTrie.Result.INTERMEDIATE_VALUE.
            buffer.Length = (0);
            count         = trie.GetNextChars(buffer);
            if (count != 20 || !".abcdefghijklmnopqru".ContentEquals(buffer))
            {
                Errln("months getNextChars()!=[.abcdefghijklmnopqru] after \"jan\"+getValue()");
            }
            // getNextChars() from a linear-match node
            trie.Next('u');
            buffer.Length = (0);
            count         = trie.GetNextChars(buffer);
            if (count != 1 || !"a".ContentEquals(buffer))
            {
                Errln("months getNextChars()!=[a] after \"janu\"");
            }
            trie.Next('a');
            buffer.Length = (0);
            count         = trie.GetNextChars(buffer);
            if (count != 1 || !"r".ContentEquals(buffer))
            {
                Errln("months getNextChars()!=[r] after \"janua\"");
            }
            trie.Next('r');
            trie.Next('y');
            // getNextChars() after a final match
            buffer.Length = (0);
            count         = trie.GetNextChars(buffer);
            if (count != 0 || buffer.Length != 0)
            {
                Errln("months getNextChars()!=[] after \"january\"");
            }
        }