diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/DocumentationRules/SA1633CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/DocumentationRules/SA1633CSharp10UnitTests.cs index 7868dc85b..6a095a2fd 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/DocumentationRules/SA1633CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/DocumentationRules/SA1633CSharp10UnitTests.cs @@ -3,9 +3,46 @@ namespace StyleCop.Analyzers.Test.CSharp10.DocumentationRules { + using System.Threading; + using System.Threading.Tasks; + using StyleCop.Analyzers.DocumentationRules; using StyleCop.Analyzers.Test.CSharp9.DocumentationRules; + using Xunit; public partial class SA1633CSharp10UnitTests : SA1633CSharp9UnitTests { + [Fact] + [WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")] + public async Task TestHeaderNotFoundAfterMappedLineDirectiveAsync() + { + var testCode = @"#line (1,1)-(1,1) ""Test0.cs"" +#line default +// +// Copyright (c) FooCorp. All rights reserved. +// + +public class TestClass +{ +} +#line default"; + + var expected = Diagnostic(FileHeaderAnalyzers.SA1633DescriptorMissing).WithLocation(1, 1); + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); + } + + [Fact] + [WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")] + public async Task TestMissingHeaderAfterMappedLineDirectiveAsync() + { + var testCode = @"#line (1,1)-(1,1) ""Test0.cs"" +#line default +public class TestClass +{ +} +#line default"; + + var expected = Diagnostic(FileHeaderAnalyzers.SA1633DescriptorMissing).WithLocation(1, 1); + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/DocumentationRules/SA1649CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/DocumentationRules/SA1649CSharp10UnitTests.cs index a101a19cc..de2d8e239 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/DocumentationRules/SA1649CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/DocumentationRules/SA1649CSharp10UnitTests.cs @@ -1,8 +1,6 @@ // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -#nullable disable - namespace StyleCop.Analyzers.Test.CSharp10.DocumentationRules { using System.Threading; @@ -47,5 +45,19 @@ public enum IgnoredEnum {{ }} var expectedDiagnostic = Diagnostic().WithLocation(0); await VerifyCSharpFixAsync("TestType2.cs", testCode, StyleCopSettings, expectedDiagnostic, "TestType.cs", fixedCode, CancellationToken.None).ConfigureAwait(false); } + + [Fact] + [WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")] + public async Task VerifyMappedLineDirectiveDoesNotChangeFileNameCheckAsync() + { + var testCode = @"#line 1 ""DifferentName.cs"" +public class {|#0:NotMatching|} +{ +} +#line default"; + + var expectedDiagnostic = Diagnostic().WithLocation(0); + await VerifyCSharpDiagnosticAsync("ActualFile.cs", testCode, testSettings: null, new[] { expectedDiagnostic }, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1507CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1507CSharp10UnitTests.cs index f7bbb8421..d52a486bf 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1507CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1507CSharp10UnitTests.cs @@ -3,9 +3,31 @@ namespace StyleCop.Analyzers.Test.CSharp10.LayoutRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp9.LayoutRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.LayoutRules.SA1507CodeMustNotContainMultipleBlankLinesInARow, + StyleCop.Analyzers.LayoutRules.SA1507CodeFixProvider>; public partial class SA1507CSharp10UnitTests : SA1507CSharp9UnitTests { + [Fact] + [WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")] + public async Task TestConsecutiveMappedLineDirectivesDoNotCountAsBlankLinesAsync() + { + var testCode = @"class TestClass +{ +#line (5,1)-(5,1) ""Remapped.cs"" +#line default + void Test() + { + } +}"; + + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1508CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1508CSharp10UnitTests.cs index c3f8022bd..ad3403f9c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1508CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1508CSharp10UnitTests.cs @@ -3,9 +3,38 @@ namespace StyleCop.Analyzers.Test.CSharp10.LayoutRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp9.LayoutRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.LayoutRules.SA1508ClosingBracesMustNotBePrecededByBlankLine, + StyleCop.Analyzers.LayoutRules.SA1508CodeFixProvider>; public partial class SA1508CSharp10UnitTests : SA1508CSharp9UnitTests { + [Fact] + [WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")] + public async Task TestMappedLineDirectiveBeforeClosingBraceAsync() + { + var testCode = @"class TestClass +{ + private void DoWork() + { + } + + public void Test() + { + if (true) + { + DoWork(); +#line (15,1)-(15,1) ""Remapped.cs"" + } + } +}"; + + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1509CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1509CSharp10UnitTests.cs index bc06e4da2..86dda4648 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1509CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1509CSharp10UnitTests.cs @@ -3,9 +3,37 @@ namespace StyleCop.Analyzers.Test.CSharp10.LayoutRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp9.LayoutRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.LayoutRules.SA1509OpeningBracesMustNotBePrecededByBlankLine, + StyleCop.Analyzers.LayoutRules.SA1509CodeFixProvider>; public partial class SA1509CSharp10UnitTests : SA1509CSharp9UnitTests { + [Fact] + [WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")] + public async Task TestMappedLineDirectiveBeforeOpeningBraceAsync() + { + var testCode = @"class TestClass +{ + private void DoWork() + { + } + + public void Test() + { +#line (10,1)-(10,1) ""Remapped.cs"" + { + DoWork(); + } + } +}"; + + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1517CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1517CSharp10UnitTests.cs index 5513c3b2a..c67480a8f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1517CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1517CSharp10UnitTests.cs @@ -3,9 +3,29 @@ namespace StyleCop.Analyzers.Test.CSharp10.LayoutRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp9.LayoutRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.LayoutRules.SA1517CodeMustNotContainBlankLinesAtStartOfFile, + StyleCop.Analyzers.LayoutRules.SA1517CodeFixProvider>; public partial class SA1517CSharp10UnitTests : SA1517CSharp9UnitTests { + [Fact] + [WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")] + public async Task TestMappedLineDirectiveAtFileStartDoesNotTriggerAsync() + { + var testCode = @"#line (1,1)-(1,1) ""Remapped.cs"" + +class TestClass +{ +} +#line default"; + + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1518CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1518CSharp10UnitTests.cs index a7a5563d4..1ee071dbf 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1518CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/LayoutRules/SA1518CSharp10UnitTests.cs @@ -3,9 +3,27 @@ namespace StyleCop.Analyzers.Test.CSharp10.LayoutRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp9.LayoutRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.LayoutRules.SA1518UseLineEndingsCorrectlyAtEndOfFile, + StyleCop.Analyzers.LayoutRules.SA1518CodeFixProvider>; public partial class SA1518CSharp10UnitTests : SA1518CSharp9UnitTests { + [Fact] + [WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")] + public async Task TestMappedLineDirectiveAsLastContentDoesNotTriggerAsync() + { + var testCode = @"class TestClass +{ +} +#line (10,1)-(10,1) ""Remapped.cs"""; + + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1102CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1102CSharp10UnitTests.cs index 2b427c3d8..860b9510a 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1102CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1102CSharp10UnitTests.cs @@ -3,9 +3,35 @@ namespace StyleCop.Analyzers.Test.CSharp10.ReadabilityRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp9.ReadabilityRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.ReadabilityRules.SA110xQueryClauses, + StyleCop.Analyzers.ReadabilityRules.SA1102CodeFixProvider>; public partial class SA1102CSharp10UnitTests : SA1102CSharp9UnitTests { + [Fact] + [WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")] + public async Task TestMappedLineDirectiveBetweenClausesAsync() + { + var testCode = @"using System.Linq; +public class TestClass +{ + public void Test() + { + var query = + from value in new int[0] +#line (10,1)-(10,1) ""Remapped.cs"" + where value > 0 + select value; + } +}"; + + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1103CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1103CSharp10UnitTests.cs index e9084f222..20c48517c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1103CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1103CSharp10UnitTests.cs @@ -3,9 +3,34 @@ namespace StyleCop.Analyzers.Test.CSharp10.ReadabilityRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp9.ReadabilityRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.ReadabilityRules.SA110xQueryClauses, + StyleCop.Analyzers.ReadabilityRules.SA1103CodeFixProvider>; public partial class SA1103CSharp10UnitTests : SA1103CSharp9UnitTests { + [Fact] + [WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")] + public async Task TestMappedLineDirectiveBetweenClausesAsync() + { + var testCode = @"using System.Linq; +public class TestClass +{ + public void Test() + { + var query = + from value in new int[0] +#line (10,1)-(10,1) ""Remapped.cs"" + select value; + } +}"; + + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1104CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1104CSharp10UnitTests.cs index 4da434339..665c8bfbc 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1104CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1104CSharp10UnitTests.cs @@ -3,9 +3,34 @@ namespace StyleCop.Analyzers.Test.CSharp10.ReadabilityRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp9.ReadabilityRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.ReadabilityRules.SA110xQueryClauses, + StyleCop.Analyzers.ReadabilityRules.SA1104SA1105CodeFixProvider>; public partial class SA1104CSharp10UnitTests : SA1104CSharp9UnitTests { + [Fact] + [WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")] + public async Task TestMappedLineDirectiveBetweenClausesAsync() + { + var testCode = @"using System.Linq; +public class TestClass +{ + public void Test() + { + var query = + from value in new int[0] +#line (10,1)-(10,1) ""Remapped.cs"" + group value by value; + } +}"; + + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1105CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1105CSharp10UnitTests.cs index d61c48777..c65b75f6a 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1105CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1105CSharp10UnitTests.cs @@ -3,9 +3,35 @@ namespace StyleCop.Analyzers.Test.CSharp10.ReadabilityRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp9.ReadabilityRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.ReadabilityRules.SA110xQueryClauses, + StyleCop.Analyzers.ReadabilityRules.SA1104SA1105CodeFixProvider>; public partial class SA1105CSharp10UnitTests : SA1105CSharp9UnitTests { + [Fact] + [WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")] + public async Task TestMappedLineDirectiveBetweenClausesAsync() + { + var testCode = @"using System.Linq; +public class TestClass +{ + public void Test() + { + var query = + from value in new int[0] +#line (10,1)-(10,1) ""Remapped.cs"" + orderby value + select value; + } +}"; + + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1025CSharp10UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1025CSharp10UnitTests.cs index ec813bcc0..cf2176a47 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1025CSharp10UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/SpacingRules/SA1025CSharp10UnitTests.cs @@ -3,9 +3,32 @@ namespace StyleCop.Analyzers.Test.CSharp10.SpacingRules { + using System.Threading; + using System.Threading.Tasks; + using Microsoft.CodeAnalysis.Testing; using StyleCop.Analyzers.Test.CSharp9.SpacingRules; + using Xunit; + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< + StyleCop.Analyzers.SpacingRules.SA1025CodeMustNotContainMultipleWhitespaceInARow, + StyleCop.Analyzers.SpacingRules.SA1025CodeFixProvider>; public partial class SA1025CSharp10UnitTests : SA1025CSharp9UnitTests { + [Fact] + [WorkItem(3992, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3992")] + public async Task TestMappedLineDirectiveDoesNotAffectIndentationAsync() + { + var testCode = @"#line (5,5)-(5,10) ""File.cs"" +class TestClass +{ + public void Test() + { + int value = 0; + } +} +#line default"; + + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } } }