private Consumer<String> assertDiagnostic(String expectedSource, ExpectedDiagnostic expectedDiagnostic) { int start = (int) expectedDiagnostic.getStartPosition(); int end = (int) expectedDiagnostic.getEndPosition();
String expectedMarkingLine = createMarkingLine(start, end); return s -> {
String[] lines = s.split("\n"); if (lines.length <= 3) { thrownew AssertionError("Not enough lines: " + s);
}
String kind = getKind(expectedDiagnostic.getKind());
assertEquals(lines[0], kind); boolean found = false; for (int i = 0; i < lines.length; i++) { if (lines[i].endsWith(expectedSource)) {
assertEquals(lines[i + 1], expectedMarkingLine, "Input: " + expectedSource + ", marking line: ");
found = true;
}
} if (!found) { thrownew AssertionError("Did not find: " + expectedSource + " in: " + s);
}
};
}
private String createMarkingLine(int start, int end) {
assertTrue(end >= start, String.format("End position %d is less than start position %d", end, start));
StringBuilder sb = new StringBuilder();
sb.append("| "); for (int i = 0; i < start; ++i) {
sb.append(' ');
}
sb.append('^'); for (int i = 1; i < end - start - 1; ++i) {
sb.append('-');
} if (start < end) {
sb.append('^');
} return sb.toString();
}
public String getKind(Diagnostic.Kind kind) { switch (kind) { case WARNING: return"| Warning:"; case ERROR: return"| Error:"; default: thrownew AssertionError("Unsupported kind: " + kind);
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.