Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void Rename_EmptyString_DoesNothing()
        {
            // Arrange
            var name         = string.Empty;
            var changeCaseOp = new ChangeCaseOperation();

            var expected = RenameResult.Empty;

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

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 4
0
        public void Rename_NullTarget_DoesNothing()
        {
            // Arrange
            string name         = null;
            var    changeCaseOp = new ChangeCaseOperation();

            var expected = RenameResult.Empty;

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

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public void RenameToLower_ValidUpperCharactersFirstOnly_OnlyFirstLowered()
        {
            // Arrange
            var name         = "SOME Upper";
            var changeCaseOp = new ChangeCaseOperation();

            changeCaseOp.ChangeFirstCharacterOnly = true;

            var expected = new RenameResult()
            {
                new Diff("S", DiffOperation.Deletion),
                new Diff("s", DiffOperation.Insertion),
                new Diff("OME Upper", DiffOperation.Equal),
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 7
0
        public void RenameToUpper_ValidLowerCharactersFirstOnly_OnlyFirstIsUppered()
        {
            // Arrange
            var name         = "this is ALMOST all lower";
            var changeCaseOp = new ChangeCaseOperation();

            changeCaseOp.Casing = ChangeCaseOperation.CasingChange.Uppercase;
            changeCaseOp.ChangeFirstCharacterOnly = true;

            var expected = new RenameResult()
            {
                new Diff("t", DiffOperation.Deletion),
                new Diff("T", DiffOperation.Insertion),
                new Diff("his is ALMOST all lower", DiffOperation.Equal),
            };

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

            // Assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Clone this instance.
        /// </summary>
        /// <returns>A clone of this instance</returns>
        public IRenameOperation Clone()
        {
            var clone = new ChangeCaseOperation(this);

            return(clone);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChangeCaseOperation"/> class by copying another.
 /// </summary>
 /// <param name="operationToCopy">Operation to copy.</param>
 public ChangeCaseOperation(ChangeCaseOperation operationToCopy)
 {
     this.Casing = operationToCopy.Casing;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ChangeCaseOperation"/> class by copying another.
 /// </summary>
 /// <param name="operationToCopy">Operation to copy.</param>
 public ChangeCaseOperation(ChangeCaseOperation operationToCopy)
 {
     this.Casing = operationToCopy.Casing;
     this.changeFirstCharacterOnly = operationToCopy.changeFirstCharacterOnly;
 }