Skip to content

Commit 18d33e4

Browse files
committed
Test field, event field, and variable declarations
1 parent 26ee139 commit 18d33e4

1 file changed

Lines changed: 134 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1137UnitTests.cs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,140 @@ void TypeWithMultipleConstraints2<T1, T2, T3>()
373373
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
374374
}
375375

376+
[Fact]
377+
public async Task TestValidVariableDeclarationAsync()
378+
{
379+
string testCode = @"
380+
using System;
381+
class Container
382+
{
383+
private int T1;
384+
private int
385+
T2;
386+
private int
387+
T3, T4;
388+
389+
private event EventHandler T5;
390+
private event EventHandler
391+
T6;
392+
private event EventHandler
393+
T7, T8;
394+
395+
void MethodName()
396+
{
397+
int t1;
398+
int
399+
t2;
400+
int
401+
t3, t4;
402+
}
403+
}
404+
";
405+
406+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
407+
}
408+
409+
[Fact]
410+
public async Task TestVariableDeclarationAsync()
411+
{
412+
string testCode = @"
413+
using System;
414+
class Container
415+
{
416+
private int
417+
X1,
418+
Y1,
419+
Z1;
420+
421+
private int
422+
X2,
423+
Y2,
424+
Z2;
425+
426+
private event EventHandler
427+
X3,
428+
Y3,
429+
Z3;
430+
431+
private event EventHandler
432+
X4,
433+
Y4,
434+
Z4;
435+
436+
void MethodName()
437+
{
438+
int
439+
X1,
440+
Y1,
441+
Z1;
442+
443+
int
444+
X2,
445+
Y2,
446+
Z2;
447+
}
448+
}
449+
";
450+
string fixedCode = @"
451+
using System;
452+
class Container
453+
{
454+
private int
455+
X1,
456+
Y1,
457+
Z1;
458+
459+
private int
460+
X2,
461+
Y2,
462+
Z2;
463+
464+
private event EventHandler
465+
X3,
466+
Y3,
467+
Z3;
468+
469+
private event EventHandler
470+
X4,
471+
Y4,
472+
Z4;
473+
474+
void MethodName()
475+
{
476+
int
477+
X1,
478+
Y1,
479+
Z1;
480+
481+
int
482+
X2,
483+
Y2,
484+
Z2;
485+
}
486+
}
487+
";
488+
489+
DiagnosticResult[] expected =
490+
{
491+
this.CSharpDiagnostic().WithLocation(7, 1),
492+
this.CSharpDiagnostic().WithLocation(8, 1),
493+
this.CSharpDiagnostic().WithLocation(12, 1),
494+
this.CSharpDiagnostic().WithLocation(13, 1),
495+
this.CSharpDiagnostic().WithLocation(17, 1),
496+
this.CSharpDiagnostic().WithLocation(18, 1),
497+
this.CSharpDiagnostic().WithLocation(22, 1),
498+
this.CSharpDiagnostic().WithLocation(23, 1),
499+
this.CSharpDiagnostic().WithLocation(29, 1),
500+
this.CSharpDiagnostic().WithLocation(30, 1),
501+
this.CSharpDiagnostic().WithLocation(34, 1),
502+
this.CSharpDiagnostic().WithLocation(35, 1),
503+
};
504+
505+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
506+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
507+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
508+
}
509+
376510
[Theory]
377511
[InlineData("class", " { }")]
378512
[InlineData("void", "() { }")]

0 commit comments

Comments
 (0)