File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
Rubberduck.Parsing/Symbols
RubberduckTests/Inspections Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,11 @@ public override void EnterRedimStmt(VBAParser.RedimStmtContext context)
169
169
_resolver . Resolve ( context ) ;
170
170
}
171
171
172
+ public override void EnterNameStmt ( VBAParser . NameStmtContext context )
173
+ {
174
+ _resolver . Resolve ( context ) ;
175
+ }
176
+
172
177
public override void EnterEraseStmt ( VBAParser . EraseStmtContext context )
173
178
{
174
179
_resolver . Resolve ( context ) ;
Original file line number Diff line number Diff line change @@ -380,6 +380,14 @@ public void Resolve(VBAParser.EraseStmtContext context)
380
380
}
381
381
}
382
382
383
+ public void Resolve ( VBAParser . NameStmtContext context )
384
+ {
385
+ foreach ( var expr in context . expression ( ) )
386
+ {
387
+ ResolveDefault ( expr ) ;
388
+ }
389
+ }
390
+
383
391
private void ResolveFileNumber ( VBAParser . FileNumberContext fileNumber )
384
392
{
385
393
if ( fileNumber . markedFileNumber ( ) != null )
Original file line number Diff line number Diff line change @@ -162,6 +162,33 @@ Dim var1 As String
162
162
Assert . IsFalse ( inspectionResults . Any ( ) ) ;
163
163
}
164
164
165
+ [ TestMethod ]
166
+ [ TestCategory ( "Inspections" ) ]
167
+ public void VariableNotUsed_DoesNotReturnsResult_UsedInNameStatement ( )
168
+ {
169
+ const string inputCode =
170
+ @"Sub Foo()
171
+ Dim var1 As String
172
+ Name ""foo"" As var1
173
+ End Sub" ;
174
+
175
+ //Arrange
176
+ var builder = new MockVbeBuilder ( ) ;
177
+ IVBComponent component ;
178
+ var vbe = builder . BuildFromSingleStandardModule ( inputCode , out component ) ;
179
+ var mockHost = new Mock < IHostApplication > ( ) ;
180
+ mockHost . SetupAllProperties ( ) ;
181
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
182
+
183
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
184
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
185
+
186
+ var inspection = new VariableNotUsedInspection ( parser . State ) ;
187
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
188
+
189
+ Assert . IsFalse ( inspectionResults . Any ( ) ) ;
190
+ }
191
+
165
192
[ TestMethod ]
166
193
[ TestCategory ( "Inspections" ) ]
167
194
public void UnassignedVariable_QuickFixWorks ( )
You can’t perform that action at this time.
0 commit comments