@@ -521,7 +521,6 @@ public void RenameRefactoring_RenameFunction_UpdatesReferences()
521
521
@"Private Function Fo|o() As Boolean
522
522
Foo = True
523
523
End Function
524
-
525
524
Private Sub Goo()
526
525
Dim var1 As Boolean
527
526
var1 = Foo()
@@ -530,7 +529,6 @@ Dim var1 As Boolean
530
529
@"Private Function Hoo() As Boolean
531
530
Hoo = True
532
531
End Function
533
-
534
532
Private Sub Goo()
535
533
Dim var1 As Boolean
536
534
var1 = Hoo()
@@ -539,6 +537,40 @@ End Sub"
539
537
PerformExpectedVersusActualRenameTests ( tdo , inputOutput ) ;
540
538
}
541
539
540
+ [ Test ]
541
+ [ Category ( "Refactorings" ) ]
542
+ [ Category ( "Rename" ) ]
543
+ public void RenameVariableWithBracketedExpressionInModule ( )
544
+ {
545
+ var tdo = new RenameTestsDataObject ( selection : "Foo" , newName : "Hoo" ) ;
546
+ var inputOutput = new RenameTestModuleDefinition ( "TestModule1" , ComponentType . Document )
547
+ {
548
+ Input =
549
+ @"Private Fo|o() As Long
550
+
551
+ Public Sub Derp()
552
+ [Something].Clear
553
+ End Sub" ,
554
+ Expected =
555
+ @"Private Hoo() As Long
556
+
557
+ Public Sub Derp()
558
+ [Something].Clear
559
+ End Sub"
560
+ } ;
561
+
562
+ tdo . UseLibraries = true ;
563
+ tdo . AdditionalSetup = t =>
564
+ {
565
+ var hostApp = new Mock < IHostApplication > ( ) ;
566
+ hostApp . Setup ( x => x . ApplicationName ) . Returns ( "EXCEL" ) ;
567
+ var mock = Mock . Get ( tdo . VBE ) ;
568
+ mock . Setup ( x => x . HostApplication ( ) ) . Returns ( hostApp . Object ) ;
569
+ } ;
570
+
571
+ PerformExpectedVersusActualRenameTests ( tdo , inputOutput ) ;
572
+ }
573
+
542
574
#endregion
543
575
#region Rename Control Tests
544
576
//All RenameControl tests are ignored because control renames depend on access to
@@ -2766,7 +2798,8 @@ private static void InitializeTestDataObject(RenameTestsDataObject tdo
2766
2798
tdo . MsgBox = new Mock < IMessageBox > ( ) ;
2767
2799
tdo . MsgBox . Setup ( m => m . ConfirmYesNo ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , It . IsAny < bool > ( ) ) ) . Returns ( tdo . MsgBoxReturn == ConfirmationOutcome . Yes ) ;
2768
2800
2769
- tdo . VBE = tdo . VBE ?? BuildProject ( tdo . ProjectName , tdo . ModuleTestSetupDefs ) ;
2801
+ tdo . VBE = tdo . VBE ?? BuildProject ( tdo . ProjectName , tdo . ModuleTestSetupDefs , tdo . UseLibraries ) ;
2802
+ tdo . AdditionalSetup ? . Invoke ( tdo ) ;
2770
2803
( tdo . ParserState , tdo . RewritingManager ) = MockParser . CreateAndParseWithRewritingManager ( tdo . VBE ) ;
2771
2804
2772
2805
CreateQualifiedSelectionForTestCase ( tdo ) ;
@@ -2775,7 +2808,6 @@ private static void InitializeTestDataObject(RenameTestsDataObject tdo
2775
2808
, $ "Target aquired ({ tdo . RenameModel . Target . IdentifierName } does not equal name specified ({ tdo . OriginalName } ) in the test") ;
2776
2809
2777
2810
var factory = SetupFactory ( tdo . RenameModel ) ;
2778
-
2779
2811
tdo . RenameRefactoringUnderTest = new RenameRefactoring ( tdo . VBE , factory . Object , tdo . MsgBox . Object , tdo . ParserState , tdo . ParserState . ProjectsProvider , tdo . RewritingManager ) ;
2780
2812
}
2781
2813
@@ -2854,10 +2886,17 @@ private static void CreateQualifiedSelectionForTestCase(RenameTestsDataObject td
2854
2886
Assert . Inconclusive ( $ "Unable to find target '{ FAUX_CURSOR } ' in { tdo . SelectionModuleName } content.") ;
2855
2887
}
2856
2888
2857
- private static IVBE BuildProject ( string projectName , List < RenameTestModuleDefinition > testComponents )
2889
+ private static IVBE BuildProject ( string projectName , List < RenameTestModuleDefinition > testComponents , bool useLibraries = false )
2858
2890
{
2859
2891
var builder = new MockVbeBuilder ( ) ;
2860
2892
var enclosingProjectBuilder = builder . ProjectBuilder ( projectName , ProjectProtection . Unprotected ) ;
2893
+
2894
+ if ( useLibraries )
2895
+ {
2896
+ enclosingProjectBuilder . AddReference ( "VBA" , MockVbeBuilder . LibraryPathVBA , 4 , 1 , true ) ;
2897
+ enclosingProjectBuilder . AddReference ( "EXCEL" , MockVbeBuilder . LibraryPathMsExcel , 1 , 8 , true ) ;
2898
+ }
2899
+
2861
2900
foreach ( var comp in testComponents )
2862
2901
{
2863
2902
if ( comp . ModuleType == ComponentType . UserForm )
@@ -2961,6 +3000,7 @@ public RenameTestsDataObject(string selection, string newName)
2961
3000
OriginalName = selection ;
2962
3001
ModuleTestSetupDefs = new List < RenameTestModuleDefinition > ( ) ;
2963
3002
RenameRefactoringUnderTest = null ;
3003
+ UseLibraries = false ;
2964
3004
}
2965
3005
2966
3006
public IVBE VBE { get ; set ; }
@@ -2978,6 +3018,8 @@ public RenameTestsDataObject(string selection, string newName)
2978
3018
public List < RenameTestModuleDefinition > ModuleTestSetupDefs { get ; set ; }
2979
3019
public string OriginalName { get ; set ; }
2980
3020
public RenameRefactoring RenameRefactoringUnderTest { get ; set ; }
3021
+ public Action < RenameTestsDataObject > AdditionalSetup { get ; set ; }
3022
+ public bool UseLibraries { get ; set ; }
2981
3023
}
2982
3024
#endregion
2983
3025
}
0 commit comments