1
2
3
4
5
6
7
8
9
10
11
12 package org.eclipse.jgit.diff;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertFalse;
16 import static org.junit.Assert.assertNotEquals;
17 import static org.junit.Assert.assertTrue;
18
19 import org.eclipse.jgit.lib.Constants;
20 import org.junit.Test;
21
22 public class RawTextIgnoreWhitespaceChangeTest {
23 private final RawTextComparator cmp = RawTextComparator.WS_IGNORE_CHANGE;
24
25 @Test
26 public void testEqualsWithoutWhitespace() {
27 final RawText a = new RawText(Constants
28 .encodeASCII("foo-a\nfoo-b\nfoo\n"));
29 final RawText b = new RawText(Constants
30 .encodeASCII("foo-b\nfoo-c\nf\n"));
31
32 assertEquals(3, a.size());
33 assertEquals(3, b.size());
34
35
36 assertFalse(cmp.equals(a, 0, b, 0));
37 assertFalse(cmp.equals(b, 0, a, 0));
38
39
40 assertTrue(cmp.equals(a, 1, b, 0));
41 assertTrue(cmp.equals(b, 0, a, 1));
42
43
44 assertFalse(cmp.equals(a, 2, b, 2));
45 assertFalse(cmp.equals(b, 2, a, 2));
46 }
47
48 @Test
49 public void testEqualsWithWhitespace() {
50 final RawText a = new RawText(Constants
51 .encodeASCII("foo-a\n \n a b c\na \n foo\na b c\n"));
52 final RawText b = new RawText(Constants
53 .encodeASCII("foo-a b\n\nab c\na\nfoo\na b c \n"));
54
55
56 assertFalse(cmp.equals(a, 0, b, 0));
57 assertFalse(cmp.equals(b, 0, a, 0));
58
59
60 assertTrue(cmp.equals(a, 1, b, 1));
61 assertTrue(cmp.equals(b, 1, a, 1));
62
63
64 assertFalse(cmp.equals(a, 2, b, 2));
65 assertFalse(cmp.equals(b, 2, a, 2));
66
67
68 assertTrue(cmp.equals(a, 3, b, 3));
69 assertTrue(cmp.equals(b, 3, a, 3));
70
71
72 assertFalse(cmp.equals(a, 4, b, 4));
73 assertFalse(cmp.equals(b, 4, a, 4));
74
75
76 assertTrue(cmp.equals(a, 5, b, 5));
77 assertTrue(cmp.equals(b, 5, a, 5));
78 }
79
80 @Test
81 public void testEqualsWithTabs() {
82 RawText a = new RawText(
83 Constants.encodeASCII("a\tb\t \na\tb\t c \n foo\na b\na b"));
84 RawText b = new RawText(
85 Constants.encodeASCII("a b \na b c\n\tfoo\nab\na \tb"));
86
87
88 assertTrue(cmp.equals(a, 0, b, 0));
89 assertTrue(cmp.equals(b, 0, a, 0));
90
91
92 assertTrue(cmp.equals(a, 1, b, 1));
93 assertTrue(cmp.equals(b, 1, a, 1));
94
95
96 assertTrue(cmp.equals(a, 2, b, 2));
97 assertTrue(cmp.equals(b, 2, a, 2));
98
99
100 assertFalse(cmp.equals(a, 3, b, 3));
101 assertFalse(cmp.equals(b, 3, a, 3));
102
103
104 assertTrue(cmp.equals(a, 4, b, 4));
105 assertTrue(cmp.equals(b, 4, a, 4));
106 }
107
108 @Test
109 public void testHashCode() {
110 RawText a = new RawText(Constants
111 .encodeASCII("a b c\n\nab c d \n\ta bc d\nxyz\na b c"));
112 RawText b = new RawText(Constants.encodeASCII(
113 "a b c\na b c\nab c d\na bc d\n \t a bc d\na b c\n"));
114
115
116 assertEquals(cmp.hash(a, 0), cmp.hash(a, 0));
117
118
119 assertEquals(cmp.hash(a, 1), cmp.hash(a, 1));
120
121
122
123 assertEquals(cmp.hash(a, 0), cmp.hash(b, 0));
124
125
126 assertEquals(cmp.hash(new RawText(Constants.encodeASCII(" ")), 0),
127 cmp.hash(new RawText(Constants.encodeASCII("\t")), 0));
128
129
130 assertEquals(cmp.hash(a, 0), cmp.hash(b, 1));
131
132
133 assertEquals(cmp.hash(a, 2), cmp.hash(b, 2));
134
135
136
137 assertNotEquals(cmp.hash(a, 3), cmp.hash(b, 3));
138
139
140 assertEquals(cmp.hash(a, 3), cmp.hash(b, 4));
141
142
143
144 assertNotEquals(cmp.hash(a, 4), cmp.hash(b, 4));
145
146
147 assertEquals(cmp.hash(a, 5), cmp.hash(b, 5));
148
149 }
150 }