public void GetExpectedIssueLocations_OnlyCommentedNoncompliant() { var code = @"public class MyNoncompliantClass { public void NoncompliantMethod(object o) { Console.WriteLine(o); // Noncompliant } }"; var locations = new IssueLocationCollector().GetExpectedIssueLocations(SourceText.From(code).Lines); locations.Should().HaveCount(1); locations.Select(l => l.IsPrimary).Should().Equal(new[] { true }); locations.Select(l => l.LineNumber).Should().Equal(new[] { 5 }); }
public void GetExpectedBuildErrors_Multiple_ExpectedErrors() { var code = @"public class Foo { public void Bar(object o) // Error [CS1234,CS2345,CS3456] { } }"; var expectedErrors = new IssueLocationCollector().GetExpectedBuildErrors(SourceText.From(code).Lines); expectedErrors.Should().HaveCount(3); expectedErrors.Select(l => l.IsPrimary).Should().Equal(new[] { true, true, true }); expectedErrors.Select(l => l.LineNumber).Should().Equal(new[] { 3, 3, 3 }); expectedErrors.Select(l => l.IssueId).Should().Equal(new[] { "CS1234", "CS2345", "CS3456" }); }
public void GetExpectedBuildErrors_ExpectedErrors() { var code = @"public class Foo { public void Bar(object o) // Error [CS1234] { // Error@+1 [CS3456] Console.WriteLine(o); } }"; var expectedErrors = new IssueLocationCollector().GetExpectedBuildErrors(SourceText.From(code).Lines); expectedErrors.Should().HaveCount(2); expectedErrors.Select(l => l.IsPrimary).Should().Equal(new[] { true, true }); expectedErrors.Select(l => l.LineNumber).Should().Equal(new[] { 3, 6 }); }
public void GetExpectedIssueLocations_Locations() { var code = @"public class Foo { public void Bar(object o) // Noncompliant { // Noncompliant @+1 Console.WriteLine(o); } }"; var locations = new IssueLocationCollector().GetExpectedIssueLocations(SourceText.From(code).Lines); locations.Should().HaveCount(2); locations.Select(l => l.IsPrimary).Should().Equal(new[] { true, true }); locations.Select(l => l.LineNumber).Should().Equal(new[] { 3, 5 }); }
public void GetExpectedIssueLocations_ExactLocations() { var code = @"public class Foo { public void Bar(object o) // ^^^ // ^ Secondary@-1 { Console.WriteLine(o); } }"; var locations = new IssueLocationCollector().GetExpectedIssueLocations(SourceText.From(code).Lines); locations.Should().HaveCount(2); locations.Select(l => l.IsPrimary).Should().BeEquivalentTo(new[] { true, false }); locations.Select(l => l.LineNumber).Should().Equal(new[] { 3, 3 }); }
public void GetIssueLocations_Noncompliant_Offset_ExactColumn_Message_Whitespaces_Xml() { var line = GetLine(2, @"<RootRootRootRootRootRoot /> <!-- Noncompliant @-2 ^5#16 [myIssueId] {{MyMessage}} --> "); var result = new IssueLocationCollector().GetIssueLocations(line).ToList(); result.Should().ContainSingle(); VerifyIssueLocations(result, expectedIsPrimary: new[] { true }, expectedLineNumbers: new[] { 1 }, expectedMessages: new string[] { "MyMessage" }, expectedIssueIds: new string[] { "myIssueId" }); result.Select(issue => issue.Start).Should().Equal(new[] { 4 }); result.Select(issue => issue.Length).Should().Equal(new[] { 16 }); }
public void GetExpectedIssueLocations_Locations_VB() { var code = @" Public Class Foo Public Sub Bar(o As Object) ' Noncompliant ' Noncompliant@+1 Console.WriteLine(o) End Sub End Class"; var locations = new IssueLocationCollector().GetExpectedIssueLocations(SourceText.From(code).Lines); locations.Should().HaveCount(2); locations.Select(l => l.IsPrimary).Should().Equal(new[] { true, true }); locations.Select(l => l.LineNumber).Should().Equal(new[] { 4, 6 }); }
public void GetExpectedIssueLocations_ExactColumns() { var code = @"public class Foo { public void Bar(object o) // Noncompliant ^17#3 // Secondary@-1 ^28#1 { Console.WriteLine(o); } }"; var locations = new IssueLocationCollector().GetExpectedIssueLocations(SourceText.From(code).Lines); locations.Should().HaveCount(2); locations.Select(l => l.IsPrimary).Should().BeEquivalentTo(new[] { true, false }); locations.Select(l => l.LineNumber).Should().Equal(new[] { 3, 3 }); locations.Select(l => l.Start).Should().Equal(new[] { 16, 27 }); locations.Select(l => l.Length).Should().Equal(new[] { 3, 1 }); }
public void GetExpectedIssueLocations_Locations_Xml() { var code = @"<Root> <SelfClosing /><!-- Noncompliant --> <SelfClosing /><!-- Noncompliant with additional comment and new line --> <InsideWithSpace><!-- Noncompliant--></InsideWithSpace> <InsideNoSpace><!--Secondary--></InsideNoSpace> <Innocent><!--Noncompliant@+1--></Innocent> <Guilty /> <!-- Noncompliant - this should not be detected as expected issue --> </Root>"; var locations = new IssueLocationCollector().GetExpectedIssueLocations(SourceText.From(code).Lines); locations.Should().HaveCount(5); locations.Select(l => l.IsPrimary).Should().Equal(new[] { true, true, true, false, true }); locations.Select(l => l.LineNumber).Should().Equal(new[] { 2, 3, 5, 6, 8 }); }