Skip to content

Commit dcc29ee

Browse files
committed
fixes #84 Seems to be solved by a previous issue. A test case was included from issue 84.
1 parent 8006986 commit dcc29ee

File tree

3 files changed

+138
-7
lines changed

3 files changed

+138
-7
lines changed

java-diff-utils/src/main/java/com/github/difflib/unifieddiff/UnifiedDiffReader.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ private UnifiedDiff parse() throws IOException, UnifiedDiffParserException {
118118
if (READER.ready()) {
119119
String tailTxt = "";
120120
while (READER.ready()) {
121-
tailTxt += READER.readLine() + "\n";
121+
if (tailTxt.length() > 0) {
122+
tailTxt += "\n";
123+
}
124+
tailTxt += READER.readLine();
122125
}
123126
data.setTailTxt(tailTxt);
124127
}

java-diff-utils/src/test/java/com/github/difflib/unifieddiff/UnifiedDiffReaderTest.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void testSimpleParse() throws IOException {
4343
assertThat(file1.getFromFile()).isEqualTo("src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt");
4444
assertThat(file1.getPatch().getDeltas().size()).isEqualTo(3);
4545

46-
assertThat(diff.getTail()).isEqualTo("2.17.1.windows.2\n\n");
46+
assertThat(diff.getTail()).isEqualTo("2.17.1.windows.2\n");
4747
}
4848

4949
@Test
@@ -101,7 +101,7 @@ public void testSimpleParse2() throws IOException {
101101
assertThat(first.getSource().size()).isGreaterThan(0);
102102
assertThat(first.getTarget().size()).isGreaterThan(0);
103103

104-
assertThat(diff.getTail()).isEqualTo("2.17.1.windows.2\n\n");
104+
assertThat(diff.getTail()).isEqualTo("2.17.1.windows.2\n");
105105
}
106106

107107
@Test
@@ -142,7 +142,7 @@ public void testParseIssue33() throws IOException {
142142
assertThat(diff.getTail()).isNull();
143143
assertThat(diff.getHeader()).isNull();
144144
}
145-
145+
146146
@Test
147147
public void testParseIssue51() throws IOException {
148148
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
@@ -158,7 +158,7 @@ public void testParseIssue51() throws IOException {
158158

159159
assertThat(diff.getTail()).isNull();
160160
}
161-
161+
162162
@Test
163163
public void testParseIssue79() throws IOException {
164164
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
@@ -173,7 +173,26 @@ public void testParseIssue79() throws IOException {
173173
assertThat(diff.getTail()).isNull();
174174
assertThat(diff.getHeader()).isNull();
175175
}
176-
176+
177+
@Test
178+
public void testParseIssue84() throws IOException {
179+
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
180+
UnifiedDiffReaderTest.class.getResourceAsStream("problem_diff_issue84.diff"));
181+
182+
assertThat(diff.getFiles().size()).isEqualTo(2);
183+
184+
UnifiedDiffFile file1 = diff.getFiles().get(0);
185+
assertThat(file1.getFromFile()).isEqualTo("config/ant-phase-verify.xml");
186+
assertThat(file1.getPatch().getDeltas().size()).isEqualTo(1);
187+
188+
UnifiedDiffFile file2 = diff.getFiles().get(1);
189+
assertThat(file2.getFromFile()).isEqualTo("/dev/null");
190+
assertThat(file2.getPatch().getDeltas().size()).isEqualTo(1);
191+
192+
assertThat(diff.getTail()).isEqualTo("2.7.4");
193+
assertThat(diff.getHeader()).startsWith("From b53e612a2ab5ff15d14860e252f84c0f343fe93a Mon Sep 17 00:00:00 2001");
194+
}
195+
177196
@Test
178197
public void testParseIssue85() throws IOException {
179198
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
@@ -192,7 +211,7 @@ public void testParseIssue85() throws IOException {
192211

193212
assertNull(diff.getTail());
194213
}
195-
214+
196215
@Test
197216
public void testTimeStampRegexp() {
198217
assertThat("2019-04-18 13:49:39.516149751 +0200").matches(UnifiedDiffReader.TIMESTAMP_REGEXP);
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
From b53e612a2ab5ff15d14860e252f84c0f343fe93a Mon Sep 17 00:00:00 2001
2+
From: nmancus1 <nmancus1
3+
Date: Thu, 4 Jun 2020 11:46:34 -0400
4+
Subject: [PATCH] minor: Add input file for Java14 instanceof with pattern
5+
matching (#7290)
6+
7+
---
8+
config/ant-phase-verify.xml | 2 +
9+
.../InputJava14InstanceofWithPatternMatching.java | 76 ++++++++++++++++++++++
10+
2 files changed, 78 insertions(+)
11+
create mode 100644 src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java14/InputJava14InstanceofWithPatternMatching.java
12+
13+
diff --git a/config/ant-phase-verify.xml b/config/ant-phase-verify.xml
14+
index d27ffef..e0285ce 100644
15+
--- a/config/ant-phase-verify.xml
16+
+++ b/config/ant-phase-verify.xml
17+
@@ -148,6 +148,8 @@
18+
<exclude name="**/InputMainFrameModelIncorrectClass.java"/>
19+
<exclude name="**/InputBeforeExecutionExclusionFileFilterIncorrectClass.java"/>
20+
<exclude name="**/InputJavaParser.java"/>
21+
+ <!-- until https://github.com/checkstyle/checkstyle/issues/7290 -->
22+
+ <exclude name="**/InputJava14InstanceofWithPatternMatching.java"/>
23+
<!-- Cannot parse until Java 14 support -->
24+
<exclude name="**/InputJava14Records.java"/>
25+
</fileset>
26+
diff --git a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java14/InputJava14InstanceofWithPatternMatching.java b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java14/InputJava14InstanceofWithPatternMatching.java
27+
new file mode 100644
28+
index 0000000..8fa3eba
29+
--- /dev/null
30+
+++ b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java14/InputJava14InstanceofWithPatternMatching.java
31+
@@ -0,0 +1,76 @@
32+
+//non-compiled with javac: Compilable with Java14
33+
+package com.puppycrawl.tools.checkstyle.grammar.java14;
34+
+
35+
+import java.util.Arrays;
36+
+import java.util.Locale;
37+
+ ...... I removed it
38+
+ ...... I removed it
39+
+ ...... I removed it
40+
+ ...... I removed it
41+
+ ...... I removed it
42+
+ ...... I removed it
43+
+ ...... I removed it
44+
+ ...... I removed it
45+
+ ...... I removed it
46+
+ ...... I removed it
47+
+ ...... I removed it
48+
+ ...... I removed it
49+
+ ...... I removed it
50+
+ ...... I removed it
51+
+ ...... I removed it
52+
+ ...... I removed it
53+
+ ...... I removed it
54+
+ ...... I removed it
55+
+ ...... I removed it
56+
+ ...... I removed it
57+
+ ...... I removed it
58+
+ ...... I removed it
59+
+ ...... I removed it
60+
+ ...... I removed it
61+
+ ...... I removed it
62+
+ ...... I removed it
63+
+ ...... I removed it
64+
+ ...... I removed it
65+
+ ...... I removed it
66+
+ ...... I removed it
67+
+ ...... I removed it
68+
+ ...... I removed it
69+
+ ...... I removed it
70+
+ ...... I removed it
71+
+ ...... I removed it
72+
+ ...... I removed it
73+
+ ...... I removed it
74+
+ ...... I removed it
75+
+ ...... I removed it
76+
+ ...... I removed it
77+
+ ...... I removed it
78+
+ ...... I removed it
79+
+ ...... I removed it
80+
+ ...... I removed it
81+
+ ...... I removed it
82+
+ ...... I removed it
83+
+ ...... I removed it
84+
+ ...... I removed it
85+
+ ...... I removed it
86+
+ ...... I removed it
87+
+ ...... I removed it
88+
+ ...... I removed it
89+
+ ...... I removed it
90+
+ ...... I removed it
91+
+ ...... I removed it
92+
+ ...... I removed it
93+
+ ...... I removed it
94+
+ ...... I removed it
95+
+ ...... I removed it
96+
+ ...... I removed it
97+
+ ...... I removed it
98+
+ ...... I removed it
99+
+ ...... I removed it
100+
+ ...... I removed it
101+
+ ...... I removed it
102+
+ ...... I removed it
103+
+ ...... I removed it
104+
+ ...... I removed it
105+
+ }
106+
+ }
107+
+}
108+
--
109+
2.7.4

0 commit comments

Comments
 (0)