From 49f3f57d6a2ca990331212854f1417996bf32ded Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sat, 14 Mar 2015 14:22:55 -0500 Subject: [PATCH 01/12] Update DiagnosticResult to support specifying either the message or the format plus arguments --- .../Helpers/DiagnosticResult.cs | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticResult.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticResult.cs index 87acc72d2..b0cc955b4 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticResult.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticResult.cs @@ -34,7 +34,10 @@ public DiagnosticResultLocation(string path, int line, int column) /// public struct DiagnosticResult { + private static readonly object[] EmptyArguments = new object[0]; + private DiagnosticResultLocation[] locations; + private string message; public DiagnosticResultLocation[] Locations { @@ -65,7 +68,33 @@ public string Id public string Message { - get; set; + get + { + if (this.message != null) + return this.message; + + if (this.MessageFormat != null) + return string.Format(this.MessageFormat.ToString(), this.MessageArguments ?? EmptyArguments); + + return null; + } + + set + { + this.message = value; + } + } + + public LocalizableString MessageFormat + { + get; + set; + } + + public object[] MessageArguments + { + get; + set; } public string Path From a59f63ca29d68633bcb134cd9fad43ed6eb00eab Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sat, 14 Mar 2015 14:25:55 -0500 Subject: [PATCH 02/12] Simplified API for creating DiagnosticResult instances --- .../Helpers/DiagnosticResult.cs | 28 +++++++++++++++++++ .../Helpers/DiagnosticVerifier.Helper.cs | 14 ++++++++++ 2 files changed, 42 insertions(+) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticResult.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticResult.cs index b0cc955b4..c1363048c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticResult.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticResult.cs @@ -39,6 +39,14 @@ public struct DiagnosticResult private DiagnosticResultLocation[] locations; private string message; + public DiagnosticResult(DiagnosticDescriptor descriptor) + : this() + { + this.Id = descriptor.Id; + this.Severity = descriptor.DefaultSeverity; + this.MessageFormat = descriptor.MessageFormat; + } + public DiagnosticResultLocation[] Locations { get @@ -120,5 +128,25 @@ public int Column return this.Locations.Length > 0 ? this.Locations[0].Column : -1; } } + + public DiagnosticResult WithArguments(params object[] arguments) + { + DiagnosticResult result = this; + result.MessageArguments = arguments; + return result; + } + + public DiagnosticResult WithLocation(int line, int column) + { + return this.WithLocation("Test0.cs", line, column); + } + + public DiagnosticResult WithLocation(string path, int line, int column) + { + DiagnosticResult result = this; + Array.Resize(ref result.locations, (result.locations?.Length ?? 0) + 1); + result.locations[result.locations.Length - 1] = new DiagnosticResultLocation(path, line, column); + return result; + } } } \ No newline at end of file diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticVerifier.Helper.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticVerifier.Helper.cs index 7f3d37f85..c03c9fbb8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticVerifier.Helper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticVerifier.Helper.cs @@ -189,6 +189,20 @@ private static Project CreateProject(string[] sources, string language = Languag return solution.GetProject(projectId); } #endregion + + #region Generate expected results + + protected DiagnosticResult CSharpDiagnostic(string diagnosticId = null) + { + DiagnosticAnalyzer analyzer = this.GetCSharpDiagnosticAnalyzer(); + var supportedDiagnostics = analyzer.SupportedDiagnostics; + if (diagnosticId == null) + return new DiagnosticResult(supportedDiagnostics.Single()); + else + return new DiagnosticResult(supportedDiagnostics.Single(i => i.Id == diagnosticId)); + } + + #endregion } } From 2a978d311720ae1ffa6d33e2824259d63152879d Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sat, 14 Mar 2015 14:36:01 -0500 Subject: [PATCH 03/12] Use simplified DiagnosticResult API in documentation tests that use simple message formats (no arguments) --- .../DocumentationRules/SA1600UnitTests.cs | 310 +++--------------- .../DocumentationRules/SA1601UnitTests.cs | 74 +---- .../DocumentationRules/SA1602UnitTests.cs | 40 +-- .../DocumentationRules/SA1604UnitTests.cs | 184 ++--------- .../DocumentationRules/SA1605UnitTests.cs | 40 +-- .../DocumentationRules/SA1606UnitTests.cs | 184 ++--------- .../DocumentationRules/SA1607UnitTests.cs | 76 +---- .../DocumentationRules/SA1608UnitTests.cs | 39 +-- .../DocumentationRules/SA1642UnitTests.cs | 20 +- .../DocumentationRules/SA1643UnitTests.cs | 20 +- 10 files changed, 150 insertions(+), 837 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs index ac8c5dcc5..f07d0e661 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs @@ -2,12 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.DocumentationRules; using TestHelper; + using Xunit; /// /// This class contains unit tests for - @@ -36,22 +34,9 @@ private async Task TestTypeDeclarationDocumentation(string type, string modifier {{ }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 1) - } - } + this.CSharpDiagnostic().WithLocation(3, 1) }; await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, type), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None); @@ -82,22 +67,9 @@ public class OuterClass }} }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 5) - } - } + this.CSharpDiagnostic().WithLocation(8, 5) }; await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, type), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None); @@ -116,22 +88,9 @@ private async Task TestDelegateDeclarationDocumentation(string modifiers, bool r {{ }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 1) - } - } + this.CSharpDiagnostic().WithLocation(3, 1) }; await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None); @@ -162,22 +121,9 @@ public class OuterClass }} }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 5) - } - } + this.CSharpDiagnostic().WithLocation(8, 5) }; await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None); @@ -208,22 +154,9 @@ public class OuterClass }} }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 5) - } - } + this.CSharpDiagnostic().WithLocation(8, 5) }; string explicitInterfaceText = isExplicitInterfaceMethod ? " IInterface." : string.Empty; @@ -255,22 +188,9 @@ public interface InterfaceName } }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 5) - } - } + this.CSharpDiagnostic().WithLocation(8, 5) }; await this.VerifyCSharpDiagnosticAsync(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, !hasDocumentation ? expected : EmptyDiagnosticResults, CancellationToken.None); @@ -303,22 +223,9 @@ string MemberName } }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 12) - } - } + this.CSharpDiagnostic().WithLocation(8, 12) }; await this.VerifyCSharpDiagnosticAsync(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, !hasDocumentation ? expected : EmptyDiagnosticResults, CancellationToken.None); @@ -346,22 +253,9 @@ public interface InterfaceName }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 25) - } - } + this.CSharpDiagnostic().WithLocation(8, 25) }; await this.VerifyCSharpDiagnosticAsync(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, !hasDocumentation ? expected : EmptyDiagnosticResults, CancellationToken.None); @@ -388,22 +282,9 @@ public interface InterfaceName this[string key] { get; set; } }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 5) - } - } + this.CSharpDiagnostic().WithLocation(8, 5) }; await this.VerifyCSharpDiagnosticAsync(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, !hasDocumentation ? expected : EmptyDiagnosticResults, CancellationToken.None); @@ -434,22 +315,9 @@ public class OuterClass }} }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 5) - } - } + this.CSharpDiagnostic().WithLocation(8, 5) }; await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None); @@ -478,22 +346,9 @@ public class OuterClass }} }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 6) - } - } + this.CSharpDiagnostic().WithLocation(7, 6) }; await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None); @@ -522,22 +377,9 @@ public class OuterClass MemberName {{ get; set; }} }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 5) - } - } + this.CSharpDiagnostic().WithLocation(9, 5) }; string explicitInterfaceText = isExplicitInterfaceProperty ? " IInterface." : string.Empty; @@ -567,22 +409,9 @@ public class OuterClass this[string key] {{ get {{ return ""; }} set {{ }} }} }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 5) - } - } + this.CSharpDiagnostic().WithLocation(9, 5) }; string explicitInterfaceText = isExplicitInterfaceIndexer ? " IInterface." : string.Empty; @@ -634,22 +463,9 @@ event System.Action{1} }} }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 5) - } - } + this.CSharpDiagnostic().WithLocation(10, 5) }; string explicitInterfaceText = isExplicitInterfaceEvent ? " IInterface." : string.Empty; @@ -677,22 +493,9 @@ public class OuterClass System.Action Action; }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 19) - } - } + this.CSharpDiagnostic().WithLocation(8, 19) }; await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None); @@ -719,22 +522,9 @@ public class OuterClass System.Action Action; }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 19) - } - } + this.CSharpDiagnostic().WithLocation(8, 19) }; await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None); @@ -1051,22 +841,9 @@ public class OuterClass { }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 14) - } - } + this.CSharpDiagnostic().WithLocation(3, 14) }; await this.VerifyCSharpDiagnosticAsync(testCodeWithDocumentation, EmptyDiagnosticResults, CancellationToken.None); @@ -1089,22 +866,9 @@ public class OuterClass { }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 14) - } - } + this.CSharpDiagnostic().WithLocation(4, 14) }; await this.VerifyCSharpDiagnosticAsync(testCodeWithDocumentation, EmptyDiagnosticResults, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1601UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1601UnitTests.cs index 1ef28db40..2809f9ffb 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1601UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1601UnitTests.cs @@ -2,12 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.DocumentationRules; using TestHelper; + using Xunit; /// /// This class contains unit tests for - @@ -47,23 +45,11 @@ public partial {0} {{ }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Partial elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 1) - } - } + this.CSharpDiagnostic().WithLocation(3, 1) }; + await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "class"), expected, CancellationToken.None); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "struct"), expected, CancellationToken.None); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "interface"), expected, CancellationToken.None); @@ -81,23 +67,11 @@ public partial {0} {{ }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Partial elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } + this.CSharpDiagnostic().WithLocation(6, 1) }; + await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "class"), expected, CancellationToken.None); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "struct"), expected, CancellationToken.None); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "interface"), expected, CancellationToken.None); @@ -132,22 +106,9 @@ public partial class TypeName partial void MemberName(); }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Partial elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 18) - } - } + this.CSharpDiagnostic().WithLocation(7, 18) }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -168,22 +129,9 @@ public partial class TypeName partial void MemberName(); }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Partial elements must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 18) - } - } + this.CSharpDiagnostic().WithLocation(10, 18) }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1602UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1602UnitTests.cs index 063a91656..0ee34959d 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1602UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1602UnitTests.cs @@ -2,12 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.DocumentationRules; using TestHelper; + using Xunit; /// /// This class contains unit tests for - @@ -49,23 +47,11 @@ enum TypeName Bar }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Enumeration items must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 5) - } - } + this.CSharpDiagnostic().WithLocation(4, 5) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -84,23 +70,11 @@ enum TypeName Bar }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Enumeration items must be documented", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 5) - } - } + this.CSharpDiagnostic().WithLocation(10, 5) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1604UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1604UnitTests.cs index dbc81b947..7ce3e0383 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1604UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1604UnitTests.cs @@ -2,12 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.DocumentationRules; using TestHelper; + using Xunit; /// /// This class contains unit tests for - @@ -63,23 +61,11 @@ private async Task TestTypeWithoutDocumentation(string typeName) {{ }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 1) - } - } + this.CSharpDiagnostic().WithLocation(4, 1) }; + await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeName), expected, CancellationToken.None); } @@ -218,23 +204,11 @@ public async Task TestDelegateWithoutDocumentation() public delegate void TypeName();"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 6) - } - } + this.CSharpDiagnostic().WithLocation(4, 6) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -297,23 +271,11 @@ public class ClassName public void Test() { } }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 17) - } - } + this.CSharpDiagnostic().WithLocation(8, 17) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -376,23 +338,11 @@ public class ClassName public ClassName() { } }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 12) - } - } + this.CSharpDiagnostic().WithLocation(8, 12) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -455,23 +405,11 @@ public class ClassName ~ClassName() { } }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 6) - } - } + this.CSharpDiagnostic().WithLocation(8, 6) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -534,23 +472,11 @@ public class ClassName public ClassName Property { get; set; } }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 22) - } - } + this.CSharpDiagnostic().WithLocation(8, 22) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -613,23 +539,11 @@ public class ClassName public ClassName this[string t] { get { return null; } } }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 22) - } - } + this.CSharpDiagnostic().WithLocation(8, 22) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -692,23 +606,11 @@ public class ClassName public ClassName Foo; }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 22) - } - } + this.CSharpDiagnostic().WithLocation(8, 22) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -771,23 +673,11 @@ public class ClassName public event System.Action Foo; }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 32) - } - } + this.CSharpDiagnostic().WithLocation(8, 32) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -850,23 +740,11 @@ public interface InterfaceName event System.Action Foo { add; remove; } }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 25) - } - } + this.CSharpDiagnostic().WithLocation(8, 25) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1605UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1605UnitTests.cs index 2f42910f1..aded2c69c 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1605UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1605UnitTests.cs @@ -2,12 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.DocumentationRules; using TestHelper; + using Xunit; /// /// This class contains unit tests for - @@ -75,23 +73,11 @@ private async Task TestTypeWithoutDocumentation(string typeName) {{ }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Partial element documentation must have summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 1) - } - } + this.CSharpDiagnostic().WithLocation(4, 1) }; + await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeName), expected, CancellationToken.None); } @@ -267,23 +253,11 @@ public class ClassName partial void Test(); }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Partial element documentation must have summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 18) - } - } + this.CSharpDiagnostic().WithLocation(8, 18) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1606UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1606UnitTests.cs index de7670fa2..c6a9fe77f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1606UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1606UnitTests.cs @@ -2,12 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.DocumentationRules; using TestHelper; + using Xunit; /// /// This class contains unit tests for - @@ -65,23 +63,11 @@ private async Task TestTypeWithoutDocumentation(string typeName) {{ }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } + this.CSharpDiagnostic().WithLocation(6, 1) }; + await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeName), expected, CancellationToken.None); } @@ -222,23 +208,11 @@ public async Task TestDelegateWithoutDocumentation() public delegate void TypeName();"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 6) - } - } + this.CSharpDiagnostic().WithLocation(6, 6) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -303,23 +277,11 @@ public class ClassName public void Test() { } }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 17) - } - } + this.CSharpDiagnostic().WithLocation(10, 17) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -384,23 +346,11 @@ public class ClassName public ClassName() { } }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 12) - } - } + this.CSharpDiagnostic().WithLocation(10, 12) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -465,23 +415,11 @@ public class ClassName ~ClassName() { } }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 6) - } - } + this.CSharpDiagnostic().WithLocation(10, 6) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -546,23 +484,11 @@ public class ClassName public ClassName Property { get; set; } }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 22) - } - } + this.CSharpDiagnostic().WithLocation(10, 22) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -627,23 +553,11 @@ public class ClassName public ClassName this[string t] { get { return null; } } }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 22) - } - } + this.CSharpDiagnostic().WithLocation(10, 22) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -708,23 +622,11 @@ public class ClassName public ClassName Foo; }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 22) - } - } + this.CSharpDiagnostic().WithLocation(10, 22) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -789,23 +691,11 @@ public class ClassName public event System.Action Foo; }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 32) - } - } + this.CSharpDiagnostic().WithLocation(10, 32) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -870,23 +760,11 @@ public interface InterfaceName event System.Action Foo { add; remove; } }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 25) - } - } + this.CSharpDiagnostic().WithLocation(10, 25) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1607UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1607UnitTests.cs index ae5217444..729d776af 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1607UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1607UnitTests.cs @@ -2,12 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.DocumentationRules; using TestHelper; + using Xunit; /// /// This class contains unit tests for - @@ -77,23 +75,11 @@ private async Task TestTypeWithoutSummaryDocumentation(string typeName) {{ }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Partial element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } + this.CSharpDiagnostic().WithLocation(6, 1) }; + await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeName), expected, CancellationToken.None); } @@ -108,23 +94,11 @@ private async Task TestTypeWithoutContentDocumentation(string typeName) {{ }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Partial element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } + this.CSharpDiagnostic().WithLocation(6, 1) }; + await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeName), expected, CancellationToken.None); } @@ -314,23 +288,11 @@ public class ClassName partial void Test(); }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Partial element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 18) - } - } + this.CSharpDiagnostic().WithLocation(10, 18) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -349,23 +311,11 @@ public class ClassName partial void Test(); }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Partial element documentation must have summary text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 18) - } - } + this.CSharpDiagnostic().WithLocation(10, 18) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1608UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1608UnitTests.cs index d8b219b04..d532fede3 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1608UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1608UnitTests.cs @@ -3,10 +3,9 @@ using System.Threading; using System.Threading.Tasks; using Analyzers.DocumentationRules; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using TestHelper; + using Xunit; /// /// This class contains unit tests for - @@ -210,23 +209,11 @@ public class ClassName { }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must not have default summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 2, 5) - } - } + this.CSharpDiagnostic().WithLocation(2, 5) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -242,23 +229,11 @@ public class ClassName { }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Element documentation must not have default summary", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 2, 5) - } - } + this.CSharpDiagnostic().WithLocation(2, 5) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs index 4155f4403..37a23a5f2 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs @@ -2,12 +2,11 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.DocumentationRules; using TestHelper; + using Xunit; using static StyleCop.Analyzers.DocumentationRules.SA1642ConstructorSummaryDocumentationMustBeginWithStandardText; /// @@ -233,22 +232,9 @@ public class Foo{0} }}"; testCode = string.Format(testCode, generic ? "" : string.Empty, modifiers); - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Constructor summary documentation must begin with standard text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 13) - } - } + this.CSharpDiagnostic().WithLocation(5, 13) }; await this.VerifyCSharpDiagnosticAsync(testCode, diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1643UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1643UnitTests.cs index e29d19653..7472b3551 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1643UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1643UnitTests.cs @@ -2,12 +2,11 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.DocumentationRules; using TestHelper; + using Xunit; using static StyleCop.Analyzers.DocumentationRules.SA1643DestructorSummaryDocumentationMustBeginWithStandardText; /// @@ -164,22 +163,9 @@ public class Foo{0} }}"; testCode = string.Format(testCode, generic ? "" : string.Empty); - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Destructor summary documentation must begin with standard text", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 13) - } - } + this.CSharpDiagnostic().WithLocation(5, 13) }; await this.VerifyCSharpDiagnosticAsync(testCode, From da74a2cc50c79b571116357ce8929fce957545cf Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sat, 14 Mar 2015 14:40:45 -0500 Subject: [PATCH 04/12] Use simplified DiagnosticResult API in documentation tests that use message formats with arguments --- .../DocumentationRules/SA1603UnitTests.cs | 97 ++++--------------- 1 file changed, 19 insertions(+), 78 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1603UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1603UnitTests.cs index d090d95be..7b091595f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1603UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1603UnitTests.cs @@ -2,11 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.DocumentationRules; using TestHelper; + using Xunit; /// /// This class contains unit tests for - @@ -65,23 +64,11 @@ public async Task TestElementStartTagSkippedToken() /// public class Foo { }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "The documentation header is composed of invalid XML: Invalid token.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 2, 13) - } - } + this.CSharpDiagnostic().WithArguments("Invalid token.").WithLocation(2, 13) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -92,23 +79,11 @@ public async Task TestElementEndTagSkippedToken() /// public class Foo { }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "The documentation header is composed of invalid XML: Invalid token.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 2, 23) - } - } + this.CSharpDiagnostic().WithArguments("Invalid token.").WithLocation(2, 23) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -119,23 +94,11 @@ public async Task TestEmptyElementSkippedToken() /// public class Foo { }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "The documentation header is composed of invalid XML: Invalid token.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 2, 13) - } - } + this.CSharpDiagnostic().WithArguments("Invalid token.").WithLocation(2, 13) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -146,24 +109,13 @@ public async Task TestElementTagsNotMatching() /// a public class Foo { }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "The documentation header is composed of invalid XML: The 'summary' start tag does not match the end tag of 'sumary'.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 2, 5), - new DiagnosticResultLocation("Test0.cs", 2, 15) - } - } + this.CSharpDiagnostic().WithArguments("The 'summary' start tag does not match the end tag of 'sumary'.") + .WithLocation(2, 5) + .WithLocation(2, 15) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -174,23 +126,12 @@ public async Task TestElementMissingEndTag() /// a public class Foo { }"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "The documentation header is composed of invalid XML: The XML tag 'summary' is not closed.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 2, 5) - } - } + this.CSharpDiagnostic().WithArguments("The XML tag 'summary' is not closed.") + .WithLocation(2, 5) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } From 4f2260f56f05fc66405593075b325566e90e02b4 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sat, 14 Mar 2015 15:11:13 -0500 Subject: [PATCH 05/12] Use simplified DiagnosticResult API in shared locations in documentation tests --- .../LayoutRules/SA1517UnitTests.cs | 13 +- .../LayoutRules/SA1518UnitTests.cs | 13 +- .../DebugMessagesUnitTestsBase.cs | 57 +--- .../FileMayOnlyContainTestBase.cs | 44 +-- .../SpacingRules/NumberSignSpacingTestBase.cs | 304 +++--------------- 5 files changed, 69 insertions(+), 362 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1517UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1517UnitTests.cs index 1d9df926f..b4b5323d7 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1517UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1517UnitTests.cs @@ -2,12 +2,11 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.LayoutRules; using TestHelper; + using Xunit; /// /// Unit tests for . @@ -157,15 +156,9 @@ protected override CodeFixProvider GetCSharpCodeFixProvider() private DiagnosticResult[] GenerateExpectedWarning(int line, int column) { return new[] - { - new DiagnosticResult { - Id = DiagnosticId, - Message = "Code must not contain blank lines at start of file", - Severity = DiagnosticSeverity.Warning, - Locations = new[] { new DiagnosticResultLocation("Test0.cs", line, column) } - } - }; + this.CSharpDiagnostic().WithLocation(line, column) + }; } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1518UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1518UnitTests.cs index 2d9b9e5c1..c07a32644 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1518UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1518UnitTests.cs @@ -2,12 +2,11 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.LayoutRules; using TestHelper; + using Xunit; /// /// Unit tests for . @@ -201,15 +200,9 @@ protected override CodeFixProvider GetCSharpCodeFixProvider() private DiagnosticResult[] GenerateExpectedWarning(int line, int column) { return new[] - { - new DiagnosticResult { - Id = DiagnosticId, - Message = "Code must not contain blank lines at end of file", - Severity = DiagnosticSeverity.Warning, - Locations = new[] { new DiagnosticResultLocation("Test0.cs", line, column) } - } - }; + this.CSharpDiagnostic().WithLocation(line, column) + }; } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/DebugMessagesUnitTestsBase.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/DebugMessagesUnitTestsBase.cs index 586471a6f..fd6928e91 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/DebugMessagesUnitTestsBase.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/DebugMessagesUnitTestsBase.cs @@ -4,9 +4,8 @@ using System.Text; using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; - using Xunit; using TestHelper; + using Xunit; public abstract class DebugMessagesUnitTestsBase : CodeFixVerifier { @@ -214,20 +213,10 @@ public void Bar() }}}} }}}}"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = string.Format("Debug.{0} must provide message text", this.MethodName), - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 9) - } - } - }; + DiagnosticResult[] expected = + { + this.CSharpDiagnostic().WithLocation(7, 9) + }; await this.VerifyCSharpDiagnosticAsync(string.Format(this.BuildTestCode(testCodeFormat), argument), expected, CancellationToken.None); } @@ -244,20 +233,10 @@ public void Bar() }}}} }}}}"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = string.Format("Debug.{0} must provide message text", this.MethodName), - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 9) - } - } - }; + DiagnosticResult[] expected = + { + this.CSharpDiagnostic().WithLocation(7, 9) + }; await this.VerifyCSharpDiagnosticAsync(string.Format(this.BuildTestCode(testCodeFormat), argument), expected, CancellationToken.None); } @@ -273,20 +252,10 @@ public void Bar() }}}} }}}}"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = string.Format("Debug.{0} must provide message text", this.MethodName), - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 9) - } - } - }; + DiagnosticResult[] expected = + { + this.CSharpDiagnostic().WithLocation(6, 9) + }; await this.VerifyCSharpDiagnosticAsync(string.Format(this.BuildTestCode(testCodeFormat), argument), expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/FileMayOnlyContainTestBase.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/FileMayOnlyContainTestBase.cs index 2f1a19c87..1b36bc639 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/FileMayOnlyContainTestBase.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/FileMayOnlyContainTestBase.cs @@ -45,20 +45,10 @@ public async Task TestTwoElements() { }"; - var expected = new[] - { - new DiagnosticResult + DiagnosticResult[] expected = { - Id = this.DiagnosticId, - Message = this.Message, - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, this.Keyword.Length + 2) - } - } - }; + this.CSharpDiagnostic().WithLocation(4, this.Keyword.Length + 2) + }; await this.VerifyCSharpDiagnosticAsync(testCode.Replace("%1", this.Keyword), expected, CancellationToken.None); } @@ -76,31 +66,11 @@ public async Task TestThreeElements() { }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.Message, - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, this.Keyword.Length + 2) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = this.DiagnosticId, - Message = this.Message, - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, this.Keyword.Length + 2) - } - } - }; + this.CSharpDiagnostic().WithLocation(4, this.Keyword.Length + 2), + this.CSharpDiagnostic().WithLocation(7, this.Keyword.Length + 2) + }; await this.VerifyCSharpDiagnosticAsync(testCode.Replace("%1", this.Keyword), expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/NumberSignSpacingTestBase.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/NumberSignSpacingTestBase.cs index 75031e8b1..88f307aa4 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/NumberSignSpacingTestBase.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/NumberSignSpacingTestBase.cs @@ -2,11 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using TestHelper; + using Xunit; public abstract class NumberSignSpacingTestBase : CodeFixVerifier { @@ -60,23 +59,11 @@ void Foo() } "; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be followed by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 21) - } - } + this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 21) }; + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(testCode, fixedTest, cancellationToken: CancellationToken.None); } @@ -112,29 +99,17 @@ void Foo() "; string test; - DiagnosticResult[] expected; test = string.Format(testFormat, this.Sign + "3"); - expected = EmptyDiagnosticResults; - await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); + await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); test = string.Format(testFormat, this.Sign + " 3"); - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be followed by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 17) - } - } + this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(8, 17) }; + await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); } @@ -170,29 +145,17 @@ void Foo() "; string test; - DiagnosticResult[] expected; test = string.Format(testFormat, this.Sign + "3"); - expected = EmptyDiagnosticResults; - await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); + await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); test = string.Format(testFormat, this.Sign + " 3"); - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be followed by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 17) - } - } + this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(8, 17) }; + await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); } @@ -226,29 +189,17 @@ void Foo() "; string test; - DiagnosticResult[] expected; test = string.Format(testFormat, " " + this.Sign + "3"); - expected = EmptyDiagnosticResults; - await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); + await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); test = string.Format(testFormat, this.Sign + "3"); - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must be preceded by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 20) - } - } + this.CSharpDiagnostic().WithArguments(string.Empty, "preceded").WithLocation(7, 20) }; + await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); @@ -256,18 +207,9 @@ void Foo() expected = new[] { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be followed by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 21) - } - } + this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 21) }; + await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); @@ -275,29 +217,10 @@ void Foo() expected = new[] { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must be preceded by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 20) - } - }, - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be followed by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 20) - } - } + this.CSharpDiagnostic().WithArguments(string.Empty, "preceded").WithLocation(7, 20), + this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 20) }; + await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); } @@ -331,29 +254,17 @@ void Foo() "; string test; - DiagnosticResult[] expected; test = string.Format(testFormat, this.Sign + "3"); - expected = EmptyDiagnosticResults; - await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); + await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); test = string.Format(testFormat, this.Sign + " 3"); - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be followed by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 25) - } - } + this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 25) }; + await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); } @@ -387,28 +298,15 @@ void Foo() "; string test; - DiagnosticResult[] expected; test = string.Format(testFormat, this.Sign + "3"); - expected = EmptyDiagnosticResults; - await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); + await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); test = string.Format(testFormat, " " + this.Sign + "3"); - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be preceded by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 27) - } - } + this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 27) }; await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); @@ -417,17 +315,7 @@ void Foo() expected = new[] { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be followed by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 26) - } - } + this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 26) }; await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); @@ -436,28 +324,8 @@ void Foo() expected = new[] { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be preceded by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 27) - } - }, - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be followed by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 27) - } - } + this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 27), + this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 27) }; await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); @@ -492,28 +360,15 @@ void Foo() "; string test; - DiagnosticResult[] expected; test = string.Format(testFormat, this.Sign + "3"); - expected = EmptyDiagnosticResults; - await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); + await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); test = string.Format(testFormat, " " + this.Sign + "3"); - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be preceded by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 23) - } - } + this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 23) }; await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); @@ -522,17 +377,7 @@ void Foo() expected = new[] { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be followed by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 22) - } - } + this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 22) }; await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); @@ -541,28 +386,8 @@ void Foo() expected = new[] { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be preceded by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 23) - } - }, - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be followed by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 23) - } - } + this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 23), + this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 23) }; await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); @@ -597,28 +422,15 @@ void Foo() "; string test; - DiagnosticResult[] expected; test = string.Format(testFormat, this.Sign + "3"); - expected = EmptyDiagnosticResults; - await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); + await this.VerifyCSharpDiagnosticAsync(test, EmptyDiagnosticResults, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); test = string.Format(testFormat, " " + this.Sign + "3"); - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be preceded by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 32) - } - } + this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 32) }; await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); @@ -627,17 +439,7 @@ void Foo() expected = new[] { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be followed by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 31) - } - } + this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 31) }; await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); @@ -646,28 +448,8 @@ void Foo() expected = new[] { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be preceded by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 32) - } - }, - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.SignName + " sign must not be followed by a space.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 32) - } - } + this.CSharpDiagnostic().WithArguments(" not", "preceded").WithLocation(7, 32), + this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 32) }; await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); From 264eb6d19a98da8c17c72d4d9d0870caf8732bc6 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sat, 14 Mar 2015 15:35:09 -0500 Subject: [PATCH 06/12] Use simplified DiagnosticResult API in SA1119, which has multiple supported diagnostics --- .../MaintainabilityRules/SA1119UnitTests.cs | 1094 ++--------------- ...atementMustNotUseUnnecessaryParenthesis.cs | 11 +- 2 files changed, 138 insertions(+), 967 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1119UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1119UnitTests.cs index 34c49307a..221b661e9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1119UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1119UnitTests.cs @@ -2,16 +2,16 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; + using Analyzers.MaintainabilityRules; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; - using Analyzers.MaintainabilityRules; using TestHelper; + using Xunit; public class SA1119UnitTests : CodeFixVerifier { private const string DiagnosticId = SA1119StatementMustNotUseUnnecessaryParenthesis.DiagnosticId; + private const string ParenthesesDiagnosticId = SA1119StatementMustNotUseUnnecessaryParenthesis.ParenthesesDiagnosticId; [Fact] public async Task TestEmptySource() @@ -43,42 +43,13 @@ public void Bar() int x = (1); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 17) - } - }, - new DiagnosticResult + + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 19) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 17), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 17), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 19) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -102,75 +73,16 @@ public void Bar() int x = ((1)); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 18) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 18) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 20) - } - }, - new DiagnosticResult + + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 21) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 17), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 17), + this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 18), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 18), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 20), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 21), + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -207,42 +119,13 @@ public void Bar() string x = (ToString()); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 20) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 20) - } - }, - new DiagnosticResult + + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 31) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 20), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 20), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 31) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -281,75 +164,15 @@ public void Bar() string x = (Local).ToString() + Local.IndexOf(('x')); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 20) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 20) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 26) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 55) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 55) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 59) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(6, 20), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 20), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 26), + this.CSharpDiagnostic(DiagnosticId).WithLocation(6, 55), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 55), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 59), + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -389,42 +212,13 @@ public void Bar() (this.Local) = Local; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 9) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 9) - } - }, - new DiagnosticResult + + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 20) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(6, 9), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 9), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 20) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -450,42 +244,12 @@ public void Bar() int x = (Local); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 17) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 23) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(6, 17), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 17), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 23) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -523,42 +287,13 @@ public void Bar() int x = ((int)3); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 17) - } - }, - new DiagnosticResult + + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 24) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 17), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 17), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 24) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -597,42 +332,12 @@ public void Bar() x = ((int)3); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 13) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 20) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(6, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 20) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -709,207 +414,27 @@ public void Bar() x = (-x); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 16) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 16) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 11, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 11, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 11, 16) - } - }, - }; + DiagnosticResult[] expected = + { + this.CSharpDiagnostic(DiagnosticId).WithLocation(6, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 17), + this.CSharpDiagnostic(DiagnosticId).WithLocation(7, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(7, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(7, 17), + this.CSharpDiagnostic(DiagnosticId).WithLocation(8, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(8, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(8, 17), + this.CSharpDiagnostic(DiagnosticId).WithLocation(9, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(9, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(9, 16), + this.CSharpDiagnostic(DiagnosticId).WithLocation(10, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(10, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(10, 16), + this.CSharpDiagnostic(DiagnosticId).WithLocation(11, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(11, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(11, 16), + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -954,75 +479,16 @@ public void Bar() x = 3 * (unchecked(5)); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 21) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 21) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 32) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 17) - } - }, - new DiagnosticResult + + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 30) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 21), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 21), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 32), + this.CSharpDiagnostic(DiagnosticId).WithLocation(6, 17), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 17), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 30), + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -1060,42 +526,12 @@ public void Bar() string x = (nameof(Foo)) + ""Bar""; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 20) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 20) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 32) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 20), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 20), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 32) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -1146,75 +582,15 @@ public void Bar() x = ("""" is string); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 18) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 18) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 31) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 13) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 26) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 18), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 18), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 31), + this.CSharpDiagnostic(DiagnosticId).WithLocation(6, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 13), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 26), + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -1254,42 +630,12 @@ public void Bar() string x = (y = ""foo""); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 20) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 20) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 30) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(6, 20), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 20), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 30) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -1342,42 +688,12 @@ public void Bar() string x = (true ? ""foo"" : ""bar""); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 20) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 20) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 41) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 20), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 20), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 41) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -1428,42 +744,12 @@ public void Bar() string x = (""foo"" ?? ""bar""); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 20) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 20) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 35) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 20), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 20), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 35) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -1516,75 +802,15 @@ public void Bar() System.Func y = ((v) => v); } }"; - var expected = new[] - { - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 41) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 41) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 48) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 41) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 41) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 50) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 41), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 41), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 48), + this.CSharpDiagnostic(DiagnosticId).WithLocation(6, 41), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 41), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(6, 50), + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -1636,42 +862,12 @@ public void Bar() int[] x = (new int[10]); } }"; - var expected = new[] - { - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 19) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 19) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 31) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 19), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 19), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 31) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -1721,42 +917,12 @@ public void Bar() var x = (from y in new int[10] select y + 1); } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 17) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId + "_p", - Message = "Statement must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Hidden, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 52) - } - } - }; + this.CSharpDiagnostic(DiagnosticId).WithLocation(5, 17), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 17), + this.CSharpDiagnostic(ParenthesesDiagnosticId).WithLocation(5, 52) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs b/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs index 71762c7dd..680a659bd 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1119StatementMustNotUseUnnecessaryParenthesis.cs @@ -2,9 +2,9 @@ { using System.Collections.Immutable; using Microsoft.CodeAnalysis; - using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; + using Microsoft.CodeAnalysis.Diagnostics; /// /// A C# statement contains parenthesis which are unnecessary and should be removed. @@ -42,6 +42,11 @@ public class SA1119StatementMustNotUseUnnecessaryParenthesis : DiagnosticAnalyze /// analyzer. /// public const string DiagnosticId = "SA1119"; + /// + /// The ID for the helper diagnostic used to mark the parentheses tokens surrounding the expression with + /// . + /// + public const string ParenthesesDiagnosticId = DiagnosticId + "_p"; private const string Title = "Statement must not use unnecessary parenthesis"; private const string MessageFormat = "Statement must not use unnecessary parenthesis"; private const string Category = "StyleCop.CSharp.MaintainabilityRules"; @@ -51,10 +56,10 @@ public class SA1119StatementMustNotUseUnnecessaryParenthesis : DiagnosticAnalyze private static readonly DiagnosticDescriptor Descriptor = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, Category, DiagnosticSeverity.Warning, true, Description, HelpLink); private static readonly DiagnosticDescriptor ParenthesisDescriptor = - new DiagnosticDescriptor(DiagnosticId + "_p", Title, MessageFormat, Category, DiagnosticSeverity.Hidden, true, Description, HelpLink, customTags: new[] { WellKnownDiagnosticTags.Unnecessary, WellKnownDiagnosticTags.NotConfigurable }); + new DiagnosticDescriptor(ParenthesesDiagnosticId, Title, MessageFormat, Category, DiagnosticSeverity.Hidden, false, Description, HelpLink, customTags: new[] { WellKnownDiagnosticTags.Unnecessary, WellKnownDiagnosticTags.NotConfigurable }); private static readonly ImmutableArray SupportedDiagnosticsValue = - ImmutableArray.Create(Descriptor); + ImmutableArray.Create(Descriptor, ParenthesisDescriptor); /// public override ImmutableArray SupportedDiagnostics From d7644b5bf000f7ce98e28f307615ccfb0a86c2c9 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sun, 15 Mar 2015 14:33:35 -0500 Subject: [PATCH 07/12] Added an overload of VerifyCSharpDiagnosticAsync which accepts a single DiagnosticResult instead of an array --- .../Verifiers/DiagnosticVerifier.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/DiagnosticVerifier.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/DiagnosticVerifier.cs index 505e32232..f4b892ecd 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/DiagnosticVerifier.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/DiagnosticVerifier.cs @@ -37,6 +37,21 @@ protected virtual DiagnosticAnalyzer GetBasicDiagnosticAnalyzer() #region Verifier wrappers + /// + /// Called to test a C# when applied on the single input source as a string. + /// + /// Input a for the expected . + /// + /// + /// A class in the form of a string to run the analyzer on. + /// A s describing the that should + /// be reported by the analyzer for the specified source. + /// The that the task will observe. + protected Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken) + { + return this.VerifyCSharpDiagnosticAsync(source, new[] { expected }, cancellationToken); + } + /// /// Called to test a C# when applied on the single input source as a string. /// From b787022e42a7045edb4c06a596a0166e9073442a Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sun, 15 Mar 2015 14:36:06 -0500 Subject: [PATCH 08/12] Use the new overload of VerifyCSharpDiagnosticAsync where applicable --- .../DocumentationRules/SA1600UnitTests.cs | 10 +--- .../DocumentationRules/SA1601UnitTests.cs | 20 ++------ .../DocumentationRules/SA1602UnitTests.cs | 10 +--- .../DocumentationRules/SA1603UnitTests.cs | 33 ++++-------- .../DocumentationRules/SA1604UnitTests.cs | 50 ++++--------------- .../DocumentationRules/SA1605UnitTests.cs | 10 +--- .../DocumentationRules/SA1606UnitTests.cs | 50 ++++--------------- .../DocumentationRules/SA1607UnitTests.cs | 20 ++------ .../DocumentationRules/SA1608UnitTests.cs | 10 +--- .../DocumentationRules/SA1642UnitTests.cs | 5 +- .../DocumentationRules/SA1643UnitTests.cs | 5 +- .../LayoutRules/SA1517UnitTests.cs | 7 +-- .../LayoutRules/SA1518UnitTests.cs | 7 +-- .../DebugMessagesUnitTestsBase.cs | 15 ++---- .../FileMayOnlyContainTestBase.cs | 5 +- .../SpacingRules/NumberSignSpacingTestBase.cs | 20 ++------ 16 files changed, 60 insertions(+), 217 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs index f07d0e661..f055484b8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1600UnitTests.cs @@ -841,10 +841,7 @@ public class OuterClass { }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(3, 14) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 14); await this.VerifyCSharpDiagnosticAsync(testCodeWithDocumentation, EmptyDiagnosticResults, CancellationToken.None); await this.VerifyCSharpDiagnosticAsync(testCodeWithEmptyDocumentation, expected, CancellationToken.None); @@ -866,10 +863,7 @@ public class OuterClass { }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(4, 14) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 14); await this.VerifyCSharpDiagnosticAsync(testCodeWithDocumentation, EmptyDiagnosticResults, CancellationToken.None); await this.VerifyCSharpDiagnosticAsync(testCodeWithEmptyDocumentation, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1601UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1601UnitTests.cs index 2809f9ffb..2ccb219a9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1601UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1601UnitTests.cs @@ -45,10 +45,7 @@ public partial {0} {{ }}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(3, 1) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 1); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "class"), expected, CancellationToken.None); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "struct"), expected, CancellationToken.None); @@ -67,10 +64,7 @@ public partial {0} {{ }}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(6, 1) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "class"), expected, CancellationToken.None); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "struct"), expected, CancellationToken.None); @@ -106,10 +100,7 @@ public partial class TypeName partial void MemberName(); }}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(7, 18) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 18); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -129,10 +120,7 @@ public partial class TypeName partial void MemberName(); }}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(10, 18) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 18); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1602UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1602UnitTests.cs index 0ee34959d..79074bfbe 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1602UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1602UnitTests.cs @@ -47,10 +47,7 @@ enum TypeName Bar }}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(4, 5) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 5); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -70,10 +67,7 @@ enum TypeName Bar }}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(10, 5) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 5); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1603UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1603UnitTests.cs index 7b091595f..bc143e74f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1603UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1603UnitTests.cs @@ -64,10 +64,7 @@ public async Task TestElementStartTagSkippedToken() /// public class Foo { }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithArguments("Invalid token.").WithLocation(2, 13) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("Invalid token.").WithLocation(2, 13); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -79,10 +76,7 @@ public async Task TestElementEndTagSkippedToken() /// public class Foo { }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithArguments("Invalid token.").WithLocation(2, 23) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("Invalid token.").WithLocation(2, 23); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -94,10 +88,7 @@ public async Task TestEmptyElementSkippedToken() /// public class Foo { }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithArguments("Invalid token.").WithLocation(2, 13) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("Invalid token.").WithLocation(2, 13); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -109,12 +100,10 @@ public async Task TestElementTagsNotMatching() /// a public class Foo { }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithArguments("The 'summary' start tag does not match the end tag of 'sumary'.") - .WithLocation(2, 5) - .WithLocation(2, 15) - }; + DiagnosticResult expected = + this.CSharpDiagnostic().WithArguments("The 'summary' start tag does not match the end tag of 'sumary'.") + .WithLocation(2, 5) + .WithLocation(2, 15); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -126,11 +115,9 @@ public async Task TestElementMissingEndTag() /// a public class Foo { }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithArguments("The XML tag 'summary' is not closed.") - .WithLocation(2, 5) - }; + DiagnosticResult expected = + this.CSharpDiagnostic().WithArguments("The XML tag 'summary' is not closed.") + .WithLocation(2, 5); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1604UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1604UnitTests.cs index 7ce3e0383..b21698525 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1604UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1604UnitTests.cs @@ -61,10 +61,7 @@ private async Task TestTypeWithoutDocumentation(string typeName) {{ }}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(4, 1) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 1); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeName), expected, CancellationToken.None); } @@ -204,10 +201,7 @@ public async Task TestDelegateWithoutDocumentation() public delegate void TypeName();"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(4, 6) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 6); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -271,10 +265,7 @@ public class ClassName public void Test() { } }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(8, 17) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 17); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -338,10 +329,7 @@ public class ClassName public ClassName() { } }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(8, 12) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 12); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -405,10 +393,7 @@ public class ClassName ~ClassName() { } }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(8, 6) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 6); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -472,10 +457,7 @@ public class ClassName public ClassName Property { get; set; } }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(8, 22) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 22); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -539,10 +521,7 @@ public class ClassName public ClassName this[string t] { get { return null; } } }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(8, 22) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 22); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -606,10 +585,7 @@ public class ClassName public ClassName Foo; }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(8, 22) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 22); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -673,10 +649,7 @@ public class ClassName public event System.Action Foo; }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(8, 32) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 32); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -740,10 +713,7 @@ public interface InterfaceName event System.Action Foo { add; remove; } }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(8, 25) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 25); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1605UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1605UnitTests.cs index aded2c69c..1121bd3d8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1605UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1605UnitTests.cs @@ -73,10 +73,7 @@ private async Task TestTypeWithoutDocumentation(string typeName) {{ }}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(4, 1) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 1); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeName), expected, CancellationToken.None); } @@ -253,10 +250,7 @@ public class ClassName partial void Test(); }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(8, 18) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 18); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1606UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1606UnitTests.cs index c6a9fe77f..6e7d8363e 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1606UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1606UnitTests.cs @@ -63,10 +63,7 @@ private async Task TestTypeWithoutDocumentation(string typeName) {{ }}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(6, 1) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeName), expected, CancellationToken.None); } @@ -208,10 +205,7 @@ public async Task TestDelegateWithoutDocumentation() public delegate void TypeName();"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(6, 6) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 6); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -277,10 +271,7 @@ public class ClassName public void Test() { } }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(10, 17) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 17); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -346,10 +337,7 @@ public class ClassName public ClassName() { } }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(10, 12) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 12); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -415,10 +403,7 @@ public class ClassName ~ClassName() { } }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(10, 6) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 6); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -484,10 +469,7 @@ public class ClassName public ClassName Property { get; set; } }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(10, 22) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 22); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -553,10 +535,7 @@ public class ClassName public ClassName this[string t] { get { return null; } } }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(10, 22) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 22); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -622,10 +601,7 @@ public class ClassName public ClassName Foo; }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(10, 22) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 22); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -691,10 +667,7 @@ public class ClassName public event System.Action Foo; }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(10, 32) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 32); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -760,10 +733,7 @@ public interface InterfaceName event System.Action Foo { add; remove; } }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(10, 25) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 25); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1607UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1607UnitTests.cs index 729d776af..ec87447a5 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1607UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1607UnitTests.cs @@ -75,10 +75,7 @@ private async Task TestTypeWithoutSummaryDocumentation(string typeName) {{ }}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(6, 1) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeName), expected, CancellationToken.None); } @@ -94,10 +91,7 @@ private async Task TestTypeWithoutContentDocumentation(string typeName) {{ }}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(6, 1) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeName), expected, CancellationToken.None); } @@ -288,10 +282,7 @@ public class ClassName partial void Test(); }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(10, 18) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 18); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -311,10 +302,7 @@ public class ClassName partial void Test(); }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(10, 18) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 18); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1608UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1608UnitTests.cs index d532fede3..b9a833f4f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1608UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1608UnitTests.cs @@ -209,10 +209,7 @@ public class ClassName { }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(2, 5) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(2, 5); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -229,10 +226,7 @@ public class ClassName { }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(2, 5) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(2, 5); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs index 37a23a5f2..21d76f27d 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1642UnitTests.cs @@ -232,10 +232,7 @@ public class Foo{0} }}"; testCode = string.Format(testCode, generic ? "" : string.Empty, modifiers); - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(5, 13) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 13); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1643UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1643UnitTests.cs index 7472b3551..88fda22c0 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1643UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1643UnitTests.cs @@ -163,10 +163,7 @@ public class Foo{0} }}"; testCode = string.Format(testCode, generic ? "" : string.Empty); - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(5, 13) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 13); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1517UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1517UnitTests.cs index b4b5323d7..8650c4040 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1517UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1517UnitTests.cs @@ -153,12 +153,9 @@ protected override CodeFixProvider GetCSharpCodeFixProvider() return new SA1517CodeFixProvider(); } - private DiagnosticResult[] GenerateExpectedWarning(int line, int column) + private DiagnosticResult GenerateExpectedWarning(int line, int column) { - return new[] - { - this.CSharpDiagnostic().WithLocation(line, column) - }; + return this.CSharpDiagnostic().WithLocation(line, column); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1518UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1518UnitTests.cs index c07a32644..4adc13743 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1518UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1518UnitTests.cs @@ -197,12 +197,9 @@ protected override CodeFixProvider GetCSharpCodeFixProvider() return new SA1518CodeFixProvider(); } - private DiagnosticResult[] GenerateExpectedWarning(int line, int column) + private DiagnosticResult GenerateExpectedWarning(int line, int column) { - return new[] - { - this.CSharpDiagnostic().WithLocation(line, column) - }; + return this.CSharpDiagnostic().WithLocation(line, column); } } } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/DebugMessagesUnitTestsBase.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/DebugMessagesUnitTestsBase.cs index fd6928e91..0496bc408 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/DebugMessagesUnitTestsBase.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/DebugMessagesUnitTestsBase.cs @@ -213,10 +213,7 @@ public void Bar() }}}} }}}}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(7, 9) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 9); await this.VerifyCSharpDiagnosticAsync(string.Format(this.BuildTestCode(testCodeFormat), argument), expected, CancellationToken.None); } @@ -233,10 +230,7 @@ public void Bar() }}}} }}}}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(7, 9) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 9); await this.VerifyCSharpDiagnosticAsync(string.Format(this.BuildTestCode(testCodeFormat), argument), expected, CancellationToken.None); } @@ -252,10 +246,7 @@ public void Bar() }}}} }}}}"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(6, 9) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 9); await this.VerifyCSharpDiagnosticAsync(string.Format(this.BuildTestCode(testCodeFormat), argument), expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/FileMayOnlyContainTestBase.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/FileMayOnlyContainTestBase.cs index 1b36bc639..96b33a7c4 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/FileMayOnlyContainTestBase.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/FileMayOnlyContainTestBase.cs @@ -45,10 +45,7 @@ public async Task TestTwoElements() { }"; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithLocation(4, this.Keyword.Length + 2) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, this.Keyword.Length + 2); await this.VerifyCSharpDiagnosticAsync(testCode.Replace("%1", this.Keyword), expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/NumberSignSpacingTestBase.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/NumberSignSpacingTestBase.cs index 88f307aa4..7eeca4150 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/NumberSignSpacingTestBase.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/SpacingRules/NumberSignSpacingTestBase.cs @@ -59,10 +59,7 @@ void Foo() } "; - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 21) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 21); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(testCode, fixedTest, cancellationToken: CancellationToken.None); @@ -105,10 +102,7 @@ void Foo() await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); test = string.Format(testFormat, this.Sign + " 3"); - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(8, 17) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(8, 17); await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); @@ -151,10 +145,7 @@ void Foo() await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); test = string.Format(testFormat, this.Sign + " 3"); - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(8, 17) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(8, 17); await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); @@ -260,10 +251,7 @@ void Foo() await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); test = string.Format(testFormat, this.Sign + " 3"); - DiagnosticResult[] expected = - { - this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 25) - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments(" not", "followed").WithLocation(7, 25); await this.VerifyCSharpDiagnosticAsync(test, expected, CancellationToken.None); await this.VerifyCSharpFixAsync(test, fixedTest, cancellationToken: CancellationToken.None); From 9fa2ea6847e10f8ee51a649b5f340dcf5aa3f48f Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sun, 15 Mar 2015 14:52:52 -0500 Subject: [PATCH 09/12] Update remaining maintainability tests (except SA1400) to the new builder syntax --- .../MaintainabilityRules/SA1401UnitTests.cs | 33 +------ .../MaintainabilityRules/SA1402UnitTests.cs | 21 +--- .../MaintainabilityRules/SA1403UnitTests.cs | 21 +--- .../MaintainabilityRules/SA1404UnitTests.cs | 98 ++----------------- .../MaintainabilityRules/SA1405UnitTests.cs | 18 +--- .../MaintainabilityRules/SA1406UnitTests.cs | 1 - .../MaintainabilityRules/SA1407UnitTests.cs | 89 +++-------------- .../MaintainabilityRules/SA1408UnitTests.cs | 61 ++---------- .../MaintainabilityRules/SA1410UnitTests.cs | 18 +--- .../MaintainabilityRules/SA1411UnitTests.cs | 46 ++------- 10 files changed, 47 insertions(+), 359 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1401UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1401UnitTests.cs index bccd8bf6b..532986308 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1401UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1401UnitTests.cs @@ -1,10 +1,9 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; -using Xunit; using StyleCop.Analyzers.MaintainabilityRules; using TestHelper; +using Xunit; namespace StyleCop.Analyzers.Test.MaintainabilityRules { @@ -27,20 +26,7 @@ public async Task TestClassWithPublicField() public string bar; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Field must be private", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 19) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 19); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -53,20 +39,7 @@ public async Task TestClassWithInternalField() internal string bar; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Field must be private", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 21) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 21); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1402UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1402UnitTests.cs index af565a298..5dda5fcc5 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1402UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1402UnitTests.cs @@ -1,11 +1,9 @@ -using System; -using System.Threading; +using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; -using Xunit; using StyleCop.Analyzers.MaintainabilityRules; using TestHelper; +using Xunit; namespace StyleCop.Analyzers.Test.MaintainabilityRules { @@ -59,20 +57,7 @@ public partial class Bar }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.Message, - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 22) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 22); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1403UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1403UnitTests.cs index 44e1fa13c..122a92d8e 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1403UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1403UnitTests.cs @@ -1,11 +1,9 @@ -using System; -using System.Threading; +using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; -using Xunit; using StyleCop.Analyzers.MaintainabilityRules; using TestHelper; +using Xunit; namespace StyleCop.Analyzers.Test.MaintainabilityRules { @@ -38,20 +36,7 @@ namespace Bar } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = this.Message, - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 15) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 15); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1404UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1404UnitTests.cs index ff5cc3ae8..b013741a1 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1404UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1404UnitTests.cs @@ -1,11 +1,10 @@ -using System.Threading; +using System; +using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; -using Xunit; using StyleCop.Analyzers.MaintainabilityRules; using TestHelper; -using System; +using Xunit; namespace StyleCop.Analyzers.Test.MaintainabilityRules { @@ -47,20 +46,7 @@ public string Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Code analysis suppression must have justification", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 6) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 6); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -77,20 +63,7 @@ public string Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Code analysis suppression must have justification", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 66) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 66); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -107,20 +80,7 @@ public string Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Code analysis suppression must have justification", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 66) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 66); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -137,20 +97,7 @@ public string Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Code analysis suppression must have justification", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 66) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 66); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -184,20 +131,7 @@ public string Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Code analysis suppression must have justification", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 66) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 66); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -215,20 +149,8 @@ public string Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Code analysis suppression must have justification", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 66) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 66); + try { await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1405UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1405UnitTests.cs index 007b89a4f..d38d6296b 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1405UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1405UnitTests.cs @@ -4,11 +4,10 @@ using System.Diagnostics; using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.MaintainabilityRules; using TestHelper; + using Xunit; public class SA1405UnitTests : DebugMessagesUnitTestsBase { @@ -48,20 +47,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = string.Format("Debug.Assert must provide message text", this.MethodName), - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1406UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1406UnitTests.cs index f0dcd5be7..2dd0ed38a 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1406UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1406UnitTests.cs @@ -4,7 +4,6 @@ using System.Diagnostics; using System.Linq; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.MaintainabilityRules; public class SA1406UnitTests : DebugMessagesUnitTestsBase diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1407UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1407UnitTests.cs index 6387c8719..517446868 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1407UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1407UnitTests.cs @@ -1,11 +1,10 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; -using Xunit; using StyleCop.Analyzers.MaintainabilityRules; using TestHelper; +using Xunit; namespace StyleCop.Analyzers.Test.MaintainabilityRules { @@ -69,20 +68,7 @@ public void Bar() int x = 1 + 1 * 1; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Arithmetic expressions must declare precedence", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 21) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 21); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -107,20 +93,7 @@ public void Bar() int x = 1 * 1 + 1; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Arithmetic expressions must declare precedence", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 17) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 17); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -171,31 +144,11 @@ public void Bar() int x = 1 * 1 + 1 * 1; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Arithmetic expressions must declare precedence", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 17) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Arithmetic expressions must declare precedence", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 25) - } - } - }; + this.CSharpDiagnostic().WithLocation(5, 17), + this.CSharpDiagnostic().WithLocation(5, 25) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -220,31 +173,11 @@ public void Bar() int x = 1 << 1 + 1 * 1; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Arithmetic expressions must declare precedence", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 22) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Arithmetic expressions must declare precedence", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 26) - } - } - }; + this.CSharpDiagnostic().WithLocation(5, 22), + this.CSharpDiagnostic().WithLocation(5, 26) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1408UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1408UnitTests.cs index c88b4b3a8..f3be28e9e 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1408UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1408UnitTests.cs @@ -1,11 +1,10 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; -using Xunit; using StyleCop.Analyzers.MaintainabilityRules; using TestHelper; +using Xunit; namespace StyleCop.Analyzers.Test.MaintainabilityRules { @@ -56,20 +55,7 @@ public void Bar() bool x = true || false && true; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Conditional expressions must declare precedence", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 26) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 26); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -94,20 +80,7 @@ public void Bar() bool x = true && false || true; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Conditional expressions must declare precedence", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 18) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 18); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -185,31 +158,11 @@ public void Bar() bool x = true && false || true && false; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Conditional expressions must declare precedence", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 18) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Conditional expressions must declare precedence", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 35) - } - } - }; + this.CSharpDiagnostic().WithLocation(5, 18), + this.CSharpDiagnostic().WithLocation(5, 35) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1410UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1410UnitTests.cs index ca19cb6c3..17fabda1a 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1410UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1410UnitTests.cs @@ -1,11 +1,10 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; -using Xunit; using StyleCop.Analyzers.MaintainabilityRules; using TestHelper; +using Xunit; namespace StyleCop.Analyzers.Test.MaintainabilityRules { @@ -56,20 +55,7 @@ public void Bar() System.Func getRandomNumber = delegate() { return 3; }; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Remove delegate parenthesis when possible", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 52) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 52); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1411UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1411UnitTests.cs index 46f7ebc91..9537912ee 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1411UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/SA1411UnitTests.cs @@ -1,11 +1,10 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; -using Xunit; using StyleCop.Analyzers.MaintainabilityRules; using TestHelper; +using Xunit; namespace StyleCop.Analyzers.Test.MaintainabilityRules { @@ -69,20 +68,7 @@ public void Bar() { } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Attribute constructor must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 21) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 21); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -97,31 +83,11 @@ public void Bar() { } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Attribute constructor must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 21) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Attribute constructor must not use unnecessary parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 67) - } - } - }; + this.CSharpDiagnostic().WithLocation(3, 21), + this.CSharpDiagnostic().WithLocation(3, 67) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } From b3aaf2f12d9d7907dd1e2831e5bc686c91a13622 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sun, 15 Mar 2015 14:54:07 -0500 Subject: [PATCH 10/12] Update remaining naming tests to the new builder syntax --- .../NamingRules/SA1300UnitTests.cs | 139 ++---------------- .../NamingRules/SA1302UnitTests.cs | 79 +--------- .../NamingRules/SA1303UnitTests.cs | 48 +----- .../NamingRules/SA1304UnitTests.cs | 48 +----- .../NamingRules/SA1306UnitTests.cs | 59 ++------ .../NamingRules/SA1309UnitTests.cs | 33 +---- .../NamingRules/SA1311UnitTests.cs | 48 +----- 7 files changed, 40 insertions(+), 414 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1300UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1300UnitTests.cs index 16bbcda45..bb422a703 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1300UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1300UnitTests.cs @@ -2,16 +2,14 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.NamingRules; using TestHelper; + using Xunit; public class SA1300UnitTests : CodeFixVerifier { private const string DiagnosticId = SA1300ElementMustBeginWithUpperCaseLetter.DiagnosticId; - private const string Message = "Element '{0}' must begin with an uppercase letter"; [Fact] public async Task TestUpperCaseNamespace() @@ -32,20 +30,7 @@ public async Task TestLowerCaseNamespace() }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = string.Format(Message, "test"), - Severity = DiagnosticSeverity.Warning, - Locations = - new [] - { - new DiagnosticResultLocation("Test0.cs", 1, 18) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(1, 18); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -69,20 +54,7 @@ public async Task TestLowerCaseClass() }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = string.Format(Message, "test"), - Severity = DiagnosticSeverity.Warning, - Locations = - new [] - { - new DiagnosticResultLocation("Test0.cs", 1, 14) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(1, 14); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -129,20 +101,7 @@ public async Task TestLowerCaseStruct() }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = string.Format(Message, "test"), - Severity = DiagnosticSeverity.Warning, - Locations = - new [] - { - new DiagnosticResultLocation("Test0.cs", 1, 15) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(1, 15); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -166,20 +125,7 @@ public async Task TestLowerCaseEnum() }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = string.Format(Message, "test"), - Severity = DiagnosticSeverity.Warning, - Locations = - new [] - { - new DiagnosticResultLocation("Test0.cs", 1, 13) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(1, 13); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -203,20 +149,7 @@ public async Task TestLowerCaseDelegate() public delegate void test(); }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = string.Format(Message, "test"), - Severity = DiagnosticSeverity.Warning, - Locations = - new [] - { - new DiagnosticResultLocation("Test0.cs", 3, 22) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(3, 22); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -264,20 +197,7 @@ public event Test testEvent } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = string.Format(Message, "testEvent"), - Severity = DiagnosticSeverity.Warning, - Locations = - new [] - { - new DiagnosticResultLocation("Test0.cs", 5, 23) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("testEvent").WithLocation(5, 23); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -303,20 +223,7 @@ public async Task TestLowerCaseEventField() public event Test testEvent; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = string.Format(Message, "testEvent"), - Severity = DiagnosticSeverity.Warning, - Locations = - new [] - { - new DiagnosticResultLocation("Test0.cs", 4, 23) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("testEvent").WithLocation(4, 23); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -344,20 +251,7 @@ public void test() }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = string.Format(Message, "test"), - Severity = DiagnosticSeverity.Warning, - Locations = - new [] - { - new DiagnosticResultLocation("Test0.cs", 3, 13) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(3, 13); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -381,20 +275,7 @@ public async Task TestLowerCaseProperty() public string test { get; set; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = string.Format(Message, "test"), - Severity = DiagnosticSeverity.Warning, - Locations = - new [] - { - new DiagnosticResultLocation("Test0.cs", 3, 15) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("test").WithLocation(3, 15); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1302UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1302UnitTests.cs index cd3a9570b..b61cdeda8 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1302UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1302UnitTests.cs @@ -1,12 +1,10 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; -using Xunit; -using StyleCop.Analyzers.MaintainabilityRules; using StyleCop.Analyzers.NamingRules; using TestHelper; +using Xunit; namespace StyleCop.Analyzers.Test.NamingRules { @@ -29,20 +27,7 @@ public interface Foo { }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Interface names must begin with I", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 2, 18) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(2, 18); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -65,20 +50,7 @@ public class Bar : Foo { }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Interface names must begin with I", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 2, 18) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(2, 18); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -102,20 +74,7 @@ public interface iFoo { }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Interface names must begin with I", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 2, 18) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(2, 18); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -138,20 +97,7 @@ public interface Foo } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Interface names must begin with I", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 22) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 22); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -207,20 +153,7 @@ public interface FileOpenDialog } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Interface names must begin with I", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 22) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 22); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1303UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1303UnitTests.cs index a314e3588..ce2e5bfa0 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1303UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1303UnitTests.cs @@ -1,10 +1,9 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; -using Xunit; using StyleCop.Analyzers.NamingRules; using TestHelper; +using Xunit; namespace StyleCop.Analyzers.Test.NamingRules { @@ -27,20 +26,7 @@ public async Task TestConstFieldStartingWithLowerCase() public const string bar = ""baz""; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Const field names must begin with upper-case letter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 25) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 25); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -106,20 +92,7 @@ public async Task TestConstFieldStartingWithLowerCaseNativeMethodsIncorrectName( public const string bar = ""baz""; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Const field names must begin with upper-case letter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 25) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 25); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -142,20 +115,7 @@ public class FooInner } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Const field names must begin with upper-case letter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 36) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 36); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1304UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1304UnitTests.cs index 91e37f23c..eb6e50638 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1304UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1304UnitTests.cs @@ -1,11 +1,10 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; -using Xunit; using StyleCop.Analyzers.NamingRules; using TestHelper; +using Xunit; namespace StyleCop.Analyzers.Test.NamingRules { @@ -28,20 +27,7 @@ public async Task TestPublicReadonlyFieldStartingWithLowerCase() public readonly string bar = ""baz""; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Non-private readonly fields must begin with upper-case letter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 28) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 28); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -72,20 +58,7 @@ public async Task TestProtectedReadonlyFieldStartingWithLowerCase() protected readonly string bar = ""baz""; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Non-private readonly fields must begin with upper-case letter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 31) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 31); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -115,20 +88,7 @@ public async Task TestInternalReadonlyFieldStartingWithLowerCase() internal readonly string bar = ""baz""; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Non-private readonly fields must begin with upper-case letter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 30) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 30); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1306UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1306UnitTests.cs index 57de18577..311c60e55 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1306UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1306UnitTests.cs @@ -2,12 +2,11 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.NamingRules; using TestHelper; + using Xunit; public class SA1306UnitTests : CodeFixVerifier { @@ -44,31 +43,11 @@ private async Task TestThatDiagnosticIsReported_SingleFieldImpl(string modifiers string Dar; }}"; - var expected = new[] - { - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = string.Format("Field '{0}' must begin with lower-case letter", "Bar"), - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 8) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = string.Format("Field '{0}' must begin with lower-case letter", "Dar"), - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 8) - } - } - }; + this.CSharpDiagnostic().WithArguments("Bar").WithLocation(4, 8), + this.CSharpDiagnostic().WithArguments("Dar").WithLocation(8, 8) + }; await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, modifiers), expected, CancellationToken.None); @@ -93,31 +72,11 @@ private async Task TestThatDiagnosticIsReported_MultipleFieldsImpl(string modifi string Bar, car, Dar; }}"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = string.Format("Field '{0}' must begin with lower-case letter", "Bar"), - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 8) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = string.Format("Field '{0}' must begin with lower-case letter", "Dar"), - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 18) - } - } - }; + this.CSharpDiagnostic().WithArguments("Bar").WithLocation(4, 8), + this.CSharpDiagnostic().WithArguments("Dar").WithLocation(4, 18) + }; await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, modifiers), expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1309UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1309UnitTests.cs index 73436ba1e..4c83c7a5e 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1309UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1309UnitTests.cs @@ -2,12 +2,11 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.NamingRules; using TestHelper; + using Xunit; public class SA1309UnitTests : CodeFixVerifier { @@ -28,20 +27,7 @@ public async Task TestFieldStartingWithAnUnderscore() public string _bar = ""baz""; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = string.Format("Field '{0}' must not begin with an underscore", "_bar"), - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 19) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("_bar").WithLocation(3, 19); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -83,20 +69,7 @@ public async Task TestFieldStartingAnUnderscorePlacedInsideNativeMethodsClassWit internal string _bar = ""baz""; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = string.Format("Field '{0}' must not begin with an underscore", "_bar"), - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 21) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("_bar").WithLocation(3, 21); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1311UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1311UnitTests.cs index a6d8f57e4..ab74ea9c7 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1311UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1311UnitTests.cs @@ -2,12 +2,11 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.NamingRules; using TestHelper; + using Xunit; public class SA1311UnitTests : CodeFixVerifier { @@ -28,20 +27,7 @@ public async Task TestStaticReadonlyFieldStartingWithLoweCase() public static readonly string bar = ""baz""; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Static readonly fields must begin with upper-case letter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 35) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 35); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -61,20 +47,7 @@ public async Task TestStaticReadonlyFieldStartingWithLoweCaseFieldIsJustOneLette internal static readonly string b = ""baz""; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Static readonly fields must begin with upper-case letter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 37) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 37); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -99,20 +72,7 @@ static Foo() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Static readonly fields must begin with upper-case letter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 35) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 35); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); From e4ab20da589d95b79803adf2e6e401a3639ed072 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sun, 15 Mar 2015 15:22:13 -0500 Subject: [PATCH 11/12] Update remaining readability tests to the new builder syntax --- .../ReadabilityRules/SA1100UnitTests.cs | 276 +---------- .../ReadabilityRules/SA1101UnitTests.cs | 32 +- .../ReadabilityRules/SA1102UnitTests.cs | 210 +------- .../ReadabilityRules/SA1106UnitTests.cs | 63 +-- .../ReadabilityRules/SA1110UnitTests.cs | 314 +----------- .../ReadabilityRules/SA1111UnitTests.cs | 464 ++---------------- .../ReadabilityRules/SA1112UnitTests.cs | 64 +-- .../ReadabilityRules/SA1113UnitTests.cs | 450 ++--------------- .../ReadabilityRules/SA1114UnitTests.cs | 280 +---------- .../ReadabilityRules/SA1121UnitTests.cs | 368 +------------- .../ReadabilityRules/SA1122UnitTests.cs | 73 +-- 11 files changed, 223 insertions(+), 2371 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1100UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1100UnitTests.cs index b902e46a8..a55e3720e 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1100UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1100UnitTests.cs @@ -1,14 +1,12 @@ -using Microsoft.CodeAnalysis.CodeFixes; - -namespace StyleCop.Analyzers.Test.ReadabilityRules +namespace StyleCop.Analyzers.Test.ReadabilityRules { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.ReadabilityRules; using TestHelper; + using Xunit; public class SA1100UnitTests : CodeFixVerifier { @@ -34,20 +32,7 @@ protected void Baz() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(14, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -90,20 +75,7 @@ protected void Baz() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(14, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -177,20 +149,7 @@ protected void Bar(string param) } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(14, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -264,20 +223,7 @@ protected void Baz() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 17) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(14, 17); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -323,20 +269,7 @@ protected void Bar(string param) } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(14, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -386,20 +319,7 @@ protected void Bar(long l) } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(14, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -449,20 +369,7 @@ protected void Bar(ref string s) } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(14, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -512,20 +419,7 @@ protected void Bar(out string s) s = string.Empty; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(14, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -575,20 +469,7 @@ protected void Bar(string param) } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(14, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -638,20 +519,7 @@ protected void Bar(ref string s, int i) } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(14, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -701,20 +569,7 @@ protected void Bar(out string s, int i) s = string.Empty; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(14, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -764,20 +619,7 @@ protected void Bar(int i, string s) } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(14, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -936,20 +778,7 @@ protected void Baz() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 11, 12) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(11, 12); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -1036,20 +865,7 @@ public string Baz() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 16) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 16); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -1094,31 +910,11 @@ protected void Baz2() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 19, 9) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 24, 9) - } - } - }; + this.CSharpDiagnostic().WithLocation(19, 9), + this.CSharpDiagnostic().WithLocation(24, 9) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -1173,20 +969,7 @@ protected void Baz() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(14, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -1228,20 +1011,7 @@ protected void Baz() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Do not prefix calls with base unless local implementation exists", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 17) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 17); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1101UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1101UnitTests.cs index 39f1a45e5..31dece7f1 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1101UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1101UnitTests.cs @@ -2,12 +2,11 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.ReadabilityRules; using TestHelper; + using Xunit; public class SA1101UnitTests : CodeFixVerifier { @@ -243,33 +242,18 @@ public void InstanceMethodName(int ParameterName) } "; - private DiagnosticResult CreateDiagnosticResult(int line, int column) - { - return new DiagnosticResult - { - Id = DiagnosticId, - Message = "Prefix local calls with this", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", line, column) - } - }; - } - [Fact] public async Task TestPrefixLocalCallsWithThisDiagnostics() { var expected = new[] { - this.CreateDiagnosticResult(90, 36), - this.CreateDiagnosticResult(94, 36), - this.CreateDiagnosticResult(96, 36), - this.CreateDiagnosticResult(98, 36), - this.CreateDiagnosticResult(100, 36), - this.CreateDiagnosticResult(105, 45), - this.CreateDiagnosticResult(106, 48), + this.CSharpDiagnostic().WithLocation(90, 36), + this.CSharpDiagnostic().WithLocation(94, 36), + this.CSharpDiagnostic().WithLocation(96, 36), + this.CSharpDiagnostic().WithLocation(98, 36), + this.CSharpDiagnostic().WithLocation(100, 36), + this.CSharpDiagnostic().WithLocation(105, 45), + this.CSharpDiagnostic().WithLocation(106, 48), }; await this.VerifyCSharpDiagnosticAsync(ReferenceCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1102UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1102UnitTests.cs index 86bb9161d..05ab671f9 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1102UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1102UnitTests.cs @@ -2,11 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.ReadabilityRules; using TestHelper; + using Xunit; public class SA1102UnitTests : CodeFixVerifier { @@ -34,20 +33,7 @@ where m > 0 select m; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 11, 21) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(11, 21); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -66,20 +52,7 @@ public void Bar() where m > 0 select m; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 33) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(9, 33); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -96,20 +69,7 @@ public void Bar() var query = from m in source where m > 0 select m; }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 38) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 38); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -141,63 +101,13 @@ group m by m into g select new {g.Key, Sum = g.Sum()}; } }"; - var expected = new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 11, 21) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 13, 21) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 16, 21) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 19, 21) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 21, 21) - } - } + this.CSharpDiagnostic().WithLocation(11, 21), + this.CSharpDiagnostic().WithLocation(13, 21), + this.CSharpDiagnostic().WithLocation(16, 21), + this.CSharpDiagnostic().WithLocation(19, 21), + this.CSharpDiagnostic().WithLocation(21, 21), }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -232,41 +142,11 @@ where m > 0 orderby m descending select m;"; - var expected = new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 2, 29) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 17) - } - } + this.CSharpDiagnostic().WithLocation(2, 29), + this.CSharpDiagnostic().WithLocation(4, 17), + this.CSharpDiagnostic().WithLocation(6, 17), }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -288,63 +168,13 @@ orderby m descending select pp);"; - var expected = new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 2, 29) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 21) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Query clause must follow previous clause.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 12, 21) - } - } + this.CSharpDiagnostic().WithLocation(2, 29), + this.CSharpDiagnostic().WithLocation(4, 17), + this.CSharpDiagnostic().WithLocation(7, 21), + this.CSharpDiagnostic().WithLocation(9, 17), + this.CSharpDiagnostic().WithLocation(12, 21), }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1106UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1106UnitTests.cs index 24a7d3d58..7573a6a31 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1106UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1106UnitTests.cs @@ -2,11 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.ReadabilityRules; using TestHelper; + using Xunit; public class SA1106UnitTests : CodeFixVerifier { @@ -32,20 +31,7 @@ public void TestMethod() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Code must not contain empty statements", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 13) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 13); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -79,20 +65,7 @@ public void TestMethod() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Code must not contain empty statements", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -127,20 +100,7 @@ public void TestMethod() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Code must not contain empty statements", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -159,20 +119,7 @@ public void TestMethod() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Code must not contain empty statements", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1110UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1110UnitTests.cs index 1befb2471..ce49dba97 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1110UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1110UnitTests.cs @@ -2,11 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.ReadabilityRules; using TestHelper; + using Xunit; public class SA1110UnitTests : CodeFixVerifier { @@ -32,20 +31,7 @@ public void Bar } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 21) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 21); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -62,20 +48,7 @@ public Foo } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -123,20 +96,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 13) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 13); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -154,20 +114,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 13) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 13); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -185,20 +132,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 13) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 13); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -217,20 +151,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 13) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 13); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -252,20 +173,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 11, 13) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(11, 13); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -303,20 +211,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -351,20 +246,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -385,20 +267,7 @@ [int index] } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 5) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 5); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -442,20 +311,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 15, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(15, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -474,20 +330,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -544,20 +387,7 @@ public void Bar() [1]; } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -592,30 +422,10 @@ public void Baz() } }"; - var expected = new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - }, - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } + this.CSharpDiagnostic().WithLocation(5, 1), + this.CSharpDiagnostic().WithLocation(6, 1) }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -647,20 +457,7 @@ public delegate void MyDel (int i); }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -694,20 +491,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -762,20 +546,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -827,20 +598,7 @@ public static Foo operator + } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -858,20 +616,7 @@ public static Foo operator + } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -904,20 +649,7 @@ public static explicit operator Foo } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Opening parenthesis or bracket must be on declaration line.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1111UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1111UnitTests.cs index 972ac1656..634a68efa 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1111UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1111UnitTests.cs @@ -2,11 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.ReadabilityRules; using TestHelper; + using Xunit; public class SA1111UnitTests : CodeFixVerifier { @@ -32,20 +31,7 @@ public void Bar(string s } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -65,20 +51,7 @@ object o } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -127,20 +100,7 @@ public Foo(string s } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -160,20 +120,7 @@ object o } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -227,20 +174,7 @@ public void Baz() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 12, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(12, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -285,20 +219,7 @@ public void Baz() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 13, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(13, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -363,20 +284,7 @@ public void Baz() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 12, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(12, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -401,20 +309,7 @@ public void Baz() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 13, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(13, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -477,20 +372,7 @@ public int this[int index } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -513,20 +395,7 @@ int index3 } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -570,20 +439,7 @@ public void Test() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 15, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(15, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -602,20 +458,7 @@ public void Test() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -635,20 +478,7 @@ public void Test() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(9, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -668,20 +498,7 @@ public void Test() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(9, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -699,20 +516,7 @@ public void Test(System.Collection.Generics.List list) } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -733,20 +537,7 @@ public void Test() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(9, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -768,20 +559,7 @@ public void Test() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 11, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(11, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -804,20 +582,7 @@ public void Test() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 12, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(12, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -836,20 +601,7 @@ public void Test() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -868,20 +620,7 @@ public void Test() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -909,20 +648,7 @@ public void Test() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 17, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(17, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -952,20 +678,7 @@ public delegate void Del(int i, string s ); }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1011,20 +724,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1082,30 +782,10 @@ public void Baz() } }"; - var expected = new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - }, - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } + this.CSharpDiagnostic().WithLocation(5, 1), + this.CSharpDiagnostic().WithLocation(6, 1) }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -1149,20 +829,7 @@ public class Foo { }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 3, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1206,20 +873,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(9, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1273,20 +927,7 @@ public void Bar() } );"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1310,20 +951,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 12, 17) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(12, 17); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1373,20 +1001,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1404,20 +1019,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of last parameter", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 5) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 5); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1112UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1112UnitTests.cs index 82c653575..64f0fc065 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1112UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1112UnitTests.cs @@ -1,10 +1,9 @@ using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; -using Xunit; using StyleCop.Analyzers.ReadabilityRules; using TestHelper; +using Xunit; namespace StyleCop.Analyzers.Test.ReadabilityRules { @@ -33,20 +32,7 @@ public void Bar( } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of opening parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -96,20 +82,7 @@ public Foo( } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of opening parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -159,21 +132,7 @@ public void Bar() } }"; - - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of opening parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -222,20 +181,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Closing parenthesis must be on line of opening parenthesis", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1113UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1113UnitTests.cs index 7aa27ecdf..0493ffa47 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1113UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1113UnitTests.cs @@ -2,11 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.ReadabilityRules; using TestHelper; + using Xunit; public class SA1113UnitTests : CodeFixVerifier { @@ -30,20 +29,7 @@ public void Bar(string s } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 21) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 21); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -60,31 +46,11 @@ public void Bar(string s } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 21) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 21) - } - } - }; + this.CSharpDiagnostic().WithLocation(4, 21), + this.CSharpDiagnostic().WithLocation(5, 21) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -115,20 +81,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 37) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 37); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -146,31 +99,11 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 37) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 37) - } - } - }; + this.CSharpDiagnostic().WithLocation(6, 37), + this.CSharpDiagnostic().WithLocation(7, 37) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -205,20 +138,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 30) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(9, 30); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -239,31 +159,11 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 30) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 10, 30) - } - } - }; + this.CSharpDiagnostic().WithLocation(9, 30), + this.CSharpDiagnostic().WithLocation(10, 30) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -297,20 +197,7 @@ public Foo(string s } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 16) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 16); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -327,31 +214,11 @@ public Foo(string s } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 16) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 16) - } - } - }; + this.CSharpDiagnostic().WithLocation(4, 16), + this.CSharpDiagnostic().WithLocation(5, 16) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -385,20 +252,7 @@ public int this[string s } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 21) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 21); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -419,31 +273,11 @@ public int this[string s } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 21) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 21) - } - } - }; + this.CSharpDiagnostic().WithLocation(4, 21), + this.CSharpDiagnostic().WithLocation(5, 21) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -485,20 +319,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 13, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(13, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -523,31 +344,11 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 13, 1) - } - }, - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 5) - } - } - }; + this.CSharpDiagnostic().WithLocation(13, 1), + this.CSharpDiagnostic().WithLocation(14, 5) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -590,20 +391,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 13) - } - }, - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 13); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -635,20 +423,7 @@ delegate void Del(string str , int i); }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 1) - } - }, - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -663,31 +438,11 @@ delegate void Del(string str , long l); }"; - var expected = new[] - { - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 1) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - } - }; + this.CSharpDiagnostic().WithLocation(4, 1), + this.CSharpDiagnostic().WithLocation(5, 1) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -716,31 +471,11 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 17) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 17) - } - } - }; + this.CSharpDiagnostic().WithLocation(6, 17), + this.CSharpDiagnostic().WithLocation(7, 17) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -783,20 +518,7 @@ public async Task TestAttributeCommaPlacedAtTheNextLineAsThePreviousParameter() public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type); }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -826,31 +548,11 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult + DiagnosticResult[] expected = { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 1) - } - }, - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - } - }; + this.CSharpDiagnostic().WithLocation(4, 1), + this.CSharpDiagnostic().WithLocation(5, 1) + }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -882,20 +584,7 @@ public class Foo } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -944,20 +633,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1026,20 +702,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1095,20 +758,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = DiagnosticId, - Message = "Comma must be on the same line as previous parameter.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 13, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(13, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1114UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1114UnitTests.cs index 4e33f9312..4c2aee626 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1114UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1114UnitTests.cs @@ -2,11 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.ReadabilityRules; using TestHelper; + using Xunit; public class SA1114UnitTests : CodeFixVerifier { @@ -33,20 +32,7 @@ public void Bar( } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -113,20 +99,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -193,20 +166,7 @@ public Foo( } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -274,20 +234,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 12, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(12, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -365,20 +312,7 @@ int i] } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -434,20 +368,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -476,30 +397,10 @@ public void Bar() } }"; - var expected = new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 1) - } - }, - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 1) - } - } + this.CSharpDiagnostic().WithLocation(8, 1), + this.CSharpDiagnostic().WithLocation(14, 1) }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -551,20 +452,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 9, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(9, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -624,30 +512,10 @@ public void Bar() } }"; - var expected = new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 14, 1) - } - }, - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 16, 1) - } - } + this.CSharpDiagnostic().WithLocation(14, 1), + this.CSharpDiagnostic().WithLocation(16, 1) }; await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); @@ -713,20 +581,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -789,20 +644,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -849,20 +691,7 @@ public delegate void Bar( string s); }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -921,20 +750,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1011,20 +827,7 @@ public void Bar() } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1098,20 +901,7 @@ public static explicit operator Foo( } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1161,20 +951,7 @@ public class Foo } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1193,20 +970,7 @@ public class Foo } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Parameter list must follow declaration.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 1) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1121UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1121UnitTests.cs index 3aceb0f4c..d713ebacb 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1121UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1121UnitTests.cs @@ -1,15 +1,14 @@ namespace StyleCop.Analyzers.Test.ReadabilityRules { + using System; using System.Linq; using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.ReadabilityRules; using TestHelper; - using System; + using Xunit; /// @@ -139,23 +138,7 @@ public void Bar() {0} test; }} }}"; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 9); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, predefined), EmptyDiagnosticResults, CancellationToken.None); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); @@ -192,23 +175,7 @@ public void Bar() var test = default({0}); }} }}"; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 28) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 28); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); } @@ -244,23 +211,7 @@ public void Bar() var test = typeof({0}); }} }}"; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 27) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 27); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); } @@ -295,23 +246,7 @@ public class Foo {{ }} }}"; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 12) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 12); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); } @@ -345,23 +280,7 @@ public enum Bar : {0} {{ }} }}"; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 23) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 23); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); } @@ -396,23 +315,7 @@ public unsafe void Bar() {0}* test; }} }}"; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 9); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); } @@ -447,23 +350,7 @@ public void Bar({0} test) {{ }} }}"; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 21) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(4, 21); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); } @@ -499,44 +386,11 @@ public class Foo get {{ return default({0}); }} }} }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 4, 12) - } - }, - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 14) - } - }, - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 30) - } - } + this.CSharpDiagnostic().WithLocation(4, 12), + this.CSharpDiagnostic().WithLocation(5, 14), + this.CSharpDiagnostic().WithLocation(7, 30), }; await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); @@ -576,44 +430,11 @@ public void Bar() ({0} param) => param; }} }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 14) - } - }, - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 17) - } - }, - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 22) - } - } + this.CSharpDiagnostic().WithLocation(6, 14), + this.CSharpDiagnostic().WithLocation(7, 17), + this.CSharpDiagnostic().WithLocation(8, 22), }; await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); @@ -652,23 +473,7 @@ public void Bar() var array = new {0}[0]; }} }}"; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 25) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 25); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); } @@ -704,23 +509,7 @@ public unsafe void Bar() var array = stackalloc {0}[0]; }} }}"; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 32) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 32); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); } @@ -757,33 +546,10 @@ public void Bar() default({0}); }} }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 18) - } - }, - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 7, 29) - } - } + this.CSharpDiagnostic().WithLocation(6, 18), + this.CSharpDiagnostic().WithLocation(7, 29), }; await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); @@ -821,23 +587,7 @@ public void Bar() var t = null as {0}; }} }}"; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 25) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 25); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); } @@ -873,23 +623,7 @@ public void Bar() {0}? t = null; }} }}"; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 9); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, fullName), expected, CancellationToken.None); } @@ -927,23 +661,7 @@ class Bar } } "; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 5) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 5); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -985,23 +703,7 @@ class Bar } } "; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 5) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 5); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -1110,23 +812,7 @@ public void Bar() }} }} "; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use built-in type alias", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 41) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 41); foreach (var item in AllTypes) { await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, "System." + item.Item2), expected, CancellationToken.None); diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1122UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1122UnitTests.cs index d76f9ffdc..4e8afc87d 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1122UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1122UnitTests.cs @@ -2,12 +2,11 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.ReadabilityRules; using TestHelper; + using Xunit; /// /// This class contains unit tests for and @@ -34,23 +33,7 @@ public void Bar() }} }}"; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use string.Empty for empty strings", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 23) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 23); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, useVerbatimLiteral ? "@" : string.Empty), expected, CancellationToken.None); } @@ -65,23 +48,7 @@ public void Bar() }} }}"; - DiagnosticResult[] expected; - - expected = - new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use string.Empty for empty strings", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 5, 24) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(5, 24); await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, useVerbatimLiteral ? "@" : string.Empty), expected, CancellationToken.None); } @@ -97,22 +64,9 @@ public void Bar() }} }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use string.Empty for empty strings", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 15) - } - } + this.CSharpDiagnostic().WithLocation(6, 15) }; await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, useVerbatimLiteral ? "@" : string.Empty, isConst ? "const" : string.Empty), isConst ? EmptyDiagnosticResults : expected, CancellationToken.None); @@ -129,22 +83,9 @@ public void Bar() }} }}"; - DiagnosticResult[] expected; - - expected = - new[] + DiagnosticResult[] expected = { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "Use string.Empty for empty strings", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 16) - } - } + this.CSharpDiagnostic().WithLocation(6, 16) }; await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, useVerbatimLiteral ? "@" : string.Empty, isConst ? "const" : string.Empty), isConst ? EmptyDiagnosticResults : expected, CancellationToken.None); From b21a8ced447383a2a0a32747e1a0930d040036b3 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sun, 15 Mar 2015 15:22:27 -0500 Subject: [PATCH 12/12] Update remaining ordering tests to the new builder syntax --- .../OrderingRules/SA1212UnitTests.cs | 48 ++----------------- 1 file changed, 4 insertions(+), 44 deletions(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1212UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1212UnitTests.cs index 1bf0a4bd5..a5cef1271 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1212UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1212UnitTests.cs @@ -2,11 +2,10 @@ { using System.Threading; using System.Threading.Tasks; - using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; - using Xunit; using StyleCop.Analyzers.OrderingRules; using TestHelper; + using Xunit; public class SA1212UnitTests : CodeFixVerifier { @@ -41,20 +40,7 @@ public int Prop } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "A get accessor appears after a set accessor within a property or indexer.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -136,20 +122,7 @@ public int Prop } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "A get accessor appears after a set accessor within a property or indexer.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 6, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); } @@ -176,20 +149,7 @@ public int this[int index] } }"; - var expected = new[] - { - new DiagnosticResult - { - Id = this.DiagnosticId, - Message = "A get accessor appears after a set accessor within a property or indexer.", - Severity = DiagnosticSeverity.Warning, - Locations = - new[] - { - new DiagnosticResultLocation("Test0.cs", 8, 9) - } - } - }; + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 9); await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None); }