Search in sources :

Example 1 with InMemoryTestClientInputFile

use of testutils.InMemoryTestClientInputFile in project sonarlint-core by SonarSource.

the class SonarLintInputFileTests method checkValidPointer.

@Test
void checkValidPointer() {
    ClientInputFile inputFile = new InMemoryTestClientInputFile("foo", "src/Foo.php", null, false, null);
    var metadata = new FileMetadata.Metadata(2, new int[] { 0, 10 }, 16);
    var file = new SonarLintInputFile(inputFile, f -> metadata);
    assertThat(file.newPointer(1, 0).line()).isEqualTo(1);
    assertThat(file.newPointer(1, 0).lineOffset()).isZero();
    // Don't fail
    file.newPointer(1, 9);
    file.newPointer(2, 0);
    file.newPointer(2, 5);
}
Also used : ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) InMemoryTestClientInputFile(testutils.InMemoryTestClientInputFile) OnDiskTestClientInputFile(testutils.OnDiskTestClientInputFile) InMemoryTestClientInputFile(testutils.InMemoryTestClientInputFile) Test(org.junit.jupiter.api.Test)

Example 2 with InMemoryTestClientInputFile

use of testutils.InMemoryTestClientInputFile in project sonarlint-core by SonarSource.

the class SonarLintInputFileTests method selectLine.

@Test
void selectLine() {
    ClientInputFile inputFile = new InMemoryTestClientInputFile("foo", "src/Foo.php", null, false, null);
    var metadata = new FileMetadata().readMetadata(new ByteArrayInputStream("bla bla a\nabcde\n\nabc".getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8, URI.create("file://foo.php"), null);
    var file = new SonarLintInputFile(inputFile, f -> metadata);
    assertThat(file.selectLine(1).start().line()).isEqualTo(1);
    assertThat(file.selectLine(1).start().lineOffset()).isZero();
    assertThat(file.selectLine(1).end().line()).isEqualTo(1);
    assertThat(file.selectLine(1).end().lineOffset()).isEqualTo(9);
    // Don't fail when selecting empty line
    assertThat(file.selectLine(3).start().line()).isEqualTo(3);
    assertThat(file.selectLine(3).start().lineOffset()).isZero();
    assertThat(file.selectLine(3).end().line()).isEqualTo(3);
    assertThat(file.selectLine(3).end().lineOffset()).isZero();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) InMemoryTestClientInputFile(testutils.InMemoryTestClientInputFile) OnDiskTestClientInputFile(testutils.OnDiskTestClientInputFile) InMemoryTestClientInputFile(testutils.InMemoryTestClientInputFile) Test(org.junit.jupiter.api.Test)

Example 3 with InMemoryTestClientInputFile

use of testutils.InMemoryTestClientInputFile in project sonarlint-core by SonarSource.

the class SonarLintInputFileTests method testRangeOverlap.

@Test
void testRangeOverlap() {
    ClientInputFile inputFile = new InMemoryTestClientInputFile("foo", "src/Foo.php", null, false, null);
    var metadata = new FileMetadata.Metadata(2, new int[] { 0, 10 }, 16);
    var file = new SonarLintInputFile(inputFile, f -> metadata);
    // Don't fail
    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)).overlap(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)))).isTrue();
    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)).overlap(file.newRange(file.newPointer(1, 0), file.newPointer(1, 2)))).isTrue();
    assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)).overlap(file.newRange(file.newPointer(1, 1), file.newPointer(1, 2)))).isFalse();
    assertThat(file.newRange(file.newPointer(1, 2), file.newPointer(1, 3)).overlap(file.newRange(file.newPointer(1, 0), file.newPointer(1, 2)))).isFalse();
}
Also used : ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) InMemoryTestClientInputFile(testutils.InMemoryTestClientInputFile) OnDiskTestClientInputFile(testutils.OnDiskTestClientInputFile) InMemoryTestClientInputFile(testutils.InMemoryTestClientInputFile) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 ClientInputFile (org.sonarsource.sonarlint.core.analysis.api.ClientInputFile)3 InMemoryTestClientInputFile (testutils.InMemoryTestClientInputFile)3 OnDiskTestClientInputFile (testutils.OnDiskTestClientInputFile)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1