DocumentFile implements Document, Closeable { List<Integer> getLineToOffset() { return lineToOffset; } DocumentFile(final File file, final Charset charset); @Override void insert(int beginLine, int beginColumn, final String textToInsert); @Override void replace(final RegionByLine regionByLine, final String textToReplace); @Override void delete(final RegionByLine regionByOffset); @Override void close();  }
@Test public void lineToOffsetMappingWithLineFeedShouldSucceed() throws IOException { final String code = "public static int main(String[] args) {" + '\n' + "int var;" + '\n' + "}"; writeContentToTemporaryFile(code); final List<Integer> expectedLineToOffset = new ArrayList<>(); expectedLineToOffset.add(0); expectedLineToOffset.add(40); expectedLineToOffset.add(49); try (DocumentFile documentFile = new DocumentFile(temporaryFile, StandardCharsets.UTF_8)) { assertEquals(expectedLineToOffset, documentFile.getLineToOffset()); } }
@Test public void lineToOffsetMappingWithCarriageReturnFeedLineFeedShouldSucceed() throws IOException { final String code = "public static int main(String[] args) {" + "\r\n" + "int var;" + "\r\n" + "}"; writeContentToTemporaryFile(code); final List<Integer> expectedLineToOffset = new ArrayList<>(); expectedLineToOffset.add(0); expectedLineToOffset.add(41); expectedLineToOffset.add(51); try (DocumentFile documentFile = new DocumentFile(temporaryFile, StandardCharsets.UTF_8)) { assertEquals(expectedLineToOffset, documentFile.getLineToOffset()); } }
@Test public void lineToOffsetMappingWithMixedLineSeparatorsShouldSucceed() throws IOException { final String code = "public static int main(String[] args) {" + "\r\n" + "int var;" + "\n" + "}"; writeContentToTemporaryFile(code); final List<Integer> expectedLineToOffset = new ArrayList<>(); expectedLineToOffset.add(0); expectedLineToOffset.add(41); expectedLineToOffset.add(50); try (DocumentFile documentFile = new DocumentFile(temporaryFile, StandardCharsets.UTF_8)) { assertEquals(expectedLineToOffset, documentFile.getLineToOffset()); } }