public void GetPreciseIssueLocations_NotStartOfLineIsOk()
        {
            var line   = GetLine(3, @"if (a > b)
{
    Console.WriteLine(a);
    //      ^^^^^^^^^
}");
            var result = new IssueLocationCollector().GetPreciseIssueLocations(line).ToList();

            result.Should().ContainSingle();
            var issueLocation = result.First();

            issueLocation.IsPrimary.Should().BeTrue();
            issueLocation.LineNumber.Should().Be(3);
            issueLocation.Start.Should().Be(12);
            issueLocation.Length.Should().Be(9);
        }
        public void GetPreciseIssueLocations_Message_And_IssueIds_Secondary()
        {
            var line   = GetLine(3, @"if (a > b)
{
    Console.WriteLine(a);
//          ^^^^^^^^^ Secondary [flow1,flow2] {{Some message}}
}");
            var result = new IssueLocationCollector().GetPreciseIssueLocations(line).ToList();

            result.Should().HaveCount(2);

            VerifyIssueLocations(result,
                                 expectedIsPrimary: new[] { false, false },
                                 expectedLineNumbers: new[] { 3, 3 },
                                 expectedMessages: new string[] { "Some message", "Some message" },
                                 expectedIssueIds: new string[] { "flow1", "flow2" });
        }
        public void GetPreciseIssueLocations_Message_Secondary()
        {
            var line   = GetLine(3, @"if (a > b)
{
    Console.WriteLine(a);
//          ^^^^^^^^^ Secondary {{Some message}}
}");
            var result = new IssueLocationCollector().GetPreciseIssueLocations(line).ToList();

            result.Should().ContainSingle();

            VerifyIssueLocations(result,
                                 expectedIsPrimary: new[] { false },
                                 expectedLineNumbers: new[] { 3 },
                                 expectedMessages: new string[] { "Some message" },
                                 expectedIssueIds: new string[] { null });
        }
コード例 #4
0
        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 GetPreciseIssueLocations_IssueIds()
        {
            var line   = GetLine(3, @"if (a > b)
{
    Console.WriteLine(a);
//          ^^^^^^^^^ [flow1,flow2]
}");
            var result = new IssueLocationCollector().GetPreciseIssueLocations(line).ToList();

            result.Should().HaveCount(2);

            VerifyIssueLocations(result,
                                 expectedIsPrimary: new[] { true, true },
                                 expectedLineNumbers: new[] { 3, 3 },
                                 expectedMessages: new string[] { null, null },
                                 expectedIssueIds: new string[] { "flow1", "flow2" });
        }
コード例 #6
0
        public void GetPreciseIssueLocations_With_Offset()
        {
            var line   = GetLine(3, @"if (a > b)
{
    Console.WriteLine(a);
//          ^^^^^^^^^ @-1
}");
            var result = new IssueLocationCollector().GetPreciseIssueLocations(line).ToList();

            result.Should().ContainSingle();

            VerifyIssueLocations(result,
                                 expectedIsPrimary: new[] { true },
                                 expectedLineNumbers: new[] { 2 },
                                 expectedMessages: new string[] { null },
                                 expectedIssueIds: new string[] { null });
        }
コード例 #7
0
        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, 6 });
        }
コード例 #8
0
        public void GetPreciseIssueLocations_NoMessage_NoIds_Secondary()
        {
            var line   = GetLine(3, @"if (a > b)
{
    Console.WriteLine(a);
//          ^^^^^^^^^ Secondary
}");
            var result = new IssueLocationCollector().GetPreciseIssueLocations(line).ToList();

            result.Should().HaveCount(1);

            VerifyIssueLocations(result,
                                 expectedIsPrimary: new[] { false },
                                 expectedLineNumbers: new[] { 3 },
                                 expectedMessages: new string[] { null },
                                 expectedIssueIds: new string[] { null });
        }
コード例 #9
0
        public void MergeLocations_Issues_Same_Line()
        {
            var result = new IssueLocationCollector().MergeLocations(
                new[] { new IssueLocation {
                            LineNumber = 3, Message = "message 1"
                        } },
                new[] { new IssueLocation {
                            LineNumber = 3, Start = 10, Length = 5, Message = "message 2"
                        } });

            result.Should().ContainSingle();

            result[0].Message.Should().Be("message 1");

            // We take only Start and Length when merging precise location comments
            result[0].Start.Should().Be(10);
            result[0].Length.Should().Be(5);
        }
コード例 #10
0
        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 });
        }
コード例 #11
0
        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 });
        }
コード例 #12
0
        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 });
        }
コード例 #13
0
        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 });
        }
コード例 #14
0
        public void MergeLocations_Issues_Different_Lines()
        {
            var result = new IssueLocationCollector().MergeLocations(
                new[] { new IssueLocation {
                            LineNumber = 3, Message = "message 1"
                        } },
                new[] { new IssueLocation {
                            LineNumber = 10, Start = 10, Length = 5, Message = "message 2"
                        } });

            result.Should().HaveCount(2);

            result[0].Message.Should().Be("message 1");
            result[0].Start.Should().NotHaveValue();
            result[0].Length.Should().NotHaveValue();

            result[1].Message.Should().Be("message 2");
            result[1].Start.Should().Be(10);
            result[1].Length.Should().Be(5);
        }
コード例 #15
0
        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 });
        }