diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 939940a315..3d68fb05cc 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -248,7 +248,7 @@ private static String getSystemProperty(String name) { return value; } - private static String[] groupWithSteps(String group, String[] includes, String... steps) { + protected static String[] groupWithSteps(String group, String[] includes, String... steps) { String[] result = new String[steps.length + includes.length + 2]; result[0] = "<" + group + ">"; System.arraycopy(includes, 0, result, 1, includes.length); @@ -261,11 +261,11 @@ private static String[] groupWithSteps(String group, String... steps) { return groupWithSteps(group, new String[]{}, steps); } - private static String[] including(String... includes) { + protected static String[] including(String... includes) { return groupWithSteps("includes", groupWithSteps("include", includes)); } - private static String[] formats(String... formats) { + protected static String[] formats(String... formats) { return groupWithSteps("formats", formats); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/markdown/FlexmarkMavenTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/markdown/FlexmarkMavenTest.java index a623ca7f3c..96d55fb82f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/markdown/FlexmarkMavenTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/markdown/FlexmarkMavenTest.java @@ -15,6 +15,10 @@ */ package com.diffplug.spotless.maven.markdown; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import org.junit.jupiter.api.Test; import com.diffplug.spotless.maven.MavenIntegrationHarness; @@ -30,4 +34,21 @@ public void testFlexmarkWithDefaultConfig() throws Exception { assertFile("markdown_test.md").sameAsResource("markdown/flexmark/FlexmarkFormatted.md"); } + + @Test + public void testFlexmarkWithDefaultConfig_endsWithCodeBlock_withNewLine() throws Exception { + List configurations = new ArrayList<>(); + + configurations.addAll(Arrays.asList(formats(groupWithSteps("format", including("*.md"), "")))); + configurations.addAll(Arrays.asList(groupWithSteps("markdown", including("**/*.md"), ""))); + + writePom(configurations.toArray(new String[0])); + + setFile("markdown_test.md").toResource("markdown/flexmark/EndsWithCodeBlockUnformatted.md"); + mavenRunner().withArguments("spotless:apply").runNoError().error(); + assertFile("markdown_test.md").sameAsResource("markdown/flexmark/EndsWithCodeBlockFormattedWithNewLine.md"); + + mavenRunner().withArguments("spotless:check").runNoError().error(); + } + } diff --git a/testlib/src/main/resources/markdown/flexmark/EndsWithCodeBlockFormatted.md b/testlib/src/main/resources/markdown/flexmark/EndsWithCodeBlockFormatted.md new file mode 100644 index 0000000000..0320afc8a8 --- /dev/null +++ b/testlib/src/main/resources/markdown/flexmark/EndsWithCodeBlockFormatted.md @@ -0,0 +1,4 @@ +``` +someCode +``` + diff --git a/testlib/src/main/resources/markdown/flexmark/EndsWithCodeBlockFormattedWithNewLine.md b/testlib/src/main/resources/markdown/flexmark/EndsWithCodeBlockFormattedWithNewLine.md new file mode 100644 index 0000000000..0320afc8a8 --- /dev/null +++ b/testlib/src/main/resources/markdown/flexmark/EndsWithCodeBlockFormattedWithNewLine.md @@ -0,0 +1,4 @@ +``` +someCode +``` + diff --git a/testlib/src/main/resources/markdown/flexmark/EndsWithCodeBlockUnformatted.md b/testlib/src/main/resources/markdown/flexmark/EndsWithCodeBlockUnformatted.md new file mode 100644 index 0000000000..46c4967896 --- /dev/null +++ b/testlib/src/main/resources/markdown/flexmark/EndsWithCodeBlockUnformatted.md @@ -0,0 +1,3 @@ +``` + someCode +``` \ No newline at end of file diff --git a/testlib/src/test/java/com/diffplug/spotless/markdown/FlexmarkStepTest.java b/testlib/src/test/java/com/diffplug/spotless/markdown/FlexmarkStepTest.java index 191ffa4cb5..f947db7f34 100644 --- a/testlib/src/test/java/com/diffplug/spotless/markdown/FlexmarkStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/markdown/FlexmarkStepTest.java @@ -29,4 +29,12 @@ void behavior() throws Exception { "markdown/flexmark/FlexmarkUnformatted.md", "markdown/flexmark/FlexmarkFormatted.md"); } + + @Test + void endsWithcodeBlock() throws Exception { + StepHarness.forStep(FlexmarkStep.create(TestProvisioner.mavenCentral())) + .testResource( + "markdown/flexmark/EndsWithCodeBlockUnformatted.md", + "markdown/flexmark/EndsWithCodeBlockFormatted.md"); + } }