@@ -46,16 +46,21 @@ Dim bb As Boolean
46
46
Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
47
47
}
48
48
49
+ // this test will eventually be removed once we can fire the inspection on a specific reference
49
50
[ TestMethod ]
50
51
[ TestCategory ( "Inspections" ) ]
51
- public void UnassignedVariableUsage_DoesNotReturnResult ( )
52
+ public void UnassignedVariableUsage_ReturnsSingleResult_MultipleReferences ( )
52
53
{
53
54
const string inputCode =
54
- @"Sub Foo()
55
- Dim b As Boolean
56
- Dim bb As Boolean
57
- b = True
58
- bb = b
55
+ @"Sub tester()
56
+ Dim myarr() As Variant
57
+ Dim i As Long
58
+
59
+ ReDim myarr(1 To 10)
60
+
61
+ For i = LBound(myarr) To UBound(myarr)
62
+ Next
63
+
59
64
End Sub" ;
60
65
61
66
//Arrange
@@ -75,19 +80,18 @@ Dim bb As Boolean
75
80
var inspection = new UnassignedVariableUsageInspection ( parser . State ) ;
76
81
var inspectionResults = inspection . GetInspectionResults ( ) ;
77
82
78
- Assert . IsFalse ( inspectionResults . Any ( ) ) ;
83
+ Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
79
84
}
80
85
81
86
[ TestMethod ]
82
87
[ TestCategory ( "Inspections" ) ]
83
- public void UnassignedVariableUsage_Ignored_DoesNotReturnResult ( )
88
+ public void UnassignedVariableUsage_DoesNotReturnResult ( )
84
89
{
85
90
const string inputCode =
86
91
@"Sub Foo()
87
92
Dim b As Boolean
88
93
Dim bb As Boolean
89
-
90
- '@Ignore UnassignedVariableUsage
94
+ b = True
91
95
bb = b
92
96
End Sub" ;
93
97
@@ -113,28 +117,24 @@ Dim bb As Boolean
113
117
114
118
[ TestMethod ]
115
119
[ TestCategory ( "Inspections" ) ]
116
- public void UnassignedVariableUsage_QuickFixWorks ( )
120
+ public void UnassignedVariableUsage_Ignored_DoesNotReturnResult ( )
117
121
{
118
122
const string inputCode =
119
123
@"Sub Foo()
124
+ '@Ignore UnassignedVariableUsage
120
125
Dim b As Boolean
121
126
Dim bb As Boolean
122
- bb = b
123
- End Sub" ;
124
127
125
- const string expectedCode =
126
- @"Sub Foo()
127
- Dim b As Boolean
128
- Dim bb As Boolean
129
- TODOTODO = TODO
128
+ bb = b
130
129
End Sub" ;
131
130
132
131
//Arrange
133
132
var builder = new MockVbeBuilder ( ) ;
134
- VBComponent component ;
135
- var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
136
- var project = vbe . Object . VBProjects . Item ( 0 ) ;
137
- var module = project . VBComponents . Item ( 0 ) . CodeModule ;
133
+ var project = builder . ProjectBuilder ( "VBAProject" , vbext_ProjectProtection . vbext_pp_none )
134
+ . AddComponent ( "MyClass" , vbext_ComponentType . vbext_ct_ClassModule , inputCode )
135
+ . Build ( ) ;
136
+ var vbe = builder . AddProject ( project ) . Build ( ) ;
137
+
138
138
var mockHost = new Mock < IHostApplication > ( ) ;
139
139
mockHost . SetupAllProperties ( ) ;
140
140
var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
@@ -145,11 +145,49 @@ Dim bb As Boolean
145
145
var inspection = new UnassignedVariableUsageInspection ( parser . State ) ;
146
146
var inspectionResults = inspection . GetInspectionResults ( ) ;
147
147
148
- inspectionResults . First ( ) . QuickFixes . First ( ) . Fix ( ) ;
149
-
150
- Assert . AreEqual ( expectedCode , module . Lines ( ) ) ;
148
+ Assert . IsFalse ( inspectionResults . Any ( ) ) ;
151
149
}
152
150
151
+ // Ignored until we can reinstate the quick fix on a specific reference
152
+ // [TestMethod]
153
+ // [TestCategory("Inspections")]
154
+ // public void UnassignedVariableUsage_QuickFixWorks()
155
+ // {
156
+ // const string inputCode =
157
+ //@"Sub Foo()
158
+ // Dim b As Boolean
159
+ // Dim bb As Boolean
160
+ // bb = b
161
+ //End Sub";
162
+
163
+ // const string expectedCode =
164
+ //@"Sub Foo()
165
+ // Dim b As Boolean
166
+ // Dim bb As Boolean
167
+ // TODOTODO = TODO
168
+ //End Sub";
169
+
170
+ // //Arrange
171
+ // var builder = new MockVbeBuilder();
172
+ // VBComponent component;
173
+ // var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
174
+ // var project = vbe.Object.VBProjects.Item(0);
175
+ // var module = project.VBComponents.Item(0).CodeModule;
176
+ // var mockHost = new Mock<IHostApplication>();
177
+ // mockHost.SetupAllProperties();
178
+ // var parser = MockParser.Create(vbe.Object, new RubberduckParserState(new Mock<ISinks>().Object));
179
+
180
+ // parser.Parse(new CancellationTokenSource());
181
+ // if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
182
+
183
+ // var inspection = new UnassignedVariableUsageInspection(parser.State);
184
+ // var inspectionResults = inspection.GetInspectionResults();
185
+
186
+ // inspectionResults.First().QuickFixes.First().Fix();
187
+
188
+ // Assert.AreEqual(expectedCode, module.Lines());
189
+ // }
190
+
153
191
[ TestMethod ]
154
192
[ TestCategory ( "Inspections" ) ]
155
193
public void UnassignedVariableUsage_IgnoreQuickFixWorks ( )
@@ -163,9 +201,9 @@ Dim bb As Boolean
163
201
164
202
const string expectedCode =
165
203
@"Sub Foo()
204
+ '@Ignore UnassignedVariableUsage
166
205
Dim b As Boolean
167
206
Dim bb As Boolean
168
- '@Ignore UnassignedVariableUsage
169
207
bb = b
170
208
End Sub" ;
171
209
0 commit comments