File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
main/java/org/wickedsource/diffparser/unified
test/java/org/wickedsource/diffparser/unified Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ public class ResizingParseWindow implements ParseWindow {
4040
4141 private List <Pattern > ignorePatterns = new ArrayList <>();
4242
43+ private boolean isEndOfStream = false ;
44+
4345 public ResizingParseWindow (InputStream in ) {
4446 Reader unbufferedReader = new InputStreamReader (in );
4547 this .reader = new BufferedReader (unbufferedReader );
@@ -105,6 +107,21 @@ private String getNextLine() throws IOException {
105107 while (matchesIgnorePattern (nextLine )) {
106108 nextLine = reader .readLine ();
107109 }
110+
111+ return getNextLineOrVirtualBlankLineAtEndOfStream (nextLine );
112+ }
113+
114+ /**
115+ * Guarantees that a virtual blank line is injected at the end of the input
116+ * stream to ensure the parser attempts to transition to the {@code END}
117+ * state, if necessary, when the end of stream is reached.
118+ */
119+ private String getNextLineOrVirtualBlankLineAtEndOfStream (String nextLine ) {
120+ if ((nextLine == null ) && !isEndOfStream ) {
121+ isEndOfStream = true ;
122+ return "" ;
123+ }
124+
108125 return nextLine ;
109126 }
110127
Original file line number Diff line number Diff line change @@ -77,4 +77,26 @@ public void testParse_WhenHunkRangeLineCountNotSpecified_ShouldSetHunkRangeLineC
7777 Assert .assertEquals (1 , hunk1 .getFromFileRange ().getLineCount ());
7878 Assert .assertEquals (1 , hunk1 .getToFileRange ().getLineCount ());
7979 }
80+
81+ @ Test
82+ public void testParse_WhenInputDoesNotEndWithEmptyLine_ShouldTransitionToEndState () throws Exception {
83+ // given
84+ DiffParser parser = new UnifiedDiffParser ();
85+ String in = ""
86+ + "--- from 2015-12-21 17:53:29.082877088 -0500\n "
87+ + "+++ to 2015-12-21 08:41:52.663714666 -0500\n "
88+ + "@@ -10,1 +10,1 @@\n "
89+ + "-from\n "
90+ + "+to\n " ;
91+
92+ // when
93+ List <Diff > diffs = parser .parse (in .getBytes ());
94+
95+ // then
96+ Assert .assertNotNull (diffs );
97+ Assert .assertEquals (1 , diffs .size ());
98+
99+ Diff diff1 = diffs .get (0 );
100+ Assert .assertEquals (1 , diff1 .getHunks ().size ());
101+ }
80102}
You can’t perform that action at this time.
0 commit comments