4
4
using RubberduckTests . Mocks ;
5
5
using Rubberduck . Inspections . Concrete ;
6
6
using Rubberduck . VBEditor . SafeComWrappers ;
7
+ using Rubberduck . Parsing . Inspections . Abstract ;
8
+ using Rubberduck . Parsing . VBA ;
7
9
8
10
namespace RubberduckTests . Inspections
9
11
{
10
12
[ TestFixture ]
11
- public class ImplementedInterfaceMemberInspectionTests
13
+ public class ImplementedInterfaceMemberInspectionTests : InspectionTestsBase
12
14
{
13
15
[ Test ]
14
16
[ Category ( "Inspections" ) ]
@@ -38,7 +40,7 @@ End Sub
38
40
Public Sub IClass1_DoSomethingElse(ByVal a As Integer)
39
41
MsgBox ""?""
40
42
End Sub" ;
41
- CheckActualEmptyBlockCountEqualsExpected ( interfaceCode , concreteCode , 0 ) ;
43
+ CheckActualEmptyBlockCountEqualsExpected ( ( "IClass1" , interfaceCode ) , ( "Class1" , concreteCode ) , 0 ) ;
42
44
}
43
45
44
46
[ Test ]
@@ -59,7 +61,7 @@ Private Sub IClass1_DoSomething(ByVal a As Integer)
59
61
End Sub
60
62
Public Sub IClass1_DoSomethingElse(ByVal a As Integer)
61
63
End Sub" ;
62
- CheckActualEmptyBlockCountEqualsExpected ( interfaceCode , concreteCode , 1 ) ;
64
+ CheckActualEmptyBlockCountEqualsExpected ( ( "IClass1" , interfaceCode ) , ( "Class1" , concreteCode ) , 1 ) ;
63
65
}
64
66
65
67
[ Test ]
@@ -81,7 +83,7 @@ public void ImplementedInterfaceMember_VariousStatements_DontReturnResult(string
81
83
MsgBox ""?""
82
84
End Sub" ;
83
85
84
- CheckActualEmptyBlockCountEqualsExpected ( interfaceCode , concreteCode , 0 ) ;
86
+ CheckActualEmptyBlockCountEqualsExpected ( ( "IClass1" , interfaceCode ) , ( "Class1" , concreteCode ) , 0 ) ;
85
87
}
86
88
87
89
[ Test ]
@@ -117,28 +119,52 @@ public void ImplementedInterfaceMember_VariousStatements_ReturnResult(string sta
117
119
Sub IClass1_Qux()
118
120
End Sub" ;
119
121
120
- CheckActualEmptyBlockCountEqualsExpected ( interfaceCode , concreteCode , 1 ) ;
122
+ CheckActualEmptyBlockCountEqualsExpected ( ( "IClass1" , interfaceCode ) , ( "Class1" , concreteCode ) , 1 ) ;
121
123
}
122
124
123
- private void CheckActualEmptyBlockCountEqualsExpected ( string interfaceCode , string concreteCode , int expectedCount )
125
+ //https://github.com/rubberduck-vba/Rubberduck/issues/5143
126
+ [ TestCase ( @"MsgBox ""?""" , "" , 1 ) ] //No implementers, only the annotation marks interface class
127
+ [ TestCase ( "" , "" , 0 ) ] //Annotated only, but no implementers - no result
128
+ [ TestCase ( @"MsgBox ""?""" , "Implements IClass1" , 1 ) ] //Annotated and an Implementer yields a single inspection result
129
+ [ Category ( "Inspections" ) ]
130
+ public void ImplementedInterfaceMember_AnnotatedOnly_ReturnsResult ( string interfaceBody , string implementsStatement , int expected )
124
131
{
125
- var builder = new MockVbeBuilder ( ) ;
126
- var project = builder . ProjectBuilder ( "TestProject1" , ProjectProtection . Unprotected )
127
- . AddComponent ( "IClass1" , ComponentType . ClassModule , interfaceCode )
128
- . AddComponent ( "Class1" , ComponentType . ClassModule , concreteCode )
129
- . Build ( ) ;
130
- var vbe = builder . AddProject ( project ) . Build ( ) ;
131
-
132
- using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
133
- {
132
+ var interfaceCode =
133
+ $@ "
134
+ '@Interface
135
+
136
+ Public Sub DoSomething(ByVal a As Integer)
137
+ End Sub
138
+ Public Sub DoSomethingElse(ByVal a As Integer)
139
+ { interfaceBody }
140
+ End Sub" ;
141
+ var concreteCode =
142
+ $@ "
143
+
144
+ { implementsStatement }
145
+
146
+ Private Sub IClass1_DoSomething(ByVal a As Integer)
147
+ MsgBox ""?""
148
+ End Sub
149
+ Public Sub IClass1_DoSomethingElse(ByVal a As Integer)
150
+ End Sub" ;
151
+ CheckActualEmptyBlockCountEqualsExpected ( ( "IClass1" , interfaceCode ) , ( "Class1" , concreteCode ) , expected ) ;
152
+ }
134
153
135
- var inspection = new ImplementedInterfaceMemberInspection ( state ) ;
136
- var inspector = InspectionsHelper . GetInspector ( inspection ) ;
137
- var actualResults = inspector . FindIssuesAsync ( state , CancellationToken . None ) . Result ;
154
+ private void CheckActualEmptyBlockCountEqualsExpected ( ( string identifier , string code ) interfaceDef , ( string identifier , string code ) implementerDef , int expectedCount )
155
+ {
156
+ var modules = new ( string , string , ComponentType ) [ ]
157
+ {
158
+ ( interfaceDef . identifier , interfaceDef . code , ComponentType . ClassModule ) ,
159
+ ( implementerDef . identifier , implementerDef . code , ComponentType . ClassModule )
160
+ } ;
138
161
139
- Assert . AreEqual ( expectedCount , actualResults . Count ( ) ) ;
140
- }
162
+ Assert . AreEqual ( expectedCount , InspectionResultsForModules ( modules ) . Count ( ) ) ;
163
+ }
141
164
165
+ protected override IInspection InspectionUnderTest ( RubberduckParserState state )
166
+ {
167
+ return new ImplementedInterfaceMemberInspection ( state ) ;
142
168
}
143
169
}
144
170
}
0 commit comments