Exemplo n.º 1
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.º 2
0
        public void RemoveCustomCaseSensitiveCharacters_MixedCasesInString_RemovesCasedCustomChars()
        {
            // Arrange
            var name = "ABCDabcdD";
            var removeCharactersOp = new RemoveCharactersOperation();
            var customOptions      = new RemoveCharactersOperation.RenameOptions()
            {
                CharactersToRemove = "ABCD",
                IsCaseSensitive    = true
            };

            removeCharactersOp.SetOptions(customOptions);

            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);
        }
Exemplo n.º 3
0
        public void RemoveCustomCharacters_ValidString_RemovesCustomChars()
        {
            // Arrange
            var name = "abz35!450k";
            var removeCharactersOp = new RemoveCharactersOperation();
            var customOptions      = new RemoveCharactersOperation.RenameOptions()
            {
                CharactersToRemove = "ak!5"
            };

            removeCharactersOp.SetOptions(customOptions);

            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>
        /// Draws the contents of the Rename Op using EditorGUILayout.
        /// </summary>
        /// <param name="controlPrefix">The prefix of the control to assign to the control names</param>
        protected override void DrawContents(Rect operationRect, int controlPrefix)
        {
            // Read and write into copies so that we don't resize the view while it's being worked on,
            // which is what is required when the user switches settings around and options (lines) are added into the GUI,
            // after it's already been measured based on it's PRE Update state.
            var originalPresetIndex = this.SelectedPresetIndex;

            var currentSplit = 0;
            int numSplits    = 2;

            if (this.GUIPresets[originalPresetIndex].IsReadOnly)
            {
                numSplits = 2;
            }
            else
            {
                numSplits = 3;
            }

            var presetsContent = new GUIContent(
                LocalizationManager.Instance.GetTranslation("preset"),
                LocalizationManager.Instance.GetTranslation("selectPresetOrSpecifyCharacters"));
            var names = new List <GUIContent>(this.GUIPresets.Count);

            foreach (var preset in this.GUIPresets)
            {
                names.Add(new GUIContent(preset.DisplayName));
            }

            GUI.SetNextControlName(GUIControlNameUtility.CreatePrefixedName(controlPrefix, presetsContent.text));
            var selectedPresetIndex = EditorGUI.Popup(
                operationRect.GetSplitVertical(++currentSplit, numSplits, LineSpacing),
                presetsContent,
                originalPresetIndex,
                names.ToArray());

            var selectedPreset = this.GUIPresets[selectedPresetIndex];
            var workingOptions = new RemoveCharactersOperation.RenameOptions();

            // We can't resize the Rects mid-GUI loop (GetHeight already said how tall it would be),
            // so if we've changed presets we just apply the defaults for the new change. They can
            // modify it next frame.
            if (selectedPresetIndex != originalPresetIndex)
            {
                if (selectedPreset.IsReadOnly)
                {
                    this.RenameOperation.SetOptionPreset(selectedPreset.PresetID);
                }
                else
                {
                    this.RenameOperation.SetOptions(workingOptions);
                }
                return;
            }

            if (selectedPreset.IsReadOnly)
            {
                // The Readonly Label just looks better disabled.
                EditorGUI.BeginDisabledGroup(true);
                var readonlyLabelContent = new GUIContent(selectedPreset.ReadOnlyLabel);
                var labelStyle           = new GUIStyle(EditorStyles.label);
                labelStyle.alignment = TextAnchor.MiddleRight;
                EditorGUI.LabelField(
                    operationRect.GetSplitVertical(++currentSplit, numSplits, LineSpacing),
                    readonlyLabelContent,
                    labelStyle);
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                var charactersFieldContent = new GUIContent(
                    LocalizationManager.Instance.GetTranslation("charactersToRemove"),
                    LocalizationManager.Instance.GetTranslation("allCharactersThatWillBeRemoved"));
                GUI.SetNextControlName(GUIControlNameUtility.CreatePrefixedName(controlPrefix, charactersFieldContent.text));
                workingOptions.CharactersToRemove = EditorGUI.TextField(
                    operationRect.GetSplitVertical(++currentSplit, numSplits, LineSpacing),
                    charactersFieldContent,
                    this.RenameOperation.CharactersToRemove);

                var caseSensitiveToggleContent = new GUIContent(
                    LocalizationManager.Instance.GetTranslation("caseSensitive"),
                    LocalizationManager.Instance.GetTranslation("flagTheSearchToMatchCase"));
                workingOptions.IsCaseSensitive = EditorGUI.Toggle(
                    operationRect.GetSplitVertical(++currentSplit, numSplits, LineSpacing),
                    caseSensitiveToggleContent,
                    this.RenameOperation.IsCaseSensitive);
            }

            if (selectedPreset.IsReadOnly)
            {
                this.RenameOperation.SetOptionPreset(selectedPreset.PresetID);
            }
            else
            {
                this.RenameOperation.SetOptions(workingOptions);
            }
        }