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);
}
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();
}
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();
}
Aggregations