Skip to content

Commit f306015

Browse files
committed
Add failing test reproducing #3828
1 parent eadfc53 commit f306015

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

RubberduckTests/Refactoring/MoveCloserToUsageTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,5 +880,43 @@ Private Sub Foo()
880880
Assert.AreEqual(inputCode, rewriter.GetText());
881881
}
882882
}
883+
884+
[Test]
885+
[Category("Move Closer")]
886+
[Category("Refactorings")]
887+
public void MoveCloser_RespectsObjectProperties_InUsages()
888+
{
889+
const string input = @"Option Explicit
890+
891+
Public Sub Test()
892+
Dim foo As Object
893+
Debug.Print ""Some statements between""
894+
Debug.Print ""Declaration and first usage!""
895+
Set foo = CreateObject(""Some.Object"")
896+
foo.Name = ""FooName""
897+
foo.OtherProperty = 1626
898+
End Sub";
899+
900+
const string expected = @"Option Explicit
901+
902+
Public Sub Test()
903+
Debug.Print ""Some statements between""
904+
Debug.Print ""Declaration and first usage!""
905+
Dim foo As Object
906+
Set foo = CreateObject(""Some.Object"")
907+
foo.Name = ""FooName""
908+
foo.OtherProperty = 1626
909+
End Sub";
910+
911+
var vbe = MockVbeBuilder.BuildFromSingleStandardModule(input, out var component);
912+
using (var state = MockParser.CreateAndParse(vbe.Object))
913+
{
914+
var messageBox = new Mock<IMessageBox>();
915+
var refactoring = new MoveCloserToUsageRefactoring(vbe.Object, state, messageBox.Object);
916+
refactoring.Refactor(state.AllUserDeclarations.First(d => d.DeclarationType == DeclarationType.Variable));
917+
var rewriter = state.GetRewriter(component);
918+
Assert.AreEqual(expected, rewriter.GetText());
919+
}
920+
}
883921
}
884922
}

0 commit comments

Comments
 (0)