Exemplo n.º 1
0
        public void NullTargetString(IStringSearchAlgorithm algorithm)
        {
            string toFind   = "missing data";
            string toSearch = null;

            ISearchMatch[] matches = algorithm.Search(toFind, toSearch).ToArray();
        }
Exemplo n.º 2
0
        public void NullSourceString(IStringSearchAlgorithm algorithm)
        {
            string toFind   = null;
            string toSearch = "this string does not contain the missing string data";

            ISearchMatch[] matches = algorithm.Search(toFind, toSearch).ToArray();
        }
Exemplo n.º 3
0
        public void EmptyEmpty(IStringSearchAlgorithm algorithm)
        {
            string toFind   = string.Empty;
            string toSearch = string.Empty;

            ISearchMatch[] matches = algorithm.Search(toFind, toSearch).ToArray();

            Assert.IsNotNull(matches, "The matches array should not be null.");
            Assert.AreEqual(0, matches.Length, "The matches array should have not items.");
        }
Exemplo n.º 4
0
        public void EmptySourceString(IStringSearchAlgorithm algorithm)
        {
            string toFind   = string.Empty;
            string toSearch = "this string does not contain the missing string data";

            ISearchMatch[] matches = algorithm.Search(toFind, toSearch).ToArray();

            Assert.IsNotNull(matches, "The matches array should not be null.");
            Assert.AreEqual(0, matches.Length, "The matches array should have not items.");
        }
Exemplo n.º 5
0
        public void Example(IStringSearchAlgorithm algorithm)
        {
            string toFind   = "he";
            string toSearch = "The brown cat ran through the kitchen";

            foreach (ISearchMatch match in algorithm.Search(toFind, toSearch))
            {
                Console.WriteLine("Match found at: {0}", match.Start);
            }
        }
Exemplo n.º 6
0
        public void ExactSingleCharMatch(IStringSearchAlgorithm algorithm)
        {
            string toFind   = "f";
            string toSearch = "f";

            ISearchMatch[] matches = algorithm.Search(toFind, toSearch).ToArray();

            Assert.IsNotNull(matches, "The matches array should not be null.");
            Assert.AreEqual(1, matches.Length, "The matches array should have not items.");
            Assert.AreEqual(0, matches[0].Start, "The start of the string match should be 0");
            Assert.AreEqual(toFind.Length, matches[0].Length, "The length of the string match should equal the string found");
        }
        private static StringBuilder PerformSearchAndReplace(IStringSearchAlgorithm algorithm, string input, string find, string replace)
        {
            StringBuilder result        = new StringBuilder();
            int           previousStart = 0;

            foreach (var match in algorithm.Search(find, input))
            {
                result.Append(input.Substring(previousStart, match.Start - previousStart));
                result.Append(replace);
                previousStart = match.Start + match.Length;
            }

            result.Append(input.Substring(previousStart));
            return(result);
        }
Exemplo n.º 8
0
        public void MultipleMatchesLeadingMiddleTrailing(IStringSearchAlgorithm algorithm)
        {
            string toFind   = "found";
            string toSearch = "leadingfound and foundtrailing";

            ISearchMatch[] matches = algorithm.Search(toFind, toSearch).ToArray();

            Assert.IsNotNull(matches, "The matches array should not be null.");
            Assert.AreEqual(2, matches.Length, "The matches array should have not items.");

            Assert.AreEqual(7, matches[0].Start, "The start of the string match should be 0");
            Assert.AreEqual(toFind.Length, matches[0].Length, "The length of the string match should equal the string found");

            Assert.AreEqual(17, matches[1].Start, "The start of the string match should be 10");
            Assert.AreEqual(toFind.Length, matches[1].Length, "The length of the string match should equal the string found");
        }