public void GetPreciseIssueLocations_Xml()
        {
            var code   = @"<Root>
<Space><SelfClosing /></Space>
<!--   ^^^^^^^^^^^^^^^ -->
<NoSpace><SelfClosing /></NoSpace>
     <!--^^^^^^^^^^^^^^^-->
<Multiline><SelfClosing /></Multiline>
<!--       ^^^^^^^^^^^^^^^
-->
</Root>";
            var line   = GetLine(2, code);
            var result = IssueLocationCollector.GetPreciseIssueLocations(line).ToList();

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

            issueLocation.Start.Should().Be(7);
            issueLocation.Length.Should().Be(15);

            line   = GetLine(4, code);
            result = IssueLocationCollector.GetPreciseIssueLocations(line).ToList();
            result.Should().ContainSingle();
            issueLocation = result.Single();
            issueLocation.Start.Should().Be(9);
            issueLocation.Length.Should().Be(15);

            line   = GetLine(6, code);
            result = IssueLocationCollector.GetPreciseIssueLocations(line).ToList();
            result.Should().ContainSingle();
            issueLocation = result.Single();
            issueLocation.Start.Should().Be(11);
            issueLocation.Length.Should().Be(15);
        }
        public void GetPreciseIssueLocations_NoComment()
        {
            var line   = GetLine(3, @"if (a > b)
{
    Console.WriteLine(a);
}");
            var result = IssueLocationCollector.GetPreciseIssueLocations(line).ToList();

            result.Should().BeEmpty();
        }
        public void GetPreciseIssueLocations_InvalidPattern()
        {
            var line   = GetLine(3, @"if (a > b)
{
    Console.WriteLine(a);
//          ^^^^^^^^^ SecondaryNoncompliantSecondary {{Some message}}
}");
            var result = IssueLocationCollector.GetPreciseIssueLocations(line).ToList();

            result.Should().BeEmpty();
        }
        public void GetPreciseIssueLocations_MultiplePatternsOnSameLine()
        {
            var    line   = GetLine(3, @"if (a > b)
{
    Console.WriteLine(a);
//  ^^^^^^^ ^^^^^^^^^ ^
}");
            Action action = () => IssueLocationCollector.GetPreciseIssueLocations(line);

            action.Should()
            .Throw <InvalidOperationException>()
            .WithMessage(@"Expecting only one precise location per line, found 3 on line 3. If you want to specify more than one precise location per line you need to omit the Noncompliant comment:
internal class MyClass : IInterface1 // there should be no Noncompliant comment
^^^^^^^ {{Do not create internal classes.}}
                         ^^^^^^^^^^^ @-1 {{IInterface1 is bad for your health.}}");
        }
        public void GetPreciseIssueLocations_Message_And_IssueIds_Secondary_XML()
        {
            var line   = GetLine(2, @"<Root>
            <Baaad />
<!--        ^^^^^^^^^ Secondary [flow1,flow2] {{Some message}}         -->
</Root>");
            var result = IssueLocationCollector.GetPreciseIssueLocations(line).ToList();

            result.Should().HaveCount(2);

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

            result.Should().ContainSingle();

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

            result.Should().ContainSingle();

            VerifyIssueLocations(result,
                                 expectedIsPrimary: new[] { true },
                                 expectedLineNumbers: new[] { 3 },
                                 expectedMessages: new string[] { null },
                                 expectedIssueIds: new string[] { null });
        }
        public void GetPreciseIssueLocations_NotStartOfLineIsOk()
        {
            var line   = GetLine(3, @"if (a > b)
{
    Console.WriteLine(a);
    //      ^^^^^^^^^
}");
            var result = 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_CS()
        {
            var line   = GetLine(3, @"if (a > b)
{
    Console.WriteLine(a);
//          ^^^^^^^^^ Secondary [flow1,flow2] {{Some message}}
}");
            var result = IssueLocationCollector.GetPreciseIssueLocations(line).ToList();

            result.Should().HaveCount(2);

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

            result.Should().HaveCount(3);

            VerifyIssueLocations(result,
                                 expectedIsPrimary: new[] { false, false, false },
                                 expectedLineNumbers: new[] { 3, 3, 3 },
                                 expectedMessages: new string[] { null, null, null },
                                 expectedIssueIds: new[] { "flow1", "flow2", "last1" });
        }