Exemple #1
0
        private void ConstructAndDeriveRegexp(string input, string expectedResult, string removedLetter)
        {
            // Arrange
            regexp = new RegularExpression(input, true);
            Console.Out.WriteLine("{0} optimized into {1}", input, regexp);
            if (expectedResult == null)
            {
                expectedDerivation = null;
            }
            else
            {
                expectedDerivation = new RegularExpression(expectedResult, true);
            }
            Console.Out.WriteLine("{0} optimized into {1}", expectedResult, expectedDerivation);

            // Act
            derivation = regexp.Derive(removedLetter);

            // Assert
            if (expectedDerivation == null)
            {
                Assert.AreEqual(null, derivation);
            }
            else
            {
                Assert.AreEqual(true, expectedDerivation.Equals(derivation));
            }
        }
 /// <summary>
 /// Two DnsResourceDataNamingAuthorityPointer are equal iff their order, preference, flags, services, regular expression and replacement fields
 /// are equal.
 /// </summary>
 public bool Equals(DnsResourceDataNamingAuthorityPointer other)
 {
     return(other != null &&
            Order.Equals(other.Order) &&
            Preference.Equals(other.Preference) &&
            Flags.Equals(other.Flags) &&
            Services.Equals(other.Services) &&
            RegularExpression.Equals(other.RegularExpression) &&
            Replacement.Equals(other.Replacement));
 }
        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");
        }
Exemple #4
0
        private void ConstructAndCompareRegexp(string input1, string input2, bool expectedEqual)
        {
            //Arrange
            exp1 = new RegularExpression(input1, true);
            Console.Out.WriteLine("{0} optimized into {1}", input1, exp1);
            exp2 = new RegularExpression(input2, true);
            Console.Out.WriteLine("{0} optimized into {1}", input2, exp2);

            //Act

            //Assert
            Assert.AreEqual(expectedEqual, exp1.Equals(exp2),
                            String.Format("the expressions \"{0}\" and \"{1}\" were expected to{2} be equal, but they are{3}",
                                          exp1, exp2, expectedEqual ? "" : " not", expectedEqual ? " not" : ""));

            Console.Out.WriteLine("the expressions \"{0}\" and \"{1}\" are{2} equal, as expected",
                                  exp1, exp2, expectedEqual ? "" : " not");
        }
        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 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");
        }
Exemple #7
0
        /// <summary>
        /// Returns true if PaymentProductFieldValidators instances are equal
        /// </summary>
        /// <param name="other">Instance of PaymentProductFieldValidators to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(PaymentProductFieldValidators other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     BoletoBancarioRequiredness == other.BoletoBancarioRequiredness ||
                     BoletoBancarioRequiredness != null &&
                     BoletoBancarioRequiredness.Equals(other.BoletoBancarioRequiredness)
                     ) &&
                 (
                     EmailAddress == other.EmailAddress ||
                     EmailAddress != null &&
                     EmailAddress.Equals(other.EmailAddress)
                 ) &&
                 (
                     ExpirationDate == other.ExpirationDate ||
                     ExpirationDate != null &&
                     ExpirationDate.Equals(other.ExpirationDate)
                 ) &&
                 (
                     FixedList == other.FixedList ||
                     FixedList != null &&
                     FixedList.Equals(other.FixedList)
                 ) &&
                 (
                     Iban == other.Iban ||
                     Iban != null &&
                     Iban.Equals(other.Iban)
                 ) &&
                 (
                     Length == other.Length ||
                     Length != null &&
                     Length.Equals(other.Length)
                 ) &&
                 (
                     Luhn == other.Luhn ||
                     Luhn != null &&
                     Luhn.Equals(other.Luhn)
                 ) &&
                 (
                     Range == other.Range ||
                     Range != null &&
                     Range.Equals(other.Range)
                 ) &&
                 (
                     RegularExpression == other.RegularExpression ||
                     RegularExpression != null &&
                     RegularExpression.Equals(other.RegularExpression)
                 ) &&
                 (
                     TermsAndConditions == other.TermsAndConditions ||
                     TermsAndConditions != null &&
                     TermsAndConditions.Equals(other.TermsAndConditions)
                 ));
        }
        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 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);
            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);
            Assert.IsTrue(expected.Equals(actual), "Pattern was parsed incorrectly");
        }