Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 211b517

Browse filesBrowse files
committed
unit tests missed
1 parent 58086a9 commit 211b517
Copy full SHA for 211b517

File tree

1 file changed

+68
-0
lines changed
Filter options

1 file changed

+68
-0
lines changed
+68Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package diffutils;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
import difflib.DiffRow;
7+
import difflib.DiffRowGenerator;
8+
9+
import junit.framework.TestCase;
10+
11+
public class DiffRowGeneratorTest extends TestCase {
12+
13+
public void testGenerator_Default() {
14+
String first = "anything \n \nother";
15+
String second ="anything\n\nother";
16+
17+
DiffRowGenerator generator = new DiffRowGenerator.Builder()
18+
.columnWidth(Integer.MAX_VALUE) // do not wrap
19+
.build();
20+
List<DiffRow> rows = generator.generateDiffRows(split(first), split(second));
21+
print(rows);
22+
23+
assertEquals(3, rows.size());
24+
}
25+
26+
public void testGenerator_InlineDiff() {
27+
String first = "anything \n \nother";
28+
String second ="anything\n\nother";
29+
30+
DiffRowGenerator generator = new DiffRowGenerator.Builder()
31+
.showInlineDiffs(true)
32+
.columnWidth(Integer.MAX_VALUE) // do not wrap
33+
.build();
34+
List<DiffRow> rows = generator.generateDiffRows(split(first), split(second));
35+
print(rows);
36+
37+
assertEquals(3, rows.size());
38+
assertTrue(rows.get(0).getOldLine().indexOf("<span") > 0);
39+
}
40+
41+
public void testGenerator_IgnoreWhitespaces() {
42+
String first = "anything \n \nother\nmore lines";
43+
String second ="anything\n\nother\nsome more lines";
44+
45+
DiffRowGenerator generator = new DiffRowGenerator.Builder()
46+
.ignoreWhiteSpaces(true)
47+
.columnWidth(Integer.MAX_VALUE) // do not wrap
48+
.build();
49+
List<DiffRow> rows = generator.generateDiffRows(split(first), split(second));
50+
print(rows);
51+
52+
assertEquals(4, rows.size());
53+
assertEquals(rows.get(0).getTag(), DiffRow.Tag.EQUAL);
54+
assertEquals(rows.get(1).getTag(), DiffRow.Tag.EQUAL);
55+
assertEquals(rows.get(2).getTag(), DiffRow.Tag.EQUAL);
56+
assertEquals(rows.get(3).getTag(), DiffRow.Tag.CHANGE);
57+
}
58+
59+
private List<String> split(String content) {
60+
return Arrays.asList(content.split("\n"));
61+
}
62+
63+
private void print(List<DiffRow> diffRows) {
64+
for (DiffRow row: diffRows) {
65+
System.out.println(row);
66+
}
67+
}
68+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.