예제 #1
0
        public void ToMarker_EndPositionExceedsSnapshotLength()
        {
            // Defensive: handle the issue end position being beyond the end of the snapshot
            // (we have not seen this in practice so far)

            // Arrange
            var issue = new Sonarlint.Issue
            {
                StartLine       = 53,
                StartLineOffset = 2,
                EndLine         = 53,
                EndLineOffset   = 12,
            };

            // The issue is on a single line in this case, but the issue end position
            // is beyond the end of the line.
            var vsLine = new VSLineDescription
            {
                ZeroBasedLineNumber = 52,
                LineLength          = 10,
                LineStartPosition   = 1599
            };

            var textSnapshotMock = CreateSnapshotMock(vsLine, vsLine, 1602);

            // Act
            var result = new IssueConverter()
                         .ToMarker(issue, textSnapshotMock.Object);

            // Assert
            result.Should().NotBeNull();
            result.Span.Start.Position.Should().Be(1601); // vsLine.LineStartPosition + issue.StartLineOffset
            result.Span.End.Position.Should().Be(1602);   // snapshot length
        }
예제 #2
0
        public void ToMarker_Calculates_Span_Positions()
        {
            const int issueStartLine = 3;
            const int issueEndLine   = 4;

            // Arrange
            var issue = new Sonarlint.Issue
            {
                StartLine       = issueStartLine,
                StartLineOffset = 10,
                EndLine         = issueEndLine,
                EndLineOffset   = 20,
            };

            var textSnapshotMock = new Mock <ITextSnapshot>();

            var startLineMock = new Mock <ITextSnapshotLine>();

            startLineMock.SetupGet(x => x.Start)
            .Returns(() => new SnapshotPoint(textSnapshotMock.Object, 35));

            var endLineMock = new Mock <ITextSnapshotLine>();

            endLineMock.SetupGet(x => x.Start)
            .Returns(() => new SnapshotPoint(textSnapshotMock.Object, 47));

            textSnapshotMock
            .SetupGet(x => x.Length)
            .Returns(1000);     // some big number to avoid ArgumentOutOfRange exceptions
            textSnapshotMock
            .Setup(x => x.GetLineFromLineNumber(issueStartLine - 1))
            .Returns(() => startLineMock.Object);
            textSnapshotMock
            .Setup(x => x.GetLineFromLineNumber(issueEndLine - 1))
            .Returns(() => endLineMock.Object);

            // Act
            var result = new IssueConverter()
                         .ToMarker(issue, textSnapshotMock.Object);

            // Assert
            result.Should().NotBeNull();
            result.Span.Start.Position.Should().Be(45); // first SnapshotPoint.Position + issue.StartLineOffset
            result.Span.End.Position.Should().Be(67);   // second SnapshotPoint.Position + issue.EndLineOffset
        }
예제 #3
0
        public void ToMarker_StartPositionExceedsSnapshotLength()
        {
            // These values were taken from a real analysis issue
            // Rule "cpp:S113 - no newline at end of file" returns an offset after the end of the file.

            // Arrange
            var issue = new Sonarlint.Issue
            {
                StartLine       = 53,
                StartLineOffset = 2,
                EndLine         = 53,
                EndLineOffset   = 3,
            };

            var firstLine = new VSLineDescription
            {
                ZeroBasedLineNumber = 52,
                LineLength          = 1,
                LineStartPosition   = 1599
            };

            // Second line should not be used in this case
            var secondLine = new VSLineDescription
            {
                ZeroBasedLineNumber = -999,
                LineLength          = -999,
                LineStartPosition   = -999
            };

            var textSnapshotMock = CreateSnapshotMock(firstLine, secondLine, 1600);

            // Act
            var result = new IssueConverter()
                         .ToMarker(issue, textSnapshotMock.Object);

            // Assert
            result.Should().NotBeNull();
            result.Span.Start.Position.Should().Be(1599); // firstLine.LineStartPosition. Ignore offset because that will take us beyond the end of file
            result.Span.End.Position.Should().Be(1600);   // snapshot length
        }
예제 #4
0
        public void ToMarker_EndLineIsZero()
        {
            // If issue.EndLine is zero the whole of the start line should be selected

            // Arrange
            var issue = new Sonarlint.Issue
            {
                StartLine       = 22,
                StartLineOffset = 2,
                EndLine         = 0,
                EndLineOffset   = 0,
            };

            var firstLine = new VSLineDescription
            {
                ZeroBasedLineNumber = 21,
                LineLength          = 34,
                LineStartPosition   = 103
            };

            // The second VS line shouldn't be used in this case
            var secondLine = new VSLineDescription
            {
                ZeroBasedLineNumber = 25,
                LineLength          = 100,
                LineStartPosition   = 1010
            };

            var textSnapshotMock = CreateSnapshotMock(firstLine, secondLine);

            // Act
            var result = new IssueConverter()
                         .ToMarker(issue, textSnapshotMock.Object);

            // Assert
            result.Should().NotBeNull();
            result.Span.Start.Position.Should().Be(103); // firstLine.LineStartPosition. Ignore issue.StartLineOffset in this case
            result.Span.End.Position.Should().Be(137);   // firstLine.LineStartPosition +  firstLine.LineLength
        }
예제 #5
0
        public void ToMarker_Calculates_Span_Positions()
        {
            // Arrange
            var issue = new Sonarlint.Issue
            {
                StartLine       = 3,
                StartLineOffset = 10,
                EndLine         = 4,
                EndLineOffset   = 20,
            };

            var firstLine = new VSLineDescription
            {
                ZeroBasedLineNumber = 2,
                LineLength          = 10,
                LineStartPosition   = 35
            };

            var secondLine = new VSLineDescription
            {
                ZeroBasedLineNumber = 3,
                LineLength          = 25,
                LineStartPosition   = 47
            };

            var textSnapshotMock = CreateSnapshotMock(firstLine, secondLine);

            // Act
            var result = new IssueConverter()
                         .ToMarker(issue, textSnapshotMock.Object);

            // Assert
            result.Should().NotBeNull();
            result.Span.Start.Position.Should().Be(45); // firstLine.LineStartPosition + issue.StartLineOffset
            result.Span.End.Position.Should().Be(67);   // secondLine.LineStartPosition + issue.EndLineOffset
        }