Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit 85ec68e

Browse files
unit tests missed
git-svn-id: http://java-diff-utils.googlecode.com/svn/trunk@49 d8d7d024-a22d-11de-b755-fd640f38fa9d
1 parent 356f234 commit 85ec68e

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
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)