@@ -60,7 +60,7 @@ private RubberduckParserState Resolve(params string[] classes)
60
60
return parser . State ;
61
61
}
62
62
63
- private RubberduckParserState Resolve ( params Tuple < string , vbext_ComponentType > [ ] components )
63
+ private RubberduckParserState Resolve ( params Tuple < string , vbext_ComponentType > [ ] components )
64
64
{
65
65
var builder = new MockVbeBuilder ( ) ;
66
66
var projectBuilder = builder . ProjectBuilder ( "TestProject" , vbext_ProjectProtection . vbext_pp_none ) ;
@@ -107,6 +107,52 @@ End Function
107
107
Assert . AreEqual ( 1 , declaration . References . Count ( item => item . IsAssignment ) ) ;
108
108
}
109
109
110
+ [ TestMethod ]
111
+ public void TypeOfIsExpression_BooleanExpressionIsReferenceToLocalVariable ( )
112
+ {
113
+ // arrange
114
+ var code_class1 = @"
115
+ Public Function Foo() As String
116
+ Dim a As Object
117
+ anything = TypeOf a Is Class2
118
+ End Function
119
+ " ;
120
+ // We only use the second class as as target of the type expression, its contents don't matter.
121
+ var code_class2 = string . Empty ;
122
+
123
+ // act
124
+ var state = Resolve ( code_class1 , code_class2 ) ;
125
+
126
+ // assert
127
+ var declaration = state . AllUserDeclarations . Single ( item =>
128
+ item . DeclarationType == DeclarationType . Variable && item . IdentifierName == "a" ) ;
129
+
130
+ Assert . AreEqual ( 1 , declaration . References . Count ( ) ) ;
131
+ }
132
+
133
+ [ TestMethod ]
134
+ public void TypeOfIsExpression_TypeExpressionIsReferenceToClass ( )
135
+ {
136
+ // arrange
137
+ var code_class1 = @"
138
+ Public Function Foo() As String
139
+ Dim a As Object
140
+ anything = TypeOf a Is Class2
141
+ End Function
142
+ " ;
143
+ // We only use the second class as as target of the type expression, its contents don't matter.
144
+ var code_class2 = string . Empty ;
145
+
146
+ // act
147
+ var state = Resolve ( code_class1 , code_class2 ) ;
148
+
149
+ // assert
150
+ var declaration = state . AllUserDeclarations . Single ( item =>
151
+ item . DeclarationType == DeclarationType . ClassModule && item . IdentifierName == "Class2" ) ;
152
+
153
+ Assert . AreEqual ( 1 , declaration . References . Count ( ) ) ;
154
+ }
155
+
110
156
[ TestMethod ]
111
157
public void FunctionCall_IsReferenceToFunctionDeclaration ( )
112
158
{
@@ -285,18 +331,18 @@ Public foo As Integer
285
331
" ;
286
332
var class1 = Tuple . Create ( code_class1 , vbext_ComponentType . vbext_ct_ClassModule ) ;
287
333
var class2 = Tuple . Create ( code_class2 , vbext_ComponentType . vbext_ct_ClassModule ) ;
288
-
334
+
289
335
// act
290
336
var state = Resolve ( class1 , class2 ) ;
291
-
337
+
292
338
// assert
293
339
var declaration = state . AllUserDeclarations . Single ( item => item . DeclarationType == DeclarationType . Variable && item . IdentifierName == "foo" ) ;
294
-
340
+
295
341
var reference = declaration . References . SingleOrDefault ( item => item . IsAssignment ) ;
296
342
Assert . IsNull ( reference ) ;
297
343
}
298
344
299
- [ TestMethod ]
345
+ [ TestMethod ]
300
346
public void PublicVariableCall_IsReferenceToVariableDeclaration ( )
301
347
{
302
348
// arrange
@@ -311,7 +357,7 @@ Public foo As Integer
311
357
" ;
312
358
// act
313
359
var state = Resolve (
314
- Tuple . Create ( code_class1 , vbext_ComponentType . vbext_ct_ClassModule ) ,
360
+ Tuple . Create ( code_class1 , vbext_ComponentType . vbext_ct_ClassModule ) ,
315
361
Tuple . Create ( code_class2 , vbext_ComponentType . vbext_ct_StdModule ) ) ;
316
362
317
363
// assert
@@ -451,7 +497,7 @@ End Sub
451
497
var declaration = state . AllUserDeclarations . Single ( item =>
452
498
item . DeclarationType == DeclarationType . Parameter && item . IdentifierName == "foo" ) ;
453
499
454
- Assert . IsNotNull ( declaration . References . SingleOrDefault ( item =>
500
+ Assert . IsNotNull ( declaration . References . SingleOrDefault ( item =>
455
501
item . ParentScoping . IdentifierName == "DoSomething" ) ) ;
456
502
}
457
503
@@ -768,7 +814,7 @@ End Sub
768
814
769
815
// assert
770
816
var declaration = state . AllUserDeclarations . Single ( item =>
771
- item . DeclarationType == DeclarationType . Parameter
817
+ item . DeclarationType == DeclarationType . Parameter
772
818
&& item . IdentifierName == "values"
773
819
&& item . IsArray ) ;
774
820
@@ -927,7 +973,7 @@ End Sub
927
973
&& item . ParentDeclaration . IdentifierName == "FooBarBaz" ) ;
928
974
929
975
Assert . IsNotNull ( declaration . References . SingleOrDefault ( item =>
930
- ! item . IsAssignment
976
+ ! item . IsAssignment
931
977
&& item . ParentScoping . IdentifierName == "DoSomething"
932
978
&& item . ParentScoping . DeclarationType == DeclarationType . Procedure ) ) ;
933
979
@@ -984,7 +1030,7 @@ End Sub
984
1030
item . DeclarationType == DeclarationType . Enumeration
985
1031
&& item . IdentifierName == "FooBarBaz" ) ;
986
1032
987
- Assert . IsNotNull ( declaration . References . SingleOrDefault ( item =>
1033
+ Assert . IsNotNull ( declaration . References . SingleOrDefault ( item =>
988
1034
item . ParentScoping . IdentifierName == "DoSomething"
989
1035
&& item . ParentScoping . DeclarationType == DeclarationType . Procedure ) ) ;
990
1036
}
@@ -1029,7 +1075,7 @@ Private Function Foo(ByVal bar As Integer)
1029
1075
1030
1076
var state = Resolve ( code ) ;
1031
1077
1032
- var declaration = state . AllUserDeclarations . Single ( item =>
1078
+ var declaration = state . AllUserDeclarations . Single ( item =>
1033
1079
item . DeclarationType == DeclarationType . Variable
1034
1080
&& item . IsArray
1035
1081
&& item . ParentScopeDeclaration . IdentifierName == "DoSomething" ) ;
@@ -1212,7 +1258,7 @@ End Sub
1212
1258
if ( declaration . Project . Name != declaration . AsTypeName )
1213
1259
{
1214
1260
Assert . Inconclusive ( "variable should be named after project." ) ;
1215
- }
1261
+ }
1216
1262
var usages = declaration . References ;
1217
1263
1218
1264
Assert . AreEqual ( 2 , usages . Count ( ) ) ;
@@ -1239,7 +1285,7 @@ End Sub
1239
1285
item . DeclarationType == DeclarationType . UserDefinedTypeMember
1240
1286
&& item . IdentifierName == "Foo" ) ;
1241
1287
1242
- var usages = declaration . References . Where ( item =>
1288
+ var usages = declaration . References . Where ( item =>
1243
1289
item . ParentScoping . IdentifierName == "DoSomething" ) ;
1244
1290
1245
1291
Assert . AreEqual ( 1 , usages . Count ( ) ) ;
@@ -1272,12 +1318,12 @@ End Sub
1272
1318
&& item . AsTypeName == item . Project . Name
1273
1319
&& item . IdentifierName == item . ParentDeclaration . IdentifierName ) ;
1274
1320
1275
- var usages = declaration . References . Where ( item =>
1321
+ var usages = declaration . References . Where ( item =>
1276
1322
item . ParentScoping . IdentifierName == "DoSomething" ) ;
1277
1323
1278
1324
Assert . AreEqual ( 2 , usages . Count ( ) ) ;
1279
1325
}
1280
-
1326
+
1281
1327
[ TestMethod ]
1282
1328
public void GivenUDT_NamedAfterModule_LocalAsTypeResolvesToUDT ( )
1283
1329
{
@@ -1303,7 +1349,7 @@ End Sub
1303
1349
item . DeclarationType == DeclarationType . UserDefinedType
1304
1350
&& item . IdentifierName == item . ComponentName ) ;
1305
1351
1306
- var usages = declaration . References . Where ( item =>
1352
+ var usages = declaration . References . Where ( item =>
1307
1353
item . ParentScoping . IdentifierName == "DoSomething" ) ;
1308
1354
1309
1355
Assert . AreEqual ( 1 , usages . Count ( ) ) ;
0 commit comments