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.assertTrue;
17
18 import org.eclipse.jgit.lib.Constants;
19 import org.junit.Test;
20
21 public class RawTextIgnoreLeadingWhitespaceTest {
22 private final RawTextComparator cmp = RawTextComparator.WS_IGNORE_LEADING;
23
24 @Test
25 public void testEqualsWithoutWhitespace() {
26 final RawText a = new RawText(Constants
27 .encodeASCII("foo-a\nfoo-b\nfoo\n"));
28 final RawText b = new RawText(Constants
29 .encodeASCII("foo-b\nfoo-c\nf\n"));
30
31 assertEquals(3, a.size());
32 assertEquals(3, b.size());
33
34
35 assertFalse(cmp.equals(a, 0, b, 0));
36 assertFalse(cmp.equals(b, 0, a, 0));
37
38
39 assertTrue(cmp.equals(a, 1, b, 0));
40 assertTrue(cmp.equals(b, 0, a, 1));
41
42
43 assertFalse(cmp.equals(a, 2, b, 2));
44 assertFalse(cmp.equals(b, 2, a, 2));
45 }
46
47 @Test
48 public void testEqualsWithWhitespace() {
49 final RawText a = new RawText(Constants
50 .encodeASCII("foo-a\n \n a b c\n a\nb \n"));
51 final RawText b = new RawText(Constants
52 .encodeASCII("foo-a b\n\nab c\na\nb\n"));
53
54
55 assertFalse(cmp.equals(a, 0, b, 0));
56 assertFalse(cmp.equals(b, 0, a, 0));
57
58
59 assertTrue(cmp.equals(a, 1, b, 1));
60 assertTrue(cmp.equals(b, 1, a, 1));
61
62
63 assertFalse(cmp.equals(a, 2, b, 2));
64 assertFalse(cmp.equals(b, 2, a, 2));
65
66
67 assertTrue(cmp.equals(a, 3, b, 3));
68 assertTrue(cmp.equals(b, 3, a, 3));
69
70
71 assertFalse(cmp.equals(a, 4, b, 4));
72 assertFalse(cmp.equals(b, 4, a, 4));
73 }
74 }