Example #1
0
        public void CanReadSimpleContentWhileCaching(int readAhead)
        {
            const string testString = "Hello world!";

            using var textReader = new StringReader(testString);
            using var charReader = new CharReader(textReader);


            Assert.That(charReader.PeekString(readAhead),
                        Is.EqualTo(testString.Substring(0, Math.Min(testString.Length, readAhead))));
            Assert.That(charReader.PeekChar(), Is.EqualTo('H'));
            Assert.That(charReader.ReadChar(), Is.EqualTo('H'));
            Assert.That(charReader.PeekChar(), Is.EqualTo('e'));
            Assert.That(charReader.ReadChar(), Is.EqualTo('e'));
            Assert.That(charReader.PeekChar(), Is.EqualTo('l'));
            Assert.That(charReader.ReadChar(), Is.EqualTo('l'));
            Assert.That(charReader.PeekChar(), Is.EqualTo('l'));
            Assert.That(charReader.ReadChar(), Is.EqualTo('l'));
            Assert.That(charReader.PeekChar(), Is.EqualTo('o'));
            Assert.That(charReader.ReadChar(), Is.EqualTo('o'));
            Assert.That(charReader.PeekChar(), Is.EqualTo(' '));
            Assert.That(charReader.ReadChar(), Is.EqualTo(' '));
            Assert.That(charReader.PeekString(6), Is.EqualTo("world!"));
            Assert.That(charReader.PeekChar(), Is.EqualTo('w'));
            Assert.That(charReader.ReadChar(), Is.EqualTo('w'));
            Assert.That(charReader.PeekChar(), Is.EqualTo('o'));
            Assert.That(charReader.ReadChar(), Is.EqualTo('o'));
            Assert.That(charReader.PeekChar(), Is.EqualTo('r'));
            Assert.That(charReader.ReadChar(), Is.EqualTo('r'));
            Assert.That(charReader.PeekChar(), Is.EqualTo('l'));
            Assert.That(charReader.ReadChar(), Is.EqualTo('l'));
            Assert.That(charReader.PeekChar(), Is.EqualTo('d'));
            Assert.That(charReader.ReadChar(), Is.EqualTo('d'));
            Assert.That(charReader.PeekChar(), Is.EqualTo('!'));
            Assert.That(charReader.ReadChar(), Is.EqualTo('!'));

            Assert.That(charReader.PeekChar(), Is.Null);
            Assert.That(charReader.ReadChar(), Is.Null);
        }