public void Multiple_WhenParamIsGiven_ShouldMatchOneOrMultipleValuesGiven()
        {
            //Arrange
            string text = "testesting 123 yahoahoahou another test";
            string expectedExpression = "y(aho)+u";

            //Act
            verbEx.Add("y")
            .Multiple("aho")
            .Add("u");

            //Assert
            Assert.IsTrue(verbEx.Test(text));
            Assert.AreEqual <string>(expectedExpression, verbEx.ToString());
        }
        //https://github.com/VerbalExpressions/CSharpVerbalExpressions
        public static void Run()
        {
            // Create an example of how to test for correctly formed URLs
            var verbEx = new VerbalExpressions()
                         .StartOfLine()
                         .Then("http")
                         .Maybe("s")
                         .Then("://")
                         .Maybe("www.")
                         .AnythingBut(" ")
                         .EndOfLine();
            var testMe = "";

            while (true)
            {
                Console.WriteLine("Input your url:");
                testMe = Console.ReadLine();
                if (verbEx.Test(testMe))
                {
                    Console.WriteLine("We have a correct URL ");
                }
                else
                {
                    Console.WriteLine("The URL is incorrect");
                }
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var urlExp = new VerbalExpressions()
                         .StartOfLine()
                         .Then("http")
                         .Maybe("s")
                         .Then("://")
                         .AnythingBut(" ")
                         .EndOfLine();

            var emailExp = new VerbalExpressions()
                           .StartOfLine()
                           .Anything()
                           .Then("@")
                           .AnythingBut(" ")
                           .Then(".")
                           .AnythingBut(" ")
                           .EndOfLine();

            var phoneExp = new VerbalExpressions()
                           .StartOfLine()
                           .Maybe("(")
                           .Range('0', '9')
                           .RepeatPrevious(3)
                           .Maybe(")")
                           .Maybe(" ")
                           .Range('0', '9')
                           .RepeatPrevious(3)
                           .Maybe("-")
                           .Range('0', '9')
                           .RepeatPrevious(4)
                           .EndOfLine();


            var url          = "http://www.exceptionnotfound.net";
            var email        = "*****@*****.**";
            var invalidEmail = "test@example";
            var phone        = "(123) 456-7890";

            Assert.IsTrue(urlExp.Test(url), "The URL is not valid!");
            Assert.IsTrue(emailExp.Test(email), "The email is not valid!");
            Assert.IsTrue(phoneExp.Test(phone), "The phone number is invalid.");
            Assert.IsTrue(emailExp.Test(invalidEmail), "The email is not valid!");
        }
        public void AddModifier_AddModifierM_Multiline()
        {
            //Arrange
            string text = string.Format("testin with {0} line break", Environment.NewLine);

            //Act
            verbEx.AddModifier('m');

            //Assert
            Assert.IsTrue(verbEx.Test(text));
        }
        public void Br_WhenCalled_ReturnsExpectedExpression()
        {
            //Arrange
            verbEx = VerbalExpressions.DefaultExpression;
            string text = string.Format("testin with {0} line break", Environment.NewLine);

            //Act
            verbEx.Br();
            //Assert
            Assert.IsTrue(verbEx.Test(text));
        }
        public void Tab_WhenCalled_ReturnsExpectedExpression()
        {
            //Arrange
            verbEx = VerbalExpressions.DefaultExpression;
            string text = string.Format("text that contains {0} a tab", @"\t");

            //Act
            verbEx.Tab();

            //Assert
            Assert.IsTrue(verbEx.Test(text));
        }
Beispiel #7
0
        public void AddModifier_AddModifierM_Multiline()
        {
            //Arrange
            VerbalExpressions verbEx = VerbalExpressions.DefaultExpression;
            string            text   = string.Format("testin with {0} line break", Environment.NewLine);

            //Act
            verbEx.AddModifier('m');

            //Assert
            Assert.True(verbEx.Test(text));
        }
        public void TestingIfWeHaveAValidURL()
        {
            verbEx = VerbalExpressions.DefaultExpression
                     .StartOfLine()
                     .Then("http")
                     .Maybe("s")
                     .Then("://")
                     .Maybe("www.")
                     .AnythingBut(" ")
                     .EndOfLine();

            var testMe = "https://www.google.com";

            Assert.IsTrue(verbEx.Test(testMe), "The URL is incorrect");
        }
Beispiel #9
0
        public void TestingIfWeHaveAValidURL()
        {
            verbEx = new VerbalExpressions()
                     .StartOfLine()
                     .Then("http")
                     .Maybe("s")
                     .Then("://")
                     .Maybe("www.")
                     .AnythingBut(" ")
                     .Then(".com")
                     .EndOfLine();

            var testMe = "https://www.google.com";

            Assert.IsTrue(verbEx.Test(testMe), "The URL is incorrect");
            Console.WriteLine("We have a correct URL ");
        }
        RegexTest()
        {
            // PM> Install-Package VerbalExpressions-official

            // http[s]://www.domain.com

            VerbalExpressions expression = new VerbalExpressions()
                                           .StartOfLine()
                                           .Then("http")
                                           .Maybe("s")
                                           .AnythingBut(" ")
                                           .EndOfLine();

            Regex regex = expression.ToRegex();

            string url = "http://www.vavatech.pl:8080";

            bool isValid = expression.Test(url);
        }
        public void BeginCaptureAndEndCapture_DuplicatesIdentifier_DoesMatch()
        {
            // Arrange
            VerbalExpressions verbEx      = VerbalExpressions.DefaultExpression;
            const string      TEST_STRING = "He said that that was the the correct answer.";

            // Act
            verbEx.BeginCapture()
            .Word()
            .EndCapture()
            .Add(@"\s", false)
            .BeginCapture()
            .Add(@"\1", false)
            .EndCapture();

            // Assert
            Assert.Equal(@"(\w+)\s(\1)", verbEx.ToString());
            Assert.True(verbEx.Test(TEST_STRING), "There is no duplicates in the textString.");
        }
Beispiel #12
0
        // PM> Install-Package VerbalExpressions-official
        private static void VerbalExpressionsTest()
        {
            // Create an example of how to test for correctly formed URLs
            var verbEx = new VerbalExpressions()
                         .StartOfLine()
                         .Then("http")
                         .Maybe("s")
                         .Then("://")
                         .Maybe("www.")
                         .AnythingBut(" ")
                         .EndOfLine();

            // Create an example URL
            var testMe = "https://www.google.com";

            Console.WriteLine(verbEx);

            if (verbEx.Test(testMe))
            {
                Console.WriteLine("The URL is incorrect");
            }

            Console.WriteLine("We have a correct URL ");
        }