From e1e8aef03ef10a5397d87b1cd6fa07a1f856e6ee Mon Sep 17 00:00:00 2001 From: Frank Vennemeyer Date: Sun, 3 Oct 2021 14:29:28 +0200 Subject: [PATCH] Verify JM14 Record formatting --- .../eclipse/java/EclipseJdtFormatterStepImplTest.java | 11 +++++++++++ .../main/resources/java/eclipse/RecordsFormatted.test | 9 +++++++++ .../resources/java/eclipse/RecordsUnformatted.test | 7 +++++++ 3 files changed, 27 insertions(+) create mode 100644 testlib/src/main/resources/java/eclipse/RecordsFormatted.test create mode 100644 testlib/src/main/resources/java/eclipse/RecordsUnformatted.test diff --git a/_ext/eclipse-jdt/src/test/java/com/diffplug/spotless/extra/eclipse/java/EclipseJdtFormatterStepImplTest.java b/_ext/eclipse-jdt/src/test/java/com/diffplug/spotless/extra/eclipse/java/EclipseJdtFormatterStepImplTest.java index 8303865016..030733181d 100644 --- a/_ext/eclipse-jdt/src/test/java/com/diffplug/spotless/extra/eclipse/java/EclipseJdtFormatterStepImplTest.java +++ b/_ext/eclipse-jdt/src/test/java/com/diffplug/spotless/extra/eclipse/java/EclipseJdtFormatterStepImplTest.java @@ -95,6 +95,17 @@ void htmlPreTag() throws Throwable { assertEquals(formatted, format(unformatted), "Failed to create internal code formatter. See Spotless issue #191"); } + @Test + void records() throws Throwable { + config.clear(); + config.setProperty( + DefaultCodeFormatterConstants.FORMATTER_KEEP_RECORD_DECLARATION_ON_ONE_LINE, + DefaultCodeFormatterConstants.ONE_LINE_IF_EMPTY); + String formatted = getTestResource("java/eclipse/RecordsFormatted.test"); + String unformatted = getTestResource("java/eclipse/RecordsUnformatted.test"); + assertEquals(formatted, format(unformatted), "Jvm14 records not formatted. See Spotless issue #951"); + } + private String format(final String input) throws Exception { EclipseJdtFormatterStepImpl formatter = new EclipseJdtFormatterStepImpl(config); return formatter.format(input); diff --git a/testlib/src/main/resources/java/eclipse/RecordsFormatted.test b/testlib/src/main/resources/java/eclipse/RecordsFormatted.test new file mode 100644 index 0000000000..aca20071d3 --- /dev/null +++ b/testlib/src/main/resources/java/eclipse/RecordsFormatted.test @@ -0,0 +1,9 @@ +public class Records { + public record EmptyRecordInOneLine(int a, int b) {} + public record CtorMultipleLines(int a, int b) { + public CtorMultipleLines(int a, int b) { + this.a = a; + this.b = b; + } + } +} \ No newline at end of file diff --git a/testlib/src/main/resources/java/eclipse/RecordsUnformatted.test b/testlib/src/main/resources/java/eclipse/RecordsUnformatted.test new file mode 100644 index 0000000000..3ce0ae08e9 --- /dev/null +++ b/testlib/src/main/resources/java/eclipse/RecordsUnformatted.test @@ -0,0 +1,7 @@ +public class Records { + public record EmptyRecordInOneLine(int a, int b) { + } + public record CtorMultipleLines(int a, int b) { + public CtorMultipleLines(int a, int b) { this.a = a; this.b = b; } + } +} \ No newline at end of file