Skip to content

Commit 4aec946

Browse files
committed
Implement SA1130 unit tests
1 parent cc64ff5 commit 4aec946

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.ReadabilityRules
5+
{
6+
using System.Collections.Generic;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using Analyzers.ReadabilityRules;
10+
using Microsoft.CodeAnalysis.Diagnostics;
11+
using TestHelper;
12+
using Xunit;
13+
14+
public class SA1130UnitTests : DiagnosticVerifier
15+
{
16+
[Fact]
17+
public async Task TestSimpleDelegateUseAsync()
18+
{
19+
var testCode = @"
20+
using System;
21+
public class TypeName
22+
{
23+
public void Test()
24+
{
25+
Action action1 = delegate { };
26+
Action action2 = delegate() { };
27+
Action<int> action3 = delegate(int i) { };
28+
}
29+
}";
30+
var expected = new[]
31+
{
32+
this.CSharpDiagnostic().WithLocation(7, 26),
33+
this.CSharpDiagnostic().WithLocation(8, 26),
34+
this.CSharpDiagnostic().WithLocation(9, 31)
35+
};
36+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
37+
}
38+
39+
[Fact]
40+
public async Task TestDelegateUseAsMethodArgumentsAsync()
41+
{
42+
var testCode = @"
43+
using System;
44+
public class TypeName
45+
{
46+
public void Test(Action argument)
47+
{
48+
49+
}
50+
51+
public void Test()
52+
{
53+
Test(delegate { });
54+
}
55+
}";
56+
var expected = this.CSharpDiagnostic().WithLocation(12, 14);
57+
58+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
59+
}
60+
61+
[Fact]
62+
public async Task TestDelegateUseAsMethodArgumentsWithConflictingExpressionOverloadAsync()
63+
{
64+
var testCode = @"
65+
using System;
66+
using System.Linq.Expressions;
67+
public class TypeName
68+
{
69+
public void Test(Action argument)
70+
{
71+
72+
}
73+
74+
public void Test(Expression<Action> argument)
75+
{
76+
77+
}
78+
79+
public void Test()
80+
{
81+
Test(delegate { });
82+
}
83+
}";
84+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
85+
}
86+
87+
/// <inheritdoc/>
88+
protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
89+
{
90+
yield return new SA1130UseLambdaSyntax();
91+
}
92+
}
93+
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
<Compile Include="ReadabilityRules\SA1125UnitTests.cs" />
303303
<Compile Include="ReadabilityRules\SA1126UnitTests.cs" />
304304
<Compile Include="ReadabilityRules\SA1127UnitTests.cs" />
305+
<Compile Include="ReadabilityRules\SA1130UnitTests.cs" />
305306
<Compile Include="ReadabilityRules\SA1128UnitTests.cs" />
306307
<Compile Include="Settings\SettingsFileCodeFixProviderUnitTests.cs" />
307308
<Compile Include="Settings\SettingsUnitTests.cs" />

0 commit comments

Comments
 (0)