use of org.sonarsource.sonarlint.core.analysis.api.ClientInputFile in project sonarlint-core by SonarSource.
the class SonarLintInputFileTests method testGetters.
@Test
void testGetters(@TempDir Path path) throws IOException {
var filePath = path.resolve("foo.php");
Files.write(filePath, "test string".getBytes(StandardCharsets.UTF_8));
ClientInputFile inputFile = new OnDiskTestClientInputFile(filePath, "file", false, StandardCharsets.UTF_8);
var file = new SonarLintInputFile(inputFile, f -> new FileMetadata().readMetadata(filePath.toFile(), StandardCharsets.UTF_8));
assertThat(file.contents()).isEqualTo("test string");
assertThat(file.charset()).isEqualByComparingTo(StandardCharsets.UTF_8);
assertThat(file.absolutePath()).isEqualTo(FileUtils.toSonarQubePath(inputFile.getPath()));
assertThat(file.file()).isEqualTo(filePath.toFile());
assertThat(file.path()).isEqualTo(filePath);
assertThat(file.getClientInputFile()).isEqualTo(inputFile);
assertThat(file.status()).isEqualTo(Status.ADDED);
assertThat(file).isEqualTo(file).isNotEqualTo(mock(SonarLintInputFile.class));
var stream = file.inputStream();
try (var reader = new BufferedReader(new InputStreamReader(stream))) {
assertThat(reader.lines().collect(Collectors.joining())).isEqualTo("test string");
}
}
use of org.sonarsource.sonarlint.core.analysis.api.ClientInputFile 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 org.sonarsource.sonarlint.core.analysis.api.ClientInputFile 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 org.sonarsource.sonarlint.core.analysis.api.ClientInputFile 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();
}
use of org.sonarsource.sonarlint.core.analysis.api.ClientInputFile in project sonarlint-core by SonarSource.
the class InputFileBuilderTests method testCreateWithLanguageSet.
@Test
void testCreateWithLanguageSet() throws IOException {
var path = tempDir.resolve("file");
Files.write(path, "test".getBytes(StandardCharsets.ISO_8859_1));
ClientInputFile file = new OnDiskTestClientInputFile(path, "file", true, StandardCharsets.ISO_8859_1, Language.CPP);
var builder = new InputFileBuilder(langDetection, metadata, issueExclusionsLoader);
var inputFile = builder.create(file);
assertThat(inputFile.language()).isEqualTo("cpp");
verifyNoInteractions(langDetection);
}
Aggregations