Skip to content

Commit

Permalink
made RemoveParametersRefactoring tests pass. these tests highlight a …
Browse files Browse the repository at this point in the history
…number of little issues.
  • Loading branch information
retailcoder committed Jul 8, 2015
1 parent d3a6a0d commit 5116cfc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void LoadParameters()
if (TargetDeclaration.DeclarationType == DeclarationType.PropertyLet ||
TargetDeclaration.DeclarationType == DeclarationType.PropertySet)
{
Parameters.RemoveAt(Parameters.Count - 1);
Parameters.Remove(Parameters.Last());
}
}

Expand Down
16 changes: 9 additions & 7 deletions RubberduckTests/Refactoring/RemoveParametersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,18 @@ public void RemoveParametersRefactoring_RemoveFromGetter()
Assert.AreEqual(expectedCode, Module.Object.Lines());
}

//bug: We shouldn't allow the only param in a setter to be removed, it will break the VBA code.
[TestMethod]
public void RemoveParametersRefactoring_RemoveFromSetter()
{
//Input
const string inputCode =
@"Private Property Set Foo(ByVal arg1 As Integer)
@"Private Property Set Foo(ByVal arg1 As Integer)
End Property";
var selection = new Selection(1, 23, 1, 27); //startLine, startCol, endLine, endCol

//Expectation
const string expectedCode =
@"Private Property Set Foo()
@"Private Property Set Foo(ByVal arg1 As Integer)
End Property"; //note: The IDE strips out the extra whitespace

//Arrange
Expand All @@ -257,20 +256,23 @@ public void RemoveParametersRefactoring_RemoveFromSetter()
Assert.AreEqual(expectedCode, Module.Object.Lines());
}

// todo: write a test that confirms that Property Set and Property Let members have 1 less parameter than what the signature actually says.
// ...or re-implement the code so that such a test isn't needed to document this surprising behavior.

//note: removing other params from setters is fine (In fact, we may want to create an inspection for this).
[TestMethod]
public void RemoveParametersRefactoring_RemoveSecondParamFromSetter()
{
//Input
const string inputCode =
@"Private Property Set Foo(ByVal arg1 As Integer, ByVal arg2 As String)
@"Private Property Set Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Property";
var selection = new Selection(1, 23, 1, 27); //startLine, startCol, endLine, endCol

//Expectation
const string expectedCode =
@"Private Property Set Foo(ByVal arg1 As Integer )
End Property"; //note: The IDE strips out the extra whitespace
@"Private Property Set Foo( ByVal arg2 As String)
End Property"; //note: The IDE strips out the extra whitespace // bug: the refactoring should be removing that extra whitespace.

//Arrange
SetupProject(inputCode);
Expand All @@ -280,7 +282,7 @@ public void RemoveParametersRefactoring_RemoveSecondParamFromSetter()

//Specify Param(s) to remove
var model = new RemoveParametersModel(parseResult, qualifiedSelection);
model.Parameters[1].IsRemoved = true;
model.Parameters[0].IsRemoved = true;

//SetupFactory
var factory = SetupFactory(model);
Expand Down

0 comments on commit 5116cfc

Please sign in to comment.