Skip to content

Commit 23587a2

Browse files
committed
Update SA1125 tests for native-sized integers
1 parent ce28c3c commit 23587a2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,46 @@
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.StyleCopDiagnosticVerifier<StyleCop.Analyzers.ReadabilityRules.SA1125UseShorthandForNullableTypes>;
712

813
public partial class SA1125CSharp9UnitTests : SA1125CSharp8UnitTests
914
{
15+
[Theory]
16+
[InlineData("System.Nullable<nint>")]
17+
[InlineData("Nullable<IntPtr>")]
18+
[InlineData("System.Nullable<nuint>")]
19+
[InlineData("Nullable<UIntPtr>")]
20+
[WorkItem(3969, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3969")]
21+
public async Task TestNativeSizedNullableTypesAsync(string nullableForm)
22+
{
23+
var testCode = @"
24+
using System;
25+
26+
class TestClass
27+
{
28+
{|#0:" + nullableForm + @"|} value;
29+
}";
30+
31+
await VerifyCSharpDiagnosticAsync(testCode, Diagnostic().WithLocation(0), CancellationToken.None).ConfigureAwait(false);
32+
}
33+
34+
[Fact]
35+
[WorkItem(3969, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3969")]
36+
public async Task TestNativeSizedNullableAliasesDoNotReportAsync()
37+
{
38+
var testCode = @"
39+
class TestClass
40+
{
41+
nint? nativeInt;
42+
nuint? nativeUInt;
43+
}";
44+
45+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
46+
}
1047
}
1148
}

0 commit comments

Comments
 (0)