コード例 #1
0
        public void TestBuildMethod2()
        {
            RegexNode literal = RegexBuilder.Literal("abc");
            RegexNode characterRange = RegexBuilder.CharacterRange('a', 'f', false, RegexQuantifier.None);
            RegexNode character = RegexBuilder.MetaCharacter(RegexMetaChars.LineEnd);
            RegexNodeConcatenation concatenation = new RegexNodeConcatenation(literal, characterRange, character);

            Regex regex = RegexBuilder.Build(concatenation);
            Assert.AreEqual("abc[a-f]$", regex.ToString());
        }
コード例 #2
0
        public void TestBuildMethod4()
        {
            RegexNode literal = RegexBuilder.Literal("abc");
            RegexNode characterRange = RegexBuilder.CharacterRange('a', 'f', false, RegexQuantifier.None);
            RegexNode character = RegexBuilder.MetaCharacter(RegexMetaChars.LineEnd);
            RegexNodeConcatenation concatenation = new RegexNodeConcatenation(literal, characterRange, character);

            Regex regex = RegexBuilder.Build(RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline, concatenation);
            Assert.IsTrue((regex.Options & RegexOptions.IgnorePatternWhitespace) == RegexOptions.IgnorePatternWhitespace);
            Assert.IsTrue((regex.Options & RegexOptions.Singleline) == RegexOptions.Singleline);
            Assert.AreEqual("abc[a-f]$", regex.ToString());
        }
コード例 #3
0
        public void TestRegexNodeAdditionOperator4()
        {
            RegexNodeLiteral literal1 = new RegexNodeLiteral("\\w*");
            RegexNodeLiteral literal2 = new RegexNodeLiteral("\\d+");
            RegexNodeConcatenation concatenation1 = new RegexNodeConcatenation(literal1, literal2);

            RegexNodeLiteral literal3 = new RegexNodeLiteral("\\W*");
            RegexNodeLiteral literal4 = new RegexNodeLiteral("\\t+");
            RegexNodeConcatenation concatenation2 = new RegexNodeConcatenation(literal3, literal4);

            RegexNode sum = concatenation1 + concatenation2;

            Assert.IsInstanceOfType(sum, typeof(RegexNodeConcatenation));
            Assert.AreNotSame(concatenation1, sum);
            Assert.AreNotSame(concatenation2, sum);
            Assert.AreEqual(literal1, ((RegexNodeConcatenation)sum).ChildNodes[0]);
            Assert.AreEqual(literal2, ((RegexNodeConcatenation)sum).ChildNodes[1]);
            Assert.AreEqual(literal3, ((RegexNodeConcatenation)sum).ChildNodes[2]);
            Assert.AreEqual(literal4, ((RegexNodeConcatenation)sum).ChildNodes[3]);
        }
コード例 #4
0
        public void TestRegexNodeAdditionOperator3()
        {
            RegexNodeLiteral literal1 = new RegexNodeLiteral("\\w*");
            RegexNodeLiteral literal2 = new RegexNodeLiteral("\\d+");
            RegexNodeConcatenation concatenation = new RegexNodeConcatenation(literal1, literal2);

            RegexNodeLiteral literal3 = new RegexNodeLiteral("\\s?");
            RegexNode sum = literal3 + concatenation;

            Assert.IsInstanceOfType(sum, typeof(RegexNodeConcatenation));
            Assert.AreNotSame(concatenation, sum);
            Assert.AreEqual(literal3, ((RegexNodeConcatenation)sum).ChildNodes[0]);
            Assert.AreEqual(literal1, ((RegexNodeConcatenation)sum).ChildNodes[1]);
            Assert.AreEqual(literal2, ((RegexNodeConcatenation)sum).ChildNodes[2]);
        }
コード例 #5
0
        public void TestConcatenationNodeNullChildAssignment2()
        {
            RegexNodeLiteral literal1 = new RegexNodeLiteral("a");
            RegexNodeLiteral literal2 = new RegexNodeLiteral("b");
            RegexNodeConcatenation concatenation = new RegexNodeConcatenation(literal1, literal2);
            Assert.AreEqual(2, concatenation.ChildNodes.Count);

            // ReSharper disable RedundantAssignment
            // -- This line is expected to cause an exception.
            concatenation = new RegexNodeConcatenation(null);
            // ReSharper restore RedundantAssignment
        }
コード例 #6
0
 public void TestConcatenationNodeNullChildAssignment1()
 {
     RegexNodeConcatenation concatenation = new RegexNodeConcatenation((List<RegexNode>)null);
     Assert.IsNull(concatenation);
 }
コード例 #7
0
 public void TestConcatenationNodeConstruction()
 {
     RegexNodeConcatenation concatenation = new RegexNodeConcatenation();
     Assert.AreEqual(concatenation.ChildNodes.Count, 0);
 }
コード例 #8
0
        public void TestConcatenationNodeRendering()
        {
            RegexNodeLiteral literal1 = new RegexNodeLiteral(@"\w*");
            RegexNodeLiteral literal2 = new RegexNodeLiteral(@"\d+");
            RegexNodeLiteral literal3 = new RegexNodeLiteral(@"\s?");
            RegexNodeLiteral literal4 = new RegexNodeLiteral(@"\t");

            RegexNodeConcatenation concatenation1 = new RegexNodeConcatenation(literal1, literal2);
            Assert.AreEqual(@"\w*\d+", concatenation1.ToRegexPattern());

            RegexNodeConcatenation concatenation2 = new RegexNodeConcatenation(new List<RegexNode>(new[] { literal1, literal2 }));
            Assert.AreEqual(@"\w*\d+", concatenation2.ToRegexPattern());

            RegexNodeConcatenation concatenation3 = new RegexNodeConcatenation(literal1, literal2);
            concatenation3.ChildNodes.Add(literal3);
            Assert.AreEqual(@"\w*\d+\s?", concatenation3.ToRegexPattern());

            concatenation3.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"(?:\w*\d+\s?)*", concatenation3.ToRegexPattern());

            concatenation3 = new RegexNodeConcatenation(new List<RegexNode>(new[] { literal4, literal2, literal3, literal1 }));
            concatenation3.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"(?:\t\d+\s?\w*)*", concatenation3.ToRegexPattern());

            RegexNodeConcatenation concatenation4 = RegexBuilder.Concatenate(literal1, literal2);
            Assert.AreEqual(@"\w*\d+", concatenation4.ToRegexPattern());

            RegexNodeConcatenation concatenation5 = RegexBuilder.Concatenate(literal1, literal2, RegexQuantifier.ZeroOrOne);
            Assert.AreEqual(@"(?:\w*\d+)?", concatenation5.ToRegexPattern());

            RegexNodeConcatenation concatenation6 = RegexBuilder.Concatenate(literal1, literal2, literal3);
            Assert.AreEqual(@"\w*\d+\s?", concatenation6.ToRegexPattern());

            RegexNodeConcatenation concatenation7 = RegexBuilder.Concatenate(literal1, literal2, literal3, RegexQuantifier.ZeroOrMore);
            Assert.AreEqual(@"(?:\w*\d+\s?)*", concatenation7.ToRegexPattern());

            RegexNodeConcatenation concatenation8 = RegexBuilder.Concatenate(literal1, literal2, literal3, literal4);
            Assert.AreEqual(@"\w*\d+\s?\t", concatenation8.ToRegexPattern());

            RegexNodeConcatenation concatenation9 = RegexBuilder.Concatenate(literal1, literal2, literal3, literal4, RegexQuantifier.OneOrMore);
            Assert.AreEqual(@"(?:\w*\d+\s?\t)+", concatenation9.ToRegexPattern());
        }