Пример #1
0
        public void TestReadUntil()
        {
            SeekableStringReader s = new SeekableStringReader("hello there");

            s.Read();
            Assert.AreEqual("ello", s.ReadUntil(' '));
            Assert.AreEqual('t', s.Peek());
            Assert.Throws <ParseException>(() => s.ReadUntil('x'));

            Assert.AreEqual("there", s.Rest());
            Assert.Throws <ParseException>(() => s.Rest());

            s.Rewind(int.MaxValue);
            Assert.AreEqual("hell", s.ReadUntil('x', 'y', 'z', ' ', 'o'));
            Assert.Throws <ParseException>(() => s.ReadUntil('x', 'y', '@'));
        }
Пример #2
0
        public void TestStuff()
        {
            using (SeekableStringReader s = new SeekableStringReader("hello"))
            {
                Assert.AreEqual('h', s.Peek());
                Assert.AreEqual("hel", s.Peek(3));
                Assert.AreEqual('h', s.Read());
                Assert.AreEqual("ell", s.Read(3));
                Assert.AreEqual("o", s.Peek(999));
                Assert.AreEqual("o", s.Read(999));
            }

            using (SeekableStringReader s2 = new SeekableStringReader("    skip.\t\n\rwhitespace.  "))
            {
                s2.SkipWhitespace();
                Assert.AreEqual("skip", s2.ReadUntil('.'));
                s2.SkipWhitespace();
                Assert.AreEqual("whitespace", s2.ReadUntil('.'));
                s2.SkipWhitespace();
                Assert.IsFalse(s2.HasMore());
                Assert.Throws <IndexOutOfRangeException>(() => s2.Peek());
            }
        }