Exemplo n.º 1
0
        public void TestMultiLineCommentWithMultipleLines(string input, string expected)
        {
            using (var source = new TextReaderSource(new StringReader(input), true))
            {
                var reader = source.CreateReader();
                Assert.IsNotNull(reader);

                var foundStart = false;
                var content    = new StringBuilder();
                var writer     = new StringWriter(content)
                {
                    NewLine = "\n",
                };

                var rangeSearcher = new MultiLineComment();
                while (reader != null)
                {
                    if (!foundStart)
                    {
                        var startIndex = rangeSearcher.FindStartCode(reader);
                        if (startIndex == -1)
                        {
                            reader = reader.Advance(reader.Length);
                            continue;
                        }

                        foundStart = true;
                        reader     = reader.Advance(startIndex + rangeSearcher.StartCodeLength);
                        Assert.IsNotNull(reader);
                    }

                    var endInfo = rangeSearcher.FindEndCode(reader);
                    if (endInfo == null)
                    {
                        writer.WriteLine(reader.ReadString(reader.Length));
                        reader = reader.Advance(reader.Length);
                        continue;
                    }

                    var contentLength = endInfo.Index - reader.Index;
                    writer.Write(reader.ReadString(contentLength));
                    reader     = reader.Advance(contentLength + rangeSearcher.EndCodeLength);
                    foundStart = false;
                }

                Assert.IsFalse(foundStart);
                Assert.AreEqual(expected, content.ToString());
            }
        }
Exemplo n.º 2
0
        public void TestMultiLineCommentWithSingleLine(string input, string expected)
        {
            var source = new TextReaderSource(new StringReader(input));
            var reader = source.CreateReader();

            Assert.IsNotNull(reader);

            var rangeSearcher = new MultiLineComment();
            var startIndex    = rangeSearcher.FindStartCode(reader);

            Assert.AreNotEqual(-1, startIndex);

            reader = reader.Advance(startIndex + rangeSearcher.StartCodeLength);
            Assert.IsNotNull(reader);

            var endInfo = rangeSearcher.FindEndCode(reader);

            Assert.IsNotNull(endInfo);
            Assert.IsFalse(endInfo.IsNestedStart);
            var endIndex = endInfo.Index;
            var result   = reader.ReadString(endIndex - reader.Index);

            Assert.AreEqual(expected, result);
        }