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 package org.eclipse.jgit.diff;
46
47 import static org.junit.Assert.assertEquals;
48 import static org.junit.Assert.assertFalse;
49 import static org.junit.Assert.assertSame;
50 import static org.junit.Assert.assertTrue;
51
52 import org.junit.Test;
53
54 public class EditTest {
55 @Test
56 public void testCreate() {
57 final Edit e = new Edit(1, 2, 3, 4);
58 assertEquals(1, e.getBeginA());
59 assertEquals(2, e.getEndA());
60 assertEquals(3, e.getBeginB());
61 assertEquals(4, e.getEndB());
62 }
63
64 @Test
65 public void testCreateEmpty() {
66 final Edit e = new Edit(1, 3);
67 assertEquals(1, e.getBeginA());
68 assertEquals(1, e.getEndA());
69 assertEquals(3, e.getBeginB());
70 assertEquals(3, e.getEndB());
71 assertTrue("is empty", e.isEmpty());
72 assertSame(Edit.Type.EMPTY, e.getType());
73 }
74
75 @Test
76 public void testSwap() {
77 final Edit e = new Edit(1, 2, 3, 4);
78 e.swap();
79 assertEquals(3, e.getBeginA());
80 assertEquals(4, e.getEndA());
81 assertEquals(1, e.getBeginB());
82 assertEquals(2, e.getEndB());
83 }
84
85 @Test
86 public void testType_Insert() {
87 final Edit e = new Edit(1, 1, 1, 2);
88 assertSame(Edit.Type.INSERT, e.getType());
89 assertFalse("not empty", e.isEmpty());
90 assertEquals(0, e.getLengthA());
91 assertEquals(1, e.getLengthB());
92 }
93
94 @Test
95 public void testType_Delete() {
96 final Edit e = new Edit(1, 2, 1, 1);
97 assertSame(Edit.Type.DELETE, e.getType());
98 assertFalse("not empty", e.isEmpty());
99 assertEquals(1, e.getLengthA());
100 assertEquals(0, e.getLengthB());
101 }
102
103 @Test
104 public void testType_Replace() {
105 final Edit e = new Edit(1, 2, 1, 4);
106 assertSame(Edit.Type.REPLACE, e.getType());
107 assertFalse("not empty", e.isEmpty());
108 assertEquals(1, e.getLengthA());
109 assertEquals(3, e.getLengthB());
110 }
111
112 @Test
113 public void testType_Empty() {
114 final Edit e = new Edit(1, 1, 2, 2);
115 assertSame(Edit.Type.EMPTY, e.getType());
116 assertSame(Edit.Type.EMPTY, new Edit(1, 2).getType());
117 assertTrue("is empty", e.isEmpty());
118 assertEquals(0, e.getLengthA());
119 assertEquals(0, e.getLengthB());
120 }
121
122 @Test
123 public void testToString() {
124 final Edit e = new Edit(1, 2, 1, 4);
125 assertEquals("REPLACE(1-2,1-4)", e.toString());
126 }
127
128 @SuppressWarnings("unlikely-arg-type")
129 @Test
130 public void testEquals1() {
131 final Edit e1 = new Edit(1, 2, 3, 4);
132 final Edit e2 = new Edit(1, 2, 3, 4);
133
134 assertEquals(e1, e1);
135 assertEquals(e2, e1);
136 assertEquals(e1, e2);
137 assertEquals(e1.hashCode(), e2.hashCode());
138 assertFalse(e1.equals(""));
139 }
140
141 @Test
142 public void testNotEquals1() {
143 assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(0, 2, 3, 4)));
144 }
145
146 @Test
147 public void testNotEquals2() {
148 assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(1, 0, 3, 4)));
149 }
150
151 @Test
152 public void testNotEquals3() {
153 assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(1, 2, 0, 4)));
154 }
155
156 @Test
157 public void testNotEquals4() {
158 assertFalse(new Edit(1, 2, 3, 4).equals(new Edit(1, 2, 3, 0)));
159 }
160
161 @Test
162 public void testExtendA() {
163 final Edit e = new Edit(1, 2, 1, 1);
164
165 e.extendA();
166 assertEquals(new Edit(1, 3, 1, 1), e);
167
168 e.extendA();
169 assertEquals(new Edit(1, 4, 1, 1), e);
170 }
171
172 @Test
173 public void testExtendB() {
174 final Edit e = new Edit(1, 2, 1, 1);
175
176 e.extendB();
177 assertEquals(new Edit(1, 2, 1, 2), e);
178
179 e.extendB();
180 assertEquals(new Edit(1, 2, 1, 3), e);
181 }
182
183 @Test
184 public void testBeforeAfterCuts() {
185 final Edit whole = new Edit(1, 8, 2, 9);
186 final Edit mid = new Edit(4, 5, 3, 6);
187
188 assertEquals(new Edit(1, 4, 2, 3), whole.before(mid));
189 assertEquals(new Edit(5, 8, 6, 9), whole.after(mid));
190 }
191 }