Search in sources :

Example 11 with TextRange

use of org.sonar.scanner.protocol.output.ScannerReport.TextRange in project sonarqube by SonarSource.

the class HighlightingLineReaderTest method read_one_syntax_highlighting_on_many_lines.

@Test
public void read_one_syntax_highlighting_on_many_lines() {
    // This highlighting begin on line 1 and finish on line 3
    TextRange textRange = newTextRange(LINE_1, LINE_3);
    when(rangeOffsetConverter.offsetToString(textRange, LINE_1, DEFAULT_LINE_LENGTH)).thenReturn(RANGE_LABEL_1);
    when(rangeOffsetConverter.offsetToString(textRange, LINE_2, 6)).thenReturn(RANGE_LABEL_2);
    when(rangeOffsetConverter.offsetToString(textRange, LINE_3, DEFAULT_LINE_LENGTH)).thenReturn(RANGE_LABEL_3);
    HighlightingLineReader highlightingLineReader = newReader(of(textRange, ANNOTATION));
    highlightingLineReader.read(line1);
    DbFileSources.Line.Builder line2 = sourceData.addLinesBuilder().setSource("line 2").setLine(2);
    highlightingLineReader.read(line2);
    highlightingLineReader.read(line3);
    assertThat(line1.getHighlighting()).isEqualTo(RANGE_LABEL_1 + ",a");
    assertThat(line2.getHighlighting()).isEqualTo(RANGE_LABEL_2 + ",a");
    assertThat(line3.getHighlighting()).isEqualTo(RANGE_LABEL_3 + ",a");
}
Also used : TextRange(org.sonar.scanner.protocol.output.ScannerReport.TextRange) Test(org.junit.Test)

Example 12 with TextRange

use of org.sonar.scanner.protocol.output.ScannerReport.TextRange in project sonarqube by SonarSource.

the class HighlightingLineReaderTest method read_many_syntax_highlighting_on_many_lines.

@Test
public void read_many_syntax_highlighting_on_many_lines() {
    TextRange textRange1 = newTextRange(LINE_1, LINE_3);
    when(rangeOffsetConverter.offsetToString(textRange1, LINE_1, DEFAULT_LINE_LENGTH)).thenReturn(RANGE_LABEL_1);
    when(rangeOffsetConverter.offsetToString(textRange1, LINE_2, DEFAULT_LINE_LENGTH)).thenReturn(RANGE_LABEL_2);
    when(rangeOffsetConverter.offsetToString(textRange1, LINE_3, DEFAULT_LINE_LENGTH)).thenReturn(RANGE_LABEL_3);
    TextRange textRange2 = newTextRange(LINE_2, LINE_4);
    when(rangeOffsetConverter.offsetToString(textRange2, LINE_2, DEFAULT_LINE_LENGTH)).thenReturn(RANGE_LABEL_2);
    when(rangeOffsetConverter.offsetToString(textRange2, LINE_3, DEFAULT_LINE_LENGTH)).thenReturn(RANGE_LABEL_2);
    when(rangeOffsetConverter.offsetToString(textRange2, LINE_4, DEFAULT_LINE_LENGTH)).thenReturn(RANGE_LABEL_4);
    TextRange textRange3 = newTextRange(LINE_2, LINE_2);
    when(rangeOffsetConverter.offsetToString(textRange3, LINE_2, DEFAULT_LINE_LENGTH)).thenReturn(RANGE_LABEL_5);
    HighlightingLineReader highlightingLineReader = newReader(of(textRange1, ANNOTATION, textRange2, HIGHLIGHTING_STRING, textRange3, COMMENT));
    highlightingLineReader.read(line1);
    highlightingLineReader.read(line2);
    highlightingLineReader.read(line3);
    highlightingLineReader.read(line4);
    assertThat(line1.getHighlighting()).isEqualTo(RANGE_LABEL_1 + ",a");
    assertThat(line2.getHighlighting()).isEqualTo(RANGE_LABEL_2 + ",a;" + RANGE_LABEL_2 + ",s;" + RANGE_LABEL_5 + ",cd");
    assertThat(line3.getHighlighting()).isEqualTo(RANGE_LABEL_3 + ",a;" + RANGE_LABEL_2 + ",s");
    assertThat(line4.getHighlighting()).isEqualTo(RANGE_LABEL_4 + ",s");
}
Also used : TextRange(org.sonar.scanner.protocol.output.ScannerReport.TextRange) Test(org.junit.Test)

Example 13 with TextRange

use of org.sonar.scanner.protocol.output.ScannerReport.TextRange in project sonarqube by SonarSource.

the class SymbolsLineReaderTest method keep_existing_processed_symbols_when_range_offset_converter_throw_RangeOffsetConverterException.

@Test
public void keep_existing_processed_symbols_when_range_offset_converter_throw_RangeOffsetConverterException() {
    TextRange declaration = newSingleLineTextRangeWithExpectedLabel(LINE_1, OFFSET_1, OFFSET_3, RANGE_LABEL_2);
    TextRange reference = newTextRange(LINE_2, LINE_2, OFFSET_1, OFFSET_3);
    doThrow(RangeOffsetConverter.RangeOffsetConverterException.class).when(rangeOffsetConverter).offsetToString(reference, LINE_2, DEFAULT_LINE_LENGTH);
    SymbolsLineReader symbolsLineReader = newReader(newSymbol(declaration, reference));
    symbolsLineReader.read(line1);
    symbolsLineReader.read(line2);
    assertThat(line1.hasSymbols()).isTrue();
    assertThat(line2.hasSymbols()).isFalse();
    assertThat(logTester.logs(WARN)).isNotEmpty();
}
Also used : TextRange(org.sonar.scanner.protocol.output.ScannerReport.TextRange) Test(org.junit.Test)

Example 14 with TextRange

use of org.sonar.scanner.protocol.output.ScannerReport.TextRange in project sonarqube by SonarSource.

the class HighlightingLineReaderTest method display_file_key_in_warning_when_range_offset_converter_throw_RangeOffsetConverterException.

@Test
public void display_file_key_in_warning_when_range_offset_converter_throw_RangeOffsetConverterException() {
    TextRange textRange1 = newTextRange(LINE_1, LINE_1);
    doThrow(RangeOffsetConverterException.class).when(rangeOffsetConverter).offsetToString(textRange1, LINE_1, DEFAULT_LINE_LENGTH);
    HighlightingLineReader highlightingLineReader = newReader(of(textRange1, ANNOTATION));
    highlightingLineReader.read(line1);
    assertThat(logTester.logs(WARN)).containsOnly("Inconsistency detected in Highlighting data. Highlighting will be ignored for file 'FILE_KEY'");
}
Also used : TextRange(org.sonar.scanner.protocol.output.ScannerReport.TextRange) Test(org.junit.Test)

Aggregations

TextRange (org.sonar.scanner.protocol.output.ScannerReport.TextRange)14 Test (org.junit.Test)11 RuleKey (org.sonar.api.rule.RuleKey)1 TrackedIssue (org.sonar.scanner.issue.tracking.TrackedIssue)1