-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathNamingStylesTests.vb
505 lines (465 loc) · 14.7 KB
/
NamingStylesTests.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.CodeFixes.NamingStyles
Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics.NamingStyles
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports Microsoft.CodeAnalysis.VisualBasic.Diagnostics.Analyzers
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Diagnostics.NamingStyles
<Trait(Traits.Feature, Traits.Features.NamingStyle)>
Public Class NamingStylesTests
Inherits AbstractVisualBasicDiagnosticProviderBasedUserDiagnosticTest_NoEditor
Private Shared ReadOnly s_options As NamingStylesTestOptionSets = New NamingStylesTestOptionSets(LanguageNames.VisualBasic)
Friend Overrides Function CreateDiagnosticProviderAndFixer(workspace As Workspace) As (DiagnosticAnalyzer, CodeFixProvider)
Return (New VisualBasicNamingStyleDiagnosticAnalyzer(), New NamingStyleCodeFixProvider())
End Function
Protected Overrides Function GetComposition() As TestComposition
Return MyBase.GetComposition().AddParts(GetType(TestSymbolRenamedCodeActionOperationFactoryWorkspaceService))
End Function
' TODO: everything else apart from locals
<Fact>
Public Async Function TestCamelCaseParameters() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M([|X|] as integer)
end sub
end module",
"module C
sub M(x as integer)
end sub
end module",
options:=s_options.ParameterNamesAreCamelCase)
End Function
<Fact>
Public Async Function TestCamelCaseLocals_LocalDeclaration1() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
dim [|X|] = 0
end sub
end module",
"module C
sub M()
dim x = 0
end sub
end module",
options:=s_options.LocalNamesAreCamelCase)
End Function
<Fact>
Public Async Function TestCamelCaseLocals_LocalDeclaration2() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
dim X as integer, [|Y|], Z as string
end sub
end module",
"module C
sub M()
dim X as integer, y, Z as string
end sub
end module",
options:=s_options.LocalNamesAreCamelCase)
End Function
<Fact>
Public Async Function TestCamelCaseLocals_LocalDeclaration3() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
dim [|X|](0 to 4) as integer, Y as new object(), Z%? as integer
end sub
end module",
"module C
sub M()
dim x(0 to 4) as integer, Y as new object(), Z%? as integer
end sub
end module",
options:=s_options.LocalNamesAreCamelCase)
End Function
<Fact>
Public Async Function TestCamelCaseLocals_LocalDeclaration4() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
dim X(0 to 4) as integer, [|Y|] as new object(), Z%? as integer
end sub
end module",
"module C
sub M()
dim X(0 to 4) as integer, y as new object(), Z%? as integer
end sub
end module",
options:=s_options.LocalNamesAreCamelCase)
End Function
<Fact>
Public Async Function TestCamelCaseLocals_LocalDeclaration5() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
dim X(0 to 4) as integer, Y as new object(), [|Z%|]? as integer
end sub
end module",
"module C
sub M()
dim X(0 to 4) as integer, Y as new object(), z%? as integer
end sub
end module",
options:=s_options.LocalNamesAreCamelCase)
End Function
<Fact>
Public Async Function TestCamelCaseLocals_UsingVariable1() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
using [|A|] = nothing
end using
end sub
end module",
"module C
sub M()
using a = nothing
end using
end sub
end module",
options:=s_options.LocalNamesAreCamelCase)
End Function
<Fact>
Public Async Function TestCamelCaseLocals_UsingVariable2() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
using A = nothing, [|B|] as new object()
end using
end sub
end module",
"module C
sub M()
using A = nothing, b as new object()
end using
end sub
end module",
options:=s_options.LocalNamesAreCamelCase)
End Function
<Fact(Skip:="Implicit declarations cannot be found by syntax. Requires https://github.com/dotnet/roslyn/issues/14061")>
Public Async Function TestCamelCaseLocals_ForVariable1_ImplicitlyDeclared() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
for [|I|] = 1 to 10
next
end sub
end module",
"module C
sub M()
for i = 1 to 10
next
end sub
end module",
options:=s_options.LocalNamesAreCamelCase)
End Function
<Fact>
Public Async Function TestCamelCaseLocals_ForVariable1_NotWhenDeclaredPreviously() As Task
Await TestMissingInRegularAndScriptAsync(
"module C
sub M()
dim I as integer
for [|I|] = 1 to 10
next
end sub
end module", New TestParameters(options:=s_options.LocalNamesAreCamelCase))
End Function
<Fact>
Public Async Function TestCamelCaseLocals_ForVariable2() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
for [|I|]? as integer = 1 to 10
next
end sub
end module",
"module C
sub M()
for i? as integer = 1 to 10
next
end sub
end module",
options:=s_options.LocalNamesAreCamelCase)
End Function
<Fact(Skip:="Implicit declarations cannot be found by syntax. Requires https://github.com/dotnet/roslyn/issues/14061")>
Public Async Function TestCamelCaseLocals_ForEachVariable1_ImplicitlyDeclared() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
for each [|X|] in {}
next
end sub
end module",
"module C
sub M()
for each x in {}
next
end sub
end module",
options:=s_options.LocalNamesAreCamelCase)
End Function
<Fact>
Public Async Function TestCamelCaseLocals_ForEachVariable1_NotWhenDeclaredPreviously() As Task
Await TestMissingInRegularAndScriptAsync(
"module C
sub M()
dim X
for each [|X|] in {}
next
end sub
end module", New TestParameters(options:=s_options.LocalNamesAreCamelCase))
End Function
<Fact>
Public Async Function TestCamelCaseLocals_ForEachVariable2() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
for each [|X|]? as integer in {}
next
end sub
end module",
"module C
sub M()
for each x? as integer in {}
next
end sub
end module",
options:=s_options.LocalNamesAreCamelCase)
End Function
<Fact>
Public Async Function TestCamelCaseLocals_CatchVariable() As Task
Await TestInRegularAndScriptAsync(
"imports System
module C
sub M()
try
catch [|Exception|] as Exception
end try
end sub
end module",
"imports System
module C
sub M()
try
catch exception as Exception
end try
end sub
end module",
options:=s_options.LocalNamesAreCamelCase)
End Function
<Fact>
Public Async Function TestCamelCaseLocals_CatchWithoutDeclarationIgnored() As Task
Await TestMissingInRegularAndScriptAsync(
"imports System
module C
sub M()
try
[|catch|]
end try
end sub
end module", New TestParameters(options:=s_options.LocalNamesAreCamelCase))
End Function
<Fact(Skip:="Implicit declarations cannot be found by syntax. Requires https://github.com/dotnet/roslyn/issues/14061")>
Public Async Function TestCamelCaseLocals_ImplicitlyDeclaredLocal() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
[|Value|] = 0
System.Console.WriteLine(Value)
end sub
end module",
"module C
sub M()
value = 0
System.Console.WriteLine(value)
end sub
end module",
options:=s_options.LocalNamesAreCamelCase)
End Function
<Fact>
Public Async Function TestCamelCaseLocals_ImplicitlyDeclaredLocal_NotOnSecondUse() As Task
Await TestMissingInRegularAndScriptAsync(
"module C
sub M()
Value = 0
System.Console.WriteLine([|Value|])
end sub
end module", New TestParameters(options:=s_options.LocalNamesAreCamelCase))
End Function
<Fact>
Public Async Function TestCamelCaseLocals_NotWhenLocalDeclaredPreviously() As Task
Await TestMissingInRegularAndScriptAsync(
"module C
sub M()
dim Value as integer
[|Value|] = 0
System.Console.WriteLine(Value)
end sub
end module", New TestParameters(options:=s_options.LocalNamesAreCamelCase))
End Function
<Fact>
Public Async Function TestCamelCaseLocals_QueryFromClauseIgnored() As Task
' This is an IRangeVariableSymbol, not ILocalSymbol
Await TestMissingInRegularAndScriptAsync(
"module C
sub M()
dim squares =
from [|STR|] in {string.Empty}
let Number = integer.Parse(STR)
select Number * Number
end sub
end module", New TestParameters(options:=s_options.LocalNamesAreCamelCase))
End Function
<Fact>
Public Async Function TestCamelCaseLocals_QueryLetClauseIgnored() As Task
' This is an IRangeVariableSymbol, not ILocalSymbol
Await TestMissingInRegularAndScriptAsync(
"module C
sub M()
dim squares =
from STR in {string.Empty}
let [|Number|] = integer.Parse(STR)
select Number * Number
end sub
end module", New TestParameters(options:=s_options.LocalNamesAreCamelCase))
End Function
<Fact>
Public Async Function TestCamelCaseLocals_ParameterIgnored() As Task
Await TestMissingInRegularAndScriptAsync(
"module C
sub M([|X|] as integer)
end sub
end module", New TestParameters(options:=s_options.LocalNamesAreCamelCase))
End Function
<Fact>
Public Async Function TestCamelCaseLocals_TupleTypeElementNameIgnored1() As Task
Await TestMissingInRegularAndScriptAsync(
"module C
sub M()
dim tuple as ([|A|] as integer, B as string)
end sub
end module", New TestParameters(options:=s_options.LocalNamesAreCamelCase))
End Function
<Fact>
Public Async Function TestCamelCaseLocals_TupleTypeElementNameIgnored2() As Task
Await TestMissingInRegularAndScriptAsync(
"module C
sub M()
dim tuple as (A as integer, ([|B|] as string, C as string)) = (0, (string.Empty, string.Empty))
end sub
end module", New TestParameters(options:=s_options.LocalNamesAreCamelCase))
End Function
<Fact>
Public Async Function TestCamelCaseLocals_TupleExpressionElementNameIgnored() As Task
Await TestMissingInRegularAndScriptAsync(
"module C
sub M()
dim tuple = ([|A|]:=0, B:=0)
end sub
end module", New TestParameters(options:=s_options.LocalNamesAreCamelCase))
End Function
<Fact>
Public Async Function TestUpperCaseConstants_ConstField() As Task
Await TestInRegularAndScriptAsync(
"module C
const [|field|] = 0
end module",
"module C
const FIELD = 0
end module",
options:=s_options.ConstantsAreUpperCase)
End Function
<Fact>
Public Async Function TestUpperCaseConstants_ConstLocal() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
const local1 = 0, [|local2|] as integer = 0
end sub
end module",
"module C
sub M()
const local1 = 0, LOCAL2 as integer = 0
end sub
end module",
options:=s_options.ConstantsAreUpperCase)
End Function
<Fact>
Public Async Function TestUpperCaseConstants_NonConstFieldIgnored() As Task
Await TestMissingInRegularAndScriptAsync(
"module C
readonly [|field|] = 0
end module", New TestParameters(options:=s_options.ConstantsAreUpperCase))
End Function
<Fact>
Public Async Function TestUpperCaseConstants_NonConstLocalIgnored() As Task
Await TestMissingInRegularAndScriptAsync(
"module C
sub M()
dim local1 = 0, [|local2|] as integer = 0
end sub
end module", New TestParameters(options:=s_options.ConstantsAreUpperCase))
End Function
<Fact>
Public Async Function TestCamelCaseLocalsUpperCaseConstants_ConstLocal() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
const [|PascalCase|] = 0
end sub
end module",
"module C
sub M()
const PASCALCASE = 0
end sub
end module",
options:=s_options.LocalsAreCamelCaseConstantsAreUpperCase)
End Function
<Fact>
Public Async Function TestCamelCaseLocalsUpperCaseConstants_NonConstLocal() As Task
Await TestInRegularAndScriptAsync(
"module C
sub M()
dim [|PascalCase|] = 0
end sub
end module",
"module C
sub M()
dim pascalCase = 0
end sub
end module",
options:=s_options.LocalsAreCamelCaseConstantsAreUpperCase)
End Function
<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38513")>
Public Async Function TestInterfaceNamesStartWithI() As Task
Await TestInRegularAndScriptAsync(
"Interface [|test|]
End Interface",
"Interface ITest
End Interface",
options:=s_options.InterfaceNamesStartWithI)
End Function
<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38513")>
Public Async Function TestTypeParameterNamesStartWithT() As Task
Await TestInRegularAndScriptAsync(
"Public Class classHolder(Of [|type|])
End Class",
"Public Class classHolder(Of TType)
End Class",
options:=s_options.TypeParameterNamesStartWithT)
End Function
<Fact, WorkItem("https://github.com/dotnet/roslyn/issues/51727")>
Public Async Function TestExternMethod() As Task
Await TestMissingInRegularAndScriptAsync(
"Public Class C
Declare Sub [|some_p_invoke|] Lib ""some""()
End Class",
New TestParameters(options:=s_options.MethodNamesArePascalCase))
End Function
End Class
End Namespace