@@ -39,5 +39,90 @@ Dim bb As Boolean
39
39
Assert . AreEqual ( expectedCode , state . GetRewriter ( component ) . GetText ( ) ) ;
40
40
}
41
41
}
42
+
43
+ // See https://github.com/rubberduck-vba/Rubberduck/issues/3636
44
+ [ Test ]
45
+ [ Category ( "QuickFixes" ) ]
46
+ public void UnassignedVariableUsage_QuickFixWorksWithBlock ( )
47
+ {
48
+ const string inputCode =
49
+ @"Sub test()
50
+ Dim wb As Workbook
51
+ With wb
52
+ Debug.Print .Name
53
+ Debug.Print .Name
54
+ Debug.Print .Name
55
+ End With
56
+ End Sub" ;
57
+
58
+ const string expectedCode =
59
+ @"Sub test()
60
+ Dim wb As Workbook
61
+ 'TODO - {0}
62
+ ' With wb
63
+ ' Debug.Print .Name
64
+ ' Debug.Print .Name
65
+ ' Debug.Print .Name
66
+ ' End With
67
+ End Sub" ;
68
+
69
+ var vbe = MockVbeBuilder . BuildFromSingleStandardModule ( inputCode , out var component ) ;
70
+ using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
71
+ {
72
+ var inspection = new UnassignedVariableUsageInspection ( state ) ;
73
+ var inspectionResult = inspection . GetInspectionResults ( CancellationToken . None ) . First ( ) ;
74
+ var expected = string . Format ( expectedCode , inspectionResult . Description ) ;
75
+
76
+ new RemoveUnassignedVariableUsageQuickFix ( state ) . Fix ( inspectionResult ) ;
77
+ var actual = state . GetRewriter ( component ) . GetText ( ) ;
78
+ Assert . AreEqual ( expected , actual ) ;
79
+ }
80
+ }
81
+
82
+ [ Test ]
83
+ [ Category ( "QuickFixes" ) ]
84
+ public void UnassignedVariableUsage_QuickFixWorksNestedWithBlock ( )
85
+ {
86
+ const string inputCode =
87
+ @"Sub test()
88
+ Dim wb As Workbook
89
+ Dim ws As Worksheet
90
+ With wb
91
+ Debug.Print .Name
92
+ With ws
93
+ Debug.Print .Name
94
+ Debug.Print .Name
95
+ Debug.Print .Name
96
+ End With
97
+ End With
98
+ End Sub" ;
99
+
100
+ const string expectedCode =
101
+ @"Sub test()
102
+ Dim wb As Workbook
103
+ Dim ws As Worksheet
104
+ With wb
105
+ Debug.Print .Name
106
+ 'TODO - {0}
107
+ ' With ws
108
+ ' Debug.Print .Name
109
+ ' Debug.Print .Name
110
+ ' Debug.Print .Name
111
+ ' End With
112
+ End With
113
+ End Sub" ;
114
+
115
+ var vbe = MockVbeBuilder . BuildFromSingleStandardModule ( inputCode , out var component ) ;
116
+ using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
117
+ {
118
+ var inspection = new UnassignedVariableUsageInspection ( state ) ;
119
+ var inspectionResult = inspection . GetInspectionResults ( CancellationToken . None ) . First ( ) ;
120
+ var expected = string . Format ( expectedCode , inspectionResult . Description ) ;
121
+
122
+ new RemoveUnassignedVariableUsageQuickFix ( state ) . Fix ( inspectionResult ) ;
123
+ var actual = state . GetRewriter ( component ) . GetText ( ) ;
124
+ Assert . AreEqual ( expected , actual ) ;
125
+ }
126
+ }
42
127
}
43
128
}
0 commit comments