|
1 | 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. |
2 | 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. |
3 | 3 |
|
4 | | -#nullable disable |
5 | | - |
6 | 4 | namespace StyleCop.Analyzers.Test.CSharp9.ReadabilityRules |
7 | 5 | { |
8 | 6 | using System.Threading; |
9 | 7 | using System.Threading.Tasks; |
10 | 8 | using Microsoft.CodeAnalysis.Testing; |
| 9 | + using StyleCop.Analyzers.Lightup; |
11 | 10 | using StyleCop.Analyzers.Test.CSharp8.ReadabilityRules; |
12 | 11 | using Xunit; |
13 | 12 | using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< |
@@ -46,5 +45,68 @@ internal static S F() |
46 | 45 |
|
47 | 46 | await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedTestCode, CancellationToken.None).ConfigureAwait(false); |
48 | 47 | } |
| 48 | + |
| 49 | + [Fact] |
| 50 | + [WorkItem(3969, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3969")] |
| 51 | + public async Task VerifyNativeSizedIntegerCreationAsync() |
| 52 | + { |
| 53 | + var testCode = @" |
| 54 | +using System; |
| 55 | +
|
| 56 | +class TestClass |
| 57 | +{ |
| 58 | + void TestMethod() |
| 59 | + { |
| 60 | + nint nativeInt = [|new nint()|]; |
| 61 | + nuint nativeUInt = [|new nuint()|]; |
| 62 | + } |
| 63 | +}"; |
| 64 | + |
| 65 | + var fixedTestCode = @" |
| 66 | +using System; |
| 67 | +
|
| 68 | +class TestClass |
| 69 | +{ |
| 70 | + void TestMethod() |
| 71 | + { |
| 72 | + nint nativeInt = default(nint); |
| 73 | + nuint nativeUInt = default(nuint); |
| 74 | + } |
| 75 | +}"; |
| 76 | + |
| 77 | + // Force C# 9 language version even in later test scenarios |
| 78 | + await new CSharpTest(LanguageVersionEx.CSharp9) |
| 79 | + { |
| 80 | + TestCode = testCode, |
| 81 | + FixedCode = fixedTestCode, |
| 82 | + }.RunAsync(CancellationToken.None).ConfigureAwait(false); |
| 83 | + } |
| 84 | + |
| 85 | + [Fact] |
| 86 | + [WorkItem(3969, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3969")] |
| 87 | + public async Task VerifyNativeSizedIntegerDefaultParameterValuesAsync() |
| 88 | + { |
| 89 | + var testCode = @" |
| 90 | +using System; |
| 91 | +
|
| 92 | +class TestClass |
| 93 | +{ |
| 94 | + void TestMethod(nint nativeInt = [|new nint()|], nuint nativeUInt = [|new nuint()|]) |
| 95 | + { |
| 96 | + } |
| 97 | +}"; |
| 98 | + |
| 99 | + var fixedTestCode = @" |
| 100 | +using System; |
| 101 | +
|
| 102 | +class TestClass |
| 103 | +{ |
| 104 | + void TestMethod(nint nativeInt = default(nint), nuint nativeUInt = default(nuint)) |
| 105 | + { |
| 106 | + } |
| 107 | +}"; |
| 108 | + |
| 109 | + await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedTestCode, CancellationToken.None).ConfigureAwait(false); |
| 110 | + } |
49 | 111 | } |
50 | 112 | } |
0 commit comments