Search in sources :

Example 6 with TextRange

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

the class HighlightingLineReaderTest method keep_existing_processed_highlighting_when_range_offset_converter_throw_RangeOffsetConverterException.

@Test
public void keep_existing_processed_highlighting_when_range_offset_converter_throw_RangeOffsetConverterException() {
    TextRange textRange2 = newTextRange(LINE_2, LINE_2);
    doThrow(RangeOffsetConverterException.class).when(rangeOffsetConverter).offsetToString(textRange2, LINE_2, DEFAULT_LINE_LENGTH);
    HighlightingLineReader highlightingLineReader = newReader(of(newSingleLineTextRangeWithExpectingLabel(LINE_1, RANGE_LABEL_1), ANNOTATION, textRange2, HIGHLIGHTING_STRING));
    highlightingLineReader.read(line1);
    highlightingLineReader.read(line2);
    assertThat(line1.hasHighlighting()).isTrue();
    assertThat(line2.hasHighlighting()).isFalse();
    assertThat(logTester.logs(WARN)).isNotEmpty();
}
Also used : TextRange(org.sonar.scanner.protocol.output.ScannerReport.TextRange) Test(org.junit.Test)

Example 7 with TextRange

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

the class HighlightingLineReaderTest method not_fail_and_stop_processing_when_range_offset_converter_throw_RangeOffsetConverterException.

@Test
public void not_fail_and_stop_processing_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, HighlightingType.ANNOTATION, newSingleLineTextRangeWithExpectingLabel(LINE_2, RANGE_LABEL_1), HIGHLIGHTING_STRING));
    highlightingLineReader.read(line1);
    highlightingLineReader.read(line2);
    assertNoHighlighting();
    assertThat(logTester.logs(WARN)).isNotEmpty();
}
Also used : TextRange(org.sonar.scanner.protocol.output.ScannerReport.TextRange) Test(org.junit.Test)

Example 8 with TextRange

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

the class SymbolsLineReaderTest method read_symbols_declared_on_a_whole_line.

@Test
public void read_symbols_declared_on_a_whole_line() {
    TextRange declaration = newTextRange(LINE_1, LINE_2, OFFSET_0, OFFSET_0);
    when(rangeOffsetConverter.offsetToString(declaration, LINE_1, DEFAULT_LINE_LENGTH)).thenReturn(RANGE_LABEL_1);
    when(rangeOffsetConverter.offsetToString(declaration, LINE_2, DEFAULT_LINE_LENGTH)).thenReturn("");
    TextRange reference = newSingleLineTextRangeWithExpectedLabel(LINE_3, OFFSET_1, OFFSET_3, RANGE_LABEL_2);
    SymbolsLineReader symbolsLineReader = newReader(newSymbol(declaration, reference));
    symbolsLineReader.read(line1);
    symbolsLineReader.read(line2);
    symbolsLineReader.read(line3);
    symbolsLineReader.read(line4);
    assertThat(line1.getSymbols()).isEqualTo(RANGE_LABEL_1 + ",1");
    assertThat(line2.getSymbols()).isEmpty();
    assertThat(line3.getSymbols()).isEqualTo(RANGE_LABEL_2 + ",1");
    assertThat(line4.getSymbols()).isEmpty();
}
Also used : TextRange(org.sonar.scanner.protocol.output.ScannerReport.TextRange) Test(org.junit.Test)

Example 9 with TextRange

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

the class SymbolsLineReaderTest method not_fail_and_stop_processing_when_range_offset_converter_throw_RangeOffsetConverterException.

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

Example 10 with TextRange

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

the class HighlightingLineReaderTest method newSingleLineTextRangeWithExpectingLabel.

private TextRange newSingleLineTextRangeWithExpectingLabel(int line, String rangeLabel) {
    TextRange textRange = newTextRange(line, line);
    when(rangeOffsetConverter.offsetToString(textRange, line, DEFAULT_LINE_LENGTH)).thenReturn(rangeLabel);
    return textRange;
}
Also used : TextRange(org.sonar.scanner.protocol.output.ScannerReport.TextRange)

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