|
23 | 23 | import com.fasterxml.jackson.databind.json.JsonMapper; |
24 | 24 | import com.fasterxml.jackson.datatype.guava.GuavaModule; |
25 | 25 | import com.google.common.collect.Range; |
| 26 | +import com.palantir.javaformat.Utils; |
26 | 27 | import com.palantir.javaformat.java.JavaFormatterOptions.Style; |
27 | 28 | import java.io.ByteArrayInputStream; |
28 | 29 | import java.io.PrintWriter; |
|
37 | 38 | * One test for each {@link CaseFile} in the given folders on the test classpath: formatting the before block gives the |
38 | 39 | * after block, and formatting that again changes nothing. For the lines that formatting changes, taken as a range, the |
39 | 40 | * service that formats in this JVM, as {@code formatDiff} does without the native binary, gives the replacements that |
40 | | - * the command line prints, which the bootstrapping and native services run. Adding a case is adding a file. The cases |
41 | | - * are in a folder of the JDK they need, and each JDK has a class that runs the folders it can parse, such as |
42 | | - * {@link FormatterCasesJava21Test}. |
| 41 | + * the command line prints, which the bootstrapping and native services run, and the command line printing text gives |
| 42 | + * what applying them gives. Adding a case is adding a file. The cases are in a folder of the JDK they need, and each |
| 43 | + * JDK has a class that runs the folders it can parse, such as {@link FormatterCasesJava21Test}. |
43 | 44 | */ |
44 | 45 | final class FormatterCasesTest { |
45 | 46 | private static final Formatter FORMATTER = Formatter.createFormatter( |
@@ -80,18 +81,19 @@ static List<DynamicTest> casesIn(String... folders) throws Exception { |
80 | 81 | .isEqualTo(once); |
81 | 82 |
|
82 | 83 | var lines = changedLines(testCase); |
| 84 | + var characters = lines.lowerEndpoint() + ":" + (lines.upperEndpoint() - 1); |
83 | 85 | List<Replacement> replacements = MAPPER.readValue( |
84 | 86 | commandLine( |
85 | | - testCase.before(), |
86 | | - "--character-ranges", |
87 | | - lines.lowerEndpoint() + ":" + (lines.upperEndpoint() - 1), |
88 | | - "--output-replacements", |
89 | | - "-"), |
| 87 | + testCase.before(), "--character-ranges", characters, "--output-replacements", "-"), |
90 | 88 | new TypeReference<>() {}); |
91 | 89 |
|
92 | 90 | assertThat(SERVICE.getFormatReplacements(testCase.before(), List.of(lines))) |
93 | 91 | .as(() -> folder + "/" + path + ", the in-process service on characters " + lines) |
94 | 92 | .isEqualTo(replacements); |
| 93 | + |
| 94 | + assertThat(commandLine(testCase.before(), "--character-ranges", characters, "-")) |
| 95 | + .as(() -> folder + "/" + path + ", the command line printing characters " + lines) |
| 96 | + .isEqualTo(Utils.applyReplacements(testCase.before(), replacements)); |
95 | 97 | })); |
96 | 98 | } |
97 | 99 | } |
|
0 commit comments