/// <summary>
        /// Rename the specified input, using the relativeCount.
        /// </summary>
        /// <param name="input">Input String to rename.</param>
        /// <param name="relativeCount">Relative count. This can be used for enumeration.</param>
        /// <returns>A new string renamed according to the rename operation's rules.</returns>
        public RenameResult Rename(string input, int relativeCount)
        {
            var renameResult = new RenameResult();

            if (!string.IsNullOrEmpty(input) && !this.Prepend)
            {
                renameResult.Add(new Diff(input, DiffOperation.Equal));
            }

            if (!string.IsNullOrEmpty(this.CountFormat))
            {
                var currentCount = this.StartingCount + (relativeCount * this.Increment);
                try
                {
                    var currentCountAsString = currentCount.ToString(this.CountFormat);
                    renameResult.Add(new Diff(currentCountAsString, DiffOperation.Insertion));
                }
                catch (System.FormatException)
                {
                    // Can't append anything if format is bad.
                }
            }

            if (this.Prepend)
            {
                renameResult.Add(new Diff(input, DiffOperation.Equal));
            }

            return(renameResult);
        }
        /// <summary>
        /// Rename the specified input, using the relativeCount.
        /// </summary>
        /// <param name="input">Input String to rename.</param>
        /// <param name="relativeCount">Relative count. This can be used for enumeration.</param>
        /// <returns>A new string renamed according to the rename operation's rules.</returns>
        public override RenameResult Rename(string input, int relativeCount)
        {
            if (string.IsNullOrEmpty(input))
            {
                return(RenameResult.Empty);
            }

            var numCharactersFromFront           = Mathf.Clamp(this.NumFrontDeleteChars, 0, input.Length);
            var numCharactersNotTrimmedFromFront = input.Length - numCharactersFromFront;
            var numCharactersFromBack            = Mathf.Clamp(this.NumBackDeleteChars, 0, numCharactersNotTrimmedFromFront);
            var numUntrimmedChars = Mathf.Max(input.Length - (numCharactersFromFront + numCharactersFromBack), 0);

            var result = new RenameResult();

            if (numCharactersFromFront > 0)
            {
                var trimmedSubstring = input.Substring(0, numCharactersFromFront);
                result.Add(new Diff(trimmedSubstring, DiffOperation.Deletion));
            }

            if (numUntrimmedChars > 0)
            {
                var trimmedSubstring = input.Substring(numCharactersFromFront, numUntrimmedChars);
                result.Add(new Diff(trimmedSubstring, DiffOperation.Equal));
            }

            if (numCharactersFromBack > 0)
            {
                var trimmedSubstring = input.Substring(input.Length - numCharactersFromBack, numCharactersFromBack);
                result.Add(new Diff(trimmedSubstring, DiffOperation.Deletion));
            }

            return(result);
        }
Exemplo n.º 3
0
        private RenameResult GetDiffResultFromStrings(string stringA, string stringB)
        {
            var renameResult          = new RenameResult();
            var consecutiveEqualChars = string.Empty;

            for (int i = 0; i < stringA.Length; ++i)
            {
                string oldLetter = stringA.Substring(i, 1);
                string newLetter = stringB.Substring(i, 1);
                if (oldLetter.Equals(newLetter))
                {
                    consecutiveEqualChars = string.Concat(consecutiveEqualChars, oldLetter);
                }
                else
                {
                    if (!string.IsNullOrEmpty(consecutiveEqualChars))
                    {
                        renameResult.Add(new Diff(consecutiveEqualChars, DiffOperation.Equal));
                        consecutiveEqualChars = string.Empty;
                    }

                    renameResult.Add(new Diff(oldLetter, DiffOperation.Deletion));
                    renameResult.Add(new Diff(newLetter, DiffOperation.Insertion));
                }
            }

            if (!string.IsNullOrEmpty(consecutiveEqualChars))
            {
                renameResult.Add(new Diff(consecutiveEqualChars, DiffOperation.Equal));
            }

            return(renameResult);
        }
Exemplo n.º 4
0
        public void RenameToUpper_ValidLowerCharacters_AreUppered()
        {
            // Arrange
            var name         = "this is all lower";
            var changeCaseOp = new ChangeCaseOperation();

            changeCaseOp.Casing = ChangeCaseOperation.CasingChange.Uppercase;

            var expectedName = "THIS IS ALL LOWER";
            var expected     = new RenameResult();

            for (int i = 0; i < name.Length; ++i)
            {
                var expectedNameChar = expectedName.Substring(i, 1);
                var nameChar         = name.Substring(i, 1);
                if (nameChar == expectedNameChar)
                {
                    expected.Add(new Diff(nameChar, DiffOperation.Equal));
                    continue;
                }

                expected.Add(new Diff(nameChar, DiffOperation.Deletion));
                expected.Add(new Diff(expectedNameChar, DiffOperation.Insertion));
            }

            // Act
            var result = changeCaseOp.Rename(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 5
0
        public void RenameToLower_ValidUpperCharacters_AreLowered()
        {
            // Arrange
            var name         = "SOME UPPER";
            var changeCaseOp = new ChangeCaseOperation();

            var expectedName = "some upper";
            var expected     = new RenameResult();

            for (int i = 0; i < name.Length; ++i)
            {
                var expectedNameChar = expectedName.Substring(i, 1);
                var nameChar         = name.Substring(i, 1);
                if (nameChar == expectedNameChar)
                {
                    expected.Add(new Diff(nameChar, DiffOperation.Equal));
                    continue;
                }

                expected.Add(new Diff(nameChar, DiffOperation.Deletion));
                expected.Add(new Diff(expectedNameChar, DiffOperation.Insertion));
            }

            // Act
            var result = changeCaseOp.Rename(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 6
0
        private RenameResult CreateDiffFromMatches(string originalName, string replacementRegex, MatchCollection matches)
        {
            var renameResult           = new RenameResult();
            var nextMatchStartingIndex = 0;

            foreach (System.Text.RegularExpressions.Match match in matches)
            {
                // Grab the substring before the match
                if (nextMatchStartingIndex < match.Index)
                {
                    string before = originalName.Substring(nextMatchStartingIndex, match.Index - nextMatchStartingIndex);
                    renameResult.Add(new Diff(before, DiffOperation.Equal));
                }

                // Add the match as a deletion
                renameResult.Add(new Diff(match.Value, DiffOperation.Deletion));

                // Add the result as an insertion
                var result = match.Result(replacementRegex);
                if (!string.IsNullOrEmpty(result))
                {
                    renameResult.Add(new Diff(result, DiffOperation.Insertion));
                }

                nextMatchStartingIndex = match.Index + match.Length;
            }

            if (nextMatchStartingIndex < originalName.Length)
            {
                var lastSubstring = originalName.Substring(nextMatchStartingIndex, originalName.Length - nextMatchStartingIndex);
                renameResult.Add(new Diff(lastSubstring, DiffOperation.Equal));
            }

            return(renameResult);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Rename the specified input, using the relativeCount.
        /// </summary>
        /// <param name="input">Input String to rename.</param>
        /// <param name="relativeCount">Relative count. This can be used for enumeration.</param>
        /// <returns>A new string renamed according to the rename operation's rules.</returns>
        public RenameResult Rename(string input, int relativeCount)
        {
            if (string.IsNullOrEmpty(input))
            {
                return(RenameResult.Empty);
            }

            var inputCaseChanged = input;

            switch (this.Casing)
            {
            case CasingChange.Lowercase:
                inputCaseChanged = input.ToLower();
                break;

            case CasingChange.Uppercase:
                inputCaseChanged = input.ToUpper();
                break;

            default:
                var message = string.Format(
                    "CaseOperation received unknown CasingOption {0}",
                    this.Casing);
                throw new System.ArgumentOutOfRangeException(message);
            }

            var renameResult          = new RenameResult();
            var consecutiveEqualChars = string.Empty;

            for (int i = 0; i < input.Length; ++i)
            {
                string oldLetter = input.Substring(i, 1);
                string newLetter = inputCaseChanged.Substring(i, 1);
                if (oldLetter.Equals(newLetter))
                {
                    consecutiveEqualChars = string.Concat(consecutiveEqualChars, oldLetter);
                }
                else
                {
                    if (!string.IsNullOrEmpty(consecutiveEqualChars))
                    {
                        renameResult.Add(new Diff(consecutiveEqualChars, DiffOperation.Equal));
                        consecutiveEqualChars = string.Empty;
                    }

                    renameResult.Add(new Diff(oldLetter, DiffOperation.Deletion));
                    renameResult.Add(new Diff(newLetter, DiffOperation.Insertion));
                }
            }

            if (!string.IsNullOrEmpty(consecutiveEqualChars))
            {
                renameResult.Add(new Diff(consecutiveEqualChars, DiffOperation.Equal));
            }

            return(renameResult);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Compares two strings and constructs a diff based on their differences. It simply compares character by character,
        /// no analysis is done to see if a character could have moved.
        /// </summary>
        /// <param name="originalString">The original string. Letters in here that aren't in the new string will be deletions.</param>
        /// <param name="newString">The new string. Letters in here that aren't in the originalString will be insertions.</param>
        /// <returns>A diff sequence representing changes between the two strings</returns>
        public static RenameResult GetDiffResultFromStrings(string originalString, string newString)
        {
            var renameResult          = new RenameResult();
            var consecutiveEqualChars = string.Empty;
            var longestLength         = Mathf.Max(originalString.Length, newString.Length);

            for (int i = 0; i < longestLength; ++i)
            {
                if (i >= newString.Length)
                {
                    // Consolidate the diff with the remainder of the string so that we get a cleaner diff
                    // (ex: ABC => ABDog comes back as [AB=],[C-],[Dog+] instead of [AB=],[C-],[D+],[og+])
                    ConsolidateRemainderOfStringIntoRenameResult(renameResult, originalString, i, DiffOperation.Deletion);
                    break;
                }
                else if (i >= originalString.Length)
                {
                    // Consolidate the diff with the remainder of the string so that we get a cleaner diff
                    // (ex: ABC => ABDog comes back as [AB=],[C-],[Dog+] instead of [AB=],[C-],[D+],[og+])
                    ConsolidateRemainderOfStringIntoRenameResult(renameResult, newString, i, DiffOperation.Insertion);
                    break;
                }
                else
                {
                    string oldLetter = originalString.Substring(i, 1);
                    string newLetter = newString.Substring(i, 1);
                    if (oldLetter.Equals(newLetter))
                    {
                        consecutiveEqualChars = string.Concat(consecutiveEqualChars, oldLetter);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(consecutiveEqualChars))
                        {
                            renameResult.Add(new Diff(consecutiveEqualChars, DiffOperation.Equal));
                            consecutiveEqualChars = string.Empty;
                        }

                        renameResult.Add(new Diff(oldLetter, DiffOperation.Deletion));
                        renameResult.Add(new Diff(newLetter, DiffOperation.Insertion));
                    }
                }
            }

            if (!string.IsNullOrEmpty(consecutiveEqualChars))
            {
                renameResult.Add(new Diff(consecutiveEqualChars, DiffOperation.Equal));
            }

            return(renameResult);
        }
Exemplo n.º 9
0
        private static RenameResult CreateSampleTextForDiffOp(string[] keys, DiffOperation diffOp)
        {
            var             renameResult   = new RenameResult();
            string          translatedText = LocalizationManager.Instance.GetTranslation("exampleTextWithInsertedWords");
            Regex           regex          = new Regex(@"{+\d+}+");
            MatchCollection matches        = regex.Matches(translatedText);
            List <Diff>     subStrings     = new List <Diff>();

            for (int i = 0; i < matches.Count; i++)
            {
                var match = matches[i];
                subStrings.Add(new Diff(translatedText.Substring(0, translatedText.IndexOf(match.Value)), DiffOperation.Equal));

                var stringToInsert = i >= 0 && i < keys.Length ? LocalizationManager.Instance.GetTranslation(keys[i]) : "modified";
                subStrings.Add(new Diff(stringToInsert, diffOp));
                translatedText = translatedText.Remove(0, translatedText.IndexOf(match.Value) + match.Value.Length);
            }

            foreach (Diff currentString in subStrings)
            {
                renameResult.Add(currentString);
            }

            return(renameResult);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Rename the specified input, using the relativeCount.
        /// </summary>
        /// <param name="input">Input String to rename.</param>
        /// <param name="relativeCount">Relative count. This can be used for enumeration.</param>
        /// <returns>A new string renamed according to the rename operation's rules.</returns>
        public RenameResult Rename(string input, int relativeCount)
        {
            if (string.IsNullOrEmpty(input))
            {
                return(new RenameResult());
            }

            RenameResult renameResult;

            if (string.IsNullOrEmpty(this.SearchString))
            {
                renameResult = new RenameResult();
                renameResult.Add(new Diff(input, DiffOperation.Equal));
                return(renameResult);
            }

            MatchCollection matches;

            try
            {
                // Regex gives us case sensitivity, even when not searching with regex.
                var regexOptions = this.SearchIsCaseSensitive ? default(RegexOptions) : RegexOptions.IgnoreCase;
                matches = Regex.Matches(input, this.SearchStringAsRegex, regexOptions);
            }
            catch (System.ArgumentException)
            {
                renameResult = new RenameResult();
                renameResult.Add(new Diff(input, DiffOperation.Equal));
                return(renameResult);
            }

            renameResult = RenameResultUtilities.CreateDiffFromReplacedMatches(input, this.ReplaceMatch, matches);
            return(renameResult);
        }
            public RenameResult Rename(string input, int relativeCount)
            {
                var result = new RenameResult();

                result.Add(new Diff(input, DiffOperation.Equal));
                return(result);
            }
Exemplo n.º 12
0
        /// <summary>
        /// Rename the specified input, using the relativeCount.
        /// </summary>
        /// <param name="input">Input String to rename.</param>
        /// <param name="relativeCount">Relative count. This can be used for enumeration.</param>
        /// <returns>A new string renamed according to the rename operation's rules.</returns>
        public override RenameResult Rename(string input, int relativeCount)
        {
            var renameResult = new RenameResult();

            if (!string.IsNullOrEmpty(input))
            {
                renameResult.Add(new Diff(input, DiffOperation.Deletion));
            }

            if (!string.IsNullOrEmpty(this.NewName))
            {
                renameResult.Add(new Diff(this.NewName, DiffOperation.Insertion));
            }

            return(renameResult);
        }
Exemplo n.º 13
0
        public void SearchRegex_MultipleMatches_AllAreReplaced()
        {
            // Arrange
            var name            = "StoolDoodad";
            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.UseRegex     = true;
            replaceStringOp.SearchString = "o";

            var expected = new RenameResult();

            expected.Add(new Diff("St", DiffOperation.Equal));
            expected.Add(new Diff("o", DiffOperation.Deletion));
            expected.Add(new Diff("o", DiffOperation.Deletion));
            expected.Add(new Diff("lD", DiffOperation.Equal));
            expected.Add(new Diff("o", DiffOperation.Deletion));
            expected.Add(new Diff("o", DiffOperation.Deletion));
            expected.Add(new Diff("dad", DiffOperation.Equal));

            // Act
            var result = replaceStringOp.Rename(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 14
0
        public void SearchRegex_EscapeCharactersInSearch_Replaces()
        {
            // Arrange
            var name            = "Char.Hero.Woot";
            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.UseRegex          = true;
            replaceStringOp.SearchString      = "\\.";
            replaceStringOp.ReplacementString = "_";

            var expected = new RenameResult();

            expected.Add(new Diff("Char", DiffOperation.Equal));
            expected.Add(new Diff(".", DiffOperation.Deletion));
            expected.Add(new Diff("_", DiffOperation.Insertion));
            expected.Add(new Diff("Hero", DiffOperation.Equal));
            expected.Add(new Diff(".", DiffOperation.Deletion));
            expected.Add(new Diff("_", DiffOperation.Insertion));
            expected.Add(new Diff("Woot", DiffOperation.Equal));

            // Act
            var result = replaceStringOp.Rename(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
        }
        private static void DrawSampleDeletionLabel(Rect rect, MulliganUserPreferences preferences)
        {
            var diffLabelStyle = new MulliganEditorGUIUtilities.DiffLabelStyle()
            {
                HideDiff            = false,
                OperationToShow     = DiffOperation.Deletion,
                DiffBackgroundColor = preferences.DeletionBackgroundColor,
                DiffTextColor       = preferences.DeletionTextColor,
            };

            var renameResult = new RenameResult();

            renameResult.Add(new Diff(LocalizationManager.Instance.GetTranslation("exampleThisIs") + " ", DiffOperation.Equal));
            renameResult.Add(new Diff(LocalizationManager.Instance.GetTranslation("exampleSampleText"), DiffOperation.Deletion));
            renameResult.Add(new Diff(" " + LocalizationManager.Instance.GetTranslation("exampleWithWords") + " ", DiffOperation.Equal));
            renameResult.Add(new Diff(LocalizationManager.Instance.GetTranslation("exampleDeleted"), DiffOperation.Deletion));

            MulliganEditorGUIUtilities.DrawDiffLabel(rect, renameResult, true, diffLabelStyle, SampleDiffLabelStyle);
        }
Exemplo n.º 16
0
        public void SearchStringCaseSensitive_MatchesCase_Replaces()
        {
            // Arrange
            var name            = "ZeldA";
            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.SearchIsCaseSensitive = true;
            replaceStringOp.SearchString          = "ZeldA";
            replaceStringOp.ReplacementString     = "blah";

            var expected = new RenameResult();

            expected.Add(new Diff("ZeldA", DiffOperation.Deletion));
            expected.Add(new Diff("blah", DiffOperation.Insertion));

            // Act
            var result = replaceStringOp.Rename(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Rename the specified input, using the relativeCount.
        /// </summary>
        /// <param name="input">Input String to rename.</param>
        /// <param name="relativeCount">Relative count. This can be used for enumeration.</param>
        /// <returns>A new string renamed according to the rename operation's rules.</returns>
        public RenameResult Rename(string input, int relativeCount)
        {
            var renameResult = new RenameResult();

            if (!string.IsNullOrEmpty(this.Prefix))
            {
                renameResult.Add(new Diff(this.Prefix, DiffOperation.Insertion));
            }

            if (!string.IsNullOrEmpty(input))
            {
                renameResult.Add(new Diff(input, DiffOperation.Equal));
            }

            if (!string.IsNullOrEmpty(this.Suffix))
            {
                renameResult.Add(new Diff(this.Suffix, DiffOperation.Insertion));
            }

            return(renameResult);
        }
Exemplo n.º 18
0
        public void SearchString_OneMatch_IsReplaced()
        {
            // Arrange
            var name            = "CHAR_Hero_Spawn";
            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.SearchString      = "Hero";
            replaceStringOp.ReplacementString = "A";

            var expected = new RenameResult();

            expected.Add(new Diff("CHAR_", DiffOperation.Equal));
            expected.Add(new Diff("Hero", DiffOperation.Deletion));
            expected.Add(new Diff("A", DiffOperation.Insertion));
            expected.Add(new Diff("_Spawn", DiffOperation.Equal));

            // Act
            var result = replaceStringOp.Rename(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 19
0
        public void SearchString_ReplaceSeparatedMatches_SubstitutesMultiple()
        {
            // Arrange
            var name            = "You do you";
            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.UseRegex          = true;
            replaceStringOp.SearchString      = "you";
            replaceStringOp.ReplacementString = "Me";

            var expected = new RenameResult();

            expected.Add(new Diff("You", DiffOperation.Deletion));
            expected.Add(new Diff("Me", DiffOperation.Insertion));
            expected.Add(new Diff(" do ", DiffOperation.Equal));
            expected.Add(new Diff("you", DiffOperation.Deletion));
            expected.Add(new Diff("Me", DiffOperation.Insertion));

            // Act
            var result = replaceStringOp.Rename(name, 0);

            Assert.AreEqual(expected, result);
        }
Exemplo n.º 20
0
        public void SearchString_NotCaseSensitiveAndDoesNotMatchCase_StillReplaces()
        {
            // Arrange
            var name            = "ZELDAzelda";
            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.SearchIsCaseSensitive = false;
            replaceStringOp.SearchString          = "ZelDa";
            replaceStringOp.ReplacementString     = "blah";

            var expected = new RenameResult();

            expected.Add(new Diff("ZELDA", DiffOperation.Deletion));
            expected.Add(new Diff("blah", DiffOperation.Insertion));
            expected.Add(new Diff("zelda", DiffOperation.Deletion));
            expected.Add(new Diff("blah", DiffOperation.Insertion));

            // Act
            var result = replaceStringOp.Rename(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 21
0
        public void SearchRegex_SpecialCharactersInSearch_Replaces()
        {
            // Arrange
            var name            = "Char_Hero_Woot";
            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.UseRegex          = true;
            replaceStringOp.SearchString      = "[a-zA-Z]*_";
            replaceStringOp.ReplacementString = "Yep";

            var expected = new RenameResult();

            expected.Add(new Diff("Char_", DiffOperation.Deletion));
            expected.Add(new Diff("Yep", DiffOperation.Insertion));
            expected.Add(new Diff("Hero_", DiffOperation.Deletion));
            expected.Add(new Diff("Yep", DiffOperation.Insertion));
            expected.Add(new Diff("Woot", DiffOperation.Equal));

            // Act
            var result = replaceStringOp.Rename(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Rename the specified input, using the relativeCount.
        /// </summary>
        /// <param name="input">Input String to rename.</param>
        /// <param name="relativeCount">Relative count. This can be used for enumeration.</param>
        /// <returns>A new string renamed according to the rename operation's rules.</returns>
        public RenameResult Rename(string input, int relativeCount)
        {
            var renameResult = new RenameResult();

            if (!string.IsNullOrEmpty(input) && !this.Prepend)
            {
                renameResult.Add(new Diff(input, DiffOperation.Equal));
            }

            var offsetCount    = (relativeCount * this.Increment) + this.StartingCount;
            var stringToInsert = this.GetStringFromSequenceForIndex(offsetCount);

            if (!string.IsNullOrEmpty(stringToInsert))
            {
                renameResult.Add(new Diff(stringToInsert, DiffOperation.Insertion));
            }

            if (this.Prepend)
            {
                renameResult.Add(new Diff(input, DiffOperation.Equal));
            }

            return(renameResult);
        }
Exemplo n.º 23
0
        private static void ConsolidateRemainderOfStringIntoRenameResult(
            RenameResult renameResult,
            string originalString,
            int indexToStartFrom,
            DiffOperation diffOpIfDifferent)
        {
            var remainderOfOldString = originalString.Substring(indexToStartFrom, originalString.Length - indexToStartFrom);

            if (renameResult.Count > 0 && renameResult[renameResult.Count - 1].Operation == diffOpIfDifferent)
            {
                // last diff in the sequence matches the desired diff for the remainder of the string. Consolidate them
                var previousDiff = renameResult[renameResult.Count - 1];
                renameResult[renameResult.Count - 1] = new Diff(
                    string.Concat(previousDiff.Result, remainderOfOldString),
                    previousDiff.Operation);
            }
            else
            {
                renameResult.Add(new Diff(remainderOfOldString, diffOpIfDifferent));
            }
        }
Exemplo n.º 24
0
        public void RemoveWhitespace_AllWhitespace_IsEmpty()
        {
            // Arrange
            var name = "    ";
            var removeCharactersOp = new RemoveCharactersOperation();

            removeCharactersOp.SetOptionPreset(RemoveCharactersOperation.PresetID.Whitespace);

            var expected = new RenameResult();

            for (int i = 0; i < name.Length; ++i)
            {
                var substring = name.Substring(i, 1);
                expected.Add(new Diff(substring, DiffOperation.Deletion));
            }

            // Act
            var result = removeCharactersOp.Rename(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void RemoveSymbols_OnlySymbolsInString_RemovesAllSymbols()
        {
            // Arrange
            var name = "`~!@#$%^&*()+-=[]{}\\|;:'\",<.>/?";
            var removeCharactersOp = new RemoveCharactersOperation();

            removeCharactersOp.Options = RemoveCharactersOperation.Symbols;

            var expected = new RenameResult();

            for (int i = 0; i < name.Length; ++i)
            {
                var substring = name.Substring(i, 1);
                expected.Add(new Diff(substring, DiffOperation.Deletion));
            }

            // Act
            var result = removeCharactersOp.Rename(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void RemoveNumbers_AllNumbersInString_RemovesAllNumbers()
        {
            // Arrange
            var name = "1234567890";
            var removeCharactersOp = new RemoveCharactersOperation();

            removeCharactersOp.Options = RemoveCharactersOperation.Numbers;

            var expected = new RenameResult();

            for (int i = 0; i < name.Length; ++i)
            {
                var substring = name.Substring(i, 1);
                expected.Add(new Diff(substring, DiffOperation.Deletion));
            }

            // Act
            var result = removeCharactersOp.Rename(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 27
0
        private List <RenameResult> GetRenameSequenceForName(string originalName, int count)
        {
            var          renameResults = new List <RenameResult>();
            string       modifiedName  = originalName;
            RenameResult result;

            if (this.operationSequence.Count == 0)
            {
                result = new RenameResult();
                result.Add(new Diff(originalName, DiffOperation.Equal));
                renameResults.Add(result);
            }
            else
            {
                foreach (var op in this.operationSequence)
                {
                    result = op.Rename(modifiedName, count);
                    renameResults.Add(result);
                    modifiedName = result.Result;
                }
            }

            return(renameResults);
        }
Exemplo n.º 28
0
        public void SearchString_ReplaceNeighboringMatches_SubstitutesMultiple()
        {
            // Arrange
            var name            = "Thisisyours";
            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.UseRegex          = true;
            replaceStringOp.SearchString      = "is";
            replaceStringOp.ReplacementString = "e";

            var expected = new RenameResult();

            expected.Add(new Diff("Th", DiffOperation.Equal));
            expected.Add(new Diff("is", DiffOperation.Deletion));
            expected.Add(new Diff("e", DiffOperation.Insertion));
            expected.Add(new Diff("is", DiffOperation.Deletion));
            expected.Add(new Diff("e", DiffOperation.Insertion));
            expected.Add(new Diff("yours", DiffOperation.Equal));

            // Act
            var result = replaceStringOp.Rename(name, 0);

            Assert.AreEqual(expected, result);
        }