aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChangeTest.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChangeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChangeTest.java
index 73b2a72ace..c2b8641ebe 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChangeTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextIgnoreWhitespaceChangeTest.java
@@ -13,6 +13,7 @@ package org.eclipse.jgit.diff;
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 class RawTextIgnoreWhitespaceChangeTest {
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));
+
+ }
}