Ejemplo n.º 1
0
 public void TestCharacterSetNodeCharacterListExpressionProperty()
 {
     RegexNodeCharacterSet characterSet = new RegexNodeCharacterSet(new[] { 'x', 'y', 'z' }, false);
     characterSet.CharacterListExpression = "abc";
     List<char> characters = new List<char>(characterSet.Characters);
     Assert.AreEqual(3, characters.Count);
     Assert.IsTrue(characters[0] == 'a' && characters[1] == 'b' && characters[2] == 'c');
     Assert.IsTrue(characterSet.CharacterListExpression == "abc");
 }
Ejemplo n.º 2
0
 public void TestCharacterSetNodeNullAssignment3()
 {
     RegexNodeCharacterSet characterSet = new RegexNodeCharacterSet(new[] { 'a', 'b', 'c' }, false);
     characterSet.CharacterListExpression = null;
     Assert.IsNull(characterSet);
 }
Ejemplo n.º 3
0
 public void TestCharacterSetNodeNullAssignment2()
 {
     RegexNodeCharacterSet characterSet = new RegexNodeCharacterSet((string)null, false);
     Assert.IsNull(characterSet);
 }
        public void TestCharacterSetNodeRendering()
        {
            // Char array, positive.
            RegexNodeCharacterSet characterSet1 = new RegexNodeCharacterSet(new[] { 'a', 'B', '0', ']', 'd', '^', 'c' }, false);
            Assert.AreEqual(@"[aB0\]d\^c]", characterSet1.ToRegexPattern());

            characterSet1.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[aB0\]d\^c]*", characterSet1.ToRegexPattern());

            characterSet1.Quantifier = RegexQuantifier.None;
            characterSet1.UseCharacterCodes = true;
            Assert.AreEqual(@"[\u0061\u0042\u0030\u005d\u0064\u005e\u0063]", characterSet1.ToRegexPattern());

            characterSet1.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[\u0061\u0042\u0030\u005d\u0064\u005e\u0063]*", characterSet1.ToRegexPattern());

            // Char array, negative.
            RegexNodeCharacterSet characterSet2 = new RegexNodeCharacterSet(new[] { 'a', 'B', '0', 'd', '^', 'x' }, true);
            Assert.AreEqual(@"[^aB0d\^x]", characterSet2.ToRegexPattern());

            characterSet2.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[^aB0d\^x]*", characterSet2.ToRegexPattern());

            characterSet2.Quantifier = RegexQuantifier.None;
            characterSet2.UseCharacterCodes = true;
            Assert.AreEqual(@"[^\u0061\u0042\u0030\u0064\u005e\u0078]", characterSet2.ToRegexPattern());

            characterSet2.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[^\u0061\u0042\u0030\u0064\u005e\u0078]*", characterSet2.ToRegexPattern());

            // Explicit pattern, positive.
            RegexNodeCharacterSet characterSet3 = new RegexNodeCharacterSet(@"aB0d\W\s", false);
            Assert.AreEqual(@"[aB0d\W\s]", characterSet3.ToRegexPattern());

            characterSet3.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[aB0d\W\s]*", characterSet3.ToRegexPattern());

            characterSet3.Quantifier = RegexQuantifier.None;
            characterSet3.UseCharacterCodes = true;
            Assert.AreEqual(@"[\u0061\u0042\u0030\u0064\u005c\u0057\u005c\u0073]", characterSet3.ToRegexPattern());

            characterSet3.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[\u0061\u0042\u0030\u0064\u005c\u0057\u005c\u0073]*", characterSet3.ToRegexPattern());

            // Explicit pattern, negative.
            RegexNodeCharacterSet characterSet4 = new RegexNodeCharacterSet(@"aB0d\W\s", true);
            Assert.AreEqual(@"[^aB0d\W\s]", characterSet4.ToRegexPattern());

            characterSet4.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[^aB0d\W\s]*", characterSet4.ToRegexPattern());

            characterSet4.Quantifier = RegexQuantifier.None;
            characterSet4.UseCharacterCodes = true;
            Assert.AreEqual(@"[^\u0061\u0042\u0030\u0064\u005c\u0057\u005c\u0073]", characterSet4.ToRegexPattern());

            characterSet4.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[^\u0061\u0042\u0030\u0064\u005c\u0057\u005c\u0073]*", characterSet4.ToRegexPattern());

            // RegexBuilder, char array, positive.
            RegexNodeCharacterSet characterSet5 = RegexBuilder.CharacterSet(new[] { 'a', 'B', '0', ']', 'd', '^', 'c' }, false, RegexQuantifier.None);
            Assert.AreEqual(@"[aB0\]d\^c]", characterSet5.ToRegexPattern());

            characterSet5.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[aB0\]d\^c]*", characterSet5.ToRegexPattern());

            characterSet5.Quantifier = RegexQuantifier.None;
            characterSet5.UseCharacterCodes = true;
            Assert.AreEqual(@"[\u0061\u0042\u0030\u005d\u0064\u005e\u0063]", characterSet5.ToRegexPattern());

            characterSet5.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[\u0061\u0042\u0030\u005d\u0064\u005e\u0063]*", characterSet5.ToRegexPattern());

            // RegexBuilder, char array, negative.
            RegexNodeCharacterSet characterSet6 = RegexBuilder.NegativeCharacterSet(new[] { 'a', 'B', '0', 'd', '^', 'x' }, false, RegexQuantifier.None);
            Assert.AreEqual(@"[^aB0d\^x]", characterSet6.ToRegexPattern());

            characterSet6.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[^aB0d\^x]*", characterSet6.ToRegexPattern());

            characterSet6.Quantifier = RegexQuantifier.None;
            characterSet6.UseCharacterCodes = true;
            Assert.AreEqual(@"[^\u0061\u0042\u0030\u0064\u005e\u0078]", characterSet6.ToRegexPattern());

            characterSet6.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[^\u0061\u0042\u0030\u0064\u005e\u0078]*", characterSet6.ToRegexPattern());

            // RegexBuilder, explicit pattern, positive.
            RegexNodeCharacterSet characterSet7 = RegexBuilder.CharacterSet(@"aB0d\W\s", RegexQuantifier.None);
            Assert.AreEqual(@"[aB0d\W\s]", characterSet7.ToRegexPattern());

            characterSet7.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[aB0d\W\s]*", characterSet7.ToRegexPattern());

            characterSet7.Quantifier = RegexQuantifier.None;
            characterSet7.UseCharacterCodes = true;
            Assert.AreEqual(@"[\u0061\u0042\u0030\u0064\u005c\u0057\u005c\u0073]", characterSet7.ToRegexPattern());

            characterSet7.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[\u0061\u0042\u0030\u0064\u005c\u0057\u005c\u0073]*", characterSet7.ToRegexPattern());

            // RegexBuilder, explicit pattern, negative.
            RegexNodeCharacterSet characterSet8 = RegexBuilder.NegativeCharacterSet(@"aB0d\W\s", RegexQuantifier.None);
            Assert.AreEqual(@"[^aB0d\W\s]", characterSet8.ToRegexPattern());

            characterSet8.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[^aB0d\W\s]*", characterSet8.ToRegexPattern());

            characterSet8.Quantifier = RegexQuantifier.None;
            characterSet8.UseCharacterCodes = true;
            Assert.AreEqual(@"[^\u0061\u0042\u0030\u0064\u005c\u0057\u005c\u0073]", characterSet8.ToRegexPattern());

            characterSet8.Quantifier = RegexQuantifier.ZeroOrMore;
            Assert.AreEqual(@"[^\u0061\u0042\u0030\u0064\u005c\u0057\u005c\u0073]*", characterSet8.ToRegexPattern());
        }