Add tests for RawTextComparator.WS_IGNORE_CHANGE.hash()
Change-Id: I1ed4df789094e09c39b3c2054fe5b9bd0c1a8f9b Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
This commit is contained in:
parent
ae2e12d584
commit
55371c5f06
|
@ -13,6 +13,7 @@
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
|
@ -103,4 +104,47 @@ public void testEqualsWithTabs() {
|
|||
assertTrue(cmp.equals(a, 4, b, 4));
|
||||
assertTrue(cmp.equals(b, 4, a, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
RawText a = new RawText(Constants
|
||||
.encodeASCII("a b c\n\nab c d \n\ta bc d\nxyz\na b c"));
|
||||
RawText b = new RawText(Constants.encodeASCII(
|
||||
"a b c\na b c\nab c d\na bc d\n \t a bc d\na b c\n"));
|
||||
|
||||
// Same line gives equal hash
|
||||
assertEquals(cmp.hash(a, 0), cmp.hash(a, 0));
|
||||
|
||||
// Empty lines produce the same hash
|
||||
assertEquals(cmp.hash(a, 1), cmp.hash(a, 1));
|
||||
|
||||
// Equal lines from different RawTexts get the same hash (RawText
|
||||
// instance is not part of the hash)
|
||||
assertEquals(cmp.hash(a, 0), cmp.hash(b, 0));
|
||||
|
||||
// A blank produces the same hash as a TAB
|
||||
assertEquals(cmp.hash(new RawText(Constants.encodeASCII(" ")), 0),
|
||||
cmp.hash(new RawText(Constants.encodeASCII("\t")), 0));
|
||||
|
||||
// Lines with only differing whitespace produce same hash
|
||||
assertEquals(cmp.hash(a, 0), cmp.hash(b, 1));
|
||||
|
||||
// Lines with different trailing whitespace produce the same hash
|
||||
assertEquals(cmp.hash(a, 2), cmp.hash(b, 2));
|
||||
|
||||
// A line with leading whitespace produces a hash different from the
|
||||
// same line without leading whitespace
|
||||
assertNotEquals(cmp.hash(a, 3), cmp.hash(b, 3));
|
||||
|
||||
// Lines with different leading whitespace produce equal hashes
|
||||
assertEquals(cmp.hash(a, 3), cmp.hash(b, 4));
|
||||
|
||||
// While different lines _should_ produce different hashes, that may not
|
||||
// always be the case. But for these two lines, it is.
|
||||
assertNotEquals(cmp.hash(a, 4), cmp.hash(b, 4));
|
||||
|
||||
// A line without trailing \n produces the same hash as one without
|
||||
assertEquals(cmp.hash(a, 5), cmp.hash(b, 5));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue