예제 #1
0
        public void GetPositionsFromInclusiveSetBlockTest()
        {
            string input = "\0";
            var visitor1 = new CheckerRegexVisitor(0, input, null);
            var inclusiveSetBlock = new InclusiveSetBlock("abc");

            var positions1 = visitor1.GetPositions(inclusiveSetBlock);
            positions1.Should().BeEquivalentTo(new[] { 1 });

            input = "a";
            var visitor2 = new CheckerRegexVisitor(0, input, null);
            var positions2 = visitor2.GetPositions(inclusiveSetBlock);
            positions2.Should().BeEquivalentTo(new[] { 1 });

            input = "d";
            var visitor3 = new CheckerRegexVisitor(0, input, null);

            var positions3 = visitor3.GetPositions(inclusiveSetBlock);
            positions3.Should().BeEmpty();
        }
예제 #2
0
        protected override object VisitInclusiveSetBlock(InclusiveSetBlock block)
        {
            string characters = block.Characters;
            int length = _input.Length;
            if (_position < length)
            {
                var currentSymbol = _input[_position];
                if (currentSymbol == 0)
                {
                    return new[] { _position + 1 };
                }

                if (characters.IndexOf(currentSymbol) != -1)
                    return new[] { _position + 1 };
            }

            return _errorResult;
        }
        public void GetLinesFromInclusiveSetBlockTest()
        {
            var input = "\0";
            var visitor1 = new BuilderRegexVisitor(0, input, null, null);
            var inclusiveSetBlock = new InclusiveSetBlock("abc");

            string[] expectedLines = new string[] { "a", "b", "c" };

            CheckVisitorResult(visitor1, inclusiveSetBlock, expectedLines);

            input = "a";
            var visitor2 = new BuilderRegexVisitor(0, input, null, null);

            expectedLines = new string[] { "a" };
            CheckVisitorResult(visitor2, inclusiveSetBlock, expectedLines);
        }
예제 #4
0
 protected virtual object VisitInclusiveSetBlock(InclusiveSetBlock block)
 {
     return block;
 }
예제 #5
0
        public void ParseTest8()
        {
            var parser = new RegexParser();
            string pattern = "[abc]";

            // Expected regular expression
            var setBlock = new InclusiveSetBlock("abc");
            var groupBlock = new AndGroupBlock(new RegexBlock[] { setBlock });

            var expected = new RegularExpression(groupBlock);

            var actual = parser.Parse(pattern);
            actual.ShouldBeEquivalentTo(expected, options => options.IncludingAllRuntimeProperties());
        }
예제 #6
0
        public void ParseTest8()
        {
            var parser = new RegexParser();
            string pattern = "[abc]";

            // Expected regular expression
            var setBlock = new InclusiveSetBlock("abc");
            var groupBlock = new AndGroupBlock(new RegexBlock[] { setBlock });

            var expected = new RegularExpression(groupBlock);

            var actual = parser.Parse(pattern);
            Assert.IsTrue(expected.Equals(actual), "Pattern was parsed incorrectly");
        }