From bd51ce7bdfa8881c739ab070add79a4f5baca1e3 Mon Sep 17 00:00:00 2001 From: Costin Zaharia Date: Mon, 11 Apr 2022 10:53:19 +0200 Subject: [PATCH] Add test cases also for C# --- .../Rules/Utilities/SymbolReferenceAnalyzerTest.cs | 10 +++++----- .../Utilities/SymbolReferenceAnalyzer/Method.cs | 7 ++++++- .../Utilities/SymbolReferenceAnalyzer/Property.cs | 3 +++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/Utilities/SymbolReferenceAnalyzerTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/Utilities/SymbolReferenceAnalyzerTest.cs index db1c61c4eb3..1d4f369be48 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/Utilities/SymbolReferenceAnalyzerTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/Utilities/SymbolReferenceAnalyzerTest.cs @@ -46,11 +46,11 @@ public class SymbolReferenceAnalyzerTest public void Verify_Method_PreciseLocation_CS(ProjectType projectType) => Verify("Method.cs", projectType, references => { - references.Select(x => x.Declaration.StartLine).Should().BeEquivalentTo(1, 3, 5); // class 'Sample' on line 1, method 'Method' on line 3, method 'Go' on line 5 + references.Select(x => x.Declaration.StartLine).Should().BeEquivalentTo(1, 3, 5, 7); // class 'Sample' on line 1, method 'Method' on line 3, method 'method' on line 5 and method 'Go' on line 7 var methodDeclaration = references.Single(x => x.Declaration.StartLine == 3); methodDeclaration.Declaration.Should().BeEquivalentTo(new TextRange { StartLine = 3, EndLine = 3, StartOffset = 16, EndOffset = 22 }); methodDeclaration.Reference.Should().HaveCount(1); - methodDeclaration.Reference.Single().Should().BeEquivalentTo(new TextRange { StartLine = 6, EndLine = 6, StartOffset = 8, EndOffset = 14 }); + methodDeclaration.Reference.Single().Should().BeEquivalentTo(new TextRange { StartLine = 9, EndLine = 9, StartOffset = 8, EndOffset = 14 }); }); [DataTestMethod] @@ -65,7 +65,7 @@ public void Verify_Method_PreciseLocation_VB(ProjectType projectType) => procedureDeclaration.Declaration.Should().BeEquivalentTo(new TextRange { StartLine = 3, EndLine = 3, StartOffset = 15, EndOffset = 21 }); procedureDeclaration.Reference.Should().HaveCount(2); procedureDeclaration.Reference[0].Should().BeEquivalentTo(new TextRange { StartLine = 11, EndLine = 11, StartOffset = 8, EndOffset = 14 }); - procedureDeclaration.Reference[1].Should().BeEquivalentTo(new TextRange { StartLine = 11, EndLine = 11, StartOffset = 8, EndOffset = 14 }); + procedureDeclaration.Reference[1].Should().BeEquivalentTo(new TextRange { StartLine = 13, EndLine = 13, StartOffset = 8, EndOffset = 14 }); var functionDeclaration = references.Single(x => x.Declaration.StartLine == 6); functionDeclaration.Declaration.Should().BeEquivalentTo(new TextRange { StartLine = 6, EndLine = 6, StartOffset = 13, EndOffset = 23 }); @@ -125,7 +125,7 @@ public void Verify_LocalFunction_CS(ProjectType projectType) => [DataRow(ProjectType.Product)] [DataRow(ProjectType.Test)] public void Verify_Method_CS(ProjectType projectType) => - Verify("Method.cs", projectType, 3, 3, 6); + Verify("Method.cs", projectType, 4, 3, 9); [DataTestMethod] [DataRow(ProjectType.Product)] @@ -155,7 +155,7 @@ public void Verify_Parameter_VB(ProjectType projectType) => [DataRow(ProjectType.Product)] [DataRow(ProjectType.Test)] public void Verify_Property_CS(ProjectType projectType) => - Verify("Property.cs", projectType, 4, 3, 7, 8); + Verify("Property.cs", projectType, 5, 3, 9, 10); [DataTestMethod] [DataRow(ProjectType.Product)] diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/Utilities/SymbolReferenceAnalyzer/Method.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/Utilities/SymbolReferenceAnalyzer/Method.cs index 70a0dc0c917..9ea2ff28586 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/Utilities/SymbolReferenceAnalyzer/Method.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/Utilities/SymbolReferenceAnalyzer/Method.cs @@ -2,6 +2,11 @@ { public void Method() { } - public void Go() => + public void method() { } + + public void Go() + { Method(); + method(); + } } diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/Utilities/SymbolReferenceAnalyzer/Property.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/Utilities/SymbolReferenceAnalyzer/Property.cs index 496b3a85175..f5c55545b9d 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/Utilities/SymbolReferenceAnalyzer/Property.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/Utilities/SymbolReferenceAnalyzer/Property.cs @@ -2,9 +2,12 @@ { public int Property { get; set; } + public int property { get; set; } + public void Go() { var x = Property; Property = 42; + property = 24; } }