Skip to content

Commit b5b1b57

Browse files
authored
Merge pull request #3076 from sharwell/using-declarations
Add tests for using declaration statements
2 parents 3d0c548 + ef8d748 commit b5b1b57

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/LayoutRules/SA1503CSharp8UnitTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,32 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp8.LayoutRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp7.LayoutRules;
10+
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.LayoutRules.SA1503BracesMustNotBeOmitted,
13+
StyleCop.Analyzers.LayoutRules.SA1503CodeFixProvider>;
714

815
public class SA1503CSharp8UnitTests : SA1503CSharp7UnitTests
916
{
17+
[Fact]
18+
[WorkItem(3074, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3074")]
19+
public async Task TestNoDiagnosticForUsingDeclarationStatementAsync()
20+
{
21+
var testCode = @"
22+
using System.IO;
23+
public class Foo
24+
{
25+
public void Method()
26+
{
27+
using var v = new MemoryStream();
28+
}
29+
}";
30+
31+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
32+
}
1033
}
1134
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/ReadabilityRules/SA1106CSharp8UnitTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,32 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp8.ReadabilityRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp7.ReadabilityRules;
10+
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.ReadabilityRules.SA1106CodeMustNotContainEmptyStatements,
13+
StyleCop.Analyzers.ReadabilityRules.SA1106CodeFixProvider>;
714

815
public class SA1106CSharp8UnitTests : SA1106CSharp7UnitTests
916
{
17+
[Fact]
18+
[WorkItem(3075, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3075")]
19+
public async Task TestNoDiagnosticForUsingDeclarationStatementAsync()
20+
{
21+
var testCode = @"
22+
using System.IO;
23+
public class Foo
24+
{
25+
public void Method()
26+
{
27+
using var v = new MemoryStream();
28+
}
29+
}";
30+
31+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
32+
}
1033
}
1134
}

0 commit comments

Comments
 (0)