Exemple #1
0
        private IRegexPatternDictionary <string> BuildTestRegexPatternDict()
        {
            IRegexPatternDictionary <string> regexDict = new RegexPatternDictionaryImpl <string>();

            regexDict.Add("hello", "this");
            regexDict.Add("wo+rld", "is");
            regexDict.Add("a.*y", "good");
            regexDict.Add("b.*", "bad");
            return(regexDict);
        }
Exemple #2
0
        public void TestGivenRegexPatternToStringDictionaryWithEscapedPatternWhenGetValueByPatternThenCorrectValueReturned()
        {
            IRegexPatternDictionary <string> regexDict = new RegexPatternDictionaryImpl <string>();

            string pattern = "hel+o";
            string value   = "world";

            regexDict.AddEscapedFullMatchPattern(pattern, value);

            Assert.True(regexDict.ContainsKey(pattern), "Pattern should exist as dictionary key");
            Assert.AreEqual(value, regexDict[pattern], "Value tied to pattern should be correct");
        }
Exemple #3
0
        public void TestGivenRegexPatternToStringDictionaryWithFullMatchPatternWhenCheckingForMatchesThenCorrectResultReturned()
        {
            IRegexPatternDictionary <string> regexDict = new RegexPatternDictionaryImpl <string>();

            regexDict.AddFullMatchPattern("hello", "this");
            regexDict.AddFullMatchPattern("wo+rld", "is");
            regexDict.AddFullMatchPattern("a.*y", "good");
            regexDict.AddFullMatchPattern("b.*", "bad");

            Assert.True(regexDict.HasMatch("hello"), "Expected 'hello' to have a match in the dictionary");
            Assert.True(regexDict.HasMatch("wooorld"), "Expected 'wooorld' to have a match in the dictionary");
            Assert.True(regexDict.HasMatch("a day"), "Expected 'a day' to have a match in the dictionary");
            Assert.True(regexDict.HasMatch("before"), "Expected 'before' to have a match in the dictionary");
            Assert.False(regexDict.HasMatch("a day ago"), "Expected 'a day ago' to not have a match in the dictionary");
            Assert.False(regexDict.HasMatch("day before"), "Expected 'day before' to not have a match in the dictionary");
        }
Exemple #4
0
        public void TestGivenRegexPatternToStringDictionaryWithEscapedPatternWhenCheckingForMatchesThenCorrectResultReturned()
        {
            IRegexPatternDictionary <string> regexDict = new RegexPatternDictionaryImpl <string>();

            regexDict.AddEscapedFullMatchPattern("hello", "this");
            regexDict.AddEscapedFullMatchPattern("wo+rld", "is");
            regexDict.AddEscapedFullMatchPattern("a.*y", "good");
            regexDict.AddEscapedFullMatchPattern("b.*", "bad");

            Assert.True(regexDict.HasMatch("hello"), "Expected 'hello' to have a match in the dictionary");
            Assert.True(regexDict.HasMatch("a.*y"), "Expected 'a.*y' to have a match in the dictionary");
            Assert.False(regexDict.HasMatch("hi"), "Expected 'hi' to not have a match in the dictionary");
            Assert.False(regexDict.HasMatch("week"), "Expected 'week' to not have a match in the dictionary");
            Assert.False(regexDict.HasMatch("john"), "Expected 'john' to not have a match in the dictionary");
            Assert.False(regexDict.HasMatch("doe"), "Expected 'doe' to not have a match in the dictionary");
        }