private static bool Matches(string pattern, string input)
        {
            var parser = new RegexParser();
            RegularExpression regex = parser.Parse(pattern);

            var checker = new Checker(input);
            return checker.Check(regex);
        }
Exemple #2
0
        public void CheckTest3()
        {
            var input = "\0\0\0";

             string regexPattern = "[^c]*";

             var parser = new RegexParser();
             var regex = parser.Parse(regexPattern);
             var checker = new Checker(input);

             Assert.IsTrue(checker.Check(regex));
        }
        public void ParseTest10()
        {
            var parser = new RegexParser();
            string pattern = ".*a.*";

            // Expected regular expression
            var anyCharacterBlock = new AnyCharacterBlock();
            var zeroOrOneBlock = new ZeroOrMoreBlock(anyCharacterBlock);
            var textBlock = new TextBlock("a");
            var groupBlock = new AndGroupBlock(new RegexBlock[] { zeroOrOneBlock, textBlock, zeroOrOneBlock });

            var expected = new RegularExpression(groupBlock);

            var actual = parser.Parse(pattern);
            Assert.IsTrue(expected.Equals(actual), "Pattern was parsed incorrectly");
        }
        public void ParseTest1()
        {
            var parser = new RegexParser();
            string pattern = "a+b+";

            // Expected regular expression
            var aBlock = new TextBlock("a");
            var bBlock = new TextBlock("b");

            var groupBlock = new AndGroupBlock(new RegexBlock[] { new OneOrMoreBlock(aBlock), new OneOrMoreBlock(bBlock) });

            var expected = new RegularExpression(groupBlock);

            var actual = parser.Parse(pattern);
            actual.ShouldBeEquivalentTo(expected,  options => options.IncludingAllRuntimeProperties(), "Pattern has been parsed incorrectly");
        }
        public void ParseTest10()
        {
            var parser = new RegexParser();
            string pattern = ".*a.*";

            // Expected regular expression
            var anyCharacterBlock = new AnyCharacterBlock();
            var zeroOrOneBlock = new ZeroOrMoreBlock(anyCharacterBlock);
            var textBlock = new TextBlock("a");
            var groupBlock = new AndGroupBlock(new RegexBlock[] { zeroOrOneBlock, textBlock, zeroOrOneBlock });

            var expected = new RegularExpression(groupBlock);

            var actual = parser.Parse(pattern);
            actual.ShouldBeEquivalentTo(expected, options => options.IncludingAllRuntimeProperties());
        }
        public void ParseTest1()
        {
            var parser = new RegexParser();
            string pattern = "a+b+";

            // Expected regular expression
            var aBlock = new TextBlock("a");
            var bBlock = new TextBlock("b");
            var plusBlock1 = new OneOrMoreBlock(aBlock);
            var plusBlock2 = new OneOrMoreBlock(bBlock);

            var groupBlock = new AndGroupBlock(new RegexBlock[] { plusBlock1, plusBlock2 });

            var expected = new RegularExpression(groupBlock);

            var actual = parser.Parse(pattern);
            Assert.IsTrue(expected.Equals(actual), "Pattern was parsed incorrectly");
        }
        public void ParseAndGenerateExpressionTest3()
        {
            int inputLength = 4;
            var input = new string('\0', inputLength);
            var builder = new LineBuilder(input, null);

            List<string> lines;

            string regexPattern = "([^emc]|em)*";

            RegexParser parser = new RegexParser();
            RegularExpression regex = parser.Parse(regexPattern);

            lines = builder.GetLines(regex).Take(10).ToList();
            Assert.IsTrue(lines.Count  > 1);
            // Check against regular expression

            CheckGeneratedLines(lines, regexPattern);
        }
        public void ParseAndGenerateExpressionTest2()
        {
            int inputLength = 10;
            var input = new string('\0', inputLength);
            var builder = new LineBuilder(input, null);

            List<string> lines;

            string regexPattern = "(o|rhh|mm)*";

            RegexParser parser = new RegexParser();
            RegularExpression regex = parser.Parse(regexPattern);

            lines = builder.GetLines(regex).ToList();
            Assert.AreNotEqual(0, lines.Count);
            // Check against regular expression

            CheckGeneratedLines(lines, regexPattern);
        }
        public void ParseTest11()
        {
            var parser = new RegexParser();
            string pattern = @".+(.)(.)(.)(.)\4\3\2\1.*";

            // Expected regular expression
            var anyCharacterBlock = new AnyCharacterBlock();
            var oneOrMoreBlock = new OneOrMoreBlock(anyCharacterBlock);
            var zeroOrOneBlock = new ZeroOrMoreBlock(anyCharacterBlock);
            var andGroupBlock = new AndGroupBlock(new [] { anyCharacterBlock });
            var b4 = new BackreferenceBlock(4);
            var b3 = new BackreferenceBlock(3);
            var b2 = new BackreferenceBlock(2);
            var b1 = new BackreferenceBlock(1);
            var groupBlock = new AndGroupBlock(new RegexBlock[] { oneOrMoreBlock, andGroupBlock, andGroupBlock, andGroupBlock, andGroupBlock, b4, b3, b2, b1, zeroOrOneBlock });

            var expected = new RegularExpression(groupBlock);

            var actual = parser.Parse(pattern);
            Assert.IsTrue(expected.Equals(actual), "Pattern was parsed incorrectly");
        }
        public void ParseTest11()
        {
            var parser = new RegexParser();
            string pattern = @".+(.)(.)(.)(.)\4\3\2\1.*";

            // Expected regular expression
            var anyCharacterBlock = new AnyCharacterBlock();
            var oneOrMoreBlock = new OneOrMoreBlock(anyCharacterBlock);
            var zeroOrOneBlock = new ZeroOrMoreBlock(anyCharacterBlock);
            var andGroupBlock = new AndGroupBlock(new [] { anyCharacterBlock });
            var b4 = new BackreferenceBlock(4);
            var b3 = new BackreferenceBlock(3);
            var b2 = new BackreferenceBlock(2);
            var b1 = new BackreferenceBlock(1);
            var groupBlock = new AndGroupBlock(new RegexBlock[] { oneOrMoreBlock, andGroupBlock, andGroupBlock, andGroupBlock, andGroupBlock, b4, b3, b2, b1, zeroOrOneBlock });

            var expected = new RegularExpression(groupBlock);

            var actual = parser.Parse(pattern);
            actual.ShouldBeEquivalentTo(expected, options => options.IncludingAllRuntimeProperties());
        }
        public void ParseTest3()
        {
            var parser = new RegexParser();
            string pattern = "(ab|bc)+";

            // Expected regular expression
            var abBlock = new TextBlock("ab");
            var bcBlock = new TextBlock("bc");

            var orGroupBlock = new OrGroupBlock(new RegexBlock[] { abBlock, bcBlock });
            var plusBlock = new OneOrMoreBlock(orGroupBlock);
            var andGroupBlock = new AndGroupBlock(new[] { plusBlock });
            var expected = new RegularExpression(andGroupBlock);

            var actual = parser.Parse(pattern);
            Assert.IsTrue(expected.Equals(actual), "Pattern was parsed incorrectly");
        }
        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());
        }
        public void ParseTest6()
        {
            var parser = new RegexParser();
            string pattern = "(a|b)";

            // Expected regular expression
            var aBlock = new TextBlock("a");
            var bBlock = new TextBlock("b");

            var orGroupBlock = new OrGroupBlock(new RegexBlock[] { aBlock, bBlock });

            var expected = new RegularExpression(orGroupBlock);

            var actual = parser.Parse(pattern);
            Assert.IsTrue(expected.Equals(actual), "Pattern was parsed incorrectly");
        }
        public void ParseTest4()
        {
            var parser = new RegexParser();
            string pattern = "(a+)*";

            // Expected regular expression
            var aBlock = new TextBlock("a");

            var plusBlock = new OneOrMoreBlock(aBlock);
            var andGroupBlock = new AndGroupBlock(new[] { plusBlock });
            var starBlock = new ZeroOrMoreBlock(andGroupBlock);
            var andGroupBlock2 = new AndGroupBlock(new[] { starBlock });
            var expected = new RegularExpression(andGroupBlock2);

            var actual = parser.Parse(pattern);
            actual.ShouldBeEquivalentTo(expected, options => options.IncludingAllRuntimeProperties());
        }
        public void ParseTest6()
        {
            var parser = new RegexParser();
            string pattern = "(a|b)";

            // Expected regular expression
            var aBlock = new TextBlock("a");
            var bBlock = new TextBlock("b");

            var orGroupBlock = new OrGroupBlock(new RegexBlock[] { aBlock, bBlock });

            var expected = new RegularExpression(orGroupBlock);

            var actual = parser.Parse(pattern);
            actual.ShouldBeEquivalentTo(expected, options => options.IncludingAllRuntimeProperties());
        }
        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");
        }
        public void ParseTest3()
        {
            var parser = new RegexParser();
            string pattern = "(ab|bc)+";

            // Expected regular expression
            var abBlock = new TextBlock("ab");
            var bcBlock = new TextBlock("bc");

            var orGroupBlock = new OrGroupBlock(new RegexBlock[] { abBlock, bcBlock });
            var plusBlock = new OneOrMoreBlock(orGroupBlock);
            var andGroupBlock = new AndGroupBlock(new[] { plusBlock });
            var expected = new RegularExpression(andGroupBlock);

            var actual = parser.Parse(pattern);
            actual.ShouldBeEquivalentTo(expected, options => options.IncludingAllRuntimeProperties());
        }
        public void ParseTest2()
        {
            var parser = new RegexParser();
            string pattern = "a*b*";

            // Expected regular expression
            var aBlock = new TextBlock("a");
            var bBlock = new TextBlock("b");

            var starBlock1 = new ZeroOrMoreBlock(aBlock);
            var starBlock2 = new ZeroOrMoreBlock(bBlock);

            var groupBlock = new AndGroupBlock(new RegexBlock[] { starBlock1, starBlock2 });

            var expected = new RegularExpression(groupBlock);

            var actual = parser.Parse(pattern);
            actual.ShouldBeEquivalentTo(expected, options => options.IncludingAllRuntimeProperties());
        }
        public void ParseTest14()
        {
            var parser = new RegexParser();
            string pattern = @"[^c]*[^r]*iii.*";

            // Expected regular expression
            var textBlock = new TextBlock("iii");

            var groupBlock =
                new AndGroupBlock(
                    new RegexBlock[]
                        {
                            new ZeroOrMoreBlock(new ExclusiveSetBlock("c")), new ZeroOrMoreBlock(new ExclusiveSetBlock("r")), textBlock,
                            new ZeroOrMoreBlock(new AnyCharacterBlock())
                        });

            var expected = new RegularExpression(groupBlock);

            var actual = parser.Parse(pattern);
            actual.ShouldBeEquivalentTo(expected, options => options.IncludingAllRuntimeProperties());
        }
        public void ParseAndGenerateExpressionTest6()
        {
            int inputLength = 12;
            var input = new string('\0', inputLength);
            var builder = new LineBuilder(input, null);

            string regexPattern = ".*";

            var parser = new RegexParser();
            RegularExpression regex = parser.Parse(regexPattern);

            var line = builder.GetLines(regex).First();
        }
        public void ParseTest4()
        {
            var parser = new RegexParser();
            string pattern = "(a+)*";

            // Expected regular expression
            var aBlock = new TextBlock("a");

            var plusBlock = new OneOrMoreBlock(aBlock);
            var andGroupBlock = new AndGroupBlock(new[] { plusBlock });
            var starBlock = new ZeroOrMoreBlock(andGroupBlock);
            var andGroupBlock2 = new AndGroupBlock(new[] { starBlock });
            var expected = new RegularExpression(andGroupBlock2);

            var actual = parser.Parse(pattern);
            Assert.IsTrue(expected.Equals(actual), "Pattern was parsed incorrectly");
        }
        public void ParseAndGenerateExpressionTest7()
        {
            //var input = "\0\0\0\0\0\0c\0o\0d\0";
            var input =   "\0\0\0\0\0\0c\0\0\0\0\0";
            var builder = new LineBuilder(input, null);

            string regexPattern = "[^c]*mmm[^c]*";

            var parser = new RegexParser();
            RegularExpression regex = parser.Parse(regexPattern);

            Assert.IsFalse(builder.GetLines(regex).Any());
        }