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);
        }
        public void GetNewName_ValidOperations_AreAppliedInOrder()
        {
            // Arrange
            var name = "Char_Hero_Idle";

            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.SearchString      = "ar_He";
            replaceStringOp.ReplacementString = "baboon";

            var trimCharactersOp = new TrimCharactersOperation();

            trimCharactersOp.NumFrontDeleteChars = 4;

            var operationSequence = new RenameOperationSequence <IRenameOperation>();

            operationSequence.Add(replaceStringOp);
            operationSequence.Add(trimCharactersOp);

            var operationSequenceReversed = new RenameOperationSequence <IRenameOperation>();

            operationSequenceReversed.Add(trimCharactersOp);
            operationSequenceReversed.Add(replaceStringOp);

            var expected         = "boonro_Idle";
            var expectedReversed = "_Hero_Idle";

            // Act
            string result         = operationSequence.GetResultingName(name, 0);
            string resultReversed = operationSequenceReversed.GetResultingName(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
            Assert.AreEqual(expectedReversed, resultReversed);
        }
Esempio n. 3
0
        public void RenameObjects_ChangeObjectToExistingObjectNameNotInRenameGroup_SkipsRename()
        {
            // Arrange
            var conflictingObject0 = this.CreatePrefabFromGameObject(
                new GameObject("ConflictingObject0"),
                string.Concat(TestFixturesDirectory, "ConflictingObject0.prefab"));

            this.CreatePrefabFromGameObject(
                new GameObject("ExistingObject"),
                string.Concat(TestFixturesDirectory, "ExistingObject.prefab"));

            var conflictingObjectsWithoutAllNamesChanging = new List <Object>();

            conflictingObjectsWithoutAllNamesChanging.Add(conflictingObject0);

            var replaceFirstNameOp = new ReplaceStringOperation();

            replaceFirstNameOp.SearchString      = "ConflictingObject0";
            replaceFirstNameOp.ReplacementString = "ExistingObject";

            var renameSequence = new RenameOperationSequence <IRenameOperation>();

            renameSequence.Add(replaceFirstNameOp);

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

            bulkRenamer.RenameObjects(conflictingObjectsWithoutAllNamesChanging);
            var expectedName = "ConflictingObject0";

            Assert.AreEqual(expectedName, conflictingObject0.name);
        }
 /// <summary>
 /// Copies the state from one operation into this one.
 /// </summary>
 /// <param name="other">Other.</param>
 public void CopyFrom(ReplaceStringOperation other)
 {
     this.UseRegex              = other.UseRegex;
     this.SearchString          = other.SearchString;
     this.SearchIsCaseSensitive = other.SearchIsCaseSensitive;
     this.ReplacementString     = other.ReplacementString;
 }
Esempio n. 5
0
        private void LoadSavedRenameOperations()
        {
            var serializedOps = EditorPrefs.GetString(RenameOpsEditorPrefsKey, string.Empty);

            if (string.IsNullOrEmpty(serializedOps))
            {
                var operation = new ReplaceStringOperation();
                var drawer    = new ReplaceStringOperationDrawer();
                drawer.SetModel(operation);
                var binding = new RenameOperationDrawerBinding(operation, drawer);
                this.RenameOperationsToApplyWithBindings.Add(binding);
            }
            else
            {
                var ops = serializedOps.Split(',');
                foreach (var op in ops)
                {
                    foreach (var binding in this.RenameOperationDrawerBindingPrototypes)
                    {
                        if (binding.Drawer.MenuDisplayPath == op)
                        {
                            this.AddRenameOperation(binding);
                            break;
                        }
                    }
                }
            }

            if (this.NumRenameOperations > 0)
            {
                this.FocusRenameOperationDeferred(this.RenameOperationsToApplyWithBindings.First().Operation);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReplaceStringOperation"/> class.
 /// This is a clone constructor, copying the values from one to another.
 /// </summary>
 /// <param name="operationToCopy">Operation to copy.</param>
 public ReplaceStringOperation(ReplaceStringOperation operationToCopy)
 {
     this.UseRegex              = operationToCopy.UseRegex;
     this.SearchString          = operationToCopy.SearchString;
     this.SearchIsCaseSensitive = operationToCopy.SearchIsCaseSensitive;
     this.ReplacementString     = operationToCopy.ReplacementString;
 }
        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 void RenameObjects_SpritesheetsWithPrefixedNumbers_Renames()
        {
            // Tests Issue #163: https://github.com/redbluegames/unity-mulligan-renamer/issues/163
            // Arrange
            var spriteSheetConfig = new SpriteSheetGenerationConfig(2, "NumberedSprites.png");

            spriteSheetConfig.NamePrefix           = "0_NumberedSprites";
            spriteSheetConfig.UseZeroBasedIndexing = true;
            var textureWithSprites     = this.SetupSpriteSheet(spriteSheetConfig);
            var replaceStringOperation = new ReplaceStringOperation();

            replaceStringOperation.SearchString      = "Numbered";
            replaceStringOperation.ReplacementString = string.Empty;

            var renameSequence = new RenameOperationSequence <IRenameOperation>();

            renameSequence.Add(replaceStringOperation);

            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>
            {
                "0_Sprites0",
                "0_Sprites1",
                "0_Sprites2",
                "0_Sprites3",
            };

            var resultingNames = new List <string>();

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

            // In order to not depend on how these sprites are Loaded, we check Contains instead of comparing
            // the lists directly
            Assert.That(resultingNames.Count, Is.EqualTo(expectedNames.Count));
            foreach (var name in resultingNames)
            {
                Assert.That(expectedNames.Contains(name), "Expected names did not contain name: " + name);
            }
        }
Esempio n. 9
0
        public void RenameObjects_SpritesheetsWithPrefixedNumbers_Renames()
        {
            // Tests Issue #163: https://github.com/redbluegames/unity-mulligan-renamer/issues/163
            // Arrange
            var spriteSheetConfig = new SpriteSheetGenerationConfig(2, "NumberedSprites.png");

            spriteSheetConfig.NamePrefix           = "0_NumberedSprites";
            spriteSheetConfig.UseZeroBasedIndexing = true;
            var textureWithSprites     = this.SetupSpriteSheet(spriteSheetConfig);
            var replaceStringOperation = new ReplaceStringOperation();

            replaceStringOperation.SearchString      = "Numbered";
            replaceStringOperation.ReplacementString = string.Empty;

            var renameSequence = new RenameOperationSequence <IRenameOperation>();

            renameSequence.Add(replaceStringOperation);

            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>
            {
                "0_Sprites0",
                "0_Sprites1",
                "0_Sprites2",
                "0_Sprites3",
            };

            var resultingNames = new List <string>();

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

            Assert.AreEqual(expectedNames, resultingNames);
        }
        public void SearchString_EmptyTarget_DoesNothing()
        {
            // Arrange
            var name            = string.Empty;
            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.SearchString = "Anything";

            var expected = RenameResult.Empty;

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

            // Assert
            Assert.AreEqual(expected, result);
        }
Esempio n. 11
0
        public void RenameObjects_RenameObjectToExistingObjectNameButAtDifferentPath_Succeeds()
        {
            // Arrange
            var conflictingObject0 = this.CreatePrefabFromGameObject(
                new GameObject("ConflictingObject0"),
                string.Concat(TestFixturesDirectory, "ConflictingObject0.prefab"));
            var existingObject = this.CreatePrefabFromGameObject(
                new GameObject("ExistingObject"),
                string.Concat(TestFixturesDirectory, "SubDirectory/ExistingObject.prefab"));

            var replaceFirstNameOp = new ReplaceStringOperation();

            replaceFirstNameOp.SearchString      = "ConflictingObject0";
            replaceFirstNameOp.ReplacementString = "ExistingObject";

            var renameSequence = new RenameOperationSequence <IRenameOperation>();

            renameSequence.Add(replaceFirstNameOp);

            var expectedNames = new List <string>
            {
                "ExistingObject",
                "ExistingObject"
            };

            var objectsToRename = new List <UnityEngine.Object>()
            {
                conflictingObject0,
                existingObject,
            };

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

            bulkRenamer.RenameObjects(objectsToRename);

            var resultingNames = new List <string>();

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

            Assert.AreEqual(expectedNames, resultingNames);
        }
        public void SearchString_PartialMatches_AreNotReplaced()
        {
            // Arrange
            var name            = "Char_Hero_Spawn";
            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.SearchString = "Heroine";

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

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

            // Assert
            Assert.AreEqual(expected, result);
        }
Esempio n. 13
0
        public void RenameObjects_MultipleAssets_Renames()
        {
            // Arrange
            var multipleObject0 = this.CreatePrefabFromGameObject(
                new GameObject("Asset0"),
                string.Concat(TestFixturesDirectory, "Asset0.prefab"));
            var multipleObject1 = this.CreatePrefabFromGameObject(
                new GameObject("Asset1"),
                string.Concat(TestFixturesDirectory, "Asset1.prefab"));
            var multipleAssets = new List <Object>()
            {
                multipleObject0,
                multipleObject1
            };

            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.SearchString      = "Asset";
            replaceStringOp.ReplacementString = "Thingy";

            var renameSequence = new RenameOperationSequence <IRenameOperation>();

            renameSequence.Add(replaceStringOp);

            var bulkRenamer = new BulkRenamer(renameSequence);

            bulkRenamer.RenameObjects(multipleAssets, true);

            var expectedNames = new List <string>
            {
                "Thingy0",
                "Thingy1"
            };

            var resultingNames = new List <string>();

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

            Assert.AreEqual(expectedNames, resultingNames);
        }
        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);
        }
Esempio n. 15
0
        public void RenameObjects_SpriteAndTexture_Renames()
        {
            // Tests Issue #139: https://github.com/redbluegames/unity-mulligan-renamer/issues/139
            // Arrange
            var spriteSheetConfig = new SpriteSheetGenerationConfig(1, "Texture.png");

            spriteSheetConfig.NamePrefix = "Texture_Sprite";
            var textureWithSprites = this.SetupSpriteSheet(spriteSheetConfig);
            var replaceNameOp      = new ReplaceStringOperation();

            replaceNameOp.SearchString      = "Texture";
            replaceNameOp.ReplacementString = "Cool";

            var renameSequence = new RenameOperationSequence <IRenameOperation>();

            renameSequence.Add(replaceNameOp);

            var path            = AssetDatabase.GetAssetPath(textureWithSprites);
            var allAssetsAtPath = AssetDatabase.LoadAllAssetsAtPath(path);

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

            bulkRenamer.RenameObjects(new List <Object>(allAssetsAtPath), true);

            // Assert
            var resultingNames = new List <string>();

            foreach (var asset in allAssetsAtPath)
            {
                resultingNames.Add(asset.name);
            }

            var expectedNames = new List <string>
            {
                "Cool",
                "Cool_Sprite1",
            };

            Assert.AreEqual(expectedNames, resultingNames);
        }
        public void SearchStringCaseSensitive_DoesNotMatchCase_DoesNotReplace()
        {
            // Arrange
            var name            = "ZELDA";
            var replaceStringOp = new ReplaceStringOperation();

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

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

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

            // Assert
            Assert.AreEqual(expected, result);
        }
        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);
        }
        public void GetNewName_AllOperations_RenamesCorrectly()
        {
            // Arrange
            var name = "Char_Hero_Idle";

            var trimCharactersOp = new TrimCharactersOperation();

            trimCharactersOp.NumFrontDeleteChars = 1;
            trimCharactersOp.NumBackDeleteChars  = 5;

            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.SearchString      = "r_H";
            replaceStringOp.ReplacementString = "t_Z";

            var addStringOp = new AddStringOperation();

            addStringOp.Prefix = "a_";
            addStringOp.Suffix = "AA";

            var enumerateOp = new EnumerateOperation();

            enumerateOp.SetCountFormat("D4");
            enumerateOp.StartingCount = 100;

            var operationSequence = new RenameOperationSequence <IRenameOperation>();

            operationSequence.Add(trimCharactersOp);
            operationSequence.Add(replaceStringOp);
            operationSequence.Add(addStringOp);
            operationSequence.Add(enumerateOp);

            var expected = "a_hat_ZeroAA0100";

            // Act
            string result = operationSequence.GetResultingName(name, 0);

            // Assert
            Assert.AreEqual(expected, result);
        }
        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);
        }
Esempio n. 20
0
        public void RenameObjects_MultipleGameObjects_Renames()
        {
            var gameObject0 = new GameObject("GameObject0");
            var gameObject1 = new GameObject("GameObject1");

            var gameObjects = new List <Object>()
            {
                gameObject0,
                gameObject1
            };

            var replaceStringOp = new ReplaceStringOperation();

            replaceStringOp.SearchString      = "Object";
            replaceStringOp.ReplacementString = "Thingy";

            var renameSequence = new RenameOperationSequence <IRenameOperation>();

            renameSequence.Add(replaceStringOp);

            var bulkRenamer = new BulkRenamer(renameSequence);

            bulkRenamer.RenameObjects(gameObjects, true);

            var expectedNames = new List <string>
            {
                "GameThingy0",
                "GameThingy1"
            };

            var resultingNames = new List <string>();

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

            Assert.AreEqual(expectedNames, resultingNames);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        public void RenameObjects_SpritesheetWithTargetNameAsSubstringInMultipleSprites_Renames()
        {
            // Tests Issue #143: https://github.com/redbluegames/unity-mulligan-renamer/issues/143
            // Arrange
            var spriteSheetConfig = new SpriteSheetGenerationConfig(4, "Texture.png");
            var targetSpriteName  = "Texture_Sprite1";

            spriteSheetConfig.NamePrefix = "Texture_Sprite";
            var textureWithSprites = this.SetupSpriteSheet(spriteSheetConfig);
            var replaceNameOp      = new ReplaceStringOperation();

            replaceNameOp.SearchString      = targetSpriteName;
            replaceNameOp.ReplacementString = "CoolSprite";

            var renameSequence = new RenameOperationSequence <IRenameOperation>();

            renameSequence.Add(replaceNameOp);

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

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

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

            bulkRenamer.RenameObjects(new List <Object>()
            {
                targetSprite
            }, true);

            // Assert
            var expectedNames = new List <string>
            {
                "CoolSprite",
                "Texture_Sprite2",
                "Texture_Sprite3",
                "Texture_Sprite4",
                "Texture_Sprite5",
                "Texture_Sprite6",
                "Texture_Sprite7",
                "Texture_Sprite8",
                "Texture_Sprite9",
                "Texture_Sprite10",
                "Texture_Sprite11",
                "Texture_Sprite12",
                "Texture_Sprite13",
                "Texture_Sprite14",
                "Texture_Sprite15",
                "Texture_Sprite16",
            };

            var resultingNames = new List <string>();

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

            // In order to not depend on how these sprites are Loaded, we check Contains instead of comparing
            // the lists directly
            Assert.That(resultingNames.Count, Is.EqualTo(expectedNames.Count));
            foreach (var name in resultingNames)
            {
                Assert.That(expectedNames.Contains(name), "Expected names did not contain name: " + name);
            }
        }
        /// <summary>
        /// Clone this instance.
        /// </summary>
        /// <returns>A clone of this instance</returns>
        public IRenameOperation Clone()
        {
            var clone = new ReplaceStringOperation(this);

            return(clone);
        }
Esempio n. 27
0
        public void RenameObjects_SpritesheetWithTargetNameAsSubstringInMultipleSprites_Renames()
        {
            // Tests Issue #143: https://github.com/redbluegames/unity-mulligan-renamer/issues/143
            // Arrange
            var spriteSheetConfig = new SpriteSheetGenerationConfig(4, "Texture.png");

            spriteSheetConfig.NamePrefix = "Texture_Sprite";
            var textureWithSprites = this.SetupSpriteSheet(spriteSheetConfig);
            var replaceNameOp      = new ReplaceStringOperation();

            replaceNameOp.SearchString      = "Texture_Sprite1";
            replaceNameOp.ReplacementString = "CoolSprite";

            var renameSequence = new RenameOperationSequence <IRenameOperation>();

            renameSequence.Add(replaceNameOp);

            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(new List <Object>()
            {
                allSprites[0]
            }, true);

            // Assert
            var expectedNames = new List <string>
            {
                "CoolSprite",
                "Texture_Sprite2",
                "Texture_Sprite3",
                "Texture_Sprite4",
                "Texture_Sprite5",
                "Texture_Sprite6",
                "Texture_Sprite7",
                "Texture_Sprite8",
                "Texture_Sprite9",
                "Texture_Sprite10",
                "Texture_Sprite11",
                "Texture_Sprite12",
                "Texture_Sprite13",
                "Texture_Sprite14",
                "Texture_Sprite15",
                "Texture_Sprite16",
            };

            var resultingNames = new List <string>();

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

            Assert.AreEqual(expectedNames, resultingNames);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ReplaceStringOperation"/> class.
 /// This is a clone constructor, copying the values from one to another.
 /// </summary>
 /// <param name="operationToCopy">Operation to copy.</param>
 public ReplaceStringOperation(ReplaceStringOperation operationToCopy)
 {
     this.CopyFrom(operationToCopy);
 }