@@ -20,30 +20,36 @@ public class UseMeaningfulNameInspectionTests
20
20
{
21
21
[ TestMethod ]
22
22
[ TestCategory ( "Inspections" ) ]
23
- public void UseMeaningfulName_ReturnsResult_NameWithoutVowels ( )
23
+ public void UseMeaningfulName_ReturnsResult_NameWithAllTheSameLetters ( )
24
24
{
25
- const string inputCode =
26
- @"Sub Ffffff()
25
+ const string inputCode =
26
+ @"
27
+ Private aaa As String
28
+ Private bbb As String
29
+ Private ccc As String
30
+ Private ddd As String
31
+ Private eee As String
32
+ Private iii As String
33
+ Private ooo As String
34
+ Private uuu As String
35
+
36
+ Sub Eeeeee()
37
+ Dim a2z as String 'This is the only declaration that should pass
38
+ Dim gGGG as String
27
39
End Sub" ;
28
40
29
- //Arrange
30
- var builder = new MockVbeBuilder ( ) ;
31
- var project = builder . ProjectBuilder ( "VBAProject" , ProjectProtection . Unprotected )
32
- . AddComponent ( "MyClass" , ComponentType . ClassModule , inputCode )
33
- . Build ( ) ;
34
- var vbe = builder . AddProject ( project ) . Build ( ) ;
35
-
36
- var mockHost = new Mock < IHostApplication > ( ) ;
37
- mockHost . SetupAllProperties ( ) ;
38
- var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
39
-
40
- parser . Parse ( new CancellationTokenSource ( ) ) ;
41
- if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
41
+ AssertVbaFragmentYieldsExpectedInspectionResultCount ( inputCode , 10 ) ;
42
+ }
42
43
43
- var inspection = new UseMeaningfulNameInspection ( null , parser . State , GetInspectionSettings ( ) . Object ) ;
44
- var inspectionResults = inspection . GetInspectionResults ( ) ;
45
44
46
- Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
45
+ [ TestMethod ]
46
+ [ TestCategory ( "Inspections" ) ]
47
+ public void UseMeaningfulName_ReturnsResult_NameWithoutVowels ( )
48
+ {
49
+ const string inputCode =
50
+ @"Sub Ffffff()
51
+ End Sub" ;
52
+ AssertVbaFragmentYieldsExpectedInspectionResultCount ( inputCode , 1 ) ;
47
53
}
48
54
49
55
[ TestMethod ]
@@ -53,25 +59,7 @@ public void UseMeaningfulName_ReturnsResult_NameUnderThreeLetters()
53
59
const string inputCode =
54
60
@"Sub Oo()
55
61
End Sub" ;
56
-
57
- //Arrange
58
- var builder = new MockVbeBuilder ( ) ;
59
- var project = builder . ProjectBuilder ( "VBAProject" , ProjectProtection . Unprotected )
60
- . AddComponent ( "MyClass" , ComponentType . ClassModule , inputCode )
61
- . Build ( ) ;
62
- var vbe = builder . AddProject ( project ) . Build ( ) ;
63
-
64
- var mockHost = new Mock < IHostApplication > ( ) ;
65
- mockHost . SetupAllProperties ( ) ;
66
- var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
67
-
68
- parser . Parse ( new CancellationTokenSource ( ) ) ;
69
- if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
70
-
71
- var inspection = new UseMeaningfulNameInspection ( null , parser . State , GetInspectionSettings ( ) . Object ) ;
72
- var inspectionResults = inspection . GetInspectionResults ( ) ;
73
-
74
- Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
62
+ AssertVbaFragmentYieldsExpectedInspectionResultCount ( inputCode , 1 ) ;
75
63
}
76
64
77
65
[ TestMethod ]
@@ -82,24 +70,7 @@ public void UseMeaningfulName_ReturnsResult_NameEndsWithDigit()
82
70
@"Sub Foo1()
83
71
End Sub" ;
84
72
85
- //Arrange
86
- var builder = new MockVbeBuilder ( ) ;
87
- var project = builder . ProjectBuilder ( "VBAProject" , ProjectProtection . Unprotected )
88
- . AddComponent ( "MyClass" , ComponentType . ClassModule , inputCode )
89
- . Build ( ) ;
90
- var vbe = builder . AddProject ( project ) . Build ( ) ;
91
-
92
- var mockHost = new Mock < IHostApplication > ( ) ;
93
- mockHost . SetupAllProperties ( ) ;
94
- var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
95
-
96
- parser . Parse ( new CancellationTokenSource ( ) ) ;
97
- if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
98
-
99
- var inspection = new UseMeaningfulNameInspection ( null , parser . State , GetInspectionSettings ( ) . Object ) ;
100
- var inspectionResults = inspection . GetInspectionResults ( ) ;
101
-
102
- Assert . AreEqual ( 1 , inspectionResults . Count ( ) ) ;
73
+ AssertVbaFragmentYieldsExpectedInspectionResultCount ( inputCode , 1 ) ;
103
74
}
104
75
105
76
[ TestMethod ]
@@ -110,24 +81,7 @@ public void UseMeaningfulName_DoesNotReturnsResult_GoodName_LowerCaseVowels()
110
81
@"Sub FooBar()
111
82
End Sub" ;
112
83
113
- //Arrange
114
- var builder = new MockVbeBuilder ( ) ;
115
- var project = builder . ProjectBuilder ( "VBAProject" , ProjectProtection . Unprotected )
116
- . AddComponent ( "MyClass" , ComponentType . ClassModule , inputCode )
117
- . Build ( ) ;
118
- var vbe = builder . AddProject ( project ) . Build ( ) ;
119
-
120
- var mockHost = new Mock < IHostApplication > ( ) ;
121
- mockHost . SetupAllProperties ( ) ;
122
- var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
123
-
124
- parser . Parse ( new CancellationTokenSource ( ) ) ;
125
- if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
126
-
127
- var inspection = new UseMeaningfulNameInspection ( null , parser . State , GetInspectionSettings ( ) . Object ) ;
128
- var inspectionResults = inspection . GetInspectionResults ( ) ;
129
-
130
- Assert . AreEqual ( 0 , inspectionResults . Count ( ) ) ;
84
+ AssertVbaFragmentYieldsExpectedInspectionResultCount ( inputCode , 0 ) ;
131
85
}
132
86
133
87
[ TestMethod ]
@@ -138,24 +92,7 @@ public void UseMeaningfulName_DoesNotReturnsResult_GoodName_UpperCaseVowels()
138
92
@"Sub FOOBAR()
139
93
End Sub" ;
140
94
141
- //Arrange
142
- var builder = new MockVbeBuilder ( ) ;
143
- var project = builder . ProjectBuilder ( "VBAProject" , ProjectProtection . Unprotected )
144
- . AddComponent ( "MyClass" , ComponentType . ClassModule , inputCode )
145
- . Build ( ) ;
146
- var vbe = builder . AddProject ( project ) . Build ( ) ;
147
-
148
- var mockHost = new Mock < IHostApplication > ( ) ;
149
- mockHost . SetupAllProperties ( ) ;
150
- var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
151
-
152
- parser . Parse ( new CancellationTokenSource ( ) ) ;
153
- if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
154
-
155
- var inspection = new UseMeaningfulNameInspection ( null , parser . State , GetInspectionSettings ( ) . Object ) ;
156
- var inspectionResults = inspection . GetInspectionResults ( ) ;
157
-
158
- Assert . AreEqual ( 0 , inspectionResults . Count ( ) ) ;
95
+ AssertVbaFragmentYieldsExpectedInspectionResultCount ( inputCode , 0 ) ;
159
96
}
160
97
161
98
[ TestMethod ]
@@ -165,24 +102,7 @@ public void UseMeaningfulName_DoesNotReturnsResult_OptionBase()
165
102
const string inputCode =
166
103
@"Option Base 1" ;
167
104
168
- //Arrange
169
- var builder = new MockVbeBuilder ( ) ;
170
- var project = builder . ProjectBuilder ( "VBAProject" , ProjectProtection . Unprotected )
171
- . AddComponent ( "MyClass" , ComponentType . ClassModule , inputCode )
172
- . Build ( ) ;
173
- var vbe = builder . AddProject ( project ) . Build ( ) ;
174
-
175
- var mockHost = new Mock < IHostApplication > ( ) ;
176
- mockHost . SetupAllProperties ( ) ;
177
- var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
178
-
179
- parser . Parse ( new CancellationTokenSource ( ) ) ;
180
- if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
181
-
182
- var inspection = new UseMeaningfulNameInspection ( null , parser . State , GetInspectionSettings ( ) . Object ) ;
183
- var inspectionResults = inspection . GetInspectionResults ( ) ;
184
-
185
- Assert . AreEqual ( 0 , inspectionResults . Count ( ) ) ;
105
+ AssertVbaFragmentYieldsExpectedInspectionResultCount ( inputCode , 0 ) ;
186
106
}
187
107
188
108
[ TestMethod ]
@@ -193,24 +113,7 @@ public void UseMeaningfulName_DoesNotReturnResult_NameWithoutVowels_NameIsInWhit
193
113
@"Sub sss()
194
114
End Sub" ;
195
115
196
- //Arrange
197
- var builder = new MockVbeBuilder ( ) ;
198
- var project = builder . ProjectBuilder ( "VBAProject" , ProjectProtection . Unprotected )
199
- . AddComponent ( "MyClass" , ComponentType . ClassModule , inputCode )
200
- . Build ( ) ;
201
- var vbe = builder . AddProject ( project ) . Build ( ) ;
202
-
203
- var mockHost = new Mock < IHostApplication > ( ) ;
204
- mockHost . SetupAllProperties ( ) ;
205
- var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
206
-
207
- parser . Parse ( new CancellationTokenSource ( ) ) ;
208
- if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
209
-
210
- var inspection = new UseMeaningfulNameInspection ( null , parser . State , GetInspectionSettings ( ) . Object ) ;
211
- var inspectionResults = inspection . GetInspectionResults ( ) ;
212
-
213
- Assert . IsFalse ( inspectionResults . Any ( ) ) ;
116
+ AssertVbaFragmentYieldsExpectedInspectionResultCount ( inputCode , 0 ) ;
214
117
}
215
118
216
119
[ TestMethod ]
@@ -222,24 +125,7 @@ public void UseMeaningfulName_Ignored_DoesNotReturnResult()
222
125
Sub Ffffff()
223
126
End Sub" ;
224
127
225
- //Arrange
226
- var builder = new MockVbeBuilder ( ) ;
227
- var project = builder . ProjectBuilder ( "VBAProject" , ProjectProtection . Unprotected )
228
- . AddComponent ( "MyClass" , ComponentType . ClassModule , inputCode )
229
- . Build ( ) ;
230
- var vbe = builder . AddProject ( project ) . Build ( ) ;
231
-
232
- var mockHost = new Mock < IHostApplication > ( ) ;
233
- mockHost . SetupAllProperties ( ) ;
234
- var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
235
-
236
- parser . Parse ( new CancellationTokenSource ( ) ) ;
237
- if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
238
-
239
- var inspection = new UseMeaningfulNameInspection ( null , parser . State , GetInspectionSettings ( ) . Object ) ;
240
- var inspectionResults = inspection . GetInspectionResults ( ) ;
241
-
242
- Assert . IsFalse ( inspectionResults . Any ( ) ) ;
128
+ AssertVbaFragmentYieldsExpectedInspectionResultCount ( inputCode , 0 ) ;
243
129
}
244
130
245
131
[ TestMethod ]
@@ -272,7 +158,6 @@ Sub Ffffff()
272
158
273
159
var inspection = new UseMeaningfulNameInspection ( null , parser . State , GetInspectionSettings ( ) . Object ) ;
274
160
var inspectionResults = inspection . GetInspectionResults ( ) ;
275
-
276
161
inspectionResults . First ( ) . QuickFixes . Single ( s => s is IgnoreOnceQuickFix ) . Fix ( ) ;
277
162
278
163
Assert . AreEqual ( expectedCode , module . Content ( ) ) ;
@@ -296,6 +181,26 @@ public void InspectionName()
296
181
Assert . AreEqual ( inspectionName , inspection . Name ) ;
297
182
}
298
183
184
+ private void AssertVbaFragmentYieldsExpectedInspectionResultCount ( string inputCode , int expectedCount )
185
+ {
186
+ var builder = new MockVbeBuilder ( ) ;
187
+ var project = builder . ProjectBuilder ( "VBAProject" , ProjectProtection . Unprotected )
188
+ . AddComponent ( "MyClass" , ComponentType . ClassModule , inputCode )
189
+ . Build ( ) ;
190
+ var vbe = builder . AddProject ( project ) . Build ( ) ;
191
+
192
+ var mockHost = new Mock < IHostApplication > ( ) ;
193
+ mockHost . SetupAllProperties ( ) ;
194
+ var parser = MockParser . Create ( vbe . Object , new RubberduckParserState ( new Mock < ISinks > ( ) . Object ) ) ;
195
+
196
+ parser . Parse ( new CancellationTokenSource ( ) ) ;
197
+ if ( parser . State . Status >= ParserState . Error ) { Assert . Inconclusive ( "Parser Error" ) ; }
198
+
199
+ var inspection = new UseMeaningfulNameInspection ( null , parser . State , GetInspectionSettings ( ) . Object ) ;
200
+ var inspectionResults = inspection . GetInspectionResults ( ) ;
201
+ Assert . AreEqual ( expectedCount , inspectionResults . Count ( ) ) ;
202
+ }
203
+
299
204
internal static Mock < IPersistanceService < CodeInspectionSettings > > GetInspectionSettings ( )
300
205
{
301
206
var settings = new Mock < IPersistanceService < CodeInspectionSettings > > ( ) ;
0 commit comments