Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EnumerateOperation"/> class.
        /// This is a clone constructor, copying the values from one to another.
        /// </summary>
        /// <param name="operationToCopy">Operation to copy.</param>
        public EnumerateOperation(EnumerateOperation operationToCopy)
        {
            this.StartingCount = operationToCopy.StartingCount;
            this.CountFormat   = operationToCopy.CountFormat;

            this.Initialize();
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        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]);
            }
        }
Exemplo n.º 4
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);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EnumerateOperation"/> class.
        /// This is a clone constructor, copying the values from one to another.
        /// </summary>
        /// <param name="operationToCopy">Operation to copy.</param>
        public EnumerateOperation(EnumerateOperation operationToCopy)
        {
            this.Initialize();

            this.formatPreset = operationToCopy.formatPreset;
            this.countFormat  = operationToCopy.countFormat;

            this.StartingCount = operationToCopy.StartingCount;
            this.Increment     = operationToCopy.Increment;
            this.Prepend       = operationToCopy.Prepend;
        }
Exemplo n.º 6
0
        public void RenameObjects_Spritesheet_Renames()
        {
            // Arrange
            var spriteSheetConfig = new SpriteSheetGenerationConfig(2, "Texture.png");

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

            replaceNameOp.NewName = "NewSprite";

            var enumerateOp = new EnumerateOperation();

            enumerateOp.StartingCount = 1;

            var renameSequence = new RenameOperationSequence <IRenameOperation>();

            renameSequence.Add(replaceNameOp);
            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);
                }
            }

            var bulkRenamer = new BulkRenamer(renameSequence);

            bulkRenamer.RenameObjects(allSprites, true);

            var expectedNames = new List <string>
            {
                "NewSprite1",
                "NewSprite2",
                "NewSprite3",
                "NewSprite4"
            };

            var resultingNames = new List <string>();

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

            Assert.AreEqual(expectedNames, resultingNames);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public void Rename_NullTarget_AddsCount()
        {
            // Arrange
            string name        = null;
            var    enumerateOp = new EnumerateOperation();

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

            var expected = new RenameResult()
            {
                new Diff("0", DiffOperation.Insertion)
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 9
0
        public void RenameStartingCount_InvalidFormat_IsIgnored()
        {
            // Arrange
            var name        = "Char_Hero";
            var enumerateOp = new EnumerateOperation();

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

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

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

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 10
0
        public void RenameFormat_SingleDigitFormat_AddsCount()
        {
            // Arrange
            var name        = "Char_Hero";
            var enumerateOp = new EnumerateOperation();

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

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

            // Act
            var result = enumerateOp.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);
        }
Exemplo n.º 12
0
        public void Rename_PrefixedCount_PrependsCount()
        {
            // Arrange
            var name        = "Char_Hero";
            var enumerateOp = new EnumerateOperation();

            enumerateOp.SetCountFormat("0");
            enumerateOp.StartingCount = 0;
            enumerateOp.Prepend       = true;

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

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

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 13
0
        public void RenameStartingCount_StartFromNonZero_AddsCorrectCount()
        {
            // Arrange
            var name        = "Char_Hero";
            var enumerateOp = new EnumerateOperation();

            enumerateOp.CountFormat   = "0";
            enumerateOp.StartingCount = -1;


            var expected = new RenameResult()
            {
                new Diff("Char_Hero", DiffOperation.Equal),
                new Diff("-1", DiffOperation.Insertion)
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
        /// <summary>
        /// Clone this instance.
        /// </summary>
        /// <returns>A clone of this instance</returns>
        public IRenameOperation Clone()
        {
            var clone = new EnumerateOperation(this);

            return(clone);
        }