public void AddQuote_Supported()
        {
            var validator = new QuoteBracketsValidator();

            validator.AddQuote('\'');
            validator.AddQuote('"');
        }
        public void DefaultValidator_BracketsPaired_QuotesParied_Overlapping_EndsNestedIn_InValid()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsFalse(validator.Validate("(a ' b ) c ' d "));
            Assert.IsFalse(validator.Validate("'a ( b ' c ) d "));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine(Resources.WelcomeMessage);

            // initialize the validator
            IValidator <string> validator = new QuoteBracketsValidator();

            do
            {
                // read the input
                string input = Console.ReadLine();

                try
                {
                    // validate
                    Console.WriteLine(Resources.ResultMessage, validator.Validate(input));
                }
                catch (Exception unKnownException)
                {
                    Console.WriteLine(Resources.UnhandledExceptionMessage, Guid.NewGuid(), unKnownException.ToString());
                }

                Console.WriteLine(Resources.QuitOrEnterMessage);
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
        public void Instantiate_AdditionalBracketsQuotes()
        {
            var validator = new QuoteBracketsValidator(new System.Collections.Generic.Dictionary <char, char>(), new char[1] {
                '\''
            });

            Assert.IsNotNull(validator);
        }
        public void Instantiate_AsIValidator()
        {
            IValidator <string> validator = new QuoteBracketsValidator(new System.Collections.Generic.Dictionary <char, char>(), new char[1] {
                '\''
            });

            Assert.IsNotNull(validator);
        }
        public void DefaultValidator_MultipleInValidCases()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsFalse(validator.Validate("((a)"));
            Assert.IsFalse(validator.Validate("(a)(a))"));
            Assert.IsFalse(validator.Validate("This (is a test"));
            Assert.IsFalse(validator.Validate("This is a) test"));
            Assert.IsFalse(validator.Validate("This 'is a test"));
            Assert.IsFalse(validator.Validate("T'This (is a' test)"));
        }
        public void DefaultValidator_MultipleValidCases()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsTrue(validator.Validate("This is a test "));
            Assert.IsTrue(validator.Validate("This (is a) test"));
            Assert.IsTrue(validator.Validate("(This (is a) test)"));
            Assert.IsTrue(validator.Validate("This 'is a' test"));
            Assert.IsTrue(validator.Validate("'This 'is a' test'"));
            Assert.IsTrue(validator.Validate("(This 'is a' test)"));
            Assert.IsTrue(validator.Validate("'This (is a) test'"));
            Assert.IsTrue(validator.Validate("'This 'is a( test)"));
        }
        public void AdvancedValidator_MultipleValidCases()
        {
            var validator = new QuoteBracketsValidator();

            validator.AddQuote('"');
            validator.AddOrUpdateBracketPair('[', ']');
            Assert.IsTrue(validator.Validate("()[]"));
            Assert.IsTrue(validator.Validate("([])"));
            Assert.IsTrue(validator.Validate("'\"\"\"\"'"));
            Assert.IsTrue(validator.Validate("'\"[\"[\"[\"[]\"]\"]\"]\"'"));
            Assert.IsTrue(validator.Validate("\"\"''([])"));
            Assert.IsTrue(validator.Validate("([[\"\"]('')]([]))"));
            Assert.IsTrue(validator.Validate("'\"\"[(\"\")]'"));
            Assert.IsTrue(validator.Validate("'\"\"[(\"\")]\"\"'"));
        }
        public void AdvancedValidator_MultipleInValidCases()
        {
            var validator = new QuoteBracketsValidator();

            validator.AddQuote('"');
            validator.AddOrUpdateBracketPair('[', ']');
            Assert.IsFalse(validator.Validate("(()"));
            Assert.IsFalse(validator.Validate("()())"));
            Assert.IsFalse(validator.Validate("(()"));
            Assert.IsFalse(validator.Validate("()())"));
            Assert.IsFalse(validator.Validate("\"'\"'"));
            Assert.IsFalse(validator.Validate("(')[']"));
            Assert.IsFalse(validator.Validate("\"[\"]\"\"'"));
            Assert.IsFalse(validator.Validate("('\"\"\"\"'"));
            Assert.IsFalse(validator.Validate("'\"[\"[\"[\"[]\"]\"]\"]\"')"));
            Assert.IsFalse(validator.Validate("(\"\"''([])"));
            Assert.IsFalse(validator.Validate("([[\"\"]('')]([]))["));
            Assert.IsFalse(validator.Validate("'\"\"[(\"\")]['"));
            Assert.IsFalse(validator.Validate("'\"\"[(\"\")]\"\"']"));
        }
        public void DefaultValidator_EmptyString_Valid()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsTrue(validator.Validate(""));
        }
        public void DefaultValidator_BracketsPaired_WithOrphanQuoteNestedIn_InValid()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsFalse(validator.Validate("(a ' b ) c"));
        }
        public void DefaultValidator_QuotesPaired_WithOrphanOpenBracketNestedIn_InValid()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsFalse(validator.Validate("'a ( b ' c"));
        }
        public void DefaultValidator_OneQuotesNotPaired_InValid()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsFalse(validator.Validate("'a' 'b' 'c "));
        }
        public void DefaultValidator_OnlyOneQuote_InValid()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsFalse(validator.Validate("a 'b c"));
        }
        public void DefaultValidator_OpenCloseBracketPair_Valid()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsTrue(validator.Validate("(a b c)"));
        }
        public void DefaultValidator_Null_Valid()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsTrue(validator.Validate(null));
        }
        public void DefaultValidator_BackertsPairQuotesPairSeperate_Valid()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsTrue(validator.Validate("'a b c' (a b c)"));
        }
        public void DefaultValidator_BackertsPairNestedInQuotes_Valid()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsTrue(validator.Validate("'(a b c)'"));
        }
        public void DefaultValidator_QuotePairNestedInBrackets_Valid()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsTrue(validator.Validate("('a b c')"));
        }
        public void AddBracketPair_Supported()
        {
            var validator = new QuoteBracketsValidator();

            validator.AddOrUpdateBracketPair('{', '}');
        }
        public void DefaultValidator_NoBracketsOrQuotes_Valid()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsTrue(validator.Validate("a b c"));
        }
        public void AddQuote_NotSupported_ThrowArgumentException()
        {
            var validator = new QuoteBracketsValidator();

            validator.AddQuote('?');
        }
        public void DefaultValidator_CloseBracketWithoutOpen_InValid()
        {
            IValidator <string> validator = new QuoteBracketsValidator();

            Assert.IsFalse(validator.Validate("a b c )"));
        }
        public void Instantiate_DefaultBracketsQuotes()
        {
            var validator = new QuoteBracketsValidator();

            Assert.IsNotNull(validator);
        }
        public void AddBracketPair_NotSupportedClosingBracket_ThrowArgumentException()
        {
            var validator = new QuoteBracketsValidator();

            validator.AddOrUpdateBracketPair('{', 'B');
        }