Ejemplo n.º 1
0
        protected override object VisitExclusiveSetBlock(ExclusiveSetBlock 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;
        }
Ejemplo n.º 2
0
        public void GetPositionsFromExclusiveSetBlockTest()
        {
            string input = "\0";
            var visitor1 = new CheckerRegexVisitor(0, input, null);
            string characters = "abc";
            var exclusiveSetBlock = new ExclusiveSetBlock(characters);

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

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

            var positions2 = visitor2.GetPositions(exclusiveSetBlock);
            positions2.Should().BeEmpty();

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

            var positions3 = visitor3.GetPositions(exclusiveSetBlock);
            positions3.Should().BeEquivalentTo(new[] { 1 });
        }
        public void GetLinesFromExclusiveSetBlockTest()
        {
            var input = "\0";
            var visitor1 = new BuilderRegexVisitor(0, input, null, null);
            var characters = "abc";
            var exclusiveSetBlock = new ExclusiveSetBlock(characters);

            List<string> expectedLines = new List<string>();
            for (char c = 'a'; c < 'z'; c++)
            {
                if (characters.IndexOf(c) == -1)
                    expectedLines.Add(c.ToString());
            }

            CheckVisitorResult(visitor1, exclusiveSetBlock, expectedLines);

            input = "a";
            var visitor2 = new BuilderRegexVisitor(0, input, null, null);
            CheckVisitorResult(visitor2, exclusiveSetBlock, Enumerable.Empty<string>());

            input = "d";
            var visitor3 = new BuilderRegexVisitor(0, input, null, null);
            CheckVisitorResult(visitor3, exclusiveSetBlock, new[] { "d" });
        }
Ejemplo n.º 4
0
 protected virtual object VisitExclusiveSetBlock(ExclusiveSetBlock block)
 {
     return block;
 }
Ejemplo n.º 5
0
        public void ParseTest9()
        {
            var parser = new RegexParser();
            string pattern = "[^abc]";

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

            var expected = new RegularExpression(groupBlock);

            var actual = parser.Parse(pattern);
            actual.ShouldBeEquivalentTo(expected, options => options.IncludingAllRuntimeProperties());
        }
Ejemplo n.º 6
0
        public void ParseTest9()
        {
            var parser = new RegexParser();
            string pattern = "[^abc]";

            // Expected regular expression
            var setBlock = new ExclusiveSetBlock("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");
        }