use of org.sonar.api.batch.fs.internal.Metadata in project sonarqube by SonarSource.
the class FileMetadataTest method windows_without_latest_eol.
@Test
public void windows_without_latest_eol() throws Exception {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "foo\r\nbar\r\nbaz", StandardCharsets.UTF_8, true);
Metadata metadata = new FileMetadata(analysisWarnings).readMetadata(new FileInputStream(tempFile), StandardCharsets.UTF_8, tempFile.getName());
assertThat(metadata.lines()).isEqualTo(3);
assertThat(metadata.nonBlankLines()).isEqualTo(3);
assertThat(metadata.hash()).isEqualTo(md5Hex("foo\nbar\nbaz"));
assertThat(metadata.originalLineStartOffsets()).containsOnly(0, 5, 10);
assertThat(metadata.originalLineEndOffsets()).containsOnly(3, 8, 13);
assertThat(metadata.isEmpty()).isFalse();
}
use of org.sonar.api.batch.fs.internal.Metadata in project sonarqube by SonarSource.
the class FileMetadataTest method mix_of_newlines_with_latest_eol.
@Test
public void mix_of_newlines_with_latest_eol() throws Exception {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "foo\nbar\r\nbaz\n", StandardCharsets.UTF_8, true);
Metadata metadata = new FileMetadata(analysisWarnings).readMetadata(new FileInputStream(tempFile), StandardCharsets.UTF_8, tempFile.getName());
assertThat(metadata.lines()).isEqualTo(4);
assertThat(metadata.nonBlankLines()).isEqualTo(3);
assertThat(metadata.hash()).isEqualTo(md5Hex("foo\nbar\nbaz\n"));
assertThat(metadata.originalLineStartOffsets()).containsOnly(0, 4, 9, 13);
assertThat(metadata.originalLineEndOffsets()).containsOnly(3, 7, 12, 13);
}
use of org.sonar.api.batch.fs.internal.Metadata in project sonarqube by SonarSource.
the class FileMetadataTest method unix_with_latest_eol.
@Test
public void unix_with_latest_eol() throws Exception {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "foo\nbar\nbaz\n", StandardCharsets.UTF_8, true);
Metadata metadata = new FileMetadata(analysisWarnings).readMetadata(new FileInputStream(tempFile), StandardCharsets.UTF_8, tempFile.getName());
assertThat(metadata.lines()).isEqualTo(4);
assertThat(metadata.nonBlankLines()).isEqualTo(3);
assertThat(metadata.hash()).isEqualTo(md5Hex("foo\nbar\nbaz\n"));
assertThat(metadata.originalLineStartOffsets()).containsOnly(0, 4, 8, 12);
assertThat(metadata.originalLineEndOffsets()).containsOnly(3, 7, 11, 12);
}
use of org.sonar.api.batch.fs.internal.Metadata in project sonarqube by SonarSource.
the class FileMetadataTest method read_with_wrong_encoding.
@Test
public void read_with_wrong_encoding() throws Exception {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "markerĀ“s\n", Charset.forName("cp1252"));
Metadata metadata = new FileMetadata(analysisWarnings).readMetadata(new FileInputStream(tempFile), StandardCharsets.UTF_8, tempFile.getName());
assertThat(metadata.lines()).isEqualTo(2);
assertThat(metadata.hash()).isEqualTo(md5Hex("marker\ufffds\n"));
assertThat(metadata.originalLineStartOffsets()).containsOnly(0, 9);
}
use of org.sonar.api.batch.fs.internal.Metadata in project sonarqube by SonarSource.
the class FileMetadataTest method start_with_newline.
@Test
public void start_with_newline() throws Exception {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "\nfoo\nbar\r\nbaz", StandardCharsets.UTF_8, true);
Metadata metadata = new FileMetadata(analysisWarnings).readMetadata(new FileInputStream(tempFile), StandardCharsets.UTF_8, tempFile.getName());
assertThat(metadata.lines()).isEqualTo(4);
assertThat(metadata.nonBlankLines()).isEqualTo(3);
assertThat(metadata.hash()).isEqualTo(md5Hex("\nfoo\nbar\nbaz"));
assertThat(metadata.originalLineStartOffsets()).containsOnly(0, 1, 5, 10);
assertThat(metadata.originalLineEndOffsets()).containsOnly(0, 4, 8, 13);
}
Aggregations