public void Or_AddComOrOrg_RegexIsAsExpecteds()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.Add("com").Or("org");

            Assert.AreEqual("(com)|(org)", verbEx.ToString());
        }
        public void Then_VerbalExpressionsUrl_DoesNotMatchEmail()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.StartOfLine().Then(CommonRegex.Url);

            Assert.IsFalse(verbEx.IsMatch("*****@*****.**"), "Should not match email address");
        }
        //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");
                }
            }
        }
Пример #4
0
        public void AddModifier_AddModifierX_IgnoreWhitspace()
        {
            VerbalExpressions verbEx = VerbalExpressions.DefaultExpression;

            verbEx.Add("test string").AddModifier('x');

            Assert.IsTrue(verbEx.IsMatch("test string #comment"));
        }
Пример #5
0
        public void AddModifier_AddModifierI_RemovesCase()
        {
            VerbalExpressions verbEx = VerbalExpressions.DefaultExpression;

            verbEx.Add("teststring").AddModifier('i');

            Assert.IsTrue(verbEx.IsMatch("TESTSTRING"));
        }
Пример #6
0
        public DnsExfiltrateParser()
        {
            AesIterations = 1000;
            AesKeyLength  = AESHelper.EKeyLength.Length256;
            AesRGBSalt    = null;

            RegexData    = new VerbalExpressions().Find("\t").Something().Find("\t").ToString();
            FileIdLength = 2;
        }
        public void Add_AddDotCom_DoesNotMatchGoogleComWithoutDot()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.Add(".com");

            var isMatch = verbEx.IsMatch("http://www.googlecom/");

            Assert.IsFalse(isMatch, "Should not match 'ecom'");
        }
        public void Something_NullAsParameter_Throws()
        {
            // Arange
            VerbalExpressions verbEx     = VerbalExpressions.DefaultExpression.Something();
            string            testString = null;

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => verbEx.IsMatch(testString));
        }
        public void Or_VerbalExpressionsUrlOrVerbalExpressionEmail_DoesMatchEmailAndUrl()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.Add(CommonRegex.Url)
            .Or(CommonRegex.Email);

            Assert.IsTrue(verbEx.IsMatch("*****@*****.**"), "Should match email address");
            Assert.IsTrue(verbEx.IsMatch("http://www.google.com"), "Should match url address");
        }
        public void Or_AddComOrOrg_DoesMatchComAndOrg()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.Add("com").Or("org");

            Console.WriteLine(verbEx);
            Assert.IsTrue(verbEx.IsMatch("org"), "Should match 'org'");
            Assert.IsTrue(verbEx.IsMatch("com"), "Should match 'com'");
        }
        public void Then_VerbalExpressionsEmail_DoesNotMatchUrl()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.StartOfLine().Then(CommonRegex.Email);

            var isMatch = verbEx.IsMatch("http://www.google.com");

            Assert.IsFalse(isMatch, "Should not match url address");
        }
        public void Then_VerbalExpressionsEmail_DoesMatchEmail()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.StartOfLine().Then(CommonRegex.Email);

            var isMatch = verbEx.IsMatch("*****@*****.**");

            Assert.IsTrue(isMatch, "Should match email address");
        }
        public void Any_WhenValueParameterIsNullOrEmpty_ShouldThrowArgumentException()
        {
            //Arrange
            verbEx = VerbalExpressions.DefaultExpression;
            string value = null;

            //Act
            //Assert
            verbEx.Any(value);
        }
        public void Range_WhenNullParameterPassed_ShouldThrowArgumentNullException()
        {
            //Arrange
            verbEx = VerbalExpressions.DefaultExpression;
            object[] value = null;

            //Act
            //Assert
            verbEx.Range(value);
        }
        public void Then_VerbalExpressionsUrl_DoesMatchUrl()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.StartOfLine()
            .Then(CommonRegex.Url);

            Assert.IsTrue(verbEx.IsMatch("http://www.google.com"), "Should match url address");
            Assert.IsTrue(verbEx.IsMatch("https://www.google.com"), "Should match url address");
            Assert.IsTrue(verbEx.IsMatch("http://google.com"), "Should match url address");
        }
        public void Multiple_WhenNullArgumentPassed_ThrowsArgumentNullException()
        {
            //Arrange
            verbEx = VerbalExpressions.DefaultExpression;
            string argument = string.Empty;

            //Act
            //Assert
            verbEx.Multiple(argument);
        }
        public void Find_WhenNullParameterValueIsPassed_ThrowsArgumentException()
        {
            //Arrange
            verbEx = VerbalExpressions.DefaultExpression;
            string value = null;

            //Act
            //Assert
            verbEx.Find(value);
        }
        public void Multiple_WhenNullOrEmptyValueParameterIsPassed_ShouldThrowArgumentException()
        {
            //Arrange
            verbEx = VerbalExpressions.DefaultExpression;
            string value = null;

            //Act
            //Assert
            verbEx.Multiple(value);
        }
        public void WithAnyCase_SetsCorrectIgnoreCaseRegexOptionAndHasMultiLineRegexOptionAsDefault()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.WithAnyCase();

            var regex = verbEx.ToRegex();

            Assert.IsTrue(regex.Options.HasFlag(RegexOptions.IgnoreCase), "RegexOptions should have ignoreCase");
            Assert.IsTrue(regex.Options.HasFlag(RegexOptions.Multiline), "RegexOptions should have MultiLine as default");
        }
        public void Add_WhenNullStringPassedAsParameter_ShouldThrowNullArgumentException()
        {
            //Arrange
            verbEx = VerbalExpressions.DefaultExpression;
            string value = null;

            //Act
            //Assert
            verbEx.Add(value);
        }
        public void EndOfLine_AddDotComEndOfLine_DoesNotMatchSlashInEnd()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.Add(".com")
            .EndOfLine();

            var isMatch = verbEx.IsMatch("http://www.google.com/");

            Assert.IsFalse(isMatch, "Should not match '/' in end");
        }
        public void Sanitize_Handles_Null_String()
        {
            //Arrange
            verbEx = VerbalExpressions.DefaultExpression;
            string value = null;

            //Act
            //Assert
            value = verbEx.Sanitize(value);
        }
        public void EndOfLine_AddDotComtEndOfLine_DoesMatchDotComInEnd()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.Add(".com")
            .EndOfLine();

            var isMatch = verbEx.IsMatch("www.google.com");

            Assert.IsTrue(isMatch, "Should match '.com' in end");
        }
        public void StartOfLine_ThenHttpMaybeWww_DoesMatchHttpInStart()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.StartOfLine()
            .Then("http")
            .Maybe("www");

            var isMatch = Regex.IsMatch("http", verbEx.ToString());

            Assert.IsTrue(isMatch, "Should match http in start");
        }
        public void WithAnyCase_AddwwwWithAnyCaseFalse_DoesNotMatchwWw()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.Add("www")
            .WithAnyCase(false);


            var isMatch = verbEx.IsMatch("wWw");

            Assert.IsFalse(isMatch, "Should not match any case");
        }
        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 StartOfLine_ThenHttpMaybeWww_DoesNotMatchWwwInStart()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.StartOfLine()
            .Then("http")
            .Maybe("www");

            var isMatch = verbEx.IsMatch("www");

            Assert.IsFalse(isMatch, "Should not match www in start");
        }
        public void StartOfLine_WhenPlacedInRandomCallOrder_ShouldAppendAtTheBeginningOfTheExpression()
        {
            verbEx = VerbalExpressions.DefaultExpression;
            verbEx.Add("test")
            .Add("ing")
            .StartOfLine();

            string text = "testing1234";

            Assert.IsTrue(verbEx.IsMatch(text), "Should match that the text starts with test");
        }
        public void Something_EmptyStringAsParameter_DoesNotMatch()
        {
            // Arange
            VerbalExpressions verbEx     = VerbalExpressions.DefaultExpression.Something();
            string            testString = string.Empty;

            // Act
            bool isMatch = verbEx.IsMatch(testString);

            // Assert
            Assert.IsFalse(isMatch, "Test string should be empty.");
        }
        public void Something_SomeStringAsParameter_DoesMatch()
        {
            // Arange
            VerbalExpressions verbEx      = VerbalExpressions.DefaultExpression.Something();
            const string      TEST_STRING = "Test string";

            // Act
            bool isMatch = verbEx.IsMatch(TEST_STRING);

            // Assert
            Assert.IsTrue(isMatch, "Test string should not be empty.");
        }