Пример #1
0
        public void TestLiteral2()
        {
            var regex = new RegexBuilder().Literal(".").ToRegex();

            Assert.IsTrue(!regex.IsMatch("The cat sat on the mat"));
            Assert.IsTrue(regex.IsMatch("The cat sat on the mat."));
        }
Пример #2
0
        public void TestLimitZeroOrOne()
        {
            var regex = new RegexBuilder(RegexScope.StartsWith)
                        .Literal("dbo.").Repeat(RegexRepeats.ZeroOrOne)
                        .ToRegex();

            Assert.IsTrue(regex.IsMatch("dbo.TableName") && regex.IsMatch("TableName"));
        }
Пример #3
0
        public void TestScopeFullLine()
        {
            var regex = new RegexBuilder(RegexScope.FullLine).Literal("cat").ToRegex();

            Assert.IsTrue(regex.IsMatch("cat"));
            Assert.IsTrue(!regex.IsMatch("The cat"));
            Assert.IsTrue(!regex.IsMatch("The cat sat"));
            Assert.IsTrue(!regex.IsMatch("cat sat"));
        }
Пример #4
0
        public void TestScopeEndsWith()
        {
            var regex = new RegexBuilder(RegexScope.EndsWith).Literal("cat").ToRegex();

            Assert.IsTrue(regex.IsMatch("cat"));
            Assert.IsTrue(regex.IsMatch("The cat"));
            Assert.IsTrue(!regex.IsMatch("The cat sat"));
            Assert.IsTrue(!regex.IsMatch("cat sat"));
        }
Пример #5
0
        public void TestScopeAnywhere()
        {
            var regex = new RegexBuilder(RegexScope.Anywhere).Literal("cat").ToRegex();

            Assert.IsTrue(regex.IsMatch("cat"));
            Assert.IsTrue(regex.IsMatch("The cat"));
            Assert.IsTrue(regex.IsMatch("The cat sat"));
            Assert.IsTrue(regex.IsMatch("cat sat"));
        }
Пример #6
0
        public void TestNotAnyOfString()
        {
            var strings = new[] { "cat", "kitty", "pussycat" };
            var regex   = new RegexBuilder().Literal("The ").Not().AnyOf(strings).ToRegex();

            Assert.IsTrue(!regex.IsMatch("The cat sits on the carpet"));
            Assert.IsTrue(!regex.IsMatch("The kitty sits on the mat"));
            Assert.IsTrue(regex.IsMatch("The dog sits on the carpet"));
        }
Пример #7
0
        public void TestAnyOfString()
        {
            var strings = new[] { "cat", "sat", "mat" };
            var regex   = new RegexBuilder().AnyOf(strings).ToRegex();

            Assert.IsTrue(regex.IsMatch("The cat sits on the carpet"));
            Assert.IsTrue(regex.IsMatch("The kitty sits on the mat"));
            Assert.IsTrue(!regex.IsMatch("The kitty sits on the carpet"));
        }
Пример #8
0
        public void TestNotAnyOfCharClass()
        {
            var chars = new[] { CharacterClass.AlphaLower, CharacterClass.Digit };
            var regex = new RegexBuilder().Not().AnyOf(chars).ToRegex();

            Assert.IsTrue(regex.IsMatch("Letters"));
            Assert.IsTrue(regex.IsMatch("LETTERS 1234"));
            Assert.IsTrue(!regex.IsMatch("letters"));
            Assert.IsTrue(!regex.IsMatch("1234"));
        }
Пример #9
0
        public void TestAnyOfChar()
        {
            var chars = new[] { '^', 'a', 'b', 'c', ']', '-' };
            var regex = new RegexBuilder().AnyOf(chars).ToRegex();

            Assert.IsTrue(regex.IsMatch("cab"));
            Assert.IsTrue(regex.IsMatch("See this [thing]"));
            Assert.IsTrue(regex.IsMatch("Over-excited"));
            Assert.IsTrue(!regex.IsMatch("Kitten"));
        }
Пример #10
0
        public void TestRaw()
        {
            var regex = new RegexBuilder(RegexScope.StartsWith)
                        .Literal("The ", true)
                        .Raw("c[auo]t")
                        .ToRegex();

            Assert.IsTrue(regex.IsMatch("The cat"));
            Assert.IsTrue(regex.IsMatch("The cut"));
            Assert.IsTrue(!regex.IsMatch("The cet"));
        }
Пример #11
0
        public void TestNotAnyOfChar()
        {
            var chars = new[] { '^', 'o', 'a' };
            var regex = new RegexBuilder().Literal("c")
                        .Not().AnyOf(chars)
                        .Literal("t").ToRegex();

            Assert.IsTrue(regex.IsMatch("cut"));
            Assert.IsTrue(!regex.IsMatch("cat"));
            Assert.IsTrue(!regex.IsMatch("cot"));
            Assert.IsTrue(!regex.IsMatch("c^t"));
        }