Ejemplo n.º 1
0
        public void PeekWithOffsetAndReadCharacters()
        {
            string stringToRead = "quick";

            CharacterStream fcs = new CharacterStream(_reader);

            char[] charsPeeked = fcs.Peek(4, stringToRead.Length);

            Assert.IsTrue(
                charsPeeked != null &&
                charsPeeked.Length == stringToRead.Length &&
                string.CompareOrdinal(
                    new string(charsPeeked), stringToRead) == 0);

            stringToRead = "The quick";

            char[] charsRead = fcs.Read(stringToRead.Length);

            Assert.IsTrue(
                charsRead != null &&
                charsRead.Length == stringToRead.Length &&
                string.CompareOrdinal(
                    new string(charsRead), stringToRead) == 0);

            charsRead    = null;
            stringToRead = " fox jumped";

            charsRead = fcs.Read(stringToRead.Length);

            Assert.IsTrue(
                charsRead != null &&
                charsRead.Length == stringToRead.Length &&
                string.CompareOrdinal(
                    new string(charsRead), stringToRead) == 0);

            charsPeeked  = null;
            stringToRead = " over the lazy";

            charsPeeked = fcs.Peek(stringToRead.Length);

            Assert.IsTrue(
                charsPeeked != null &&
                charsPeeked.Length == stringToRead.Length &&
                string.CompareOrdinal(
                    new string(charsPeeked), stringToRead) == 0);
        }
Ejemplo n.º 2
0
        public void EndOfStream()
        {
            string          stringToRead = "The quick fox jumped over the ";
            CharacterStream fcs          = new CharacterStream(_reader);

            char[] charsRead = fcs.Read(stringToRead.Length);

            Assert.IsTrue(
                !fcs.EndOfSource &&
                charsRead != null &&
                charsRead.Length == stringToRead.Length &&
                string.CompareOrdinal(
                    new string(charsRead), stringToRead) == 0);

            stringToRead = "lazy brown dog";

            char[] charsPeeked = fcs.Peek(stringToRead.Length);

            Assert.IsTrue(
                !fcs.EndOfSource &&
                charsPeeked != null &&
                charsPeeked.Length == stringToRead.Length &&
                string.CompareOrdinal(
                    new string(charsPeeked), stringToRead) == 0);

            charsRead = fcs.Read(stringToRead.Length);

            Assert.IsTrue(
                !fcs.EndOfSource &&
                charsRead != null &&
                charsRead.Length == stringToRead.Length &&
                string.CompareOrdinal(
                    new string(charsRead), stringToRead) == 0);

            bool peekResult = fcs.Peek(out char pch);

            Assert.IsTrue(!peekResult && !fcs.EndOfSource && pch == '\0');

            bool readResult = fcs.Read(out char rch);

            Assert.IsTrue(!readResult && fcs.EndOfSource && rch == '\0');
        }
Ejemplo n.º 3
0
        public void ReadCharactersAtEnd()
        {
            string stringToRead = "The quick fox jumped over the lazy brown ";

            CharacterStream fcs = new CharacterStream(_reader);

            char[] charsRead = fcs.Read(stringToRead.Length);

            Assert.IsTrue(
                charsRead != null &&
                charsRead.Length == stringToRead.Length &&
                string.CompareOrdinal(
                    new string(charsRead), stringToRead) == 0);

            charsRead = null;
            charsRead = fcs.Read(4);

            Assert.IsTrue(
                charsRead != null &&
                charsRead.Length == 3 &&
                string.CompareOrdinal(
                    new string(charsRead), "dog") == 0);
        }
Ejemplo n.º 4
0
        public void ReadCharacters()
        {
            string stringToRead = "The quick";

            CharacterStream fcs = new CharacterStream(_reader);

            char[] charsRead = fcs.Read(stringToRead.Length);

            Assert.IsTrue(
                charsRead != null &&
                charsRead.Length == stringToRead.Length &&
                string.CompareOrdinal(
                    new string(charsRead), stringToRead) == 0);
        }