1
- using System ;
2
1
using System . Linq ;
3
- using System . Threading ;
4
2
using NUnit . Framework ;
5
3
using Rubberduck . Inspections . Concrete ;
6
4
using Rubberduck . Parsing . Inspections . Abstract ;
7
- using Rubberduck . Parsing . Symbols ;
8
5
using Rubberduck . Parsing . VBA ;
9
6
using Rubberduck . VBEditor ;
10
7
using Rubberduck . VBEditor . SafeComWrappers ;
11
- using RubberduckTests . Mocks ;
12
8
13
9
namespace RubberduckTests . Inspections
14
10
{
@@ -144,7 +140,7 @@ Dim target As String
144
140
target = Range(""A1"")
145
141
target.Value = ""all good""
146
142
End Sub" ;
147
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "Excel.1.8.xml " ) ;
143
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "Excel" ) ;
148
144
}
149
145
150
146
[ Test ]
@@ -160,7 +156,7 @@ Dim target As Collection
160
156
testParam = target
161
157
testParam.Add 100
162
158
End Sub" ;
163
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "VBA.4.2.xml " ) ;
159
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "VBA" ) ;
164
160
}
165
161
166
162
[ Test ]
@@ -196,7 +192,7 @@ public void ObjectVariableNotSet_GivenVariantVariableAssignedNewObject_ReturnsRe
196
192
Private Sub TestSub(ByRef testParam As Variant)
197
193
testParam = New Collection
198
194
End Sub" ;
199
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "VBA.4.2.xml " ) ;
195
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "VBA" ) ;
200
196
}
201
197
202
198
[ Test ]
@@ -229,7 +225,7 @@ Dim target As Range
229
225
target.Value = ""forgot something?""
230
226
231
227
End Sub" ;
232
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "Excel.1.8.xml " ) ;
228
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "Excel" ) ;
233
229
}
234
230
235
231
[ Test ]
@@ -247,7 +243,7 @@ Dim target As Range
247
243
target.Value = ""All good""
248
244
249
245
End Sub" ;
250
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "Excel.1.8.xml " ) ;
246
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "Excel" ) ;
251
247
}
252
248
253
249
[ Test ]
@@ -289,7 +285,7 @@ Private Sub TestSelfAssigned()
289
285
Dim arg1 As new Collection
290
286
arg1.Add 7
291
287
End Sub" ;
292
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "VBA.4.2.xml " ) ;
288
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "VBA" ) ;
293
289
}
294
290
295
291
[ Test ]
@@ -346,7 +342,7 @@ public void ObjectVariableNotSet_FunctionReturnNotSet_ReturnsResult()
346
342
Private Function Test() As Collection
347
343
Test = New Collection
348
344
End Function" ;
349
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "VBA.4.2.xml " ) ;
345
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "VBA" ) ;
350
346
}
351
347
352
348
[ Test ]
@@ -497,7 +493,7 @@ Dim bar As Collection
497
493
bar.Add ""x"", ""x""
498
494
foo = ""Test"" & bar.Item(""x"")
499
495
End Sub" ;
500
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "VBA.4.2 " ) ;
496
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "VBA" ) ;
501
497
}
502
498
503
499
[ Test ]
@@ -531,7 +527,7 @@ Dim foo As Range
531
527
Dim bar As Variant
532
528
bar = foo
533
529
End Sub" ;
534
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "Excel.1.8.xml " ) ;
530
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "Excel" ) ;
535
531
}
536
532
537
533
[ Test ]
@@ -547,7 +543,7 @@ Dim bar As Variant
547
543
bar = foo
548
544
End Sub" ;
549
545
//The default member of Recordset is Fields, which is an object.
550
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "ADODB.6.1 " ) ;
546
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "ADODB" ) ;
551
547
}
552
548
553
549
[ Test ]
@@ -563,7 +559,7 @@ Dim bar As Variant
563
559
foo = bar
564
560
End Sub" ;
565
561
//The default member of Recordset is Fields, which is an object and only has a paramterized default member.
566
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "ADODB.6.1 " ) ;
562
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "ADODB" ) ;
567
563
}
568
564
569
565
[ Test ]
@@ -577,7 +573,7 @@ Private Sub Test()
577
573
Dim foo As Variant
578
574
foo = New Connection
579
575
End Sub" ;
580
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "ADODB.6.1 " ) ;
576
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "ADODB" ) ;
581
577
}
582
578
583
579
[ Test ]
@@ -592,7 +588,7 @@ Dim foo As Variant
592
588
foo = New Recordset
593
589
End Sub" ;
594
590
//The default member of Recordset is Fields, which is an object.
595
- AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "ADODB.6.1 " ) ;
591
+ AssertInputCodeYieldsExpectedInspectionResultCount ( input , expectResultCount , "ADODB" ) ;
596
592
}
597
593
598
594
[ Test ]
@@ -762,12 +758,11 @@ Private Sub Baz(arg As Variant)
762
758
End Sub
763
759
" ;
764
760
765
- var vbe = MockVbeBuilder . BuildFromModules (
761
+ var inspectionResults = InspectionResultsForModules (
766
762
( "Class1" , class1Code , ComponentType . ClassModule ) ,
767
763
( "Class2" , class2Code , ComponentType . ClassModule ) ,
768
764
( "Module1" , moduleCode , ComponentType . StandardModule ) ) ;
769
765
770
- var inspectionResults = InspectionResults ( vbe . Object ) ;
771
766
Assert . IsFalse ( inspectionResults . Any ( ) ) ;
772
767
}
773
768
@@ -850,12 +845,11 @@ Private Sub Baz(arg As Variant)
850
845
End Sub
851
846
" ;
852
847
853
- var vbe = MockVbeBuilder . BuildFromModules (
848
+ var inspectionResults = InspectionResultsForModules (
854
849
( "Class1" , class1Code , ComponentType . ClassModule ) ,
855
850
( "Class2" , class2Code , ComponentType . ClassModule ) ,
856
851
( "Module1" , moduleCode , ComponentType . StandardModule ) ) ;
857
852
858
- var inspectionResults = InspectionResults ( vbe . Object ) ;
859
853
Assert . IsFalse ( inspectionResults . Any ( ) ) ;
860
854
}
861
855
@@ -942,13 +936,12 @@ Private Sub Baz(arg As Variant)
942
936
End Sub
943
937
" ;
944
938
945
- var vbe = MockVbeBuilder . BuildFromModules (
939
+ var inspectionResults = InspectionResultsForModules (
946
940
( "Class1" , class1Code , ComponentType . ClassModule ) ,
947
941
( "Class2" , class2Code , ComponentType . ClassModule ) ,
948
942
( "Class3" , class3Code , ComponentType . ClassModule ) ,
949
943
( "Module1" , moduleCode , ComponentType . StandardModule ) ) ;
950
944
951
- var inspectionResults = InspectionResults ( vbe . Object ) ;
952
945
Assert . IsFalse ( inspectionResults . Any ( ) ) ;
953
946
}
954
947
@@ -1035,13 +1028,12 @@ Private Sub Baz(arg As Variant)
1035
1028
End Sub
1036
1029
" ;
1037
1030
1038
- var vbe = MockVbeBuilder . BuildFromModules (
1031
+ var inspectionResults = InspectionResultsForModules (
1039
1032
( "Class1" , class1Code , ComponentType . ClassModule ) ,
1040
1033
( "Class2" , class2Code , ComponentType . ClassModule ) ,
1041
1034
( "Class3" , class3Code , ComponentType . ClassModule ) ,
1042
1035
( "Module1" , moduleCode , ComponentType . StandardModule ) ) ;
1043
1036
1044
- var inspectionResults = InspectionResults ( vbe . Object ) ;
1045
1037
Assert . IsFalse ( inspectionResults . Any ( ) ) ;
1046
1038
}
1047
1039
@@ -1128,13 +1120,12 @@ Private Sub Baz(arg As Variant)
1128
1120
End Sub
1129
1121
" ;
1130
1122
1131
- var vbe = MockVbeBuilder . BuildFromModules (
1123
+ var inspectionResults = InspectionResultsForModules (
1132
1124
( "Class1" , class1Code , ComponentType . ClassModule ) ,
1133
1125
( "Class2" , class2Code , ComponentType . ClassModule ) ,
1134
1126
( "Class3" , class3Code , ComponentType . ClassModule ) ,
1135
1127
( "Module1" , moduleCode , ComponentType . StandardModule ) ) ;
1136
1128
1137
- var inspectionResults = InspectionResults ( vbe . Object ) ;
1138
1129
Assert . IsFalse ( inspectionResults . Any ( ) ) ;
1139
1130
}
1140
1131
@@ -1186,13 +1177,12 @@ Private Sub Baz(arg As Variant)
1186
1177
End Sub
1187
1178
" ;
1188
1179
1189
- var vbe = MockVbeBuilder . BuildFromModules (
1180
+ var inspectionResults = InspectionResultsForModules (
1190
1181
( "Class1" , class1Code , ComponentType . ClassModule ) ,
1191
1182
( "Class2" , class2Code , ComponentType . ClassModule ) ,
1192
1183
( "Class3" , class3Code , ComponentType . ClassModule ) ,
1193
1184
( "Module1" , moduleCode , ComponentType . StandardModule ) ) ;
1194
1185
1195
- var inspectionResults = InspectionResults ( vbe . Object ) ;
1196
1186
var inspectionResult = inspectionResults . Single ( ) ;
1197
1187
1198
1188
var expectedSelection = new Selection ( 6 , selectionStartColumn , 6 , selectionEndColumn ) ;
@@ -1249,13 +1239,12 @@ Private Sub Baz(arg As Variant)
1249
1239
End Sub
1250
1240
" ;
1251
1241
1252
- var vbe = MockVbeBuilder . BuildFromModules (
1242
+ var inspectionResults = InspectionResultsForModules (
1253
1243
( "Class1" , class1Code , ComponentType . ClassModule ) ,
1254
1244
( "Class2" , class2Code , ComponentType . ClassModule ) ,
1255
1245
( "Class3" , class3Code , ComponentType . ClassModule ) ,
1256
1246
( "Module1" , moduleCode , ComponentType . StandardModule ) ) ;
1257
1247
1258
- var inspectionResults = InspectionResults ( vbe . Object ) ;
1259
1248
var inspectionResult = inspectionResults . Single ( ) ;
1260
1249
1261
1250
var expectedSelection = new Selection ( 6 , selectionStartColumn , 6 , selectionEndColumn ) ;
@@ -1312,13 +1301,12 @@ Private Sub Baz(arg As Variant)
1312
1301
End Sub
1313
1302
" ;
1314
1303
1315
- var vbe = MockVbeBuilder . BuildFromModules (
1304
+ var inspectionResults = InspectionResultsForModules (
1316
1305
( "Class1" , class1Code , ComponentType . ClassModule ) ,
1317
1306
( "Class2" , class2Code , ComponentType . ClassModule ) ,
1318
1307
( "Class3" , class3Code , ComponentType . ClassModule ) ,
1319
1308
( "Module1" , moduleCode , ComponentType . StandardModule ) ) ;
1320
1309
1321
- var inspectionResults = InspectionResults ( vbe . Object ) ;
1322
1310
var inspectionResult = inspectionResults . Single ( ) ;
1323
1311
1324
1312
var expectedSelection = new Selection ( 6 , selectionStartColumn , 6 , selectionEndColumn ) ;
@@ -1364,12 +1352,11 @@ Private Sub Baz(arg As Variant)
1364
1352
End Sub
1365
1353
" ;
1366
1354
1367
- var vbe = MockVbeBuilder . BuildFromModules (
1355
+ var inspectionResults = InspectionResultsForModules (
1368
1356
( "Class1" , class1Code , ComponentType . ClassModule ) ,
1369
1357
( "Class2" , class2Code , ComponentType . ClassModule ) ,
1370
1358
( "Module1" , moduleCode , ComponentType . StandardModule ) ) ;
1371
1359
1372
- var inspectionResults = InspectionResults ( vbe . Object ) ;
1373
1360
var inspectionResult = inspectionResults . Single ( ) ;
1374
1361
1375
1362
var expectedSelection = new Selection ( 4 , selectionStartColumn , 4 , selectionEndColumn ) ;
@@ -1410,13 +1397,11 @@ Dim fooBar As New Class1
1410
1397
End Function
1411
1398
" ;
1412
1399
1413
- var vbe = MockVbeBuilder . BuildFromModules (
1400
+ var inspectionResults = InspectionResultsForModules (
1414
1401
( "Class1" , class1Code , ComponentType . ClassModule ) ,
1415
1402
( "Class2" , class2Code , ComponentType . ClassModule ) ,
1416
1403
( "Module1" , moduleCode , ComponentType . StandardModule ) ) ;
1417
1404
1418
- var inspectionResults = InspectionResults ( vbe . Object ) ;
1419
-
1420
1405
Assert . IsFalse ( inspectionResults . Any ( ) ) ;
1421
1406
}
1422
1407
@@ -1427,30 +1412,8 @@ protected override IInspection InspectionUnderTest(RubberduckParserState state)
1427
1412
1428
1413
private void AssertInputCodeYieldsExpectedInspectionResultCount ( string inputCode , int expected , params string [ ] testLibraries )
1429
1414
{
1430
- var builder = new MockVbeBuilder ( ) ;
1431
- var projectBuilder = builder . ProjectBuilder ( "TestProject1" , "TestProject1" , ProjectProtection . Unprotected )
1432
- . AddComponent ( "Class1" , ComponentType . ClassModule , inputCode ) ;
1433
-
1434
- foreach ( var testLibrary in testLibraries )
1435
- {
1436
- var libraryDescriptionComponents = testLibrary . Split ( '.' ) ;
1437
- var libraryName = libraryDescriptionComponents [ 0 ] ;
1438
- var libraryPath = MockVbeBuilder . LibraryPaths [ libraryName ] ;
1439
- int majorVersion = Int32 . Parse ( libraryDescriptionComponents [ 1 ] ) ;
1440
- int minorVersion = Int32 . Parse ( libraryDescriptionComponents [ 2 ] ) ;
1441
- projectBuilder . AddReference ( libraryName , libraryPath , majorVersion , minorVersion , true ) ;
1442
- }
1443
-
1444
- var project = projectBuilder . Build ( ) ;
1445
- var vbe = builder . AddProject ( project ) . Build ( ) ;
1446
-
1447
- using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
1448
- {
1449
- var inspection = InspectionUnderTest ( state ) ;
1450
- var inspectionResults = inspection . GetInspectionResults ( CancellationToken . None ) ;
1451
-
1452
- Assert . AreEqual ( expected , inspectionResults . Count ( ) ) ;
1453
- }
1415
+ var inspectionResults = InspectionResultsForModules ( ( "Class1" , inputCode , ComponentType . ClassModule ) , testLibraries ) ;
1416
+ Assert . AreEqual ( expected , inspectionResults . Count ( ) ) ;
1454
1417
}
1455
1418
}
1456
1419
}
0 commit comments