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 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 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);
        }
예제 #4
0
        public void RenameObjects_EnumeratedObjectsWithDependentChanges_Renames()
        {
            // Arrange
            var enumeratedObject0 = this.CreatePrefabFromGameObject(
                new GameObject("EnumeratedObject0"),
                string.Concat(TestFixturesDirectory, "EnumeratedObject0.prefab"));
            var enumeratedObject1 = this.CreatePrefabFromGameObject(
                new GameObject("EnumeratedObject1"),
                string.Concat(TestFixturesDirectory, "EnumeratedObject1.prefab"));
            var enumeratedObject2 = this.CreatePrefabFromGameObject(
                new GameObject("EnumeratedObject2"),
                string.Concat(TestFixturesDirectory, "EnumeratedObject2.prefab"));

            var enumeratedObjects = new List <Object>()
            {
                enumeratedObject0,
                enumeratedObject1,
                enumeratedObject2,
            };

            var removeCharactersOp     = new RemoveCharactersOperation();
            var removeCharacterOptions = new RemoveCharactersOperation.RenameOptions();

            removeCharacterOptions.CharactersToRemove = "\\d";
            removeCharacterOptions.CharactersAreRegex = true;
            removeCharacterOptions.IsCaseSensitive    = false;
            removeCharactersOp.SetOptions(removeCharacterOptions);

            var enumerateOp = new EnumerateOperation();

            enumerateOp.StartingCount = 1;

            var renameSequence = new RenameOperationSequence <IRenameOperation>();

            renameSequence.Add(removeCharactersOp);
            renameSequence.Add(enumerateOp);

            // Act
            var bulkRenamer = new BulkRenamer(renameSequence);

            bulkRenamer.RenameObjects(enumeratedObjects, true);

            // Assert
            // Build two lists to compare against because Assert displays their differences nicely in its output.
            var expectedNames = new List <string>
            {
                "EnumeratedObject1",
                "EnumeratedObject2",
                "EnumeratedObject3"
            };

            var resultingNames = new List <string>();

            foreach (var obj in enumeratedObjects)
            {
                resultingNames.Add(obj.name);
            }

            Assert.AreEqual(expectedNames, resultingNames);
        }
        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);
        }
예제 #6
0
        public void RenameObjects_SpritesheetWithNamesThatWillOverlap_Renames()
        {
            // Tests Issue #126: https://github.com/redbluegames/unity-mulligan-renamer/issues/126
            // Arrange
            var spriteSheetConfig = new SpriteSheetGenerationConfig(2, "Texture.png");

            spriteSheetConfig.NamePrefix           = "Texture_Sprite";
            spriteSheetConfig.UseZeroBasedIndexing = true;
            var textureWithSprites = this.SetupSpriteSheet(spriteSheetConfig);
            var removeNumbersOp    = new RemoveCharactersOperation();

            removeNumbersOp.SetOptionPreset(RemoveCharactersOperation.PresetID.Numbers);
            var enumerateOp = new EnumerateOperation();

            enumerateOp.StartingCount = 1;
            enumerateOp.Increment     = 1;

            var renameSequence = new RenameOperationSequence <IRenameOperation>();

            renameSequence.Add(removeNumbersOp);
            renameSequence.Add(enumerateOp);

            var path            = AssetDatabase.GetAssetPath(textureWithSprites);
            var allAssetsAtPath = AssetDatabase.LoadAllAssetsAtPath(path);
            var allSprites      = new List <Object>();

            foreach (var asset in allAssetsAtPath)
            {
                if (asset is Sprite)
                {
                    allSprites.Add(asset);
                }
            }

            // Act
            var bulkRenamer = new BulkRenamer(renameSequence);

            bulkRenamer.RenameObjects(allSprites, true);

            // Assert
            var expectedNames = new List <string>
            {
                "Texture_Sprite1",
                "Texture_Sprite2",
                "Texture_Sprite3",
                "Texture_Sprite4",
            };

            var resultingNames = new List <string>();

            foreach (var sprite in allSprites)
            {
                resultingNames.Add(sprite.name);
            }

            Assert.AreEqual(expectedNames, resultingNames);
        }
        public void RemoveCharacters_EmptyTarget_IsUnchanged()
        {
            // Arrange
            var name = string.Empty;
            var removeCharactersOp = new RemoveCharactersOperation();

            var expected = RenameResult.Empty;

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

            // Assert
            Assert.AreEqual(expected, result);
        }
예제 #8
0
        public void RemoveSymbols_StringHasWhitespaceAndSymbols_KeepsWhitespace()
        {
            // Arrange
            var name = "!A !";
            var removeCharactersOp = new RemoveCharactersOperation();

            removeCharactersOp.SetOptionPreset(RemoveCharactersOperation.PresetID.Symbols);

            var expected = new RenameResult()
            {
                new Diff("!", DiffOperation.Deletion),
                new Diff("A ", DiffOperation.Equal),
                new Diff("!", DiffOperation.Deletion),
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
예제 #9
0
        public void RemoveWhitespace_LettersSymbolsAndWhitespaceInString_RemovesOnlyWhitespace()
        {
            // Arrange
            var name = "A1! B";
            var removeCharactersOp = new RemoveCharactersOperation();

            removeCharactersOp.SetOptionPreset(RemoveCharactersOperation.PresetID.Whitespace);

            var expected = new RenameResult()
            {
                new Diff("A1!", DiffOperation.Equal),
                new Diff(" ", DiffOperation.Deletion),
                new Diff("B", DiffOperation.Equal),
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
예제 #10
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);
        }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoveCharactersOperation"/> class.
 /// This is a clone constructor, copying the values from one to another.
 /// </summary>
 /// <param name="operationToCopy">Operation to copy.</param>
 public RemoveCharactersOperation(RemoveCharactersOperation operationToCopy)
 {
     this.CopyFrom(operationToCopy);
 }
예제 #14
0
 /// <summary>
 /// Copies the state from one operation into this one
 /// </summary>
 /// <param name="other">Other.</param>
 private void CopyFrom(RemoveCharactersOperation other)
 {
     this.SetOptions(other.CurrentOptions);
     this.currentPresetID = other.currentPresetID;
 }
예제 #15
0
        /// <summary>
        /// Clone this instance.
        /// </summary>
        /// <returns>A clone of this instance</returns>
        public IRenameOperation Clone()
        {
            var clone = new RemoveCharactersOperation(this);

            return(clone);
        }
예제 #16
0
 /// <summary>
 /// Copies the state from one operation into this one
 /// </summary>
 /// <param name="other">Other.</param>
 public void CopyFrom(RemoveCharactersOperation other)
 {
     this.Config = other.Config;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoveCharactersOperation"/> class.
 /// This is a clone constructor, copying the values from one to another.
 /// </summary>
 /// <param name="operationToCopy">Operation to copy.</param>
 public RemoveCharactersOperation(RemoveCharactersOperation operationToCopy)
 {
     this.Initialize();
     this.Options = operationToCopy.Options;
 }