Skip to content

Commit 57bc54d

Browse files
danmoseleysharwell
authored andcommitted
Test for #3277
1 parent c8ce94b commit 57bc54d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/ReadabilityRules/SA1129CSharp9UnitTests.cs

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

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

815
public class SA1129CSharp9UnitTests : SA1129CSharp8UnitTests
916
{
17+
/// <summary>
18+
/// Verifies that target type new expressions for value types will generate diagnostics.
19+
/// </summary>
20+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
21+
[Fact]
22+
public async Task VerifyValueTypeWithTargetTypeNewAsync()
23+
{
24+
var testCode = @"struct S
25+
{
26+
internal static S F()
27+
{
28+
S s = {|#0:new()|};
29+
return s;
30+
}
31+
}
32+
";
33+
34+
var fixedTestCode = @"struct S
35+
{
36+
internal static S F()
37+
{
38+
S s = default;
39+
return s;
40+
}
41+
}
42+
";
43+
DiagnosticResult[] expected =
44+
{
45+
Diagnostic().WithLocation(0),
46+
};
47+
48+
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
49+
}
1050
}
1151
}

0 commit comments

Comments
 (0)