public void RemoveCustomCaseSensitiveCharacters_MixedCasesInString_RemovesCasedCustomChars()
        {
            // Arrange
            var name = "ABCDabcdD";
            var removeCharactersOp = new RemoveCharactersOperation();

            removeCharactersOp.Options = new RemoveCharactersOperation.RemoveCharactersOperationOptions()
            {
                CharactersToRemove = "ABCD",
                IsCaseSensitive    = true
            };

            var expected = new RenameResult()
            {
                new Diff("A", DiffOperation.Deletion),
                new Diff("B", DiffOperation.Deletion),
                new Diff("C", DiffOperation.Deletion),
                new Diff("D", DiffOperation.Deletion),
                new Diff("abcd", DiffOperation.Equal),
                new Diff("D", DiffOperation.Deletion),
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void RemoveSymbols_SymbolsAndAlphanumericsInString_RemovesOnlySymbols()
        {
            // Arrange
            var name = "A!@#$%BD*(";
            var removeCharactersOp = new RemoveCharactersOperation();

            removeCharactersOp.Options = RemoveCharactersOperation.Symbols;

            var expected = new RenameResult()
            {
                new Diff("A", DiffOperation.Equal),
                new Diff("!", DiffOperation.Deletion),
                new Diff("@", DiffOperation.Deletion),
                new Diff("#", DiffOperation.Deletion),
                new Diff("$", DiffOperation.Deletion),
                new Diff("%", DiffOperation.Deletion),
                new Diff("BD", DiffOperation.Equal),
                new Diff("*", DiffOperation.Deletion),
                new Diff("(", DiffOperation.Deletion),
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void RemoveCustomCharacters_ValidString_RemovesCustomChars()
        {
            // Arrange
            var name = "abz35!450k";
            var removeCharactersOp = new RemoveCharactersOperation();

            removeCharactersOp.Options = new RemoveCharactersOperation.RemoveCharactersOperationOptions()
            {
                CharactersToRemove = "ak!5"
            };

            var expected = new RenameResult()
            {
                new Diff("a", DiffOperation.Deletion),
                new Diff("bz3", DiffOperation.Equal),
                new Diff("5", DiffOperation.Deletion),
                new Diff("!", DiffOperation.Deletion),
                new Diff("4", DiffOperation.Equal),
                new Diff("5", DiffOperation.Deletion),
                new Diff("0", DiffOperation.Equal),
                new Diff("k", DiffOperation.Deletion),
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
        /// <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);
        }
Beispiel #5
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);
        }
        public void Rename_Pascal_CapitalizesFirst()
        {
            // Arrange
            var name          = "what a pig";
            var toCamelCaseOp = new ToCamelCaseOperation();

            toCamelCaseOp.UsePascal           = true;
            toCamelCaseOp.DelimiterCharacters = " ";

            var expected = new RenameResult()
            {
                new Diff("w", DiffOperation.Deletion),
                new Diff("W", DiffOperation.Insertion),
                new Diff("hat ", DiffOperation.Equal),
                new Diff("a", DiffOperation.Deletion),
                new Diff("A", DiffOperation.Insertion),
                new Diff(" ", DiffOperation.Equal),
                new Diff("p", DiffOperation.Deletion),
                new Diff("P", DiffOperation.Insertion),
                new Diff("ig", DiffOperation.Equal),
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
        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);
        }
        /// <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);
        }
        /// <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);
        }
Beispiel #10
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);
        }
Beispiel #11
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);
        }
Beispiel #12
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);
        }
        public void Rename_SpaceDelimeter_CapitalizesWords()
        {
            // Arrange
            var name          = "this is my name";
            var toCamelCaseOp = new ToCamelCaseOperation();

            toCamelCaseOp.DelimiterCharacters = " ";

            var expected = new RenameResult()
            {
                new Diff("this ", DiffOperation.Equal),
                new Diff("i", DiffOperation.Deletion),
                new Diff("I", DiffOperation.Insertion),
                new Diff("s ", DiffOperation.Equal),
                new Diff("m", DiffOperation.Deletion),
                new Diff("M", DiffOperation.Insertion),
                new Diff("y ", DiffOperation.Equal),
                new Diff("n", DiffOperation.Deletion),
                new Diff("N", DiffOperation.Insertion),
                new Diff("ame", DiffOperation.Equal),
            };

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

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

            removeCharactersOp.Options = RemoveCharactersOperation.Numbers;

            var expected = new RenameResult()
            {
                new Diff("A", DiffOperation.Equal),
                new Diff("2", DiffOperation.Deletion),
                new Diff("5", DiffOperation.Deletion),
                new Diff("1", DiffOperation.Deletion),
                new Diff("B", DiffOperation.Equal),
                new Diff("6", DiffOperation.Deletion),
                new Diff("3", DiffOperation.Deletion),
                new Diff("7", DiffOperation.Deletion),
                new Diff("k", DiffOperation.Equal),
                new Diff("9", DiffOperation.Deletion),
                new Diff("1", DiffOperation.Deletion),
                new Diff("1", DiffOperation.Deletion),
                new Diff("p", DiffOperation.Equal),
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
        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);
        }
            public RenameResult Rename(string input, int relativeCount)
            {
                var result = new RenameResult();

                result.Add(new Diff(input, DiffOperation.Equal));
                return(result);
            }
Beispiel #17
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);
        }
        public void Rename_CharacterDelimiter_DelimitersArentCapitalized()
        {
            // Arrange
            var name          = "thisxisxmyxname";
            var toCamelCaseOp = new ToCamelCaseOperation();

            toCamelCaseOp.DelimiterCharacters = "x";

            var expected = new RenameResult()
            {
                new Diff("thisx", DiffOperation.Equal),
                new Diff("i", DiffOperation.Deletion),
                new Diff("I", DiffOperation.Insertion),
                new Diff("sx", DiffOperation.Equal),
                new Diff("m", DiffOperation.Deletion),
                new Diff("M", DiffOperation.Insertion),
                new Diff("yx", DiffOperation.Equal),
                new Diff("n", DiffOperation.Deletion),
                new Diff("N", DiffOperation.Insertion),
                new Diff("ame", DiffOperation.Equal),
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void Rename_TwoDelimitersBackToBack_SkipsBoth()
        {
            // Arrange
            var name          = "what==a=pig";
            var toCamelCaseOp = new ToCamelCaseOperation();

            toCamelCaseOp.DelimiterCharacters = "=";

            var expected = new RenameResult()
            {
                new Diff("what==", DiffOperation.Equal),
                new Diff("a", DiffOperation.Deletion),
                new Diff("A", DiffOperation.Insertion),
                new Diff("=", DiffOperation.Equal),
                new Diff("p", DiffOperation.Deletion),
                new Diff("P", DiffOperation.Insertion),
                new Diff("ig", DiffOperation.Equal),
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void RenameCount_CountSeveralItems_CountsUp()
        {
            // Arrange
            var names = new string[]
            {
                "BlockA",
                "BlockB",
                "BlockC",
                "BlockD",
                "BlockE",
            };
            var enumerateOp = new EnumerateOperation();

            enumerateOp.SetCountFormat("0");
            enumerateOp.StartingCount = 1;

            var expectedRenameResults = new RenameResult[]
            {
                new RenameResult()
                {
                    new Diff("BlockA", DiffOperation.Equal), new Diff("1", DiffOperation.Insertion)
                },
                new RenameResult()
                {
                    new Diff("BlockB", DiffOperation.Equal), new Diff("2", DiffOperation.Insertion)
                },
                new RenameResult()
                {
                    new Diff("BlockC", DiffOperation.Equal), new Diff("3", DiffOperation.Insertion)
                },
                new RenameResult()
                {
                    new Diff("BlockD", DiffOperation.Equal), new Diff("4", DiffOperation.Insertion)
                },
                new RenameResult()
                {
                    new Diff("BlockE", DiffOperation.Equal), new Diff("5", DiffOperation.Insertion)
                },
            };

            // Act
            var results = new List <RenameResult>(names.Length);

            for (int i = 0; i < names.Length; ++i)
            {
                results.Add(enumerateOp.Rename(names[i], i));
            }

            // Assert
            Assert.AreEqual(
                expectedRenameResults.Length,
                results.Count,
                "Expected Results and results should have the same number of entries but didn't.");
            for (int i = 0; i < results.Count; ++i)
            {
                var expected = expectedRenameResults[i];
                Assert.AreEqual(expected, results[i]);
            }
        }
Beispiel #21
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);
        }
Beispiel #22
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);
        }
        /// <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);
        }
        public void Rename_EmptySequence_AddsNothing()
        {
            // Arrange
            string name     = "Blah";
            var    renameOp = new AdjustNumberingOperation();
            var    expected = new RenameResult()
            {
                new Diff("Blah", DiffOperation.Equal)
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
Beispiel #25
0
        public void Rename_Symbols_AreUnchanged()
        {
            // Arrange
            var name         = "!@#$%^&*()_-=+[]\\;',.";
            var changeCaseOp = new ChangeCaseOperation();

            var expected = new RenameResult()
            {
                new Diff(name, DiffOperation.Equal)
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
Beispiel #26
0
        public void Rename_DeleteTargetNameIsNotEmpty_IsDeleted()
        {
            // Arrange
            var name          = "Char_Hero";
            var replaceNameOp = new ReplaceNameOperation();

            var expected = new RenameResult()
            {
                new Diff(name, DiffOperation.Deletion)
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
        /// <summary>
        /// Draw a DiffLabel, which draws a simple EditorGUILabel populated with the results from a rename op (diff).
        /// </summary>
        /// <param name="rect">Rect to draw in</param>
        /// <param name="renameResult">The result of a RenameOp, which contains the diffs to render</param>
        /// <param name="showBefore">Flag to show the name before the op, instead of the result</param>
        /// <param name="resultLabelStyle">Style of the DiffLabel</param>
        /// <param name="style">Style for the EditorGUILabel itself</param>
        public static void DrawDiffLabel(Rect rect, RenameResult renameResult, bool showBefore, DiffLabelStyle resultLabelStyle, GUIStyle style)
        {
            var labelText = string.Empty;

            if (!resultLabelStyle.HideDiff)
            {
                ApplyBackgroundColorToDiff(
                    rect,
                    style,
                    renameResult,
                    resultLabelStyle.OperationToShow,
                    resultLabelStyle.DiffBackgroundColor);
            }

            labelText = showBefore ? renameResult.GetOriginalColored(resultLabelStyle.DiffTextColor) :
                        renameResult.GetResultColored(resultLabelStyle.DiffTextColor);
            EditorGUI.LabelField(rect, labelText, style);
        }
        public void Rename_EmptyDelimeters_RemainsUnchanged()
        {
            // Arrange
            var name          = "whats in a name";
            var toCamelCaseOp = new ToCamelCaseOperation();

            toCamelCaseOp.DelimiterCharacters = string.Empty;

            var expected = new RenameResult()
            {
                new Diff(name, DiffOperation.Equal)
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void SearchString_EmptySearch_DoesNothing()
        {
            // Arrange
            var name            = "ThisIsAName";
            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.SearchString = string.Empty;

            var expected = new RenameResult()
            {
                new Diff(name, DiffOperation.Equal)
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void RenameFormat_NoFormat_DoesNothing()
        {
            // Arrange
            var name        = "Char_Hero";
            var enumerateOp = new EnumerateOperation();

            enumerateOp.SetCountFormat(string.Empty);

            var expected = new RenameResult()
            {
                new Diff(name, DiffOperation.Equal)
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }