コード例 #1
0
ファイル: ParserTests.cs プロジェクト: repos-css/More
        public void CommentStreamPosition()
        {
            using (var stream = new CommentlessStream(new StringReader("he /*blah*/ wo")))
            {
                Assert.AreEqual(0, stream.Position);
                Assert.AreEqual('h', stream.Read());
                Assert.AreEqual(1, stream.Position);
                Assert.AreEqual('e', stream.Read());
                Assert.AreEqual(2, stream.Position);
                Assert.AreEqual(' ', stream.Read());
                Assert.AreEqual(3, stream.Position);
                Assert.AreEqual(' ', stream.Read());
                Assert.AreEqual(12, stream.Position);
                Assert.AreEqual('w', stream.Read());
                Assert.AreEqual(13, stream.Position);
                Assert.AreEqual('o', stream.Read());
                Assert.AreEqual(14, stream.Position);
                Assert.AreEqual(-1, stream.Peek());
            }

            using (var stream = new CommentlessStream(new StringReader("hello\n//blah\nworld")))
            {
                Assert.AreEqual(0, stream.Position);

                Assert.AreEqual('h', stream.Read());
                Assert.AreEqual(1, stream.Position);
                Assert.AreEqual('e', stream.Read());
                Assert.AreEqual(2, stream.Position);
                Assert.AreEqual('l', stream.Read());
                Assert.AreEqual(3, stream.Position);
                Assert.AreEqual('l', stream.Read());
                Assert.AreEqual(4, stream.Position);
                Assert.AreEqual('o', stream.Read());
                Assert.AreEqual(5, stream.Position);
                Assert.AreEqual('\n', stream.Read());
                Assert.AreEqual(6, stream.Position);

                Assert.AreEqual('w', stream.Read());
                Assert.AreEqual(14, stream.Position);
                Assert.AreEqual('o', stream.Read());
                Assert.AreEqual(15, stream.Position);
                Assert.AreEqual('r', stream.Read());
                Assert.AreEqual(16, stream.Position);
                Assert.AreEqual('l', stream.Read());
                Assert.AreEqual(17, stream.Position);
                Assert.AreEqual('d', stream.Read());

                Assert.AreEqual(-1, stream.Peek());
            }
        }
コード例 #2
0
ファイル: ParserTests.cs プロジェクト: repos-css/More
        private static string TryStripComments(string str)
        {
            var read = new StringBuilder();

            using (var stream = new CommentlessStream(new StringReader(str)))
            {
                int i;
                while ((i = stream.Read()) != -1)
                {
                    read.Append((char)i);
                }
            }

            var peek = new StringBuilder();
            using (var stream = new CommentlessStream(new StringReader(str)))
            {
                int i;
                while ((i = stream.Peek()) != -1)
                {
                    peek.Append((char)i);
                    stream.Read();
                }
            }

            using (var stream = new CommentlessStream(new StringReader(str)))
            {
                int i;
                while ((i = stream.Peek()) != -1)
                {
                    Assert.AreEqual(i, stream.Read());
                }

                Assert.AreEqual(-1, stream.Read());
            }

            Assert.AreEqual(read.ToString(), peek.ToString());

            return read.ToString();
        }