3
3
using Rubberduck . Inspections . Concrete . UnreachableCaseInspection ;
4
4
using Rubberduck . Parsing ;
5
5
using Rubberduck . Parsing . Grammar ;
6
+ using Rubberduck . Parsing . Inspections . Abstract ;
6
7
using Rubberduck . Parsing . Symbols ;
7
- using Rubberduck . Resources . Inspections ;
8
+ using Rubberduck . Parsing . VBA ;
8
9
using Rubberduck . VBEditor . SafeComWrappers ;
9
10
using Rubberduck . VBEditor . SafeComWrappers . Abstract ;
10
11
using RubberduckTests . Mocks ;
15
16
namespace RubberduckTests . Inspections . UnreachableCase
16
17
{
17
18
[ TestFixture ]
18
- public class UnreachableCaseInspectionTests
19
+ public class UnreachableCaseInspectionTests : InspectionTestsBase
19
20
{
20
21
private IUnreachableCaseInspectionFactoryProvider _factoryProvider ;
21
22
@@ -1896,10 +1897,10 @@ Public Property Get AValue() As {propertyType}
1896
1897
AValue = myVal
1897
1898
End Property
1898
1899
" ;
1899
- var components = new List < ( string moduleName , string inputCode ) > ( )
1900
+ var components = new List < ( string moduleName , string inputCode , ComponentType componentType ) > ( )
1900
1901
{
1901
- ( "TestModule1" , inputCode ) ,
1902
- ( "Class1" , inputClassCode )
1902
+ ( "TestModule1" , inputCode , ComponentType . StandardModule ) ,
1903
+ ( "Class1" , inputClassCode , ComponentType . ClassModule )
1903
1904
} ;
1904
1905
1905
1906
( string expectedMsg , string actualMsg ) = CheckActualResultsEqualsExpected ( components , unreachable : 1 ) ;
@@ -1942,10 +1943,10 @@ Public Property Get AValue() As {propertyType}
1942
1943
AValue = myVal
1943
1944
End Property
1944
1945
" ;
1945
- var components = new List < ( string moduleName , string inputCode ) > ( )
1946
+ var components = new List < ( string moduleName , string inputCode , ComponentType componentType ) > ( )
1946
1947
{
1947
- ( "TestModule1" , inputCode ) ,
1948
- ( "Class1" , inputClassCode )
1948
+ ( "TestModule1" , inputCode , ComponentType . StandardModule ) ,
1949
+ ( "Class1" , inputClassCode , ComponentType . ClassModule )
1949
1950
} ;
1950
1951
1951
1952
( string expectedMsg , string actualMsg ) = CheckActualResultsEqualsExpected ( components , unreachable : 2 ) ;
@@ -1977,10 +1978,10 @@ Option Explicit
1977
1978
1978
1979
Public Const MY_CONSTANT As { propertyType }
1979
1980
" ;
1980
- var components = new List < ( string moduleName , string inputCode ) > ( )
1981
+ var components = new List < ( string moduleName , string inputCode , ComponentType componentType ) > ( )
1981
1982
{
1982
- ( "TestModule1" , inputCode ) ,
1983
- ( "TestModule2" , inputModule2Code )
1983
+ ( "TestModule1" , inputCode , ComponentType . StandardModule ) ,
1984
+ ( "TestModule2" , inputModule2Code , ComponentType . StandardModule )
1984
1985
} ;
1985
1986
1986
1987
( string expectedMsg , string actualMsg ) = CheckActualResultsEqualsExpected ( components , unreachable : 1 ) ;
@@ -2469,7 +2470,7 @@ End Sub
2469
2470
2470
2471
var vbe = CreateStandardModuleProject ( inputCode ) ;
2471
2472
2472
- IEnumerable < Rubberduck . Parsing . Inspections . Abstract . IInspectionResult > actualResults ;
2473
+ var actualResults = Enumerable . Empty < IInspectionResult > ( ) ;
2473
2474
using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
2474
2475
{
2475
2476
var inspection = new UnreachableCaseInspection ( state ) ;
@@ -2481,7 +2482,7 @@ End Sub
2481
2482
actualResults = inspector . FindIssuesAsync ( state , CancellationToken . None ) . Result ;
2482
2483
}
2483
2484
2484
- var actualUnreachable = actualResults . Where ( ar => ar . Description . Equals ( InspectionResults . UnreachableCaseInspection_Unreachable ) ) ;
2485
+ var actualUnreachable = actualResults . Where ( ar => ar . Description . Equals ( Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_Unreachable ) ) ;
2485
2486
2486
2487
Assert . AreEqual ( expectedUnreachableCount , actualUnreachable . Count ( ) ) ;
2487
2488
}
@@ -2523,7 +2524,7 @@ End Sub
2523
2524
" ;
2524
2525
var vbe = CreateStandardModuleProject ( inputCode ) ;
2525
2526
2526
- IEnumerable < Rubberduck . Parsing . Inspections . Abstract . IInspectionResult > actualResults ;
2527
+ var actualResults = Enumerable . Empty < IInspectionResult > ( ) ;
2527
2528
using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
2528
2529
{
2529
2530
var inspection = new UnreachableCaseInspection ( state ) ;
@@ -2535,7 +2536,7 @@ End Sub
2535
2536
actualResults = inspector . FindIssuesAsync ( state , CancellationToken . None ) . Result ;
2536
2537
}
2537
2538
2538
- var actualUnreachable = actualResults . Where ( ar => ar . Description . Equals ( InspectionResults . UnreachableCaseInspection_Unreachable ) ) ;
2539
+ var actualUnreachable = actualResults . Where ( ar => ar . Description . Equals ( Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_Unreachable ) ) ;
2539
2540
2540
2541
Assert . AreEqual ( expectedUnreachableCount , actualUnreachable . Count ( ) ) ;
2541
2542
}
@@ -2564,61 +2565,44 @@ private static (bool IsType, string ExpressionValue, string TypeName) TestGetVal
2564
2565
return ( true , expressionValue , typename ) ;
2565
2566
}
2566
2567
2567
- private static ( string expectedMsg , string actualMsg ) CheckActualResultsEqualsExpected ( string inputCode , int unreachable = 0 , int mismatch = 0 , int caseElse = 0 , int inherentlyUnreachable = 0 , int overflow = 0 )
2568
+ private ( string expectedMsg , string actualMsg ) CheckActualResultsEqualsExpected ( string inputCode , int unreachable = 0 , int mismatch = 0 , int caseElse = 0 , int inherentlyUnreachable = 0 , int overflow = 0 )
2568
2569
{
2569
- var components = new List < ( string moduleName , string inputCode ) > ( ) { ( "TestModule1" , inputCode ) } ;
2570
+ var components = new List < ( string moduleName , string inputCode , ComponentType componentType ) > ( ) { ( "TestModule1" , inputCode , ComponentType . StandardModule ) } ;
2570
2571
return CheckActualResultsEqualsExpected ( components , unreachable , mismatch , caseElse , inherentlyUnreachable , overflow ) ;
2571
2572
}
2572
2573
2573
- private static ( string expectedMsg , string actualMsg ) CheckActualResultsEqualsExpected ( List < ( string moduleName , string inputCode ) > components , int unreachable = 0 , int mismatch = 0 , int caseElse = 0 , int inherentlyUnreachable = 0 , int overflow = 0 )
2574
+ private ( string expectedMsg , string actualMsg ) CheckActualResultsEqualsExpected ( List < ( string moduleName , string inputCode , ComponentType componentType ) > components , int unreachable = 0 , int mismatch = 0 , int caseElse = 0 , int inherentlyUnreachable = 0 , int overflow = 0 )
2574
2575
{
2575
2576
var expected = new Dictionary < string , int >
2576
2577
{
2577
- { InspectionResults . UnreachableCaseInspection_Unreachable , unreachable } ,
2578
- { InspectionResults . UnreachableCaseInspection_InherentlyUnreachable , inherentlyUnreachable } ,
2579
- { InspectionResults . UnreachableCaseInspection_TypeMismatch , mismatch } ,
2580
- { InspectionResults . UnreachableCaseInspection_Overflow , overflow } ,
2581
- { InspectionResults . UnreachableCaseInspection_CaseElse , caseElse } ,
2578
+ { Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_Unreachable , unreachable } ,
2579
+ { Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_InherentlyUnreachable , inherentlyUnreachable } ,
2580
+ { Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_TypeMismatch , mismatch } ,
2581
+ { Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_Overflow , overflow } ,
2582
+ { Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_CaseElse , caseElse } ,
2582
2583
} ;
2583
2584
2584
- var vbe = CreateStandardModuleProject ( components ) ;
2585
+ var actualResults = InspectionResultsForModules ( components ) ;
2585
2586
2586
- IEnumerable < Rubberduck . Parsing . Inspections . Abstract . IInspectionResult > actualResults ;
2587
- using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
2588
- {
2589
- var inspector = InspectionsHelper . GetInspector ( new UnreachableCaseInspection ( state ) ) ;
2590
- actualResults = inspector . FindIssuesAsync ( state , CancellationToken . None ) . Result ;
2591
- }
2592
- var actualUnreachable = actualResults . Where ( ar => ar . Description . Equals ( InspectionResults . UnreachableCaseInspection_Unreachable ) ) ;
2593
- var actualMismatches = actualResults . Where ( ar => ar . Description . Equals ( InspectionResults . UnreachableCaseInspection_TypeMismatch ) ) ;
2594
- var actualUnreachableCaseElses = actualResults . Where ( ar => ar . Description . Equals ( InspectionResults . UnreachableCaseInspection_CaseElse ) ) ;
2595
- var actualInherentUnreachable = actualResults . Where ( ar => ar . Description . Equals ( InspectionResults . UnreachableCaseInspection_InherentlyUnreachable ) ) ;
2596
- var actualOverflow = actualResults . Where ( ar => ar . Description . Equals ( InspectionResults . UnreachableCaseInspection_Overflow ) ) ;
2587
+ var actualUnreachable = actualResults . Where ( ar => ar . Description . Equals ( Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_Unreachable ) ) ;
2588
+ var actualMismatches = actualResults . Where ( ar => ar . Description . Equals ( Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_TypeMismatch ) ) ;
2589
+ var actualUnreachableCaseElses = actualResults . Where ( ar => ar . Description . Equals ( Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_CaseElse ) ) ;
2590
+ var actualInherentUnreachable = actualResults . Where ( ar => ar . Description . Equals ( Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_InherentlyUnreachable ) ) ;
2591
+ var actualOverflow = actualResults . Where ( ar => ar . Description . Equals ( Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_Overflow ) ) ;
2597
2592
2598
2593
var actualMsg = BuildResultString ( actualUnreachable . Count ( ) , actualMismatches . Count ( ) , actualUnreachableCaseElses . Count ( ) , actualInherentUnreachable . Count ( ) , actualOverflow . Count ( ) ) ;
2599
- var expectedMsg = BuildResultString ( expected [ InspectionResults . UnreachableCaseInspection_Unreachable ] ,
2600
- expected [ InspectionResults . UnreachableCaseInspection_TypeMismatch ] ,
2601
- expected [ InspectionResults . UnreachableCaseInspection_CaseElse ] ,
2602
- expected [ InspectionResults . UnreachableCaseInspection_InherentlyUnreachable ] ,
2603
- expected [ InspectionResults . UnreachableCaseInspection_Overflow ]
2594
+ var expectedMsg = BuildResultString ( expected [ Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_Unreachable ] ,
2595
+ expected [ Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_TypeMismatch ] ,
2596
+ expected [ Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_CaseElse ] ,
2597
+ expected [ Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_InherentlyUnreachable ] ,
2598
+ expected [ Rubberduck . Resources . Inspections . InspectionResults . UnreachableCaseInspection_Overflow ]
2604
2599
) ;
2605
2600
2606
2601
return ( expectedMsg , actualMsg ) ;
2607
2602
}
2608
2603
2609
2604
private Moq . Mock < IVBE > CreateStandardModuleProject ( string inputCode )
2610
- => CreateStandardModuleProject ( new List < ( string moduleName , string inputCode ) > ( ) { ( "TestModule1" , inputCode ) } ) ;
2611
-
2612
- private static Moq . Mock < IVBE > CreateStandardModuleProject ( List < ( string moduleName , string inputCode ) > components )
2613
- {
2614
- var builder = new MockVbeBuilder ( ) ;
2615
- var project = builder . ProjectBuilder ( "VBAProject" , ProjectProtection . Unprotected ) ;
2616
- components . ForEach ( input => project . AddComponent ( input . moduleName , NameToComponentType ( input . moduleName ) , input . inputCode ) ) ;
2617
- return builder . AddProject ( project . Build ( ) ) . Build ( ) ;
2618
- }
2619
-
2620
- private static ComponentType NameToComponentType ( string name )
2621
- => name . StartsWith ( "Class" ) ? ComponentType . ClassModule : ComponentType . StandardModule ;
2605
+ => MockVbeBuilder . BuildFromModules ( new List < ( string moduleName , string inputCode , ComponentType componentType ) > ( ) { ( "TestModule1" , inputCode , ComponentType . StandardModule ) } ) ;
2622
2606
2623
2607
private static string BuildResultString ( int unreachableCount , int mismatchCount , int caseElseCount , int inherentCount , int overflowCount )
2624
2608
=> $ "Unreachable={ unreachableCount } , Mismatch={ mismatchCount } , CaseElse={ caseElseCount } , Inherent={ inherentCount } , Overflow={ overflowCount } ";
@@ -2649,5 +2633,10 @@ private IParseTreeVisitorResults GetParseTreeValueResults(string inputCode, out
2649
2633
}
2650
2634
return valueResults ;
2651
2635
}
2636
+
2637
+ protected override IInspection InspectionUnderTest ( RubberduckParserState state )
2638
+ {
2639
+ return new UnreachableCaseInspection ( state ) ;
2640
+ }
2652
2641
}
2653
2642
}
0 commit comments