@@ -880,5 +880,43 @@ Private Sub Foo()
880
880
Assert . AreEqual ( inputCode , rewriter . GetText ( ) ) ;
881
881
}
882
882
}
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
+ }
883
921
}
884
922
}
0 commit comments