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