@@ -69,11 +69,7 @@ void parsing_git_diff_output_works() throws IOException {
6969 @ MethodSource ("getFormatters" )
7070 void reformat_a_subpath_of_a_git_directory_for_only_changed_lines (FormatterService formatterService )
7171 throws IOException , InterruptedException {
72- runCommandInRepo ("git" , "init" );
73- runCommandInRepo ("git" , "config" , "user.name" , "Test User" );
74- runCommandInRepo ("git" , "config" , "user.email" , "test-user@palantir.com" );
75- runCommandInRepo ("git" , "config" , "commit.gpgsign" , "false" );
76- runCommandInRepo ("git" , "commit" , "--allow-empty" , "-m" , "Init" );
72+ initRepo ();
7773
7874 Path subdir = repo .resolve ("subdir" );
7975 Files .createDirectories (subdir );
@@ -92,6 +88,44 @@ void reformat_a_subpath_of_a_git_directory_for_only_changed_lines(FormatterServi
9288 assertThat (dontTouchMe ).hasContent (" class DontTouchMe {}" );
9389 }
9490
91+ @ ParameterizedTest
92+ @ MethodSource ("getFormatters" )
93+ void reflows_the_long_string_of_a_changed_line (FormatterService formatterService )
94+ throws IOException , InterruptedException {
95+ initRepo ();
96+ Path longString = repo .resolve ("LongString.java" );
97+ Files .writeString (longString , """
98+ class LongString {
99+ }
100+ """ );
101+ runCommandInRepo ("git" , "add" , "." );
102+ runCommandInRepo ("git" , "commit" , "-m" , "A class" );
103+
104+ Files .writeString (longString , """
105+ class LongString {
106+ String changed = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.";
107+ }
108+ """ );
109+
110+ FormatDiff .formatDiff (repo , formatterService );
111+
112+ assertThat (longString ).hasContent ("""
113+ class LongString {
114+ String changed =
115+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et"
116+ + " dolore magna.";
117+ }
118+ """ );
119+ }
120+
121+ private void initRepo () throws IOException , InterruptedException {
122+ runCommandInRepo ("git" , "init" );
123+ runCommandInRepo ("git" , "config" , "user.name" , "Test User" );
124+ runCommandInRepo ("git" , "config" , "user.email" , "test-user@palantir.com" );
125+ runCommandInRepo ("git" , "config" , "commit.gpgsign" , "false" );
126+ runCommandInRepo ("git" , "commit" , "--allow-empty" , "-m" , "Init" );
127+ }
128+
95129 private void runCommandInRepo (String ... args ) throws IOException , InterruptedException {
96130 Process process =
97131 new ProcessBuilder ().command (args ).directory (repo .toFile ()).start ();
@@ -107,6 +141,9 @@ private void runCommandInRepo(String... args) throws IOException, InterruptedExc
107141
108142 private static Stream <FormatterService > getFormatters () throws IOException {
109143 return Stream .of (
144+ // In this JVM, as formatDiff runs it without the native binary.
145+ FormatterServiceLoader .load (
146+ getClasspath ().stream ().map (Path ::toFile ).toList ()),
110147 new BootstrappingFormatterService (
111148 javaBinPath (), Runtime .version ().feature (), getClasspath ()),
112149 new NativeImageFormatterService (
0 commit comments