예제 #1
0
 protected virtual object VisitZeroOrOneBlock(ZeroOrOneBlock block)
 {
     return Visit(block.InnerBlock);
 }
예제 #2
0
        public void ParseTest7()
        {
            var parser = new RegexParser();
            string pattern = "a?";

            // Expected regular expression
            var aBlock = new TextBlock("a");
            var zeroOrOneBlock = new ZeroOrOneBlock(aBlock);
            var groupBlock = new AndGroupBlock(new RegexBlock[] { zeroOrOneBlock });

            var expected = new RegularExpression(groupBlock);

            var actual = parser.Parse(pattern);
            actual.ShouldBeEquivalentTo(expected, options => options.IncludingAllRuntimeProperties());
        }
예제 #3
0
        public IEnumerable<int> GetPositionsFromZeroOrOneBlock(int position, ZeroOrOneBlock block)
        {
            yield return position;

            foreach (var nextPosition in GetPositions(position, block.InnerBlock))
            {
                yield return nextPosition;
            }
        }
예제 #4
0
        public void GetPositionsFromZeroOrOneBlockTest()
        {
            int patternLength = 3;
            var pattern = new string('\0', patternLength);
            var builder = new Checker(pattern);
            var textBlock = new TextBlock("a");
            var zeroOrOneBlock = new ZeroOrOneBlock(textBlock);

            var positions = builder.GetPositionsFromZeroOrOneBlock(0, zeroOrOneBlock).ToList();

            CollectionAssert.AreEquivalent(new[] { 0, 1 }, positions);
        }
예제 #5
0
        public void ParseTest7()
        {
            var parser = new RegexParser();
            string pattern = "a?";

            // Expected regular expression
            var aBlock = new TextBlock("a");
            var zeroOrOneBlock = new ZeroOrOneBlock(aBlock);
            var groupBlock = new AndGroupBlock(new RegexBlock[] { zeroOrOneBlock });

            var expected = new RegularExpression(groupBlock);

            var actual = parser.Parse(pattern);
            Assert.IsTrue(expected.Equals(actual), "Pattern was parsed incorrectly");
        }
예제 #6
0
        public void GetLinesFromZeroOrOneBlockTest()
        {
            int patternLength = 3;
            var pattern = new string('\0', patternLength);
            LineBuilder builder = new LineBuilder(pattern, null);
            string text = "a";
            var textBlock = new TextBlock(text);
            var zeroOrOneBlock = new ZeroOrOneBlock(textBlock);

            List<string> lines = builder.GetLinesFromZeroOrOneBlock(0, zeroOrOneBlock).ToList();

            string[] expectedLines = new[] { "", "a" };
            CollectionAssert.AreEquivalent(expectedLines, lines);
        }