1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.diff; |
21 |
|
|
22 |
|
import com.xpn.xwiki.XWikiException; |
23 |
|
|
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import org.suigeneris.jrcs.diff.delta.Chunk; |
27 |
|
import org.suigeneris.jrcs.diff.delta.Delta; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (110) |
Complexity: 14 |
Complexity Density: 0.15 |
|
33 |
|
public class DiffTest extends org.jmock.cglib.MockObjectTestCase |
34 |
|
{ |
35 |
|
private DiffPlugin plugin; |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
37 |
13 |
@Override... |
38 |
|
protected void setUp() |
39 |
|
{ |
40 |
13 |
this.plugin = new DiffPlugin("diff", DiffPlugin.class.getName(), null); |
41 |
|
} |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
43 |
1 |
public void testSimpleLineDiff() throws XWikiException... |
44 |
|
{ |
45 |
1 |
String text1 = "A"; |
46 |
1 |
String text2 = "A B"; |
47 |
1 |
List diffs = this.plugin.getDifferencesAsList(text1, text2); |
48 |
1 |
assertEquals("There should be one difference", 1, diffs.size()); |
49 |
1 |
Delta delta = (Delta) diffs.get(0); |
50 |
1 |
Chunk orig = delta.getOriginal(); |
51 |
1 |
Chunk revised = delta.getRevised(); |
52 |
1 |
assertEquals("Original should be", "A", orig.toString()); |
53 |
1 |
assertEquals("Revised should be", "A B", revised.toString()); |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
56 |
1 |
public void testSimpleLineDiff2() throws XWikiException... |
57 |
|
{ |
58 |
1 |
String text1 = "A\nB\nC"; |
59 |
1 |
String text2 = "A\nB B\nC"; |
60 |
1 |
List diffs = this.plugin.getDifferencesAsList(text1, text2); |
61 |
1 |
assertEquals("There should be one difference", 1, diffs.size()); |
62 |
1 |
Delta delta = (Delta) diffs.get(0); |
63 |
1 |
Chunk orig = delta.getOriginal(); |
64 |
1 |
Chunk revised = delta.getRevised(); |
65 |
1 |
assertEquals("Original should be", "B", orig.toString()); |
66 |
1 |
assertEquals("Revised should be", "B B", revised.toString()); |
67 |
|
} |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
69 |
1 |
public void testSimpleWordDiff() throws XWikiException... |
70 |
|
{ |
71 |
1 |
String text1 = "I love Paris"; |
72 |
1 |
String text2 = "I live in Paris"; |
73 |
1 |
List diffs = this.plugin.getWordDifferencesAsList(text1, text2); |
74 |
1 |
assertEquals("There should be two differences", 1, diffs.size()); |
75 |
1 |
Delta delta1 = (Delta) diffs.get(0); |
76 |
1 |
Chunk orig1 = delta1.getOriginal(); |
77 |
1 |
Chunk revised1 = delta1.getRevised(); |
78 |
1 |
Delta delta2 = (Delta) diffs.get(0); |
79 |
1 |
Chunk orig2 = delta2.getOriginal(); |
80 |
1 |
Chunk revised2 = delta2.getRevised(); |
81 |
1 |
assertEquals("Original 1 should be", "love", orig1.toString()); |
82 |
1 |
assertEquals("Revised 1 should be", "livein", revised1.toString()); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
85 |
1 |
public void testSimpleWordDiff2() throws XWikiException... |
86 |
|
{ |
87 |
1 |
String text1 = "I love Paris and London"; |
88 |
1 |
String text2 = "I live in Paris and London"; |
89 |
1 |
List diffs = this.plugin.getWordDifferencesAsList(text1, text2); |
90 |
1 |
assertEquals("There should be two differences", 1, diffs.size()); |
91 |
1 |
Delta delta1 = (Delta) diffs.get(0); |
92 |
1 |
Chunk orig1 = delta1.getOriginal(); |
93 |
1 |
Chunk revised1 = delta1.getRevised(); |
94 |
|
|
95 |
1 |
assertEquals("Original 1 should be", "love", orig1.toString()); |
96 |
1 |
assertEquals("Revised 1 should be", "livein", revised1.toString()); |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
99 |
1 |
public void testSimpleWordDiff3() throws XWikiException... |
100 |
|
{ |
101 |
1 |
String text1 = "I love Paris and London"; |
102 |
1 |
String text2 = "I love London and Paris"; |
103 |
1 |
List diffs = this.plugin.getWordDifferencesAsList(text1, text2); |
104 |
1 |
assertEquals("There should be two differences", 2, diffs.size()); |
105 |
1 |
Delta delta1 = (Delta) diffs.get(0); |
106 |
1 |
Chunk orig1 = delta1.getOriginal(); |
107 |
1 |
Chunk revised1 = delta1.getRevised(); |
108 |
1 |
Delta delta2 = (Delta) diffs.get(1); |
109 |
1 |
Chunk orig2 = delta2.getOriginal(); |
110 |
1 |
Chunk revised2 = delta2.getRevised(); |
111 |
|
|
112 |
1 |
assertEquals("Original 1 should be", "Parisand", orig1.toString()); |
113 |
1 |
assertEquals("Revised 1 should be", "", revised1.toString()); |
114 |
1 |
assertEquals("Original 2 should be", "", orig2.toString()); |
115 |
1 |
assertEquals("Revised 2 should be", "andParis", revised2.toString()); |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
118 |
1 |
public void testSimpleWordDiff4() throws XWikiException... |
119 |
|
{ |
120 |
1 |
String text1 = "I love Paris and I like London"; |
121 |
1 |
String text2 = "I love London and I like Paris"; |
122 |
1 |
List diffs = this.plugin.getWordDifferencesAsList(text1, text2); |
123 |
1 |
assertEquals("There should be two differences", 2, diffs.size()); |
124 |
1 |
Delta delta1 = (Delta) diffs.get(0); |
125 |
1 |
Chunk orig1 = delta1.getOriginal(); |
126 |
1 |
Chunk revised1 = delta1.getRevised(); |
127 |
1 |
Delta delta2 = (Delta) diffs.get(1); |
128 |
1 |
Chunk orig2 = delta2.getOriginal(); |
129 |
1 |
Chunk revised2 = delta2.getRevised(); |
130 |
|
|
131 |
1 |
assertEquals("Original 1 should be", "Paris", orig1.toString()); |
132 |
1 |
assertEquals("Revised 1 should be", "London", revised1.toString()); |
133 |
1 |
assertEquals("Original 2 should be", "London", orig2.toString()); |
134 |
1 |
assertEquals("Revised 2 should be", "Paris", revised2.toString()); |
135 |
|
} |
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
137 |
1 |
public void testSimpleWordDiffAsHTML() throws XWikiException... |
138 |
|
{ |
139 |
1 |
String text1 = "A"; |
140 |
1 |
String text2 = "A B"; |
141 |
1 |
String html = this.plugin.getWordDifferencesAsHTML(text1, text2); |
142 |
1 |
assertEquals( |
143 |
|
"Diff is incorrect", |
144 |
|
"<div class=\"diffmodifiedline\"><span class=\"diffremoveword\">A</span><span class=\"diffaddword\">A B</span></div>", |
145 |
|
html); |
146 |
|
} |
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
148 |
1 |
public void testSimpleWordDiffAsHTML2() throws XWikiException... |
149 |
|
{ |
150 |
1 |
String text1 = "A C"; |
151 |
1 |
String text2 = "A B"; |
152 |
1 |
String html = this.plugin.getWordDifferencesAsHTML(text1, text2); |
153 |
1 |
assertEquals( |
154 |
|
"Diff is incorrect", |
155 |
|
"<div class=\"diffmodifiedline\">A <span class=\"diffremoveword\">C</span><span class=\"diffaddword\">B</span></div>", |
156 |
|
html); |
157 |
|
} |
158 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
159 |
1 |
public void testSimpleWordDiffAsHTML3() throws XWikiException... |
160 |
|
{ |
161 |
1 |
String text1 = "A B C D E F"; |
162 |
1 |
String text2 = "A C B D E G"; |
163 |
1 |
String html = this.plugin.getWordDifferencesAsHTML(text1, text2); |
164 |
1 |
assertEquals( |
165 |
|
"Diff is incorrect", |
166 |
|
"<div class=\"diffmodifiedline\">A <span class=\"diffremoveword\">B</span> C <span class=\"diffaddword\">B</span> D E <span class=\"diffremoveword\">F</span><span class=\"diffaddword\">G</span></div>", |
167 |
|
html); |
168 |
|
} |
169 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
170 |
1 |
public void testSimpleLineDiffAsHTML2() throws XWikiException... |
171 |
|
{ |
172 |
1 |
String text1 = "A C"; |
173 |
1 |
String text2 = "A B"; |
174 |
1 |
String html = this.plugin.getDifferencesAsHTML(text1, text2); |
175 |
1 |
assertEquals( |
176 |
|
"Diff is incorrect", |
177 |
|
"<div class=\"diff\"><div class=\"diffmodifiedline\">A <span class=\"diffremoveword\">C</span><span class=\"diffaddword\">B</span></div></div>", |
178 |
|
html); |
179 |
|
} |
180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
181 |
1 |
public void testSimpleLineDiffAsHTML3() throws XWikiException... |
182 |
|
{ |
183 |
1 |
String text1 = "A B C D E F"; |
184 |
1 |
String text2 = "A C B D E G"; |
185 |
1 |
String html = this.plugin.getDifferencesAsHTML(text1, text2); |
186 |
1 |
assertEquals( |
187 |
|
"Diff is incorrect", |
188 |
|
"<div class=\"diff\"><div class=\"diffmodifiedline\">A <span class=\"diffremoveword\">B</span> C <span class=\"diffaddword\">B</span> D E <span class=\"diffremoveword\">F</span><span class=\"diffaddword\">G</span></div></div>", |
189 |
|
html); |
190 |
|
} |
191 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
192 |
1 |
public void testSimpleLineDiffAsHTML4() throws XWikiException... |
193 |
|
{ |
194 |
1 |
String text1 = "A B C\nD E F\nG H I\nJ K L\n"; |
195 |
1 |
String text2 = "A B C\nG H I\nD E F\nJ K L\n"; |
196 |
1 |
String html = this.plugin.getDifferencesAsHTML(text1, text2); |
197 |
1 |
assertEquals( |
198 |
|
"Diff is incorrect", |
199 |
|
"<div class=\"diff\"><div class=\"diffunmodifiedline\">A B C</div><div class=\"diffmodifiedline\"><span class=\"diffremoveword\">D E F</span></div><div class=\"diffunmodifiedline\">G H I</div><div class=\"diffmodifiedline\"><span class=\"diffaddword\">D E F</span></div><div class=\"diffunmodifiedline\">J K L</div></div>", |
200 |
|
html); |
201 |
|
} |
202 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
203 |
1 |
public void testMultiLineDiffAsHTML() throws XWikiException... |
204 |
|
{ |
205 |
1 |
String text1 = "A\n"; |
206 |
1 |
String text2 = "AA\nAB\n"; |
207 |
1 |
String html = this.plugin.getDifferencesAsHTML(text1, text2); |
208 |
1 |
assertEquals( |
209 |
|
"Diff is incorrect", |
210 |
|
"<div class=\"diff\"><div class=\"diffmodifiedline\"><span class=\"diffremoveword\">A</span><span class=\"diffaddword\">AA</span></div><div class=\"diffmodifiedline\"><span class=\"diffaddword\">AB</span></div></div>", |
211 |
|
html); |
212 |
|
} |
213 |
|
} |