public void Checksum_WhitespaceIsIgnored()
        {
            // 1. If the input only varies by whitespace then the checksums should be the same
            var checksum1 = ChecksumCalculator.Calculate("abc");

            ChecksumCalculator.Calculate(" a  b  \r\n\t c \n\n").Should().Be(checksum1);

            ChecksumCalculator.Calculate("\ra\rb\r\rc\r").Should().Be(checksum1);
            ChecksumCalculator.Calculate("\na\nb\n\nc\n").Should().Be(checksum1);
            ChecksumCalculator.Calculate("\r\na\r\nb\r\n\r\nc\r\n").Should().Be(checksum1);


            // 2. Logically, a whitespace-only string should have the same checksum as an empty string
            var emptyChecksum          = ChecksumCalculator.Calculate("");
            var whitespaceOnlyChecksum = ChecksumCalculator.Calculate("\r \t\n\n\r\t  ");

            emptyChecksum.Should().Be(whitespaceOnlyChecksum);
        }
Example #2
0
        public void CreateFilterableIssue_IssueLineInSnapshot_ReturnsFilterableIssue(int issueStartLine, int bufferLineCount)
        {
            var issue = new Sonarlint.Issue {
                StartLine = issueStartLine
            };
            var mockSnapshot = CreateMockTextSnapshot(bufferLineCount, "some text");

            // Act
            var actual = IssueToFilterableIssueConverter.CreateFilterableIssue(issue, mockSnapshot.Object);

            // Assert
            actual.Should().BeOfType(typeof(DaemonIssueAdapter));

            var adapterIssue = (DaemonIssueAdapter)actual;

            adapterIssue.SonarLintIssue.Should().BeSameAs(issue);

            actual.WholeLineText.Should().Be("some text");
            actual.LineHash.Should().Be(ChecksumCalculator.Calculate("some text"));
        }
Example #3
0
        public void ShouldReport_ServerIssueMatchesOnLineHash_ReturnsFalse()
        {
            // Arrange
            string wholeLineText = "whole line text";
            string lineHash      = ChecksumCalculator.Calculate(wholeLineText);

            Diagnostic diag = CreateDiagnostic("RightRuleId", CreateSourceLocation());

            SetLiveIssue(diag, startLine: 101, wholeLineText: wholeLineText);

            var serverIssue = CreateServerIssue("RIGHTRULEID", 999, lineHash); // rule id comparison is case-insensitive

            SetServerIssues(serverIssue);

            SuppressionHandler handler = new SuppressionHandler(issueFactoryMock.Object, issueProviderMock.Object);

            // Act
            bool result = handler.ShouldIssueBeReported(syntaxTreeMock.Object, diag);

            // Assert
            result.Should().BeFalse();
        }
Example #4
0
        public void ShouldReport_NoMatchingServerIssues_ReturnsTrue()
        {
            // Arrange
            string wholeLineText = "whole line text";
            string lineHash      = ChecksumCalculator.Calculate(wholeLineText);

            Diagnostic diag = CreateDiagnostic("RuleId 1", CreateSourceLocation());

            SetLiveIssue(diag, startLine: 10, wholeLineText: wholeLineText);

            var serverIssue1 = CreateServerIssue("Wrong rule id", 10, lineHash);                // wrong rule id
            var serverIssue2 = CreateServerIssue("RuleId 1", 999, "wrong hash");                // wrong line and hash
            var serverIssue3 = CreateServerIssue("RuleId 1", 999, lineHash.ToUpperInvariant()); // wrong line and wrong-case hash

            SetServerIssues(serverIssue1, serverIssue2, serverIssue3);

            SuppressionHandler handler = new SuppressionHandler(issueFactoryMock.Object, issueProviderMock.Object);

            // Act
            bool result = handler.ShouldIssueBeReported(syntaxTreeMock.Object, diag);

            // Assert
            result.Should().BeTrue();
        }
Example #5
0
 public void Checksum_ThrowsOnNull()
 {
     Exceptions.Expect <ArgumentNullException>(() => ChecksumCalculator.Calculate(null));
 }
Example #6
0
        private static void AssertExpectedChecksum(string text, string expected)
        {
            string checksum = ChecksumCalculator.Calculate(text);

            Assert.AreEqual(expected, checksum, $"Unexpected checksum. Input text: {text}");
        }
Example #7
0
        public void Checksum_ThrowsOnNull()
        {
            Action act = () => ChecksumCalculator.Calculate(null);

            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("text");
        }