Beispiel #1
0
        public void TryParseQuantifierTest1()
        {
            int minlen;
            int maxlen;

            int pos = 0;

            Assert.IsFalse(RegexParser.TryParseQuantifier(null, ref pos, out minlen, out maxlen));
            Assert.AreEqual(0, pos);
            Assert.AreEqual(1, minlen);
            Assert.AreEqual(1, maxlen);

            Assert.IsFalse(RegexParser.TryParseQuantifier(string.Empty, ref pos, out minlen, out maxlen));
            Assert.AreEqual(0, pos);
            Assert.AreEqual(1, minlen);
            Assert.AreEqual(1, maxlen);

            Assert.IsFalse(RegexParser.TryParseQuantifier("A", ref pos, out minlen, out maxlen));
            Assert.AreEqual(0, pos);
            Assert.AreEqual(1, minlen);
            Assert.AreEqual(1, maxlen);

            Assert.IsFalse(RegexParser.TryParseQuantifier("{1", ref pos, out minlen, out maxlen));
            Assert.AreEqual(0, pos);
            Assert.AreEqual(1, minlen);
            Assert.AreEqual(1, maxlen);

            Assert.IsFalse(RegexParser.TryParseQuantifier("{1,", ref pos, out minlen, out maxlen));
            Assert.AreEqual(0, pos);
            Assert.AreEqual(1, minlen);
            Assert.AreEqual(1, maxlen);

            Assert.IsFalse(RegexParser.TryParseQuantifier("{1,2", ref pos, out minlen, out maxlen));
            Assert.AreEqual(0, pos);
            Assert.AreEqual(1, minlen);
            Assert.AreEqual(1, maxlen);

            Assert.IsFalse(RegexParser.TryParseQuantifier("{,2", ref pos, out minlen, out maxlen));
            Assert.AreEqual(0, pos);
            Assert.AreEqual(1, minlen);
            Assert.AreEqual(1, maxlen);

            Assert.IsFalse(RegexParser.TryParseQuantifier("{}", ref pos, out minlen, out maxlen));
            Assert.AreEqual(0, pos);
            Assert.AreEqual(1, minlen);
            Assert.AreEqual(1, maxlen);

            Assert.IsFalse(RegexParser.TryParseQuantifier("{,}", ref pos, out minlen, out maxlen));
            Assert.AreEqual(0, pos);
            Assert.AreEqual(1, minlen);
            Assert.AreEqual(1, maxlen);
        }
Beispiel #2
0
        public void TryParseQuantifierTest0()
        {
            int minlen;
            int maxlen;

            int pos = 0;

            Assert.IsTrue(RegexParser.TryParseQuantifier("*", ref pos, out minlen, out maxlen));
            Assert.AreEqual(1, pos);
            Assert.AreEqual(0, minlen);
            Assert.AreEqual(int.MaxValue, maxlen);

            pos = 0;
            Assert.IsTrue(RegexParser.TryParseQuantifier("+", ref pos, out minlen, out maxlen));
            Assert.AreEqual(1, pos);
            Assert.AreEqual(1, minlen);
            Assert.AreEqual(int.MaxValue, maxlen);

            pos = 0;
            Assert.IsTrue(RegexParser.TryParseQuantifier("?", ref pos, out minlen, out maxlen));
            Assert.AreEqual(1, pos);
            Assert.AreEqual(0, minlen);
            Assert.AreEqual(1, maxlen);

            pos = 0;
            Assert.IsTrue(RegexParser.TryParseQuantifier("{1,2}", ref pos, out minlen, out maxlen));
            Assert.AreEqual(5, pos);
            Assert.AreEqual(1, minlen);
            Assert.AreEqual(2, maxlen);

            pos = 0;
            Assert.IsTrue(RegexParser.TryParseQuantifier("{22}", ref pos, out minlen, out maxlen));
            Assert.AreEqual(4, pos);
            Assert.AreEqual(22, minlen);
            Assert.AreEqual(22, maxlen);

            pos = 0;
            Assert.IsTrue(RegexParser.TryParseQuantifier("{1,}", ref pos, out minlen, out maxlen));
            Assert.AreEqual(4, pos);
            Assert.AreEqual(1, minlen);
            Assert.AreEqual(int.MaxValue, maxlen);

            pos = 0;
            Assert.IsTrue(RegexParser.TryParseQuantifier("{,2}", ref pos, out minlen, out maxlen));
            Assert.AreEqual(4, pos);
            Assert.AreEqual(0, minlen);
            Assert.AreEqual(2, maxlen);
        }